Skip to content

Wosiu6/games-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Games API

License GitHub

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

Prerequisites

  • .NET 9 SDK
  • PostgreSQL (or use In-Memory DB for testing)

Setup

  1. Database Configuration
    Edit applicationSettings.json in each API project to use either:

    • In-Memory DB (for quick testing)
    • PostgreSQL - create two databases:
      • GamesDb
      • IdentityDb
  2. 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"
  3. Run Migrations (see below)

  4. Seed Data & Authentication
    Run in Debug mode to auto-seed initial data.
    Use the /users/login endpoint to get a JWT token, then:

    • In Swagger: Click Authorize → paste Bearer <token>
    • In Postman/Insomnia: Add Authorization: Bearer <token> header

Games API

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

Identity API

Method Endpoint Description
POST /users Register a new user
POST /users/login Login and receive JWT token

Running Migrations

Games API (ApplicationDbContext)

# 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

Identity API (IdentityDbContext)

# 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

Authentication & Authorization

  • JWT tokens issued on login (/users/login)
  • Protected endpoints require valid Bearer token
  • Role/claim-based authorization applied via policies
  • Swagger UI supports token input via Authorize button

TODO

  • 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

License

MIT


About

.net api featuring cqrs, clean architecture and jwt-based auth

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published