This document establishes comprehensive standards for dependency management in the WeWrite project to ensure consistency, maintainability, and reliability.
Use absolute imports (@/) for:
- Cross-directory imports (more than 2 levels up)
- Commonly used utilities and services
- UI components from other directories
- Firebase and database modules
// ✅ Good - Use absolute imports
import { Button } from '@/components/ui/button';
import { database } from '@/firebase/database';
import { formatDate } from '@/utils/dateUtils';
// ❌ Avoid - Deep relative imports
import { Button } from '../../../components/ui/button';
import { database } from '../../../firebase/database';Use relative imports for:
- Files in the same directory
- Direct parent/child relationships
- Closely related components
// ✅ Good - Use relative imports for same directory
import { UserBadge } from './UserBadge';
import { PageHeader } from '../PageHeader';
// ❌ Avoid - Absolute imports for same directory
import { UserBadge } from '@/components/pages/UserBadge';Organize imports in the following order with blank lines between groups:
// 1. External libraries
import React, { useState, useEffect } from 'react';
import { format } from 'date-fns';
import { ChevronLeft, Search } from 'lucide-react';
// 2. Internal absolute imports (@/)
import { Button } from '@/components/ui/button';
import { database } from '@/firebase/database';
import { useAuth } from '@/hooks/useAuth';
// 3. Relative imports
import { UserBadge } from './UserBadge';
import './styles.css';Current path mappings in tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./app/*"]
}
}
}Standard prefixes:
@/components/*- UI components and layouts@/utils/*- Utility functions and helpers@/hooks/*- Custom React hooks@/services/*- Business logic and API services@/firebase/*- Firebase configuration and database@/providers/*- React context providers@/types/*- TypeScript type definitions
app/
├── components/
│ ├── ui/ # Reusable UI components
│ │ ├── button.tsx
│ │ ├── input.tsx
│ │ └── modal.tsx
│ ├── layout/ # Layout components
│ │ ├── Header.tsx
│ │ ├── Sidebar.tsx
│ │ └── Footer.tsx
│ ├── features/ # Feature-specific components
│ │ ├── Dashboard.tsx
│ │ ├── TrendingPages.tsx
│ │ └── RecentActivity.tsx
│ ├── pages/ # Page-specific components
│ │ ├── PageHeader.tsx
│ │ ├── PageMetadata.tsx
│ │ └── SinglePageView.tsx
│ └── utils/ # Component utilities
│ ├── PillLink.tsx
│ └── Loader.tsx
├── hooks/ # Custom React hooks
├── services/ # Business logic services
├── utils/ # General utilities
├── firebase/ # Firebase configuration
├── providers/ # React context providers
└── types/ # TypeScript definitions
Components:
- Use PascalCase for component files:
UserProfile.tsx - Use kebab-case for utility files:
date-utils.ts - Use camelCase for hooks:
useAuth.ts
Exports:
- Use named exports for utilities and hooks
- Use default exports for React components
- Create index files for barrel exports when appropriate
// ✅ Good - Component with default export
export default function UserProfile() {
return <div>Profile</div>;
}
// ✅ Good - Utility with named exports
export const formatDate = (date: Date) => { /* */ };
export const parseDate = (str: string) => { /* */ };
// ✅ Good - Barrel export (index.ts)
export { formatDate, parseDate } from './date-utils';
export { validateEmail } from './validation-utils';Always use Bun for consistency:
# ✅ Install production dependencies
bun add package-name
# ✅ Install development dependencies
bun add --dev package-name
# ❌ Don't mix package managers
npm install package-name # Avoid
yarn add package-name # Avoid
pnpm add package-name # AvoidVersion Management:
- Pin exact versions for critical dependencies
- Use caret ranges (^) for most packages
- Use tilde ranges (~) for patch-level updates only
{
"dependencies": {
"react": "18.2.0", // Exact version for critical
"next": "^14.0.0", // Caret for minor updates
"lodash": "~4.17.21" // Tilde for patch only
}
}Production Dependencies:
- Core framework packages (React, Next.js)
- UI libraries and components
- Database and authentication
- Runtime utilities
Development Dependencies:
- Build tools and bundlers
- Testing frameworks
- Linting and formatting
- Type definitions
Avoid Installing:
- Packages with known security vulnerabilities
- Unmaintained packages (no updates > 2 years)
- Packages with excessive dependencies
- Duplicate functionality packages
Weekly Tasks:
- Run
bun run deps:auditto check health - Review and update outdated packages
- Remove unused dependencies
Monthly Tasks:
- Update major dependencies (with testing)
- Review security advisories
- Optimize bundle size
# Health monitoring
bun run deps:check # Comprehensive dependency analysis
bun run deps:validate # Validate all import statements
bun run deps:map # Generate dependency visualizations
bun run deps:dashboard # Create interactive dashboard
# Fixing and maintenance
bun run deps:fix # Automatically fix import paths
bun run deps:heal # Self-healing dependency system
bun run deps:heal:plan # Preview healing actions
# Testing and validation
bun run deps:test # Test dependency system
bun run deps:audit # Complete dependency audit
bun run deps:health # Full health check with dashboardHusky pre-commit hook automatically runs:
- Dependency validation (
bun run deps:validate) - ESLint checks (
bun run lint) - TypeScript compilation (
bunx tsc --noEmit)
GitHub Actions workflow runs on every push:
- Dependency health checks
- Import validation
- Security audits
- Bundle size analysis
Enhanced ESLint rules for import management:
{
"rules": {
"import/no-unresolved": "error",
"import/no-cycle": "error",
"import/no-unused-modules": "warn",
"import/order": ["warn", {
"groups": ["builtin", "external", "internal", "parent", "sibling"],
"newlines-between": "always"
}]
}
}Strict TypeScript settings to catch import issues:
{
"compilerOptions": {
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true
}
}VS Code settings for consistency:
{
"typescript.preferences.includePackageJsonAutoImports": "auto",
"typescript.suggest.autoImports": true,
"typescript.suggest.paths": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll.eslint": true
}
}1. Circular Dependencies
# Identify circular dependencies
bun run deps:check
# Common causes:
# - Mutual imports between components
# - Service layer circular references
# - Context provider loops
# Solutions:
# - Extract shared logic to separate modules
# - Use dependency injection patterns
# - Implement proper layered architecture2. Missing Dependencies
# Auto-install missing dependencies
bun run deps:heal
# Manual installation
bun add missing-package-name3. Broken Import Paths
# Auto-fix import paths
bun run deps:fix
# Manual fixes:
# - Update relative paths to absolute (@/)
# - Fix typos in import statements
# - Ensure file extensions are correct4. Bundle Size Issues
# Analyze bundle size
bun run analyze:bundle
# Remove unused dependencies
bun run deps:heal
# Use tree-shaking friendly imports
import { specific } from 'library'; // ✅ Good
import * as library from 'library'; // ❌ Avoid- Use absolute imports (@/) for cross-directory references
- Organize imports by external → internal → relative
- Follow consistent file naming conventions
- Run dependency health checks weekly
- Keep dependencies up to date and secure
- Use automated tools for import path management
- Implement proper error handling and validation
- Document any deviations from standards
These standards are enforced through:
- Pre-commit hooks (Husky)
- CI/CD pipeline checks (GitHub Actions)
- ESLint and TypeScript configuration
- Automated dependency monitoring
- Regular team code reviews
For questions or exceptions to these standards, please discuss with the development team and update this document accordingly.