Skip to content

coder7475/school_management_apis

Repository files navigation

Nest Logo

📘 School Management API

A modular Node.js REST API built with NestJS, Drizzle ORM, and PostgreSQL.

NPM Version License Discord Follow NestJS on Twitter


📖 Description

This project implements a Mini School Management API with:

  • Authentication & Authorization using JWT + role-based guards (admin, teacher, student)
  • Students & Classes Management with enrollments
  • PostgreSQL + Drizzle ORM for schema & migrations
  • Validation using class-validator DTOs
  • Secure Cookies for access/refresh tokens
  • Optional Docker setup for database

🚀 Getting Started

1. Clone & Install

git clone https://github.com/<your-repo>/school-management-api.git
cd school-management-api
pnpm install

2. Run Database (Postgres with Docker)

docker compose up -d

3. Database Management (Drizzle ORM)

Generate schema & migrations:

pnpm drizzle-kit generate
pnpm drizzle-kit migrate
pnpm drizzle-kit studio

Seed database with dummy data:

pnpm run db:seed

4. Start Server

# development
pnpm run start:dev

# production
pnpm run start:prod

API will be available at: 👉 http://localhost:3000/api


🏗️ Database

ER Diagram

ER_diagram

  • users – Authentication + roles (admin, teacher, student)
  • students – Student records
  • classes – Class records

⚡ API Endpoints (Highlights)

Auth Module

  • POST /auth/signup – Register user (admin/teacher/student)
  • POST /auth/login – Login and receive JWT tokens
  • POST /auth/refresh – Refresh access token
  • POST /auth/logout – Logout and clear cookies
  • GET /auth/me – Get logged-in user

Student Module

  • POST /students – Create student (admin only)
  • GET /students – List students (admin/teacher)
  • GET /students/:id – Get student details

Class Module

  • POST /classes – Create class (admin only)
  • POST /classes/:id/enroll – Enroll student in class (admin/teacher)
  • GET /classes/:id/students – List students in a class (admin/teacher)

🔒 Authentication & Security

  • JWT Access Token (15 min expiry) stored in httpOnly cookie
  • Refresh Token (7 days expiry) stored in httpOnly cookie
  • Role-based guards restrict endpoints to admin, teacher, or student
  • Password hashing with bcrypt (saltRounds = 10)

🛠️ Development Tools

Generate Module/Resource (no tests)

nest g res <module_name> --no-spec

Example:

nest g res auth --no-spec

🧪 API Testing

  • Download and import the Postman Collection to try out all endpoints quickly.
  • Make sure to set the baseUrl environment variable in Postman to http://localhost:3000/api (or your deployed URL).
  • Auth endpoints require no token, but most others require a valid JWT (see Auth section above).

📖 API Documentation


📚 Resources


📜 License

This project is MIT licensed.