How hoangthien1101/cuoi_ki_be works
Project’s Main Components
• Presentation Layer: This is represented by the TNN/Controllers folder. It contains various controllers (e.g., LoginController, GioHangController, HoaDonController, etc.) which handle HTTP requests and responses. Although a specific Views folder is not explicitly seen, the usage of ViewModels (in TNN/ViewModel) implies that there is a front-end (likely Razor pages) for rendering UI.
• Business Logic Layer: This layer is embodied by the TNN/Service folder (with interfaces for repositories and services such as ILoginService, ITokenServices, etc.) and includes utility classes in TNN/Helpers. The ViewModels in TNN/ViewModel also bridge the domain and presentation layers.
• Data Access Layer: This is split into two parts:
• TNN/Data: This folder contains Entity Framework models and the DbContext (CuaHangDienLanhContext) for interacting with the database.
• TNN/DataReader: Contains components like DataBase.cs, DataDapper.cs, and CustomParameter.cs which likely handle lower-level database access (possibly using Dapper). This suggests that the project might be using a hybrid approach by mixing EF with direct data access via Dapper.
• Static Resources and Configuration: The TNN/wwwroot folder houses public assets (such as images and other static files), and the appsettings.json files provide configuration parameters (including connection strings, environment settings, etc.). The TNN/UpLoad folder indicates file upload capabilities.
Relationships and Interactions
• Client requests hit the Controllers in the Presentation Layer, which are responsible for coordinating user interactions.
• Controllers then invoke methods in the Services (business layer) to process requests, perform validation, or manage business logic.
• The Services interface with the Data Access Layer (via data repositories in both TNN/Data and TNN/DataReader) to perform CRUD operations or complex queries.
• Security concerns (such as user authentication and password hashing) are handled by dedicated classes (e.g., in TNN/Helpers/PasswordHasher.cs and CreateSHA256.cs) and by services such as ITokenServices.
• External interactions include handling file uploads (TNN/UpLoad/HinhAnh and IUpLoadHinhAnhRepo) and possibly sending emails (ISendMailService).
Important Architectural Patterns and Design Principles
• MVC Pattern: Notice how Controllers and ViewModels are clearly present. This separation ensures that presentation and business logic remain decoupled.
• Repository/Service Pattern: The presence of interfaces like IHangRepo, IUserRepo, and various service interfaces indicates a separation between business logic and data access.
• Separation of Concerns: By dividing the application into Controllers, Services, Data Access, and Helpers, each component focuses on a specific responsibility.
• Use of Configuration Files: The appsettings.json and launchSettings.json files are crucial for environment-specific configuration management.
• Hybrid Data Access: Combining Entity Framework (via the DbContext) with a utility-based Dapper approach provides both high-level model management and fine-tuned SQL execution.