How gabriel7729/quickchatapi works
Main Components and Layers
• API/Web Layer – The "ApiTemplate.Web" project hosts the endpoints, configuration, and middleware. This layer is responsible for handling HTTP requests, user authentication, endpoint routing, and managing client interactions.
• Core/Domain Layer – The "ApiTemplate.Core" project contains business logic, domain entities (such as Chat, User, and Validation aggregates), abstractions, specifications, interfaces, constants, and core services. This layer encapsulates the core business rules.
• Infrastructure/Data Layer – The "ApiTemplate.Infrastructure" project handles data persistence and external integrations, including the Entity Framework context (AppDbContext), repository implementations, migrations, DTO mappings, and third-party integrations like email and PDF services.
• Shared Kernel – The "ApiTemplate.SharedKernel" provides commonly used abstractions, base classes (like EntityBase), domain event handling, and specifications that are used across other layers.
Relationships and Interactions
• The Web layer communicates with the Core layer by invoking business logic (for example, through endpoints such as authentication, chat, and user management endpoints) while applying concepts like dependency injection (via Autofac).
• The Core layer, which defines interfaces (e.g., IAuthService, IChatService, IOtpService, etc.), delegates persistence operations to the Infrastructure layer.
• The Infrastructure layer implements these interfaces and handles data access through the Entity Framework repository methods.
• Domain events (using Mediator pattern) and outbox patterns are used for asynchronous event emission and handling, ensuring robust decoupled interactions between services.
• Specifications (as described in the Ardalis Specifications approach) are used for dynamically passing query requirements from the Core to Infrastructure layer, encapsulating query logic.
Architectural Patterns & Design Principles
• Clean Architecture / Onion Architecture – Separation into distinct layers (UI/Web, Core/Domain, Infrastructure, and Shared Kernel) minimizes coupling.
• Dependency Injection and Inversion of Control (using Autofac) – Dependencies flow inward, with each layer only aware of abstractions defined by inner layers.
• Use of Specifications – For building database queries in a clean and reusable manner.
• Guard Clauses – Used to enforce preconditions in business logic.
• Event-driven communication – Using Mediator to dispatch domain events.