Architecture Overview
The Huellitas backend follows a clean architecture pattern, separating concerns into four distinct projects:- Maintainability - Each layer has a single responsibility
- Testability - Easy to unit test business logic independently
- Scalability - Can swap implementations without affecting other layers
- Dependency Flow - Dependencies point inward (API → Service → Data → Core)
Project Details
Huellitas.Core (Domain Layer)
The core project contains domain entities, data transfer objects (DTOs), and interfaces. It has no dependencies on other projects.Directory Structure
Key Components
Entities define the domain models with Entity Framework annotations:Usuario.cs:8
IProductoRepositorio.cs:6
Huellitas.Data (Data Access Layer)
The data project handles database operations using Entity Framework Core and implements repository interfaces.Directory Structure
Huellitas.Core- References entities and interfacesNpgsql.EntityFrameworkCore.PostgreSQL- PostgreSQL providerMicrosoft.EntityFrameworkCore- ORM framework
DbContext Implementation
huellitasContext.cs:6
Repository Pattern
ProductoRepositorio.cs:10
Huellitas.Service (Business Logic Layer)
The service project implements business logic, validation, and orchestrates repository calls.Directory Structure
Huellitas.Core- Uses entities and repository interfacesBCrypt.Net- Password hashingSystem.IdentityModel.Tokens.Jwt- JWT generation
Service Layer Pattern
ProductoService.cs:9
Huellitas.API (Presentation Layer)
The API project exposes HTTP endpoints and handles web-specific concerns.Directory Structure
Huellitas.Core- Uses entities and DTOsHuellitas.Data- Registers DbContextHuellitas.Service- Uses service interfacesMicrosoft.AspNetCore.Authentication.JwtBearer- JWT middlewareSwashbuckle.AspNetCore- Swagger/OpenAPI
Controller Example
ProductosController.cs:15
Dependency Graph
Project References
FromHuellitas.API.csproj:
Key Design Patterns
Repository Pattern
- Abstracts data access logic
- Implemented in
Huellitas.Data - Interfaces defined in
Huellitas.Core
Service Pattern
- Encapsulates business logic
- Separates controllers from data access
- Enables easy unit testing
Dependency Injection
- All dependencies injected via constructor
- Configured in
Program.cs:65-68 - Uses ASP.NET Core DI container
Async/Await
- All database operations use async methods
- Improves scalability and responsiveness
- Pattern:
Task<T>return types
Benefits of This Architecture
Separation of Concerns
Separation of Concerns
Each project has a clear responsibility. Controllers handle HTTP, services handle business logic, repositories handle data access.
Testability
Testability
Business logic in services can be unit tested without touching the database by mocking repositories.
Flexibility
Flexibility
Can swap PostgreSQL for SQL Server by only changing the Data project.
Team Scalability
Team Scalability
Multiple developers can work on different layers simultaneously without conflicts.
Next Steps
Authentication
Explore JWT authentication implementation
Database
Learn about Entity Framework and data models