How chandara-code/nest-js-heroku works
This project is a NestJS REST API boilerplate designed to serve as a backend for common applications. It is built using NestJS and leverages TypeORM for database operations, which includes migrations and seeding. Additionally, it supports a variety of authentication mechanisms (email/password plus multiple social logins like Apple, Facebook, Google, and Twitter), file uploading (both local and S3), internationalization (i18n), and mailing (via nodemailer). There is also robust testing infrastructure with both unit and end-to-end (E2E) tests, along with Docker configurations for containerized deployment and CI/CD integration using GitHub and GitLab workflows.
And List Main Components
• API Gateway / Entry Point: Represented by the central NestJS application (src/app.module.ts, src/main.ts).
• REST API Modules: Include various domain-specific modules such as:
• Articles, Auth (with multiple submodules for each social provider), Files, Firebase Admin, Forgot, Home, Mail, Session, and Users.
• Database: Represented by the TypeORM integration (src/config/database.config.ts, src/database/ folder with migrations, seeds, and the data source configuration).
• Authentication Services: Covering standard email login, social logins, token handling (JWT, refresh tokens) and strategies under src/api/auth and associated strategies.
• External Services and Integrations: Such as:
• Social login providers (Apple, Facebook, Google, Twitter).
• Mailing server (with nodemailer, and maildev for local testing).
• File storage services (local file system and Amazon S3).
• Firebase Admin for push notifications.
• Configuration and Environment Management: Using @nestjs/config and various config files located in src/config.
• Internationalization (i18n): Managed via translation files under src/assets/i18n.
• Logging and API Response Handling: Custom error handling, logging (docker-compose and logging docs in /docs), and response formatting in src/core.
• Testing Infrastructure: Unit and E2E tests in the test directory.
• DevOps/CI Integration: Dockerfiles, docker-compose files, CI configurations (GitHub Actions, GitLab pipelines) indicating containerized deployment.
Relationships and Data Flow
• The REST API layers interact with the database via TypeORM, and each module (articles, users, etc.) is responsible for its own domain logic.
• Authentication components (controllers, services, strategies) interact with the user management module and the database for token generation and validation.
• File uploads service connects with storage backends (local or S3) and is integrated with the main API.
• External API calls (for social logins, mailing, or Firebase notifications) are handled by designated modules that encapsulate the integration logic.
• Configuration modules act as cross-cutting components that inject necessary settings into all parts of the application.
• Testing flows (E2E tests, unit tests) simulate user and admin interactions with these endpoints.
Architectural Patterns and Design Principles
• Modular Architecture: Each functionality is split into well-defined modules (e.g., each API segment in src/api has its own module, controller, and service).
• Separation of Concerns: Clear separation between business logic (services), presentation (controllers), and data access (TypeORM entities and repositories).
• Dependency Injection: Utilized throughout via NestJS to manage configurations and service dependencies.
• Microservice Readiness: The project layout makes it relatively easy to separate modules into individual microservices if required.