An open API service indexing awesome lists of open source software.

https://github.com/coder7475/school_management_apis


https://github.com/coder7475/school_management_apis

Last synced: 28 days ago
JSON representation

Awesome Lists containing this project

README

          



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

```bash
git clone https://github.com//school-management-api.git
cd school-management-api
pnpm install
```

### 2. Run Database (Postgres with Docker)

```bash
docker compose up -d
```

### 3. Database Management (Drizzle ORM)

Generate schema & migrations:

```bash
pnpm drizzle-kit generate
pnpm drizzle-kit migrate
pnpm drizzle-kit studio
```

Seed database with dummy data:

```bash
pnpm run db:seed
```

### 4. Start Server

```bash
# development
pnpm run start:dev

# production
pnpm run start:prod
```

API will be available at:
๐Ÿ‘‰ `http://localhost:3000/api`

---

## ๐Ÿ—๏ธ Database

### ER Diagram

![ER_diagram](./er_diagram.png)

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

```bash
nest g res --no-spec
```

Example:

```bash
nest g res auth --no-spec
```

### ๐Ÿงช API Testing

- Download and import the [Postman Collection](./Mini%20School%20Management%20API.postman_collection.json) 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](https://school-management-apis.vercel.app/)).
- Auth endpoints require no token, but most others require a valid JWT (see Auth section above).

### ๐Ÿ“– API Documentation

- Interactive Swagger UI available at: [http://localhost:3000/api/docs](http://localhost:3000/api/docs)
- Explore all endpoints, schemas, and try requests directly from the browser.

---

## ๐Ÿ“š Resources

- [NestJS Docs](https://docs.nestjs.com)
- [Drizzle ORM Docs](https://orm.drizzle.team/)
- [PostgreSQL Docs](https://www.postgresql.org/docs/)

---

## ๐Ÿ“œ License

This project is [MIT licensed](./LICENSE).