- Overview
- Architecture
- Features
- Technology Stack
- Project Structure
- Prerequisites
- Installation
- Configuration
- Running the Application
- API Documentation
- Database
- Authentication & Authorization
- Logging
- Caching
- Testing
- Deployment
- Contributing
- License
Unife API is a comprehensive university management system built with .NET 8, implementing Clean Architecture principles, CQRS pattern, and Domain-Driven Design (DDD). The system provides robust APIs for managing university operations including student enrollment, staff administration, academic departments, and comprehensive authentication systems.
The project follows Clean Architecture principles with clear separation of concerns:
???????????????????????????????????????????????????????????????
? WebAPI Layer ?
? (Controllers, Middleware, etc.) ?
???????????????????????????????????????????????????????????????
? Business Layer ?
? (CQRS, Services, DTOs, Validators, etc.) ?
???????????????????????????????????????????????????????????????
? Data Access Layer ?
? (Repositories, DbContext, etc.) ?
???????????????????????????????????????????????????????????????
? Domain Layer ?
? (Entities, Enums, etc.) ?
???????????????????????????????????????????????????????????????
? Core Layer ?
? (Utilities, Base Classes, Interfaces) ?
???????????????????????????????????????????????????????????????
- Clean Architecture: Dependency inversion and separation of concerns
- CQRS (Command Query Responsibility Segregation): Using MediatR for command and query handling
- Domain-Driven Design (DDD): Rich domain models and clear business logic encapsulation
- Repository Pattern: Data access abstraction
- Unit of Work Pattern: Transaction management
- Specification Pattern: Query specification and reusability
- ?? JWT Authentication & Authorization with refresh tokens
- ?? Multi-role User Management (Admin, Staff, Student)
- ?? University Management (Universities, Faculties, Departments)
- ?? Email Verification System with OTP
- ?? Phone Verification System with OTP
- ?? Password Management (Change, Reset, Forgot Password)
- ?? User Profile Management
- ?? Session Management with Redis
- ?? Comprehensive Logging with Serilog
- ?? Redis Caching for performance optimization
- ??? Response Compression (Zstd, Brotli, Gzip, Deflate)
- ? FluentValidation for request validation
- ??? AutoMapper for object mapping
- ?? Swagger/OpenAPI documentation
- ?? Health Checks for system monitoring
- ?? High Performance with optimized queries and caching
- ?? Configurable Settings via appsettings.json
- ?? CORS support for cross-origin requests
- ?? Docker support for containerization
- .NET 8.0 - Latest LTS version
- ASP.NET Core - Web API framework
- Entity Framework Core 9.0.6 - ORM for database operations
- PostgreSQL - Primary database with Npgsql provider
- Redis - Caching and session storage
- MediatR 12.5.0 - CQRS implementation
- AutoMapper 13.0.1 - Object-to-object mapping
- FluentValidation 12.0.0 - Model validation
- JWT Bearer Authentication - Token-based authentication
- System.IdentityModel.Tokens.Jwt 8.12.1 - JWT handling
- Microsoft.AspNetCore.Authentication.JwtBearer 8.0.10 - JWT middleware
- Serilog 4.3.0 - Structured logging
- Serilog.AspNetCore 9.0.0 - ASP.NET Core integration
- Serilog.Sinks.Console 6.0.0 - Console logging
- Serilog.Sinks.File 7.0.0 - File logging
- ZstdNet 1.4.5 - Zstandard compression
- Built-in Brotli/Gzip - Additional compression options
- StackExchange.Redis 2.8.41 - Redis client
- Swashbuckle.AspNetCore 6.6.2 - Swagger/OpenAPI
- Microsoft.VisualStudio.Azure.Containers.Tools.Targets - Docker support
Solution1/
??? Core/ # Core utilities and base classes
? ??? Entities/ # Base entity classes
? ??? Security/JWT/ # JWT utilities and configurations
? ??? Utilities/ # Common utilities (Password, OTP, etc.)
? ??? ObjectStorage/ # Object storage abstractions
?
??? Domain/ # Domain entities and business rules
? ??? Entities/ # Domain entities
? ? ??? AuthorizationModuleEntities/ # User management entities
? ? ??? UniversityModul/ # University-related entities
? ? ??? AcademicModulEntities/ # Academic entities
? ??? Enums/ # Domain enumerations
? ??? Repositories/ # Repository interfaces
?
??? DataAccess/ # Data access layer
? ??? Concrete/EntityFramework/ # EF Core implementations
? ??? Database/Context/ # Database context
? ??? ObjectStorage/Redis/ # Redis implementations
?
??? Business/ # Business logic layer
? ??? Features/CQRS/ # CQRS commands and queries
? ? ??? Auth/ # Authentication features
? ? ??? User/ # User management features
? ? ??? Universities/ # University management features
? ??? DTOs/ # Data Transfer Objects
? ??? Services/ # Business services
? ??? Validators/ # FluentValidation validators
? ??? Mappings/ # AutoMapper profiles
? ??? Extensions/ # Service collection extensions
?
??? WebAPI/ # Presentation layer
??? Controllers/ # API controllers
??? Middlewares/ # Custom middlewares
??? Compression/ # Compression providers
??? HealthChecks/ # Health check implementations
- .NET 8.0 SDK
- PostgreSQL 12+
- Redis 6+
- Visual Studio 2022 or VS Code
- Docker (optional, for containerization)
git clone https://github.com/yourusername/unife-api.git
cd unife-api/Solution1dotnet restore- Install PostgreSQL
- Create a new database named
unife_db - Update connection string in
appsettings.json
- Install Redis
- Start Redis server
- Update Redis connection string in
appsettings.json
dotnet ef database update --project DataAccess --startup-project WebAPIUpdate appsettings.json in the WebAPI project:
{
"ConnectionStrings": {
"UnifeDatabase": "Server=localhost;Database=unife_db;Port=5432;User Id=postgres;Password=yourpassword;",
"UnifeObjectStorageConnectionString": "localhost:6379,password=yourredispassword,ssl=false"
}
}{
"Jwt": {
"SecretKey": "your-super-secret-key-that-must-be-at-least-32-characters-long",
"Issuer": "UnifeAPI",
"Audience": "UnifeAPI",
"AccessTokenExpirationMinutes": 15,
"RefreshTokenExpirationDays": 7
}
}{
"EmailSettings": {
"SmtpHost": "smtp.gmail.com",
"SmtpPort": "587",
"Username": "your-email@gmail.com",
"Password": "your-app-password",
"EnableSsl": "true",
"FromAddress": "your-email@gmail.com"
}
}cd WebAPI
dotnet runThe API will be available at:
- HTTP:
http://localhost:5085 - Swagger UI:
http://localhost:5085/swagger
dotnet run --environment Productiondocker build -t unife-api .
docker run -p 5085:80 unife-apiAccess the interactive API documentation at http://localhost:5085/swagger
Most endpoints require JWT authentication. Include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>
POST /api/auth/signin- User sign inPOST /api/auth/signup- User registrationPOST /api/auth/refresh-token- Refresh access tokenPOST /api/auth/logout- User logoutPOST /api/auth/verify-email- Email verificationPOST /api/auth/verify-phone- Phone verification
GET /api/user/profile- Get user profilePUT /api/user/profile- Update user profilePOST /api/user/disable-account- Disable user accountPOST /api/auth/change-password- Change passwordPOST /api/auth/forgot-password- Forgot password
GET /api/universities- Get universities (paginated)POST /api/universities- Create universityPUT /api/universities/{id}- Update universityDELETE /api/universities/{id}- Delete university
GET /health- Application health check
- Admin: System administrators
- Staff: University staff members
- Student: University students
- Role/Permission: Role-based access control
- SecurityEvent: Security audit trail
- University: University information
- Faculty: University faculties
- Department: Academic departments
- Rector: University leadership
- Academician: Academic staff
- AcademicDepartment: Academic department details
- Soft Delete: Entities support soft deletion
- Audit Trail: Comprehensive logging for all entities
- UUID Primary Keys: Using GUIDs for better security
- Optimistic Concurrency: Preventing data conflicts
- Indexing: Optimized for performance
- Access Tokens: Short-lived (15 minutes default)
- Refresh Tokens: Long-lived (7 days default)
- Token Rotation: Automatic token refresh
- Session Management: Redis-based session tracking
-
Admin (UserTypeId: 1)
- Full system access
- User management
- University management
-
Staff (UserTypeId: 2)
- Limited administrative access
- Faculty/department management
-
Student (UserTypeId: 3)
- Personal profile management
- Academic information access
- OTP Verification: Email and phone verification
- Password Security: Bcrypt hashing with salt
- Rate Limiting: Protection against brute force attacks
- Session Security: Secure session management
- CORS Configuration: Controlled cross-origin access
- Structured Logging: JSON-formatted logs
- Multiple Sinks: Console and file outputs
- Log Levels: Configurable per namespace
- Request Logging: HTTP request/response logging
- Performance Tracking: Response time monitoring
- Console: Real-time development logging
- Files:
logs/unife-{date}.log(7-day retention) - Structured Data: Machine-readable format
- Session Storage: User session management
- Cache Storage: Application data caching
- Verification Storage: OTP and verification codes
- Multi-level Caching: Memory + Redis
- Cache Invalidation: Automatic and manual
- Performance Optimization: Reduced database load
- Distributed Caching: Scalable across instances
# Run all tests
dotnet test
# Run specific project tests
dotnet test Tests/Unit.Tests/
dotnet test Tests/Integration.Tests/- Unit Tests: Business logic and utilities
- Integration Tests: API endpoints and database
- Validation Tests: FluentValidation rules
- Security Tests: Authentication and authorization
Create environment-specific appsettings:
appsettings.Development.jsonappsettings.Staging.jsonappsettings.Production.json
# Build image
docker build -t unife-api:latest .
# Run container
docker run -d \
--name unife-api \
-p 80:80 \
-e ASPNETCORE_ENVIRONMENT=Production \
unife-api:latest- Update JWT secret keys
- Configure production database
- Set up Redis cluster
- Configure HTTPS certificates
- Set up monitoring and alerting
- Configure log aggregation
- Set up backup strategies
- Follow Clean Architecture principles
- Write comprehensive unit tests
- Use meaningful commit messages
- Update documentation for new features
- Follow C# coding conventions
- Fork the repository
- Create a feature branch
- Make your changes
- Add/update tests
- Update documentation
- Submit a pull request
- Use C# 12.0 features appropriately
- Follow Microsoft C# coding conventions
- Use meaningful variable and method names
- Add XML documentation for public APIs
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Email: support@unife.com
- Issues: GitHub Issues
- Documentation: Wiki
- Microsoft for .NET 8 and ASP.NET Core
- Entity Framework Core team
- MediatR community
- AutoMapper contributors
- FluentValidation team
- Serilog community
- Redis team
- All open-source contributors
Built with ?? using .NET 8 and Clean Architecture principles