Skip to content

Code Organization Best Practices

Group files related to a specific business capability together. This provides better context for the AI and improves code cohesion.

txt
src/
├── features/  # Or domains, modules, bounded contexts
│   ├── users/
│   │   ├── user.controller.js  # Handles HTTP requests
│   │   ├── user.service.js     # Business logic
│   │   ├── user.model.js       # Data model/schema
│   │   ├── user.routes.js      # API routes
│   │   ├── user.dto.ts         # Data Transfer Objects (if using TS)
│   │   └── user.test.js        # Feature tests
│   │
│   ├── products/
│   │   └── ... (similar files)
│   │
│   └── orders/
│       └── ... (similar files)

└── shared/  # Common utilities, middleware, base classes
    ├── middleware/
    ├── utils/
    └── config/
  • Avoid: Structuring primarily by technical layer (controllers/, services/, models/) as it scatters feature code.

Built with VitePress