Clean Architecture ASP.NET Core 10 Web API for personal expense tracking. Features JWT auth, EF Core PostgreSQL, Swagger docs, layered design (Repository/Service patterns).
| Category | Tech |
|---|---|
| Framework | ASP.NET Core 10 |
| ORM | EF Core + Npgsql |
| DB | PostgreSQL/SQLite/SQL Server |
| Auth | JWT + ASP.NET Identity |
| Docs | Swagger/OpenAPI |
| Logging | Serilog |
| Mapping | AutoMapper |
The solution is divided into multiple projects to separate concerns:
- Contracts – interface definitions for repositories.
- Entities – domain models and EF Core configurations.
- Repository – data access layer using Entity Framework Core.
- Service.Contracts – service interfaces.
- Service – business logic implementations.
- ExpenseTrackerApi – the main API project hosting controllers and app configuration.
- ExpenseTrackerApi.Presentation – additional presentation artifacts having the controllers (e.g. Swagger XML).
- Shared – common DTOs.
Each project targets .NET 10 and uses a shared ExpenseTrackerApi.slnx solution file.
Prerequisites:
- .NET 10 SDK
- PostgreSQL (or SQLite/SQL Server)
- EF Tools:
dotnet tool install --global dotnet-ef
1. Setup
git clone <repo> && cd ExpenseTrackerAPI
dotnet restore2. Config (ExpenseTrackerApi/appsettings.json or env):
ConnectionStrings:sqlConnection = "Host=localhost;Database=ExpenseTracker;Username=postgres;Password=pass"
JwtSettings:SecretKey = "your-32+char-secret" (or SECRETExpense env)
3. DB & Run
cd ExpenseTrackerApi
dotnet ef database update
dotnet runPorts: HTTPS 5001, HTTP 5002. Swagger: /swagger
Test Admin: Register/login via /api/authentication, use Bearer token.
| Method | Endpoint | Desc |
|---|---|---|
| GET | /api/expenses |
List expenses |
| GET | /api/expenses/{id} |
Get expense |
| POST | /api/expenses |
Create expense |
| PUT | /api/expenses/{id} |
Update expense |
| DELETE | /api/expenses/{id} |
Delete expense |
| POST | /api/authentication |
Register/login |
Quick Test:
# Login (get token)
TOKEN=$(curl -s -X POST http://localhost:5002/api/authentication/login \\
-H "Content-Type: application/json" -d '{"email":"test@test.com","password":"Test123456"}' | jq -r .token)
# Get expenses
curl http://localhost:5002/api/expenses -H "Authorization: Bearer $TOKEN"- JWT auth (SECRETExpense env)
- User-scoped expense CRUD + categories
- EF migrations (Npgsql/PostgreSQL)
- Swagger docs + XML comments
- Serilog logging
docker build -t expense-tracker .
docker run -p 5001:5001 -e ConnectionStrings__sqlConnection="your-pg-conn" -e SECRETExpense="your-secret" expense-trackerAdd xUnit:
dotnet new xunit -n ExpenseTracker.Tests
dotnet add ExpenseTracker.Tests reference Service Service.Contracts Entities
dotnet test- Azure:
dotnet publish -c Release - Env: DB conn, SECRETExpense, ASPNETCORE_ENVIRONMENT=Production
- Disable dev CORS/Swagger if needed
- Fork/branch (feat/...)
dotnet ef migrations add Name- Test/PR
MIT License.
Inspired by: roadmap.sh Expense Tracker