How manhhiep2003/ssphis works
Main Components
• API Clients & External Consumers: Represent the browsers, mobile apps, or any external systems that interact with this API, likely through HTTP requests.
• API Gateway / Entry Point: The service is started via src/index.ts. This acts as the primary entry point that initializes the server (likely Express or similar) and assembles the middleware, routes, and configuration.
• Routing Layer: Located in the src/routes folder, which maps API endpoints to specific controllers.
• Controllers: Found inside src/controllers. Each controller (e.g., auth.controller.ts, appointments.controller.ts, etc.) handles incoming requests, calls the appropriate service functions, and returns responses.
• Service Layer: In the src/services directory. These files (e.g., user.service.ts, appointments.service.ts) contain the core business logic and coordinate communication between controllers and the database.
• Middleware: Placed in src/middlewares, these provide request validations (e.g., validateRequest, JWT verification, authorization checks). They act as filters or preprocessors for incoming requests.
• Database & ORM: The project uses Prisma as its ORM. This is evident from the prisma directory with migrations and schema files. The Prisma client (generated using npm run prisma:generate) handles database interactions.
• Configuration & Utilities: Settings in src/configs (database, Swagger API docs, and VNPay configuration) and helpers under src/utils support the overall project functionality.
• API Documentation: Swagger files exist in src/docs, and Swagger is initialized through src/swagger.ts. This provides a visual and interactive representation of the API endpoints.
• Deployment & Environment: Files like Dockerfile, docker-compose.yml, .env.example, and configuration files (e.g., eslint.config.mjs, prettierrc) suggest containerized deployment and development consistency tools.
Relationships and Interactions
• API Clients send HTTP requests that first hit the Entry Point (src/index.ts) of the application.
• The requests flow into the Routing Layer (src/routes) where endpoints are mapped to specific controllers.
• Controllers then invoke business logic in the Services layer (src/services).
• The service layer makes calls to the database using the Prisma client, with database schema and migration changes defined under the prisma directory.
• Middlewares are applied at various stages (pre-route or post-route) to enforce authentication, validation, and authorization before reaching the controllers.
• Configuration files in src/configs and external integrations (e.g., VNPay for payments) support enhanced features like payment processing and documenting the API via Swagger.
Architectural Patterns and Design Principles
• Separation of Concerns: Different layers (controllers, services, routes, middleware) encapsulate distinct responsibilities.
• MVC / Layered Architecture: Although not strictly an MVC model, the organization clearly separates the request handling (controller), business logic (service), and data access (Prisma / database).
• RESTful API Design: Clearly defined endpoints with corresponding routes and controllers.
• Use of Docker & Environment Variables: The presence of Docker-related files indicates containerized deployment best practices.
• Database Migrations and Schema Evolution: Managed via Prisma migrations which reveal the iterative nature of model updates.
Key Technologies, Frameworks, and Libraries to Highlight
• Node.js – the runtime environment.
• Express (or comparable HTTP server framework) – likely used given the conventional “controllers” and “routes” structure.
• Prisma – as the ORM for database management and migrations.
• Swagger – for API documentation.
• VNPay Integration – for payment processing (as seen in the configuration and utility files).
• Docker – for containerization and deployment.
• Various utils and middleware libraries for JWT handling, request validation, and authorization.