How hoangphuc101202/commerce-be works
Main Components
• Client/API Consumers: Represent external clients (web, mobile, admin panels, etc.) that interact with the API.
• API Layer (Controllers): Includes controllers (CategoriesController, InvoiceController, PaymentController, ProductsController, SupplierController, UsersController) that expose endpoints to the clients.
• Business Logic (Services): Represents the service layer where implementations like CategoriesService, InvoiceService, PaymentService, ProductsService, SupplierService, and UserService encapsulate business logic. Interfaces for contracts in the Services/Interface folder highlight abstraction.
• Data Access Layer (Repositories): Contains repository implementations (CategoryRepository, InvoiceRepository, etc.) and their corresponding interfaces. This layer abstracts the database interactions using Entity Framework Core.
• Database and ORM: SQL Server backed by Entity Framework Core. Migrations in the Migrations folder indicate changes managed by EF migrations.
• Infrastructure: Includes various cross-cutting concerns such as Dependency Injection (ServiceCollectionExtension), Authentication (TokenProvider, MailService), Mapping (MappingProfile), and Password security (PasswordHasher).
• Middleware: Custom middleware components (API Response formatting, Exception Handling, Unauthorized/Forbidden handling) that manage cross-cutting API concerns.
• Exception Handling: The custom HTTP exceptions and handling classes ensure that errors are managed consistently across the system.
• External Services & Caching: Although not extensively detailed in the file tree, the README notes Redis for caching and Docker for deployment. Also, JWT Authentication is used for securing the APIs.
Relationships and Interactions
• Client requests hit the API controllers where they are first processed by the middleware pipeline (error handling, authentication/authorization).
• Controllers then delegate requests to the corresponding service implementation for business logic.
• Services interact with repositories (data access layer) to perform CRUD operations or complex interactions with the database.
• The database (SQL Server) is managed via Entity Framework Core along with migration files.
• External integrations such as email service (via MailService) and token generation (TokenProvider) facilitate authentication and notification functionalities.
• Docker and docker-compose are used for containerizing the application and possibly orchestrating multiple containers (like the API, SQL Server, and Redis caching).
Architectural Patterns and Design Principles
• Layered Architecture: The project is clearly divided into Controllers, Services, and Repositories.
• Dependency Injection: Facilitated through extension methods under DependencyInjection and used across the application for loose coupling.
• Separation of Concerns: Each directory isolates specific responsibilities – controllers handle HTTP, services encapsulate business logic, and repositories abstract data persistence.
• Custom Middleware: Enhances modular error handling, logging, and authorization mechanisms.
• DTOs and Auto-mapping: The Model/DTO folder indicates the use of Data Transfer Objects and mapping profiles to decouple the domain models from the API contracts.
• Use of Docker Containerization: Indicates a focus on repeatable deployments and scalability.
Relevant Technologies and Frameworks
• .NET 8.0 and C# are used for application building.
• Entity Framework Core for ORM and database migrations.
• SQL Server as the primary database.
• Swagger for API documentation.
• JWT for authentication, along with custom token providers.
• Redis for caching.
• Docker for containerization.
• Third-party frameworks/libraries like Serilog for logging and possibly AutoMapper (inferred by MappingProfile).