How krlosoul/netcoreapitemplate works
Main Components and Layers
• API Layer (Presentation): Represented by the “Api” directory. This component exposes HTTP endpoints, has controllers for users and roles, applies filters, middlewares for exception handling, versioning, Swagger configuration, and authentication (JWT and Keycloak).
• Application Layer (CQRS + Mediator): Represented by the “Application” directory. This layer contains features organized by domain (Roles and Users) and implements commands, queries, DTOs, mappers, validators and behaviours to enforce validations.
• Core (Domain Layer): Shows the business entities (User, Role, UserRole), core constants, shared DTOs, exceptions, enums, and interfaces for abstractions (e.g., repository, unit of work, JWT service, etc.). This layer defines the core business logic and contracts.
• Infrastructure Layer: Contains implementation details such as data access (Entity configurations, Repository, UnitOfWork), details of connecting to the SQL Server DB, and implementations of external services (Kafka, Redis, RabbitMQ, Hangfire, MinIO, etc.). It also contains dependency injection configuration.
• Database: SQL Server. Represented by the DDL provided in the README. The Infrastructure layer interfaces with the database using Repository and UnitOfWork.
• External Integrations: Include services such as Vault for secret management, MinIO for file storage, ElasticSearch/Kibana (via ELK) for logging, Kafka & RabbitMQ for messaging, Keycloak for authentication/authorization, Alfresco for document management, Redis for caching, Hangfire for background jobs, and circuit breakers, among others.
Relationships and Data Flow
• That user interactions (HTTP Requests) enter through the API layer.
• From API, the flow continues to the Application layer using the Mediator pattern; commands and queries are issued that encapsulate the business logic.
• The Application layer communicates with the Core for domain validations and business rule enforcement.
• When persistence is needed, the Application layer forwards requests to the Infrastructure layer, which handles Repository/UnitOfWork operations with the SQL Server.
• External services (Vault, MinIO, Kafka, etc.) are invoked through specific service interfaces defined in Core/Application and implemented in Infrastructure.
Architectural Patterns and Design Principles
• Hexagonal Architecture (Ports & Adapters): Emphasize the separation between the core business logic (Core) and the outer layers (API, Infrastructure).
• CQRS (Command Query Responsibility Segregation): Indicate distinct flows for commands (state changes) and queries (data retrieval).
• Mediator Pattern: Show a central component (the mediator) coordinating request handling in the Application layer.
• Dependency Injection and Abstraction: The Application and Core layers define interfaces which are implemented in the Infrastructure layer.
• Containerization: Docker and Docker Compose are used to deploy the API and its external integrations; represent these containers in a separate “Deployment/Container” cluster.