How vuongnguyen333/trello-api works
Project type and purpose
• This is a Node.js back-end RESTful API (no frontend in this repo) for managing “boards,” “columns,” and “cards” (a Kanban‐style service).
• It uses Express, MongoDB, input validation, WebSockets, and versioned routes (v1, v2).
File structure
• Top‐level config:
• .env.example, src/config (cors, environment, mongodb)
• src/server.js (entry point)
• Routing & HTTP layer:
• src/routes/v1/*.js, src/routes/v2/index.js
• Controllers:
• src/controllers/*Controller.js
• Services (business logic):
• src/services/*Service.js
• Data layer:
• src/models/*.js (Mongoose schemas)
• Cross-cutting:
• src/middlewares/errorHandlingMiddleware.js
• src/utils/*.js (errors, formatters, validators, algorithms, constants)
• src/validations/*.js
• Real-time (WebSocket) support:
• src/sockets/exampleSocket.js
• Providers (external integrations):
• src/providers/exampleProvider.js
README
• (Empty in this case—structure itself implies MVC + service + socket architecture.)
Diagramming the architecture
a. Main components
1. Client(s): HTTP clients (web/mobile) and WebSocket clients
2. API Gateway / Express App
3. Route Modules (v1, v2)
4. Controllers
5. Validation & Middleware Layer
6. Services (business logic)
7. Data Layer (MongoDB via Mongoose models)
8. External Providers (exampleProvider)
9. Socket Server
10. Utilities (ApiError, formatters, etc.)
b. Relationships and data flow
• HTTP Request → Express App
• Passes through CORS + Environment middlewares
• Hits versioned Route Module
• Runs Validation → Controller → Service
• Service interacts with Mongoose Models → MongoDB
• Response bubbles back through Controller → Route → Express → Client
• Errors handled by errorHandlingMiddleware
• WebSocket connections managed by Socket Server → exampleSocket
• Services or Controllers may emit socket events on data changes
• Providers can be called by Services for external integration
c. Architectural patterns & design principles
• MVC‐style separation: Routes → Controllers → Services → Models
• Layered architecture (Validation & Middleware, Business, Data)
• Single responsibility per module
• Versioned API for backward compatibility
• Asynchronous event‐driven sockets for real-time updates
d. Key technologies & libraries
• Node.js + Express
• Mongoose + MongoDB
• Joi or custom validators (in src/validations)
• WebSocket library (socket.io or ws in exampleSocket)
• dotenv for environment vars
• ESLint, Babel for build
Final advice
• Be exhaustive in naming each layer and module group
• Real-time vs. RESTful flows distinctly
• Environment/configuration as a separate component