A comprehensive REST API for managing students, classes, and user authentication in educational institutions. Built with NestJS, TypeScript, and PostgreSQL.
This system provides a robust backend solution for educational institutions to manage student enrollment, class organization, and user authentication with role-based access control.
- 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 registration and login
- Three user roles: Admin, Teacher, Student
- Automatic student record creation for student users
- User profile management
- Create, retrieve, and manage student records
- Paginated student listing
- Student enrollment in classes
- Age and personal information tracking
- Create and manage classes with name and section
- Unique class identification system
- Student enrollment tracking
- Class-wise student listing
- 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
- Node.js (v18 or higher)
- PostgreSQL database
- npm or yarn package manager
git clone https://github.com/AMFahim/student_management_system.git
cd student_management_systemnpm install
# or
yarn installCreate 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# Generate Prisma client
npx prisma generate
# Run database migrations
npx prisma migrate dev
# Seed the database (optional)
npx prisma db seed# Development mode with hot reload
npm run start:dev
# Production mode
npm run start:prod# 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:devOnce the application is running, visit:
- Swagger UI:
http://localhost:5000/docs - API Base URL:
http://localhost:5000
To access protected endpoints:
- Register or login via
/auth/signupor/auth/login - Copy the
access_tokenfrom the response - In Swagger UI, click "Authorize" and enter:
Bearer <access_token>
POST /auth/signup- User registrationPOST /auth/login- User login
GET /students- List all students (paginated)GET /students/:id- Get student by IDPOST /students- Create new student (Admin only)
GET /classes- List all classesPOST /classes- Create new class (Admin only)POST /classes/:id/enroll- Enroll student in classGET /classes/:id/students- Get students in class
id(String, Primary Key)name(String)email(String, Unique)passwordHash(String)role(Enum: ADMIN, TEACHER, STUDENT)createdAt(DateTime)updatedAt(DateTime)
id(String, Primary Key)name(String)age(Integer)classId(String, Optional)userId(String, Unique Foreign Key)
id(String, Primary Key)name(String)section(String)- Unique constraint on (name, section)