A .NET 9 Web API for managing games and user libraries using Clean Architecture, CQRS, and PostgreSQL. Features JWT-based authentication with fine-grained endpoint authorization.
The solution is structured into two APIs:
- Games API - Core game management (CRUD, achievements, progress), User-specific game library management
- Identity API - User registration and authentication
- .NET 9 SDK
- PostgreSQL (or use In-Memory DB for testing)
-
Database Configuration
EditapplicationSettings.jsonin each API project to use either:- In-Memory DB (for quick testing)
- PostgreSQL - create two databases:
GamesDbIdentityDb
-
JWT Key Configuration
For production, set the JWT key using environment variables or Azure Key Vault:export JwtSettings__Key="your-super-secure-jwt-key-at-least-256-bits-long"
-
Run Migrations (see below)
-
Seed Data & Authentication
Run in Debug mode to auto-seed initial data.
Use the/users/loginendpoint to get a JWT token, then:- In Swagger: Click Authorize → paste
Bearer <token> - In Postman/Insomnia: Add
Authorization: Bearer <token>header
- In Swagger: Click Authorize → paste
| Method | Endpoint | Description |
|---|---|---|
GET |
/games |
Get all games |
POST |
/games |
Create a new game |
PUT |
/games/{id} |
Update a game |
DELETE |
/games/{id} |
Delete a game |
GET |
/games/{id}/achievements |
Get achievements for a game |
POST |
/games/{id}/achievements |
Create achievement |
PUT |
/achievements/{id} |
Update achievement |
POST |
/achievements/{id}/progress |
Progress user achievement |
POST |
/users/games |
Add game to user library |
GET |
/users/library |
Get user's game library |
| Method | Endpoint | Description |
|---|---|---|
POST |
/users |
Register a new user |
POST |
/users/login |
Login and receive JWT token |
# Initial migration
dotnet ef migrations add InitialGamesCreate \
--project apis/Infrastructure/Infrastructure.csproj \
--startup-project apis/GamesApi/GamesApi.csproj \
--context ApplicationDbContext \
--verbose
# Add new migration
dotnet ef migrations add YourMigrationName \
--project apis/Infrastructure/Infrastructure.csproj \
--startup-project apis/GamesApi/GamesApi.csproj \
--context ApplicationDbContext \
--verbose
# Apply to database
dotnet ef database update \
--project apis/Infrastructure/Infrastructure.csproj \
--startup-project apis/GamesApi/GamesApi.csproj \
--context ApplicationDbContext \
--verbose# Initial migration
dotnet ef migrations add InitialIdentityCreate \
--project apis/Infrastructure/Infrastructure.csproj \
--startup-project apis/IdentityApi/IdentityApi.csproj \
--context IdentityDbContext \
--verbose
# Add new migration
dotnet ef migrations add YourMigrationName \
--project apis/Infrastructure/Infrastructure.csproj \
--startup-project apis/IdentityApi/IdentityApi.csproj \
--context IdentityDbContext \
--verbose
# Apply to database
dotnet ef database update \
--project apis/Infrastructure/Infrastructure.csproj \
--startup-project apis/IdentityApi/IdentityApi.csproj \
--context IdentityDbContext \
--verbose- JWT tokens issued on login (
/users/login) - Protected endpoints require valid
Bearertoken - Role/claim-based authorization applied via policies
- Swagger UI supports token input via Authorize button
- Implement API Gateway
- Docker compose and Dockermake files
- Global exception handler
- Fluent Validation
- Add Load Balancer for scalability
- Use Azure Flexible Database for PostgreSQL
- Add Rate Limiting and Caching, possibly Redis
MIT