Skip to content

debugwithsushant/StudentManagementSystem

Repository files navigation

πŸŽ“ Student Management System β€” ASP.NET Core Web API

A fully functional Student Management REST API built with ASP.NET Core, Entity Framework Core, JWT Authentication, Serilog Logging, and Swagger UI.


πŸš€ Technologies Used

  • 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)

πŸ“ Project Structure

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

βš™οΈ Setup Instructions

Step 1: Clone Repository

git clone https://github.com/debugwithsushant/StudentManagementSystem.git
cd StudentManagementSystem

Step 2: Configure Database

Open appsettings.json and update connection string:

"ConnectionStrings": {
  "DefaultConnection": "Server=localhost\\SQLEXPRESS;Database=StudentDB;Trusted_Connection=True;TrustServerCertificate=True;"
}

Replace localhost\\SQLEXPRESS with your SQL Server instance name.

Step 3: Install NuGet Packages

dotnet restore

Or install manually via NuGet Package Manager:

Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
Microsoft.AspNetCore.Authentication.JwtBearer
Serilog.AspNetCore
Serilog.Sinks.Console
Serilog.Sinks.File

Step 4: Apply Migrations

Open Package Manager Console and run:

Add-Migration InitialCreate
Update-Database

This will create StudentDB database and Students table automatically.

Step 5: Run the Project

dotnet run

Or press F5 in Visual Studio.

Step 6: Open Swagger UI

https://localhost:7260/swagger

πŸ” JWT Authentication

Login to get Token

POST /api/auth/login

{
  "username": "admin",
  "password": "admin123"
}

Response

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Authorize in Swagger

  1. Click Authorize πŸ”“ button in Swagger UI
  2. Enter token in this format:
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
  1. Click Authorize β†’ Close
  2. All secured endpoints are now accessible βœ…

πŸ“Œ API Endpoints

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 βœ…

πŸ“ Request & Response Examples

GET /api/students

[
  {
    "id": 1,
    "name": "Ram",
    "email": "ram@gmail.com",
    "age": 20,
    "course": "BCA",
    "createdDate": "2026-04-10T13:18:26.45"
  }
]

POST /api/students

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"
}

PUT /api/students/1

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"
}

DELETE /api/students/1

Response β€” 200 OK:

Student with ID 1 deleted successfully...!

πŸ›‘οΈ Global Exception Handling

All unhandled exceptions return structured JSON:

{
  "statusCode": 500,
  "message": "An unexpected error occurred...!",
  "detail": "Exception details here"
}

πŸ“‹ Logging

Serilog is configured for:

  • Console β€” real-time logs while running
  • File β€” saved in Logs/log.txt (daily rolling)

Log levels used:

  • LogInformation β€” normal operations
  • LogWarning β€” not found cases
  • LogError β€” unhandled exceptions

πŸ—„οΈ Database Schema

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
);

πŸ—οΈ Architecture

Request
   ↓
Controller  (handles HTTP requests)
   ↓
Service     (business logic)
   ↓
Repository  (database operations)
   ↓
DbContext   (Entity Framework Core)
   ↓
SQL Server

πŸ‘¨β€πŸ’» Author

Your Full Name


🏁 Conclusion

This project demonstrates a complete Student Management REST API with clean layered architecture, JWT security, global error handling, structured logging, and full Swagger documentation.

About

Student Management System API built with ASP.NET Core, featuring CRUD operations, Entity Framework Core (code-first), SQL Server integration, and Swagger documentation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages