How nhtbao101/be-ecormerce-supabase works
This project is a NestJS backend application, built using TypeScript with a modular architecture. It is designed for server-side operations (such as user management, product management, orders, etc.), and it follows a clean separation of concerns using Nest’s module system. The file tree indicates that the project uses dedicated modules (e.g., auth, admin, category, order, product, and user), has clear concerns for database migrations and entities, and leverages repositories and services to encapsulate business logic.
Main Components
• API / HTTP Layer: Represented by the entry point (src/main.ts and api/index.ts) and controllers located in the various modules. Each controller (for auth, admin, and other modules) handles specific routes and endpoints.
• Authentication Layer: The auth module comprises controllers, strategies (admin and user), DTOs, guards, and custom decorators, which enforce access and roles.
• Business Logic Layer: These are the services within each module (e.g., admin.service.ts, product.service.ts, etc.) which encapsulate core business operations.
• Data Access Layer: The repository folders in both src/auth and src (e.g., category.repository.ts, product.repository.ts) along with the entities (admin.entity.ts, product.entity.ts, etc.) which are integral to ORM mapping and database operations.
• Database Layer: Although not directly visible as a physical database, the existence of a migrations folder (with various migration scripts) and the src/database folder (providing configuration) indicates interactions with a database.
• Infrastructure & Configuration: Files like nest-cli.json, package.json, deployment configs (vercel.json), and CI/CD configurations (.github/workflows) illustrate the development, testing, and deployment infrastructure.
Relationships and Interactions
• Clients interact with the API endpoint; requests are routed through controllers.
• Controllers delegate incoming requests to services where business logic is processed.
• Services call repositories for data persistence and retrieval, interfacing with the database entities.
• The authentication module is woven through the system via guards, strategies, and decorators to protect routes and manage permissions.
• Migrations update the schema of the database, ensuring the entities remain in-sync with the structural requirements.
Important Architectural Patterns
• Modular Architecture: Each feature domain (auth, admin, category, order, product, user) is encapsulated in its own module, supporting separation of concerns and improved maintainability.
• Dependency Injection: Core to NestJS, services and repositories are injected into controllers, enabling loose coupling.
• MVC-Like Pattern: While not strict MVC, controllers (presentation), services (business logic), and repositories/entities (data layer) clearly mimic the pattern.
• Strategy and Guard Patterns in Authentication: These protect endpoints and enforce role-based access.
Technologies and Frameworks
• NestJS Framework for building the backend.
• TypeScript as the language.
• Likely an ORM (given entities and migrations) such as TypeORM or Sequelize.
• GitHub Actions and possibly other CI/CD integrations (as indicated by .github/workflows) for automated testing and deployment.
• Configuration tools like ESLint, Prettier, and deployment tools (vercel, Mau for AWS integration).