A modern, production-ready authentication and authorization server built with .NET 10, implementing Clean Architecture principles, CQRS pattern, and Domain-Driven Design (DDD).
This project follows Clean Architecture with clear separation of concerns across multiple layers:
βββββββββββββββββββββββββββββββββββββββ
β Presentation Layer β
β (Web.Api) β
βββββββββββββββββββββββββββββββββββββββ€
β Application Layer β
β (Use Cases & Handlers) β
βββββββββββββββββββββββββββββββββββββββ€
β Domain Layer β
β (Entities & Business Logic) β
βββββββββββββββββββββββββββββββββββββββ
β
β Dependencies
β
ββββββββββ΄βββββββββ
β Infrastructure β
β (EF Core, Auth) β
βββββββββββββββββββ
- Clean Architecture: Dependency inversion with core business logic independent of external concerns
- CQRS: Command Query Responsibility Segregation for read/write operations
- Domain Events: Event-driven architecture for decoupled domain logic
- Result Pattern: Railway-oriented programming for error handling
- Repository Pattern: Data access abstraction via DbContext
- Decorator Pattern: Cross-cutting concerns (validation, logging) via Scrutor
- JWT Bearer Token authentication
- Permission-based authorization system
- Secure password hashing with BCrypt
- User registration and login
- Claims-based identity management
- User Management: Registration, authentication, profile retrieval
- Todo Management: Full CRUD operations with priority levels
- Domain Events: Async event handling for domain state changes
- FluentValidation: Request validation with decorator pattern
- Entity Framework Core: PostgreSQL database with migrations
- Health Checks: Application and database health monitoring
- Structured Logging: Serilog with Seq integration
- Swagger/OpenAPI: Interactive API documentation
- Docker Support: Multi-container deployment with docker-compose
- Framework: .NET 9.0
- Database: PostgreSQL 17
- ORM: Entity Framework Core 9.0
- Authentication: JWT Bearer Tokens
- Validation: FluentValidation 12.0
- Logging: Serilog with Seq
- Testing: xUnit, NetArchTest
- Containerization: Docker & Docker Compose
- .NET 10 SDK
- Docker Desktop (for containerized deployment)
- PostgreSQL 17 (if running without Docker)
-
Clone the repository
git clone https://github.com/Dapplesoft-AD/AuthServer.git cd AuthServer
-
Run with Docker Compose
docker-compose up --build
local
docker compose -f docker-local-compose.yml up -d --build- Access the application
- API:
http://localhost:5000 - Swagger UI:
http://localhost:5000/swagger - Seq Logs:
http://localhost:8081
- API:
-
Clone the repository
git clone https://github.com/Dapplesoft-AD/AuthServer.git cd AuthServer
-
Update connection string (if needed)
Edit
src/Web.Api/appsettings.Development.json:"ConnectionStrings": { "Database": "Host=localhost;Database=clean-architecture;Username=postgres;Password=postgres" }
-
Apply database migrations
cd src/Web.Api dotnet ef database update -
Run the application
dotnet run
-
Access Swagger UI
Navigate to:
https://localhost:5001/swagger
AuthServer/
βββ src/
β βββ Domain/ # Enterprise business rules
β β βββ Users/ # User aggregate
β β βββ Todos/ # Todo aggregate
β βββ Application/ # Application business rules
β β βββ Abstractions/ # Interfaces & contracts
β β βββ Users/ # User use cases
β β βββ Todos/ # Todo use cases
β βββ Infrastructure/ # External concerns
β β βββ Authentication/ # JWT & password hashing
β β βββ Authorization/ # Permission system
β β βββ Database/ # EF Core DbContext
β β βββ DomainEvents/ # Event dispatcher
β βββ SharedKernel/ # Shared primitives
β β βββ Entity.cs # Base entity
β β βββ Result.cs # Result pattern
β β βββ Error.cs # Error handling
β βββ Web.Api/ # Presentation layer
β βββ Endpoints/ # Minimal API endpoints
β βββ Middleware/ # HTTP pipeline
βββ tests/
βββ ArchitectureTests/ # Architecture enforcement tests
| Method | Endpoint | Description |
|---|---|---|
| POST | /users/register |
Register a new user |
| POST | /users/login |
Authenticate and receive JWT token |
| GET | /users/{id} |
Get user by ID (requires auth) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /todos |
Get all todos for authenticated user |
| GET | /todos/{id} |
Get specific todo by ID |
| POST | /todos |
Create a new todo |
| PUT | /todos/{id}/complete |
Mark todo as completed |
| DELETE | /todos/{id} |
Delete a todo |
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Application health check |
dotnet test tests/ArchitectureTestsArchitecture tests enforce:
- Domain layer has no dependencies on Application, Infrastructure, or Presentation
- Application layer has no dependencies on Infrastructure or Presentation
- Infrastructure layer has no dependencies on Presentation
Edit appsettings.json:
{
"Jwt": {
"Secret": "your-secret-key-min-32-characters",
"Issuer": "AuthServer",
"Audience": "AuthServer",
"ExpirationInMinutes": 60
}
}{
"ConnectionStrings": {
"Database": "Host=localhost;Database=clean-architecture;Username=postgres;Password=postgres"
}
}The project includes:
Dockerfilefor the Web APIdocker-compose.ymlorchestrating:- web-api: .NET application (ports 5000, 5001)
- postgres: PostgreSQL database (port 5432)
- seq: Structured log viewer (port 8081)
admin@auth.dapplesoft.com
admin12345This project maintains high code quality standards:
- β TreatWarningsAsErrors: Enabled
- β Nullable Reference Types: Enabled
- β SonarAnalyzer: Static code analysis
- β Architecture Tests: Layer dependency enforcement
- β Central Package Management: Consistent versioning
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Dapplesoft-AD
- Clean Architecture by Robert C. Martin
- Domain-Driven Design by Eric Evans
- CQRS pattern inspiration from various enterprise implementations
Built with β€οΈ using .NET 9