Skip to content

FluxHarsh/Project-CourseSellingBE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

▢️ Running the Project Locally npm install node index.js

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published