Backend API for the Education Platform built with Node.js, Express, TypeScript, and MongoDB.
- Authentication: JWT-based authentication with role-based access control
- Group Management: Platform-wide group administration for SuperAdmins
- Group Admin API: Student management, enrollment requests, and settings for group admins
- User Enrollment: Self-enrollment and approval workflows
- Security: Rate limiting, input validation with Zod, password hashing
- Runtime: Node.js 18+
- Framework: Express.js
- Database: MongoDB with Mongoose ODM
- Language: TypeScript
- Validation: Zod
- Authentication: JWT
- Security: Helmet, CORS, bcryptjs
- Node.js 18+
- MongoDB 4.4+
- npm or yarn
-
Clone and navigate to backend directory:
cd education-platform/backend -
Install dependencies:
npm install
-
Set up environment variables: Copy
.envfile and update values:cp .env.example .env # Edit .env with your configuration -
Start MongoDB: Make sure MongoDB is running on your system.
-
Run in development mode:
npm run dev
The server will start on
http://localhost:3001
POST /api/auth/register- Register new userPOST /api/auth/login- Login userPOST /api/auth/logout- Logout userGET /api/auth/me- Get current user infoGET /api/auth/verify- Verify token validity
GET /api/groups- List all groupsPOST /api/groups- Create new groupGET /api/groups/:id- Get group detailsPUT /api/groups/:id- Update groupDELETE /api/groups/:id- Delete group
All routes require group admin authentication and are prefixed with /api/admin/groups/:groupId
GET /students- List students with pagination/searchPOST /students/:studentId/remove- Remove student from groupPOST /students/:studentId/update-role- Update student roleGET /students/:studentId/details- Get student details
GET /enrollment-requests- List pending requestsPOST /enrollment-requests/:requestId/approve- Approve requestPOST /enrollment-requests/:requestId/reject- Reject requestPOST /enrollment-requests/bulk-approve- Bulk approve requests
GET /settings- Get group settingsPUT /settings- Update group settings
POST /students/bulk-remove- Remove multiple studentsPOST /students/bulk-add- Add multiple students
GET /stats- Get group statistics
- student: Can view courses, enroll in groups (if allowed)
- instructor: Can manage their group's students and settings
- admin: Same as instructor, plus additional permissions
- superadmin: Platform-wide administration, can manage all groups
npm run dev- Start development server with hot reloadnpm run build- Build for productionnpm start- Start production servernpm test- Run testsnpm run lint- Run ESLint
backend/
├── src/
│ ├── index.ts # Main application entry
│ ├── models/ # Mongoose models
│ │ ├── User.ts # User model
│ │ ├── Group.ts # Group model
│ │ ├── Institution.ts # Institution model
│ │ └── EnrollmentRequest.ts
│ ├── routes/ # API routes
│ │ ├── auth.ts # Authentication routes
│ │ └── group-admin.ts # Group admin routes
│ ├── middleware/ # Express middleware
│ │ └── auth.ts # Authentication middleware
│ └── utils/ # Utility functions
├── package.json
├── tsconfig.json
└── .env
| Variable | Description | Default |
|---|---|---|
MONGODB_URI |
MongoDB connection string | (required) |
DATABASE_NAME |
Database name | education_dev |
JWT_SECRET |
JWT signing secret | (required) |
PORT |
Server port | 3001 |
NODE_ENV |
Environment | development |
CORS_ORIGIN |
Allowed CORS origin | http://localhost:5173 |
The project includes a seed script to populate the database with test users. This is automatically run by dev.sh, or you can run it manually:
npm run seed| Role | Password | |
|---|---|---|
| SuperAdmin | superadmin@test.com |
Test1234 |
| Admin | admin1@test.com |
Test1234 |
| Instructor (Director) | director@ies-example.com |
Test1234 |
| Instructor | profesor.mates@ies-example.com |
Test1234 |
| Student | alumno1@ies-example.com |
Test1234 |
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run specific test file
npm test -- path/to/test.ts-
Build the application:
npm run build
-
Set environment variables for production
-
Start the server:
npm start
- JWT tokens expire in 7 days
- Passwords are hashed with bcryptjs (12 rounds)
- Rate limiting is applied to bulk operations
- Input validation with Zod schemas
- CORS configured for specific origins
- Helmet for security headers
- Follow TypeScript strict mode
- Use Zod for all input validation
- Write tests for new features
- Follow conventional commit messages
- Run linting before committing
ISC