How luanroger/allinoneaspnet works
Main Architectural Layers and Components
a. API/Presentation Layer
• Entry Point: The Program.cs file configures the entire application.
• Endpoint Mappings: The “Endpoints” folder defines grouped routes (UserEndpoints and ClientEndpoints) using Minimal API’s MapGroup. These endpoints serve as the public interface, handle the HTTP request/response cycle, and forward requests to the controllers.
• Swagger UI: Integrated Swagger middlewares (UseSwagger and UseSwaggerUI) automatically document the endpoints and serve as an interactive interface.
b. Application/Domain Layer
• Controllers: Located in the “Controllers” folder (UserController and ClientController). They encapsulate business logic for user signin/login and client CRUD operations.
• Models: The “Models” folder contains domain models (for both User and Client), as well as specialized read and request models. This separation ensures that the API’s input/output contracts differ from persistence objects.
• Validation: FluentValidation classes (in the “Validators” folder) define rules for request models. They are injected into controllers to guard against invalid data.
• Exception Handling: Custom exceptions (in the “Exceptions” folder) represent domain-level errors for cases like “UserNotFound”, “InvalidRequest”, or “ClientNotFound”.
c. Persistence/Infrastructure Layer
• Repository Pattern: Interfaces (in “Repositories”) and classes (UserRepository and ClientRepository) encapsulate data access logic. They use EF Core’s DatabaseContext (in “Repositories/Contexts”) to perform CRUD operations against a SQLite database.
• Entity Framework Core: Models are annotated with data annotation attributes to define database schemas. The DatabaseContext ties these models to underlying tables.
d. Cross-Cutting Services
• JWT Authentication: A dedicated “JwtService” (under “Services/Jwt”) is used in controllers to generate tokens. JWT-related constants (in JwtConsts) and middleware configuration (in Program.cs) ensure that endpoints (especially in the “client” group) are secured.
• Logging: Serilog is used as the logging mechanism. The Program.cs file configures Serilog to capture application events that are then used in controllers and other components.
• Dependency Injection: All controllers, repositories, validators, DbContext, and the JWT service are registered in the DI container. This results in clean constructor injection throughout the system.
How to Represent Interactions and Data Flow
– Begin at the Client (API consumer) side. Show the HTTP client sending requests to the ASP.NET API.
– For requests targeting registration or login, represent those being forwarded to the corresponding Controller.
– In each controller, show the following sub-flows:
• Validation: The controller invokes the appropriate FluentValidation component.
• Business Logic: If validation passes, the controller either registers a new user (or logs in an existing one) and calls the JWT service to generate a token OR manages client data.
• Data Persistence: When client/user data changes, controllers call the appropriate Repository. The repositories in turn interact with the DatabaseContext which uses EF Core to read or write to the SQLite database.
• Use logging symbols to indicate that Serilog is recording events.