How hodinhtuankiet/trello-backend-express works
Main Components
• Express Server: The project entry point is src/server.js, which sets up the Express application.
• Controllers: Controllers (e.g., boardController.js, cardController.js, etc.) in the controllers directory receive the incoming requests from the routes.
• Services: Business logic is kept in the services folder (e.g., boardService.js, cardService.js) and is called by the controllers.
• Models: The models (e.g., boardModel.js, cardModel.js) represent data and interact with the database (configured in src/config/mongodb.js, for example).
• Middlewares: Include middleware components for error handling (errorHandlingMiddleware.js) that process requests and responses.
• Configurations: All configuration-related files (CORS, environment variables, MongoDB configurations) reside in src/config.
• Providers and Utilities: The provider and utils directories encapsulate helper functions, abstractions, and error classes (ApiError.js, algorithms, formatter, sorts, etc.).
• Validations: Validation scripts for data consistency (in the validations folder) augment input processing.
• Sockets: There is preliminary support for WebSockets in the sockets directory for future real-time features.
Architectural Interactions and Data Flow
• Routes invoking specific controllers which, in turn, call service functions.
• That services interact with the models to perform database operations (as configured in src/config/mongodb.js).
• Middleware usage on the request/response pipeline, particularly error handling middleware.
• Support for configuration files (like CORS and environment settings) that are loaded at startup.
• Optionally, note the planned integration of WebSocket connections and queue management (e.g., Redis) as future expansion points.
Architectural Patterns and Design Principles
• Layered Architecture: Clearly separate mix-and-match layers (routing, controller, service, model) which facilitates easier testing and maintenance.
• API Versioning: Distinct routes for v1 and v2 show that versioning is an important design choice.
• Modular Organization: The clear division into directories (controllers, services, models, etc.) reflects a modular design that promotes single responsibility and loose coupling.
• Planned Scalability: The presence of sockets and future integrations (Redis for background jobs) indicates an architecture designed to scale and incorporate additional features over time.