How maryamaljanabi/nestjs-crud-api works
Main Components
• API Server: Represented by the Nest.js application. This includes the main entry points (src/main.ts) and the modular structure with an AppModule, as well as specialized modules like the "products" module.
• Controller (products.controller.ts): Handles HTTP requests for CRUD operations.
• Service (products.service.ts): Contains the business logic.
• Data Transfer Objects (DTOs in the dto folder): Define the input data format for creating/updating products.
• Entity (product.entity.ts): Defines the database table structure for products.
• Database: Illustrate the MySQL database (as configured using docker-compose.yml and seeded using init/seed.sql) that stores the products.
• ORM Layer: Show TypeORM’s role in bridging the Nest.js API and the MySQL database. This includes the TypeORM configuration found in src/config/typeorm.config.ts that establishes connections and manages entity mapping.
• External Tools: Include Docker-related components (the docker-compose.yml configuration for running the MySQL container and Adminer for database GUI access).
• Within the Nest.js API, illustrate the flow:
– Requests reach the Products Controller.
– The controller calls the Products Service.
– The service, using TypeORM (or underlying repositories), interacts with the MySQL database.
• Optionally, note the connection between the API and the OpenAPI/Swagger endpoint (e.g., http://localhost:API_PORT/api/) which serves as a documentation layer.
Architectural Patterns and Design Principles
• MVC Pattern: Emphasize that Nest.js is an opinionated framework organizing code into modules, controllers, services, and entities (aligning with MVC).
• Layered Architecture: Separate the presentation layer (controllers), business logic (services), and data access layer (entities and TypeORM repositories).
• Containerization: Mark the use of Docker for isolating the database and auxiliary tools (like Adminer).
Relevant Technologies
• Node.js & Nest.js for the server.
• TypeScript (used throughout the code).
• MySQL (as the relational database).
• TypeORM (as the ORM library managing database connections and entity mappings).
• Docker (for containerizing the database and managing deployment via docker-compose.yml).
• Swagger/OpenAPI (for API documentation).
• Testing with Jest (as seen in the products module’s test folder).