Prerequisites
Before setting up the backend, ensure you have:- .NET 9.0 SDK or later
- PostgreSQL database server
- Visual Studio 2022 or VS Code with C# extension
- Entity Framework Core CLI tools
Project Structure Overview
The Huellitas backend follows a clean architecture pattern with four distinct projects:Installation Steps
1. Clone the Repository
2. Install Dependencies
Restore NuGet packages for all projects:Microsoft.AspNetCore.Authentication.JwtBearer(9.0.0) - JWT authenticationNpgsql.EntityFrameworkCore.PostgreSQL(9.0.2) - PostgreSQL providerMicrosoft.EntityFrameworkCore.Design(9.0.0) - EF Core migrationsSwashbuckle.AspNetCore(10.1.0) - API documentationBCrypt.Net- Password hashing
3. Configure Database Connection
Create anappsettings.json file in the Huellitas.API/ directory:
4. Create the Database
Create a PostgreSQL database:5. Run Migrations
Apply Entity Framework migrations to create database tables:Usuario- User accountsRol- User roles (Admin, Cliente)Categoria- Product categoriesproducto- ProductsPedido- OrdersDetalle- Order details
6. Run the Application
Start the development server:- HTTP:
http://localhost:5000 - HTTPS:
https://localhost:5001 - Swagger UI:
https://localhost:5001/swagger
Configuration Details
CORS Policy
The API is configured to accept requests from any origin (PermitirFrontend policy):
Program.cs:54
In production, restrict CORS to specific origins for security.
JWT Authentication
Authentication is configured inProgram.cs:14-42 using Bearer tokens:
Program.cs:25
Dependency Injection
Services and repositories are registered inProgram.cs:65-68:
Program.cs:65
Environment Variables
For production deployment, configure these environment variables:| Variable | Description | Example |
|---|---|---|
ConnectionStrings__DefaultConnection | PostgreSQL connection string | Host=db;Database=huellitas;... |
Jwt__Key | JWT signing key | your-secure-key-here |
Jwt__Issuer | JWT issuer | HuellitasAPI |
Jwt__Audience | JWT audience | HuellitasClients |
Troubleshooting
Migration Errors
If you encounter migration errors:JWT Configuration Error
If you see “ERROR FATAL! No se encontró la propiedad ‘Key’”, ensure yourappsettings.json contains the Jwt section with a valid Key property.
Database Connection Issues
Verify your PostgreSQL connection:Next Steps
Project Structure
Learn about the four-project architecture
Authentication
Understand JWT authentication implementation
Database
Explore Entity Framework and data models