Skip to content

Latest commit

 

History

History
117 lines (86 loc) · 2.84 KB

File metadata and controls

117 lines (86 loc) · 2.84 KB

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.