Course Selling Backend API
A backend-only course selling application built using Node.js, Express, and MongoDB. This project focuses on backend architecture, authentication, authorization, database design, and clean route structuring. There is no frontend included yet β the backend is designed to work with any client (web or mobile).
π Features
Authentication & Authorization Separate authentication flows for Users and Admins Secure password hashing using bcrypt JWT-based authentication Different JWT secrets for users and admins Custom middleware for role-based access control
User Capabilities
Sign up and sign in Browse available courses (public) Purchase courses (authenticated) View purchased courses
Admin Capabilities
Sign up and sign in Create courses Update existing courses View all courses created by the admin
π§ High-Level System Flow
User/Admin signs up β password is hashed and stored User/Admin signs in β JWT token is issued Token is sent in request headers for protected routes Middleware verifies token and attaches user/admin ID to the request Routes allow or restrict access based on role
π Project Structure . βββ index.js # Application entry point βββ db.js # Database connection, schemas & models βββ config.js # JWT secrets configuration βββ routes/ β βββ user.js # User-related routes β βββ admin.js # Admin-related routes β βββ course.js # Course & purchase routes βββ middleware/ β βββ user.js # User authentication middleware β βββ admin.js # Admin authentication middleware βββ .env # Environment variables (ignored) βββ .env.example # Sample env file βββ package.json βββ .gitignore
𧬠Database Design (MongoDB + Mongoose)
User Schema
email (unique) password (hashed) firstName lastName
Admin Schema
email (unique) password (hashed) firstName lastName
Course Schema
title description price imageUrl creatorId (Admin reference)
Purchase Schema
userId (User reference) courseId (Course reference)
π Environment Variables
Create a .env file in the root directory:
MONGO_URL=your_mongodb_connection_string JWT_USER_PASSWORD=your_user_jwt_secret JWT_ADMIN_PASSWORD=your_admin_jwt_secret
The server will start on the configured port after a successful MongoDB connection.
π Tech Stack
Node.js Express.js MongoDB Mongoose bcrypt jsonwebtoken dotenv
π Notes
This project is backend-only No frontend is included yet Designed to be easily extendable with a frontend or mobile application
π€ Feedback
Feedback and suggestions around backend design, structure, or API flow are welcome.