How nguyenchithannh/trello-apis works
The project is a RESTful API backend for a Trello-like project management application. It is built with Node.js, Express, and MongoDB, incorporating real-time features through Socket.IO, comprehensive authentication (including JWT and Google OAuth), and integration with external services like Cloudinary, Twilio, and Nodemailer.
Main Components
• API Layer: Representing the HTTP RESTful endpoints organized into versioned routes (v1 and v2) for different functionalities (authentication, boards, columns, cards, invites, OTP, users, and messages).
• Controller Layer: Each route forwards requests to its respective controller (e.g., authController, boardController, cardController). These serve as the interface between the routes and the core business logic.
• Service Layer: Controllers call services (e.g., authService, boardService, cardService) which contain business logic and coordinate with models.
• Data Models (Persistence Layer): The MongoDB models (e.g., boardModel, userModel, cardModel, etc.) and the configuration files (e.g., mongodb.js) that establish the connection to MongoDB.
• External Integrations & Providers: Separate modules to deal with external services such as OAuth (Passport.js), email services (Nodemailer, Gmail integration), Cloudinary (for image uploads), and Twilio (for SMS notifications).
• Real-time/Sockets: Socket configuration and handling modules for real-time updates integrated via Socket.IO.
• Utility and Validation Layers: Modules for algorithms, formatters, constants, sorting, and request validations that ensure data integrity.
Detail the Flow and Interactions
• Clients (web or mobile applications) interact with the API by making HTTP requests to various endpoints.
• API Routes (organized under src/routes/v1 and v2) map to Controllers where the incoming HTTP requests are initially handled.
• Controllers validate the input (utilizing validations from src/validations) and then delegate processing to appropriate services.
• Services execute business logic, interact with the database through models available in src/models, and engage with external providers as needed.
• For real-time interactions, the socket layer (src/sockets) handles events to update clients in real time (for example, when moving cards or sending messages).
Architectural Patterns and Design Principles
• Layered Architecture / Separation of Concerns: Distinct layers for API routing, controllers, services, and data models.
• Modularization: Each major feature (such as boards, cards, and columns) is split into its own controller, service, and model, making future extensions or maintenance easier.
• API Versioning: Multiple versions (v1, v2) of routes are maintained, likely to support API evolution.
• Integration with External Services: Clear boundaries between core logic and integrations like email, SMS, and image hosting.
• Error Handling: Use of custom utility classes for error management ensures centralized error processing.