Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Education Platform Backend

Backend API for the Education Platform built with Node.js, Express, TypeScript, and MongoDB.

Features

  • 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

Tech Stack

  • Runtime: Node.js 18+
  • Framework: Express.js
  • Database: MongoDB with Mongoose ODM
  • Language: TypeScript
  • Validation: Zod
  • Authentication: JWT
  • Security: Helmet, CORS, bcryptjs

Quick Start

Prerequisites

  • Node.js 18+
  • MongoDB 4.4+
  • npm or yarn

Installation

  1. Clone and navigate to backend directory:

    cd education-platform/backend
  2. Install dependencies:

    npm install
  3. Set up environment variables: Copy .env file and update values:

    cp .env.example .env
    # Edit .env with your configuration
  4. Start MongoDB: Make sure MongoDB is running on your system.

  5. Run in development mode:

    npm run dev

    The server will start on http://localhost:3001

API Endpoints

Authentication

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - Login user
  • POST /api/auth/logout - Logout user
  • GET /api/auth/me - Get current user info
  • GET /api/auth/verify - Verify token validity

Group Management (SuperAdmin)

  • GET /api/groups - List all groups
  • POST /api/groups - Create new group
  • GET /api/groups/:id - Get group details
  • PUT /api/groups/:id - Update group
  • DELETE /api/groups/:id - Delete group

Group Admin API

All routes require group admin authentication and are prefixed with /api/admin/groups/:groupId

Student Management

  • GET /students - List students with pagination/search
  • POST /students/:studentId/remove - Remove student from group
  • POST /students/:studentId/update-role - Update student role
  • GET /students/:studentId/details - Get student details

Enrollment Requests

  • GET /enrollment-requests - List pending requests
  • POST /enrollment-requests/:requestId/approve - Approve request
  • POST /enrollment-requests/:requestId/reject - Reject request
  • POST /enrollment-requests/bulk-approve - Bulk approve requests

Group Settings

  • GET /settings - Get group settings
  • PUT /settings - Update group settings

Bulk Operations

  • POST /students/bulk-remove - Remove multiple students
  • POST /students/bulk-add - Add multiple students

Statistics

  • GET /stats - Get group statistics

User Roles

  • 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

Development

Available Scripts

  • npm run dev - Start development server with hot reload
  • npm run build - Build for production
  • npm start - Start production server
  • npm test - Run tests
  • npm run lint - Run ESLint

Project Structure

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

Environment Variables

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

Database Seeding

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

Test Users

Role Email 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

Testing

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run specific test file
npm test -- path/to/test.ts

Deployment

  1. Build the application:

    npm run build
  2. Set environment variables for production

  3. Start the server:

    npm start

Security Considerations

  • 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

Contributing

  1. Follow TypeScript strict mode
  2. Use Zod for all input validation
  3. Write tests for new features
  4. Follow conventional commit messages
  5. Run linting before committing

License

ISC

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages