How hoang81102/blindbox_backend works
Project Type and Purpose
• The project is a backend web API developed in ASP.NET Core, intended to serve as the backend for managing user authentication, product listings (BlindBox), orders, payments, vouchers, and related features.
• The README provides a link to a deployed Swagger UI, confirming that the API endpoints are documented for external consumption.
• Although it doesn’t include a frontend directory, the focus is on building a robust API with clear layers, deployable on Railway.
Main Architectural Components
• API Layer (Presentation): This includes the Controllers folder within BlindBoxSS.API. Controllers such as AdminController, AuthController, CartController, etc., receive incoming HTTP requests.
• Business Logic Layer (Services): Found under Services, subdivided into specific domains (e.g., AccountService, OrderS, Product, Payment, Wallet, etc.). This layer holds the business logic, validation, and coordination of operations.
• Data Access Layer (DAL):
• DAO: Contains the BlindBoxDbContext, EF Core migrations, and configuration settings for database connectivity.
• Repositories and Repository folders: Implement repository patterns with interfaces and concrete classes (e.g., IGenericRepository, ICategoryRepository, IUnitOfWork, etc.) that abstract data operations.
• Model Definitions: The Models directory holds the domain entities (like BlindBox, Order, Category, etc.) that are shared across the layers.
• Infrastructure and Cross-Cutting Concerns:
• Dependency Injection: DI directory with installers registers services, repositories, and components.
• Caching: RedisConfiguration in the Configurations folder and Cache-related services (ResponseCacheService) indicate use of Redis caching.
• Exception Handling: The Exceptions folder contains a GlobalExceptionHandler for centralized error management.
• Email and External Requests: Services/Email and Services/Request show integrations with email systems and handling webhooks/payment requests.
Relationships and Interactions
• Endpoints in the Controllers invoke methods in the Services layer. The services contain the core business logic.
• The Services layer then calls into the Repositories (via the Repository Pattern and the Unit of Work pattern) which in turn communicate with the database (via the DAO’s DbContext).
• Cross-cutting concerns like caching, dependency injection, and exception handling wrap around these interactions.
• External systems (like clients calling the API through Swagger or any integrated third-party services such as Redis caching) interact with specific endpoints or configurations.
Important Architectural Patterns and Design Principles
• Separation of Concerns: The clear separation between controllers (presentation), services (business logic), repositories/DAO (data access), and models.
• Repository and Unit of Work Patterns: Multiple repository folders and the UnitOfWork implementation ensure abstraction of data operations.
• Dependency Injection: The DI folder with installers standardizes the registration of services and repositories.
• Caching Strategies: Integration of Redis caching enhances performance for repeated queries.
• Error Handling: Global error handling via the GlobalExceptionHandler promotes robust and centralized exception management.
Essential Elements
– DAO (with BlindBoxDbContext and migrations)
– Repositories and their unit-of-work host.
• Side notes or annotations for dependency injection (DI installers), caching (Redis), and error handling.