How tanloc10203/mail-system-api works
Main Components
• Inbound Port/Adapter (Controllers & API endpoints)
• Components like the user.controller.ts and endpoints for registration, login, getting email lists, sending emails, etc.
• Domain Layer (Core Business Logic)
• Domain entities defined under folders such as src/@core/domain and src/user/domain.
• Business rules, validations, and value objects (e.g., API response, user domain entities).
• Application/Service Layer
• Use cases implemented in services, such as user.service.ts and modules orchestrating business logic.
• Outbound Port/Adapter (Infrastructure)
• Persistence adapters: see the infrastructure persistence directories and document repositories (e.g., user/infrastructure/persistence/document).
• Database configuration (MongoDB via Mongoose; note database-config files).
• External integrations: Gmail API integration as a third-party service.
• Cross-Cutting Concerns
• Internationalization (i18n) folders (src/i18n) with language keys.
• Interceptors (e.g., serializer and language interceptors in src/@core/interceptor).
• Exception handling and filters (located in src/@core/exceptions and src/@core/filters).
• Utility modules and config loaders (src/configs, src/utils, and environment setup files).
Relationships and Interactions
• The Controllers (inbound adapters) receive HTTP requests and forward them to the respective Services.
• Services interact with domain entities from the domain layer to execute business logic.
• Outbound adapters (repositories, persistence layers) implement the ports (interfaces) defined in the domain layer. They interact with MongoDB and translate between domain entities and database schemas (via mappers).
• The configuration files and i18n setups are used across the system to manage environment variables, error messages, and localization.
• Integration with the Gmail API acts as an external adapter facilitating email-sending functions.
Architectural Patterns
• Layered Modularity: Clearly isolate controllers, services, and repositories.
• Use of NestJS Modules: Divide the system into modules (e.g., user module, auth module, core module) that encapsulate functionality.