How mayumisiano/nlw-connect-devstage works
Main Components
• API Layer: Represented by the TechLibrary.Api project. This is where the Controllers (BooksController, CheckoutController, LoginController, UserController) directly expose the endpoints.
• Domain Layer: Found under TechLibrary.Api/Domain/Entities. Include the key entities (Book, Checkout, User) which encapsulate the core business data.
• Use Cases / Application Layer: The TechLibrary.Api/UseCases folder contains business logic for specific actions (filtering books, registering checkouts, handling login, and user registration). These are key application services orchestrating interactions between layers.
• Infrastructure Layer:
• Data Access: Under TechLibrary.Api/Infrastructure/DataAccess, which contains the TechLibraryDbContext (likely using an ORM such as Entity Framework).
• Security: Under TechLibrary.Api/Infrastructure/Security, which is split into Cryptography (e.g., BCryptAlgorithm) and Token management (JwtTokenGenerator). This shows dedicated security mechanisms for both password management and token-based authentication.
• Services: For example, the LoggedUserService under TechLibrary.Api/Services/LoggedUser encapsulates logic related to currently authenticated users.
• Communication Layer: The TechLibrary.Communication project holds definitions for request and response models. This serves as the DTO (Data Transfer Object) layer to standardize how data is sent and received.
• Exception Handling: The TechLibrary.Exceptions project defines custom exception types (ConflictException, NotFoundException, InvalidLoginException, etc.) used across the system.
• Configuration & Startup: Files like Program.cs, appsettings.json, and launchSettings.json indicate application configuration and startup routines.
Out Relationships and Interactions
• From Controllers to Use Cases.
• From Use Cases to the Domain Entities.
• From Use Cases to the DataAccess component (TechLibraryDbContext) when persisting or retrieving data.
• From Use Cases to Security components when performing authentication and token generation.
• The Communication project (with its Request/Response models) connects to the API layer, as these models define the contract over which Controllers exchange data.
• The Custom Exceptions can be represented as an intersecting utility used across the Use Cases and API layers to handle error scenarios gracefully.
• Optionally, include a configuration node representing appsettings to indicate externalized configuration and environment-based setups.
Architectural Patterns and Technologies
• The API is structured using the MVC-inspired pattern (Controllers, Use Cases, Domain) even though it is clearly an API back-end.
• The separation into Use Cases and Domain Entities suggests a Clean Architecture or Onion Architecture approach, where application logic (use cases) is decoupled from both the presentation (controllers) and infrastructure details.
• Security is handled using modular components (BCrypt for cryptographic hashing and JWT for token generation), emphasizing separation of security concerns.
• Data Access is isolated within its own namespace making it easier to swap out or modify the persistence style if needed.