Project Structures
Choose the architecture that best fits your project needs. SargenJS supports two main architectural patterns.
Layered Architecture
Traditional MVC (Model-View-Controller) pattern with clear separation of concerns across layers.
Structure:
Best for:
- • Traditional web applications
- • Teams familiar with MVC pattern
- • Projects with clear business logic separation
- • CRUD-heavy applications
Modular Architecture
Feature-based organization where each module contains all related functionality.
Structure:
Best for:
- • Microservices architecture
- • Large-scale applications
- • Team-based development
- • Feature-driven development
Detailed Comparison
| Aspect | Layered | Modular |
|---|---|---|
| Organization | By technical layer | By business feature |
| Scalability | Good for small-medium projects | Excellent for large projects |
| Team Collaboration | Layer-based teams | Feature-based teams |
| Code Reusability | Moderate | High |
| Learning Curve | Familiar MVC pattern | Requires understanding of modules |
| Maintenance | Easy for small projects | Better for complex projects |
File Organization Details
Layered Structure
src/routes/
Contains route definitions and URL mappings. Routes handle HTTP requests and delegate to controllers.
src/controllers/
Business logic handlers. Controllers process requests, call services, and return responses.
src/services/
Core business logic and data processing. Services contain reusable business operations.
src/models/
Data models and database schemas. Models define data structure and relationships.
Modular Structure
src/config/
Application configuration files. Database connections, environment settings, etc.
src/common/
Shared utilities, middleware, and common functionality used across modules.
src/modules/
Feature-based modules. Each module contains its own routes, controllers, services, and models.
Module Structure
Each module is self-contained with its own routes, controller, service, and model files.
Choosing the Right Structure
Choose Layered When:
- • Building a traditional web application
- • Team is familiar with MVC pattern
- • Project size is small to medium
- • Clear separation of concerns is needed
- • Rapid prototyping is required
Choose Modular When:
- • Building a large-scale application
- • Multiple teams working on different features
- • Planning to extract modules as microservices
- • High code reusability is important
- • Feature-driven development approach
Migration Between Structures
While SargenJS doesn't provide automatic migration between structures, you can manually reorganize your code: