A production-ready ASP.NET Core 9 Web API built with modern backend best practices, featuring JWT authentication, role- and policy-based authorization, and secure configuration management.
GameStore API is a backend service for managing games and genres with secure access control.
It demonstrates real-world backend architecture, emphasizing scalability, maintainability, and security.
The API uses Entity Framework Core for data access, AutoMapper for DTO mapping, and Scalar for API exploration.
- JWT-based authentication
- Access & refresh token implementation
- Role-based authorization (
Admin,User) - Policy-based authorization
- Admin-only protected endpoints
- Secure token validation and lifecycle management
- User registration
- Login
- Refresh token
- Admin registration (accessible only by Admins)
- Automatic first admin seeding on initial run (if no admin exists)
- Full CRUD operations for Games
- Full CRUD operations for Genres
- One-to-many relationship (Genre โ Games)
- Only authenticated users can Create and Update
- Only Admin users can Delete
- Clean separation of concerns: Controllers โ Interfaces โ Services
- Business logic and database access handled exclusively in services
- Dedicated DTOs for requests and responses
- AutoMapper for entity โ DTO mapping and update operations
- Centralized global exception handling
- Configuration logic extracted into extension methods
- .NET 9
- ASP.NET Core Web API
- Entity Framework Core
- SQL Server
- JWT Authentication
- Policy-based Authorization
- AutoMapper
- Unit & Integration Testing (XUnit,Moq and FluentAssertion)
- Scalar (used instead of Swagger)
- User Secrets (for secure local development)
- Genre โ Games (One-to-Many)
- Code-first approach using Entity Framework Core
- Automatic admin seeding during first application run
- Secrets never committed to source control
- JWT Secret Key stored securely using User Secrets
- Database connection string hidden
- Environment-based configuration
- Role and policy checks enforced at API level
{
"Jwt": {
"Issuer": "GameStoreApi",
"Audience": "GameStoreClient",
"AccessTokenExpirationMinutes": 15,
"RefreshTokenExpirationDays": 7
},
"ConnectionStrings": {
"GameStore": ""
}
}dotnet user-secrets init
dotnet user-secrets set "Jwt:SecretKey" "YOUR_SUPER_SECURE_SECRET_KEY"
dotnet user-secrets set "ConnectionStrings:GameStore" "YOUR_DB_CONNECTION_STRING"-
Clone the repository
-
Configure User Secrets
-
Update the database (if migrations exist)
-
Run the application
dotnet run- Scalar UI is enabled for API exploration
- JWT Bearer authentication supported
- Role & policy restrictions enforced at endpoint level
- Unit Testing: Covers services using xUnit, Moq, and FluentAssertions (
GameStore.Test). - Integration Testing: Uses
WebApplicationFactorywith an isolated in-memory SQLite database provider for end-to-end endpoint verification (GameStore.IntegrationTests).
GameStore
โ
โโโ GameStore.Api # Main API Project
โ โโโ Controllers
โ โโโ Services
โ โโโ Interfaces
โ โโโ DTOs
โ โโโ Entities
โ โโโ Mappings
โ โโโ Extensions
โ โโโ Middleware
โ โโโ Data
โ โโโ Program.cs
โ
โโโ GameStore.Test # Unit Tests (xUnit, Moq)
โโโ GameStore.IntegrationTests # Integration Tests (SQLite, WebApplicationFactory)
This project is for learning and demonstration purposes.
GameStore API
Built with โค๏ธ using ASP.NET Core 9