A RESTful backend API for a full-stack e-commerce application built with Node.js, Express.js, MongoDB, and Mongoose.
The API handles authentication, users, products, categories, cart, wishlist, orders, image management, and administrative operations.
- 🔐 User authentication and authorization
- 🔑 JWT access and refresh tokens
- 🍪 HTTP-only cookies for authentication
- 👤 User management
- 👑 Role-based authorization and admin access
- 🛍️ Product management
- 📂 Category management
- 🛒 Shopping cart
- ❤️ Wishlist
- 📦 Order creation and management
- 📊 Dashboard data and statistics
- 🖼️ Image management with Cloudinary
- 🔒 Password hashing with bcrypt
- 🌐 RESTful API architecture
- 🛡️ CORS and cookie handling
- Node.js
- Express.js
- MongoDB
- Mongoose
- JWT
- bcrypt
- Cookie Parser
- CORS
- Cloudinary
ecomerce-backend/
│
├── config/
│ └── ...
│
├── controllers/
│ └── ...
│
├── middleware/
│ └── ...
│
├── models/
│ ├── User.js
│ ├── Product.js
│ ├── Category.js
│ ├── Cart.js
│ ├── Order.js
│ └── Wishlist.js
│
├── routes/
│ ├── auth.routes.js
│ ├── users.routes.js
│ ├── products.routes.js
│ ├── categories.routes.js
│ ├── cart.routes.js
│ ├── wishlist.routes.js
│ ├── orders.routes.js
│ ├── admin.routes.js
│ └── dashboard.routes.js
│
├── server.js
├── package.json
└── ...
The API uses JWT-based authentication with access and refresh tokens.
Authentication includes:
- Access tokens
- Refresh tokens
- HTTP-only cookies
- Password hashing with bcrypt
- Protected routes
- Role-based authorization
- Admin access control
Administrative routes are protected and accessible only to authorized users.
The backend provides REST API endpoints for:
| Module | Description |
|---|---|
| Authentication | User registration, login, logout and token handling |
| Users | User account and profile management |
| Products | Product management |
| Categories | Category management |
| Cart | Shopping cart operations |
| Wishlist | Wishlist operations |
| Orders | Order creation and management |
| Admin | Administrative operations |
| Dashboard | Dashboard statistics and data |
Product images are managed using Cloudinary.
Cloudinary provides cloud-based storage and management for product images used by the e-commerce application.
The application uses MongoDB as its database with Mongoose for data modeling and database operations.
Main models include:
UserProductCategoryCartOrderWishlist
git clone https://github.com/SedjaiRadja/ecomerce-backend.gitcd ecomerce-backendnpm installCreate a .env file in the root directory.
Add the required environment variables used by the application, including your MongoDB, JWT, and Cloudinary configuration.
Example:
PORT=5000
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret
JWT_REFRESH_SECRET=your_refresh_token_secret
CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
⚠️ Never commit your.envfile or expose your secret keys publicly.
npm run devThe API will be available at:
http://localhost:5000
This backend is part of a complete full-stack e-commerce application.
- Frontend: Next.js customer-facing application
- Backend: Node.js / Express REST API
- Dashboard: Next.js administration dashboard
Completed
The backend provides the core API and business logic required by the e-commerce frontend and administration dashboard.
Radja Sedjai
Frontend / Full-Stack Developer
GitHub: @SedjaiRadja
⭐ If you find this project interesting, feel free to explore the repository.