How vungbt/next-chapter-api works
Main Components
• API Gateway/Entry Point: Represent the HTTP entry point, as requests enter via the endpoint defined in src/index.ts.
• Routers: Located in src/routers, they map incoming requests to the appropriate controllers.
• Controllers: In src/controllers, these process the incoming requests (for example, auth, authors, categories, contents, files, users).
• Middlewares: In src/middlewares, which sit between request entry and routing logic, handling functions such as authentication, base operations, and pagination.
• Service Layer: Found in src/services; this layer contains the core business logic and orchestrates data operations.
• Data/Database Layer:
• Models: Defined using Sequelize in src/sequelize/models.
• Migrations and Seeders: Located in src/sequelize/migrations and src/sequelize/seeders, which manage schema evolution and initial data.
• Configuration Layer: Under src/configs – including environment configurations, i18n (internationalization), validator configurations, and cloudinary settings.
• Utility Layer: Under src/utils which includes error handling utilities, JWT management, logger configurations (e.g., Morgan), and helper functions.
• Validation Layer: In src/validation; this validates incoming request payloads against expected rules.
• Constants/Language: Contains definitions and language JSON files that drive user-facing messages and errors.
Representing Relationships & Interactions
• Requests Flow: Illustrate how HTTP requests from clients reach the API Gateway (entry point) and are then routed to specific routers.
• Controllers → Services: Show that controllers delegate business logic operations to the service layer.
• Services → Database Layer: Indicate that services query or modify data through Sequelize models, which are affected by migrations and seeders.
• Middlewares: Position these as interceptors around the API endpoints to manage tasks like authentication, pagination, and error handling.
• External Integrations: Include an external “Cloudinary” component (from src/configs/cloudinary and src/services/files/cloudinary) for file storage/management.
Key Architectural Patterns & Design Principles
• Layered / N-tier Architecture: Clearly demarcates presentation (routes/controllers), business logic (services), and data access (sequelize models, migrations).
• Separation of Concerns: Each directory (e.g., configs, controllers, middlewares, services, validations) has its dedicated purpose.
• Modular Design: Supporting multiple languages (i18n) and validation rule files (under src/configs/validator/rule), which suggests modularity for extensibility.
• Containerization: The presence of docker-compose.yml indicates that the entire system might be developed and deployed in containerized environments.
Final Touches
• Remember to incorporate deployment elements such as Docker containers and any CI/CD workflows (as seen from the .github/workflows and Docker Compose).