A Node.js REST API for managing schools, levels, classes, students, teachers, and courses.
- Express.js REST API
- MongoDB database with Mongoose
- JWT Authentication
- Request validation with Joi
- Swagger UI documentation
- Comprehensive CRUD operations
- Logging with Morgan and Debug
- Node.js (v14 or higher)
- MongoDB (local or remote instance)
- npm
- Install dependencies:
npm install-
Configure environment variables (optional):
- Copy
.env.exampleto.envand update values - Or use
config/default.jsonfor configuration
- Copy
-
Start MongoDB:
- Make sure MongoDB is running on
mongodb://localhost:27017 - Or update the connection string in
config/default.json
- Make sure MongoDB is running on
-
Create admin user (optional but recommended):
npm run seedThis creates a default admin user:
- Username:
admin - Password:
admin123 - Email:
admin@school.com
- Start the server:
# Development mode (with nodemon)
npm run dev
# Production mode
npm startThe server will start on http://localhost:3000
Swagger UI is available at: http://localhost:3000/api-docs
POST /api/v1/auth/login- User loginPOST /api/v1/auth/logout- User logout
GET /api/v1/schools- Get all schoolsGET /api/v1/schools/:id- Get school by IDPOST /api/v1/schools- Create schoolPUT /api/v1/schools/:id- Update schoolDELETE /api/v1/schools/:id- Delete school
GET /api/v1/levels- Get all levels (Senior 4, Senior 5, Senior 6)GET /api/v1/levels/:id- Get level by IDPOST /api/v1/levels- Create levelPUT /api/v1/levels/:id- Update levelDELETE /api/v1/levels/:id- Delete level
GET /api/v1/classes- Get all classesGET /api/v1/classes/:id- Get class by IDPOST /api/v1/classes- Create classPUT /api/v1/classes/:id- Update classDELETE /api/v1/classes/:id- Delete class
GET /api/v1/students- Get all studentsGET /api/v1/students/:id- Get student by IDPOST /api/v1/students- Create studentPUT /api/v1/students/:id- Update studentDELETE /api/v1/students/:id- Delete student
GET /api/v1/teachers- Get all teachersGET /api/v1/teachers/:id- Get teacher by IDPOST /api/v1/teachers- Create teacherPUT /api/v1/teachers/:id- Update teacherDELETE /api/v1/teachers/:id- Delete teacher
GET /api/v1/courses- Get all coursesGET /api/v1/courses/:id- Get course by IDPOST /api/v1/courses- Create coursePUT /api/v1/courses/:id- Update courseDELETE /api/v1/courses/:id- Delete course
Most endpoints require JWT authentication. Include the token in the Authorization header:
Authorization: Bearer <your-token>
Or use the x-auth-token header:
x-auth-token: <your-token>
curl -X POST http://localhost:3000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": "password123"}'curl -X POST http://localhost:3000/api/v1/schools \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-token>" \
-d '{
"name": "Example High School",
"address": "123 Main St",
"email": "info@example.com",
"principalName": "John Doe"
}'demo-mis/
├── config/
│ ├── database.js
│ ├── swagger.js
│ ├── default.json
│ └── development.json
├── controllers/
│ ├── authController.js
│ ├── schoolController.js
│ ├── levelController.js
│ ├── classController.js
│ ├── studentController.js
│ ├── teacherController.js
│ └── courseController.js
├── middleware/
│ ├── auth.js
│ ├── errorHandler.js
│ └── validate.js
├── models/
│ ├── User.js
│ ├── School.js
│ ├── Level.js
│ ├── Class.js
│ ├── Student.js
│ ├── Teacher.js
│ └── Course.js
├── routes/
│ ├── index.js
│ ├── authRoutes.js
│ ├── schoolRoutes.js
│ ├── levelRoutes.js
│ ├── classRoutes.js
│ ├── studentRoutes.js
│ ├── teacherRoutes.js
│ └── courseRoutes.js
├── validations/
│ ├── authValidation.js
│ ├── schoolValidation.js
│ ├── levelValidation.js
│ ├── classValidation.js
│ ├── studentValidation.js
│ ├── teacherValidation.js
│ └── courseValidation.js
├── server.js
└── package.json
Edit config/default.json to customize:
- Server port
- MongoDB connection URI
- JWT secret and expiration
- Swagger host settings
ISC