A comprehensive online learning platform for managing courses, user enrollment, and educational content with role-based access control.
- Description
- Features
- Technologies Used
- Setup Instructions
- Default Users
- API Routes
- Scripts
- File Structure
- Database Schema
- Contributing
- License
A Node.js application for managing courses with user authentication and enrollment features, built with Express.js and a database abstraction layer that supports easy ORM switching.
- JWT-based authentication for APIs
- Role-based access (public, registered, admin)
- Course management (CRUD operations)
- Course enrollment system
- Admin dashboard
- User profiles with profile picture upload
- Database abstraction layer (easy ORM switching)
- Security middleware: helmet, express-rate-limit
- Multi-environment support (MySQL for dev, PostgreSQL for prod)
- Backend: Node.js, Express.js
- Database: MySQL (development), PostgreSQL (production) with Sequelize ORM
- Architecture: Database abstraction layer
- Authentication: bcrypt, express-session, jsonwebtoken (JWT)
- Security: helmet, express-rate-limit
- View Engine: EJS
- Validation: express-validator
- Deployment: Vercel (serverless)
-
Clone the repository
git clone https://github.com/dracudev/learnhub-app cd learnhub-app -
Install dependencies
npm install
-
Set up environment variables Create a
.envfile in the root directory:# Development (MySQL) PORT=3000 DB_HOST=localhost DB_USER=root DB_PASS=your_mysql_password DB_NAME=course_management DB_PORT=3306 SESSION_SECRET=your_secret_key_here NODE_ENV=development # Production (PostgreSQL) POSTGRES_URL=your_postgresql_connection_string
-
Set up the database
# Run migrations to create tables npm run migrate # Seed the database with initial data npm run seed
-
Start the development server
npm run dev
After seeding, you can log in with:
Admin User:
- Email: admin@admin.com
- Password: admin
Regular User:
- Email: user@user.com
- Password: user
GET /auth/signup- Sign up formPOST /auth/signup- Create new userGET /auth/login- Login formPOST /auth/login- Authenticate userPOST /auth/logout- Logout user
GET /courses- List all coursesGET /courses/:id- Course detailsGET /admin/dashboard- Admin dashboard (admin only)GET /courses/create- Create course form (admin only)POST /courses/create- Create new course (admin only)GET /courses/:id/edit- Edit course form (admin only)POST /courses/:id/edit- Update course (admin only)POST /courses/:id/delete- Delete course (admin only)
GET /user/profile- User profile and enrolled coursesPOST /user/enroll/:courseId- Enroll in coursePOST /user/unenroll/:courseId- Unenroll from course
npm start- Start production server (with deployment script)npm run dev- Start development server with nodemonnpm run migrate- Run database migrationsnpm run seed- Run all seedersnpm run neon:setup- Set up production database (PostgreSQL)npm run build- Install dependencies
├── app.js # Main application entry point
├── package.json # Dependencies and scripts
├── vercel.json # Deployment configuration
├── api/
│ └── index.js # Serverless function entry
├── database/
│ ├── config/ # Database configuration
│ ├── migrations/ # Database migrations
│ ├── schemas/ # Database schemas
│ └── seeders/ # Sample data
├── public/
│ ├── images/ # Static images
│ └── styles/ # CSS files
└── src/
├── server.js # Express server
├── controllers/ # Route handlers
├── middleware/ # Custom middleware
├── models/ # Database models
├── routes/ # Route definitions
└── views/ # EJS templates
| Column | Type | Details |
|---|---|---|
| id | INTEGER | Primary Key |
| name | STRING | |
| STRING | Unique | |
| password | STRING | Hashed |
| role | STRING | public, registered, admin |
| profile_picture | STRING | |
| created_at | DATETIME |
| Column | Type | Details |
|---|---|---|
| id | INTEGER | Primary Key |
| title | STRING | |
| description | TEXT | |
| category | STRING | |
| visibility | STRING | public, private |
| created_at | DATETIME |
| Column | Type | Details |
|---|---|---|
| id | INTEGER | Primary Key |
| user_id | INTEGER | Foreign Key (Users) |
| course_id | INTEGER | Foreign Key (Courses) |
| enrollment_date | DATETIME | |
| (user_id, course_id) | UNIQUE | Composite unique constraint |
This project is licensed under the ISC License - see the LICENSE file for details.
