A fully functional Student Management REST API built with ASP.NET Core, Entity Framework Core, JWT Authentication, Serilog Logging, and Swagger UI.
- ASP.NET Core 8.0
- Entity Framework Core 8.0
- SQL Server (SQLEXPRESS)
- JWT Authentication
- Serilog (Console + File Logging)
- Swagger UI (with JWT Support)
- Layered Architecture (Controller β Service β Repository)
StudentManagementSystem/
βββ Auth/
β βββ JwtHelper.cs
βββ Controllers/
β βββ AuthController.cs
β βββ StudentsController.cs
βββ Data/
β βββ ApplicationDbContext.cs
βββ Middleware/
β βββ ExceptionMiddleware.cs
βββ Migrations/
βββ Models/
β βββ Student.cs
β βββ StudentDTO.cs
βββ Repository/
β βββ IStudentRepository.cs
β βββ StudentRepository.cs
βββ Services/
β βββ IStudentService.cs
β βββ StudentService.cs
βββ Logs/
β βββ log.txt (auto-generated)
βββ appsettings.json
βββ Program.cs
git clone https://github.com/debugwithsushant/StudentManagementSystem.git
cd StudentManagementSystemOpen appsettings.json and update connection string:
"ConnectionStrings": {
"DefaultConnection": "Server=localhost\\SQLEXPRESS;Database=StudentDB;Trusted_Connection=True;TrustServerCertificate=True;"
}Replace
localhost\\SQLEXPRESSwith your SQL Server instance name.
dotnet restoreOr install manually via NuGet Package Manager:
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Microsoft.AspNetCore.Authentication.JwtBearer
Serilog.AspNetCore
Serilog.Sinks.Console
Serilog.Sinks.File
Open Package Manager Console and run:
Add-Migration InitialCreate
Update-Database
This will create StudentDB database and Students table automatically.
dotnet runOr press F5 in Visual Studio.
https://localhost:7260/swagger
POST /api/auth/login
{
"username": "admin",
"password": "admin123"
}{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}- Click Authorize π button in Swagger UI
- Enter token in this format:
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
- Click Authorize β Close
- All secured endpoints are now accessible β
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /api/auth/login |
Get JWT Token | β |
| GET | /api/students |
Get all students | β |
| GET | /api/students/{id} |
Get student by ID | β |
| POST | /api/students |
Add new student | β |
| PUT | /api/students/{id} |
Update student | β |
| DELETE | /api/students/{id} |
Delete student | β |
[
{
"id": 1,
"name": "Ram",
"email": "ram@gmail.com",
"age": 20,
"course": "BCA",
"createdDate": "2026-04-10T13:18:26.45"
}
]Request:
{
"name": "Shyam",
"email": "shyam@gmail.com",
"age": 21,
"course": "BCS"
}Response β 201 Created:
{
"id": 2,
"name": "Shyam",
"email": "shyam@gmail.com",
"age": 21,
"course": "BCS",
"createdDate": "2026-04-10T13:19:17.63"
}Request:
{
"name": "Sita",
"email": "sita@gmail.com",
"age": 25,
"course": "B.Com"
}Response β 200 OK:
{
"id": 1,
"name": "Sita",
"email": "sita@gmail.com",
"age": 25,
"course": "B.Com",
"createdDate": "2026-04-10T13:18:26.45"
}Response β 200 OK:
Student with ID 1 deleted successfully...!
All unhandled exceptions return structured JSON:
{
"statusCode": 500,
"message": "An unexpected error occurred...!",
"detail": "Exception details here"
}Serilog is configured for:
- Console β real-time logs while running
- File β saved in
Logs/log.txt(daily rolling)
Log levels used:
LogInformationβ normal operationsLogWarningβ not found casesLogErrorβ unhandled exceptions
CREATE TABLE Students (
Id INT PRIMARY KEY IDENTITY(1,1),
Name NVARCHAR(MAX) NOT NULL,
Email NVARCHAR(MAX) NOT NULL,
Age INT NOT NULL,
Course NVARCHAR(MAX) NOT NULL,
CreatedDate DATETIME2 NOT NULL
);Request
β
Controller (handles HTTP requests)
β
Service (business logic)
β
Repository (database operations)
β
DbContext (Entity Framework Core)
β
SQL Server
Your Full Name
- GitHub: https://github.com/debugwithsushant
- Email: sushantpawar1232@gmail.com
This project demonstrates a complete Student Management REST API with clean layered architecture, JWT security, global error handling, structured logging, and full Swagger documentation.