Skip to content

School Management System API built with NestJS, Prisma & PostgreSQL. Features JWT authentication, role-based access control, and student/class management with comprehensive Swagger documentation.

Notifications You must be signed in to change notification settings

AMFahim/student_management_system

Repository files navigation

Student Management System

A comprehensive REST API for managing students, classes, and user authentication in educational institutions. Built with NestJS, TypeScript, and PostgreSQL.

Overview

This system provides a robust backend solution for educational institutions to manage student enrollment, class organization, and user authentication with role-based access control.

Features

Authentication & Authorization

  • JWT-based authentication with access and refresh tokens
  • Role-based access control (Admin, Teacher, Student)
  • Secure password hashing with bcrypt
  • Protected API endpoints with guard decorators

User Management

  • User registration and login
  • Three user roles: Admin, Teacher, Student
  • Automatic student record creation for student users
  • User profile management

Student Management

  • Create, retrieve, and manage student records
  • Paginated student listing
  • Student enrollment in classes
  • Age and personal information tracking

Class Management

  • Create and manage classes with name and section
  • Unique class identification system
  • Student enrollment tracking
  • Class-wise student listing

Technology Stack

  • Framework: NestJS 11.x
  • Language: TypeScript
  • Database: PostgreSQL
  • ORM: Prisma 6.x
  • Authentication: JWT with Passport
  • Password Hashing: bcryptjs
  • Documentation: Swagger/OpenAPI
  • Validation: class-validator & class-transformer

Prerequisites

  • Node.js (v18 or higher)
  • PostgreSQL database
  • npm or yarn package manager

Installation

1. Clone the repository

git clone https://github.com/AMFahim/student_management_system.git
cd student_management_system

2. Install dependencies

npm install
# or
yarn install

3. Environment Setup

Create a .env file in the root directory:

# Database
DATABASE_URL="postgresql://username:password@localhost:5432/database_name"

# JWT Configuration
JWT_SECRET="your-super-secret-jwt-key"
JWT_REFRESH_SECRET="your-super-secret-refresh-key"
JWT_EXPIRATION="15m"
JWT_REFRESH_EXPIRATION="7d"

# Application
PORT=5000

4. Database Setup

# Generate Prisma client
npx prisma generate

# Run database migrations
npx prisma migrate dev

# Seed the database (optional)
npx prisma db seed

Development

Running the application

# Development mode with hot reload
npm run start:dev

# Production mode
npm run start:prod

Docker Development (Optional)

# Start PostgreSQL with Docker Compose
docker compose up -d

# Use local environment variables
cp .env.local .env

# Run migrations
npx prisma migrate dev

# Start the application
npm run start:dev

API Documentation

Once the application is running, visit:

  • Swagger UI: http://localhost:5000/docs
  • API Base URL: http://localhost:5000

Authentication

To access protected endpoints:

  1. Register or login via /auth/signup or /auth/login
  2. Copy the access_token from the response
  3. In Swagger UI, click "Authorize" and enter: Bearer <access_token>

API Endpoints

Authentication

  • POST /auth/signup - User registration
  • POST /auth/login - User login

Students

  • GET /students - List all students (paginated)
  • GET /students/:id - Get student by ID
  • POST /students - Create new student (Admin only)

Classes

  • GET /classes - List all classes
  • POST /classes - Create new class (Admin only)
  • POST /classes/:id/enroll - Enroll student in class
  • GET /classes/:id/students - Get students in class

Database Schema

Users Table

  • id (String, Primary Key)
  • name (String)
  • email (String, Unique)
  • passwordHash (String)
  • role (Enum: ADMIN, TEACHER, STUDENT)
  • createdAt (DateTime)
  • updatedAt (DateTime)

Students Table

  • id (String, Primary Key)
  • name (String)
  • age (Integer)
  • classId (String, Optional)
  • userId (String, Unique Foreign Key)

Classes Table

  • id (String, Primary Key)
  • name (String)
  • section (String)
  • Unique constraint on (name, section)

About

School Management System API built with NestJS, Prisma & PostgreSQL. Features JWT authentication, role-based access control, and student/class management with comprehensive Swagger documentation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published