How ssr707/e-commerce-backend works
Main system components
• API Layer: Represent the REST API endpoints grouped under “src/api”. Each sub-directory (address, auth, etc.) includes its own controller, service, and module. Controllers handle incoming HTTP requests and delegate tasks to services.
• Service Layer (Business Logic): Each module has corresponding service classes that encapsulate the business logic.
• Data Access Layer: Within “src/core”, the project defines entities that represent the domain models and repositories to abstract database operations. These components represent the communication between the service layer and the database.
• Common Utilities & Helpers: The “src/common” directory includes shared functionality such as decorators (for authentication and user management), guard implementations (JWT, admin, self guard, etc.), and common enums.
• Infrastructure Libraries: The “src/infrastructure” directory collects custom middleware and external integrations. For example, there are modules handling bcrypt (for secure password hashing), custom JWT (for token management), email service (for notifications), and file handling. These components serve as utility libraries that underpin authentication, messaging, and media management.
• Configuration & Environment: Look at “.env.example”, “nest-cli.json”, and “src/config” which handle environment variables and other configuration settings.
• External Deployment/CI Tools: The presence of GitHub Action workflows (in .github/workflows) and CircleCI images in the README hints at the automated testing, continuous integration, and deployment pipeline.
Relationships and Interactions
• API Controllers (in “src/api”) interact with corresponding Service classes to process HTTP requests.
• Service classes then call the Repository methods (in “src/core/repository”) to fetch or persist data from the database. Although the physical database isn’t explicitly shown in the file tree, it is implied by the domain entity files.
• Infrastructure modules (like JWT, email, and file handling) are utilized by services or guards to encrypt data, manage sessions, trigger notifications, or handle file operations.
• Guards and decorators (in “src/common”) wrap around controllers or methods to enforce security and manage user roles before business logic is executed.
Architectural Patterns and Design Principles
• Modular Architecture: The project uses a modular structure where each domain (address, auth, cart, etc.) has its own sub-directory with controllers, services, and Data Transfer Objects (DTOs). This reflects a separation-of-concerns and ease in scaling functionality.
• Layered Architecture: Clear separation between API, Business Logic, and Data Access layers.
• Dependency Injection: As recommended in NestJS practices, employ dependency injection between controllers, services, and repositories.
• Reusability via Common Modules: Utility functions and shared functionality are centralized in the common and infrastructure folders.
Relevant Technologies, Frameworks, and Libraries
• NestJS and TypeScript for building the server-side application.
• Node.js is the underlying runtime platform.
• bcrypt, custom-jwt, and email libraries for security and messaging.
• Testing frameworks (likely Jest, as seen in the “test” directory) for unit and end-to-end testing.
• External CI/CD integrations via GitHub Actions and CircleCI.
Final Touches
• Lastly, annotate any external integrations such as the deployment step instructions using Mau (as described in the README) to show how the application is deployed on AWS or other platforms.