How lucasblackarken/locadoradecarro works
Project type and purpose
• This is a backend-only RESTful API for a car-rental system built with ASP.NET Core 8.0.
• It follows Domain-Driven Design (DDD), CQRS + MediatR, FluentValidation, Entity Framework Core, and uses IdentityServer4 for authentication (Client Credentials).
• It exposes endpoints to register cars, list available/unavailable cars, rent cars, return cars (with late fees), and manage rentals.
A. Presentation/API Layer
• CarrosController
• AluguelController
B. Application Layer (CQRS + MediatR)
• Commands & CommandValidators (FluentValidation)
• Queries
• CommandHandlers & QueryHandlers (MediatR handlers)
C. Domain Layer
• Entities (Carro, Aluguel, Cliente)
• DTOs (CarroDTO, AluguelDTO)
• Repository interfaces (ICarroRepository, IAluguelRepository)
D. Infrastructure Layer
• EF Core DbContext (AppDbContext)
• Repository implementations (CarroRepository, AluguelRepository)
• Migrations
E. Cross-cutting / Support
• IdentityServer4 (Auth Server – Client Credentials flow)
• AutoMapper (mapping between Entities↔DTOs)
• Utils
F. Data Store & External Services
• SQL Server database
• (Optional) Logging, Monitoring, Message bus, etc.
1. Client → API Controllers (HTTP + Bearer token from IdentityServer)
2. Controller → MediatR.Send(command/query)
3. MediatR Pipeline
• ValidationBehavior → FluentValidation validators
• Logging/AuditBehavior (if any)
• Handler execution
4. Handler → Domain/Repository interface → Infrastructure repository
5. Repository → AppDbContext → SQL Server
6. Handler → Constructs DTO → returns to Controller → serializes JSON → Client
Architectural patterns & design principles
• DDD: Separation of Domain, Application, Infrastructure, Presentation projects.
• CQRS: Commands (state-changing) vs. Queries (read-only).
• Mediator: Decouples sending requests from handling logic.
• FluentValidation: Pre-handler input validation pipeline.
• Repository pattern + EF Core: Abstract data access behind interfaces.
• SOLID & Clean Code: Single Responsibility, Dependency Inversion via interfaces & DI.
Detailed elements
• Layer names and key classes (e.g., AluguelCarroCommandHandler).
• Data flow: Command/Query → Handler → Database → DTO → Response.
• Authentication flow: Client credentials → IdentityServer → JWT → API.
• EF Core migrations block under Infrastructure.