A robust and scalable e-commerce backend API built with Node.js, Express.js, and MongoDB. FastShop provides a complete backend solution for modern e-commerce applications with user authentication, product management, file uploads, and more.
- User Authentication - Secure user registration and login with Passport.js
- Product Management - CRUD operations for products with detailed schemas
- Image Upload - Cloudinary integration for efficient image storage
- Review System - User reviews and ratings for products
- Security - Built-in authentication middleware and session management
- Template Engine - EJS templates for server-side rendering
- RESTful API - Clean and organized API endpoints
Data Validation - Joi schema validation for request data
| Technology | Purpose | Version |
|---|---|---|
| Runtime Environment | Latest | |
| Web Framework | 5.1.0 | |
| Database | 8.18.0 | |
| ODM | 8.18.0 | |
| Image Storage | 1.41.3 | |
| Authentication | 0.7.0 | |
| Template Engine | 3.1.10 |
FastShop/Backend/
βββ π api/
β βββ π middleware/ # Custom middleware functions
β β βββ auth.middleware.js # Authentication middleware
β β βββ index.middleware.js # Middleware setup
β βββ π routes/ # API route definitions
β βββ home.routes.js # Home page routes
β βββ product.routes.js # Product CRUD routes
βββ π config/
β βββ π conn/
β β βββ db.js # Database connection
β βββ cloudinary.config.js # Cloudinary configuration
βββ π init/ # Database initialization
β βββ data.js # Sample data
β βββ initData.js # Data seeding script
βββ π models/ # MongoDB schemas
β βββ product.model.js # Product data model
β βββ user.model.js # User data model
βββ π utils/ # Utility functions
βββ π views/ # EJS templates
β βββ π components/ # Reusable components
β βββ π template/ # Page templates
βββ π server.js # Application entry point
βββ π package.json # Dependencies and scripts
-
Clone the repository
git clone <repository-url> cd FastShop/Backend
-
Install dependencies
pnpm install
-
Environment Configuration
Create a
.envfile in the root directory:# Server Configuration PORT=3000 # Database MONGODB_URI=mongodb://localhost:27017/fastshop # Session Secret SESSION_SECRET=your-super-secret-session-key # Cloudinary Configuration CLOUDINARY_CLOUD_NAME=your-cloud-name CLOUDINARY_API_KEY=your-api-key CLOUDINARY_API_SECRET=your-api-secret
-
Start the application
# Development mode pnpm run dev # Production mode pnpm start
GET /- HomepageGET /signup- User registration pageGET /login- User login pagePOST /signup- Register new userPOST /login- Authenticate user
GET /products- Get all productsGET /products/:id- Get product by IDPOST /products- Create new product (Auth required)PUT /products/:id- Update product (Auth required)DELETE /products/:id- Delete product (Auth required)POST /products/:id/reviews- Add product review (Auth required)
{
"success": true,
"data": {
"product": {
"id": "507f1f77bcf86cd799439011",
"title": "Sample Product",
"description": "Product description",
"price": 299.99,
"category": "Electronics",
"images": ["image1.jpg", "image2.jpg"],
"reviews": [],
"rating": 4.5,
"stock": 50
}
},
"message": "Product retrieved successfully"
}{
username: String,
email: String,
password: String, // Hashed
createdAt: Date,
isAdmin: Boolean
}{
title: String,
description: String,
price: Number,
category: String,
brand: String,
stock: Number,
images: [{ url: String, public_id: String }],
reviews: [ReviewSchema],
rating: Number,
dimensions: { width: Number, height: Number, depth: Number },
owner: ObjectId // Reference to User
}# Start development server with auto-reload
pnpm run dev
# Start production server
pnpm start
# Run tests (when available)
pnpm test- Use ES6+ features
- Follow RESTful API conventions
- Implement proper error handling
- Use async/await for asynchronous operations
- Validate all inputs with Joi
- Maintain consistent naming conventions
NODE_ENV=production
PORT=3000
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/fastshop
SESSION_SECRET=your-production-session-secret
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secretWe welcome contributions! Please follow these steps:
- π΄ Fork the repository
- πΏ Create a feature branch (
git checkout -b feature/AmazingFeature) - πΎ Commit your changes (
git commit -m 'Add some AmazingFeature') - π€ Push to the branch (
git push origin feature/AmazingFeature) - π Open a Pull Request
- Write clear commit messages
- Add tests for new features
- Update documentation as needed
- Follow the existing code style
- Ensure all tests pass
- Express.js team for the amazing framework
- MongoDB team for the flexible database
- Cloudinary for seamless image management
- Passport.js for authentication solutions
- All open source contributors
β Star this repository if you find it helpful!
Made with β€οΈ by the Onkar sathe