A clean architecture ASP.NET Core 8 Web API for managing hostel fee tracking, payments, and reminders.
Controllers → Services → Repositories → Entity Framework → SQL Server
The solution follows Clean Architecture with 4 projects:
| Project | Type | Responsibility |
|---|---|---|
HostelManagement.API |
ASP.NET Core 8 Web API | Controllers, Services, Middleware, Mapping |
HostelManagement.Core |
Class Library | Entities, Enums, DTOs, Interfaces |
HostelManagement.Infrastructure |
Class Library | DbContext, Migrations, Repositories, Seed Data |
HostelManagement.Tests |
xUnit Test Project | Unit Tests, Integration Tests |
HostelManagementSystem/
├── HostelManagement.API/
│ ├── Controllers/ # API endpoints
│ │ ├── FeeController.cs
│ │ ├── PaymentController.cs
│ │ ├── ReminderController.cs
│ │ └── StudentController.cs
│ ├── Mappings/ # AutoMapper profiles
│ │ └── MappingProfile.cs
│ ├── Middleware/ # Global exception handling
│ │ └── ExceptionMiddleware.cs
│ ├── Services/ # Business logic layer
│ │ ├── FeeService.cs
│ │ └── StudentService.cs
│ ├── Program.cs
│ └── appsettings.json
├── HostelManagement.Core/
│ ├── DTOs/ # Data Transfer Objects
│ ├── Entities/ # Domain models
│ ├── Enums/ # Enumerations
│ └── Interfaces/ # Contract definitions
├── HostelManagement.Infrastructure/
│ ├── Data/
│ │ ├── HostelDbContext.cs
│ │ └── SeedData.cs
│ ├── Migrations/
│ └── Repositories/ # Data access implementations
└── HostelManagement.Tests/
├── FeeServiceTests.cs
└── FeeRepositoryIntegrationTests.cs
- .NET 8 - Cross-platform framework
- ASP.NET Core 8 Web API - REST API framework
- Entity Framework Core 8 - ORM (Code First)
- SQL Server LocalDB - Database
- AutoMapper - Object mapping
- Swagger / Swashbuckle - API documentation
- xUnit - Unit testing
- Moq - Mocking framework
- FluentAssertions - Test assertions
- Clean Architecture - Separation of concerns
- Repository Pattern - Data abstraction
- Dependency Injection - IoC container
# Clone the repository
git clone <repository-url>
cd HostelManagementSystem
# Restore dependencies
dotnet restore
# Apply migrations (Database will be created automatically)
dotnet ef database update --project HostelManagement.Infrastructure --startup-project HostelManagement.API
# Run the application
dotnet run --project HostelManagement.APIThe API will be available at https://localhost:7254 or http://localhost:5041.
- Provider: SQL Server LocalDB
- Database Name:
HostelManagementDB - Connection String:
Server=(localdb)\MSSQLLocalDB;Database=HostelManagementDB;Trusted_Connection=True;TrustServerCertificate=True;
- Students - Student registration information
- Fees - Fee records linked to students
- Payments - Payment transactions linked to fees
- ReminderLogs - Reminder history linked to students
The application automatically seeds:
- 5 Students
- 10 Fee Records
- 15 Payments
- 3 Reminder Logs
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/fees |
Get all fees |
| GET | /api/fees/{id} |
Get fee by ID |
| POST | /api/fees |
Create a new fee |
| PUT | /api/fees/{id} |
Update a fee |
| DELETE | /api/fees/{id} |
Delete a fee |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/payments |
Record a payment |
| GET | /api/payments/student/{studentId} |
Get payments by student |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/reminders |
Get all reminders |
| POST | /api/reminders/send |
Send a reminder (query: ?studentId=N) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/students |
Get all students |
| POST | /api/students |
Create a new student |
Swagger UI is available at /swagger when running in Development mode.
When a payment is recorded:
RemainingAmount = TotalFee - Sum(All Payments)- If
RemainingAmount == 0→ Status = Paid - If
RemainingAmount > 0and future due date → Status = Partial - If
DueDate < Today→ Status = Overdue
A reminder is automatically generated when a fee becomes overdue and a payment is made.
- Fee amount must be greater than zero
- Payment amount must be greater than zero
- Payment cannot exceed remaining balance
- Student must exist when creating a fee
- Valid payment methods: Cash, BankTransfer, JazzCash, EasyPaisa, CreditCard
# Run all tests
dotnet test
# Run with verbose output
dotnet test --verbosity detailedThe test project includes:
- Unit Tests: Service layer tests with Moq (17 tests)
- Integration Tests: Repository tests with InMemory database (3 tests)