Skip to content

Onkarsathe007/FastShop

Repository files navigation

πŸ›οΈ FastShop Backend

Node.js Express.js MongoDB Cloudinary License: MIT

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.

✨ Features

  • 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

πŸš€ Tech Stack

Technology Purpose Version
Node.js Runtime Environment Latest
Express Web Framework 5.1.0
MongoDB Database 8.18.0
Mongoose ODM 8.18.0
Cloudinary Image Storage 1.41.3
Passport Authentication 0.7.0
EJS Template Engine 3.1.10

πŸ“ Project Structure

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

πŸ› οΈ Installation

Prerequisites

  • Node.js Node.js (v14 or higher)
  • MongoDB MongoDB instance
  • pnpm pnpm package manager

Setup Steps

  1. Clone the repository

    git clone <repository-url>
    cd FastShop/Backend
  2. Install dependencies

    pnpm install
  3. Environment Configuration

    Create a .env file 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
  4. Start the application

    # Development mode
    pnpm run dev
    
    # Production mode
    pnpm start

πŸ“š API Documentation

🏠 Home Routes

  • GET / - Homepage
  • GET /signup - User registration page
  • GET /login - User login page
  • POST /signup - Register new user
  • POST /login - Authenticate user

πŸ“¦ Product Routes

  • GET /products - Get all products
  • GET /products/:id - Get product by ID
  • POST /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)

πŸ“„ Response Format

{
  "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"
}

πŸ—„οΈ Database Schema

User Model

{
  username: String,
  email: String,
  password: String, // Hashed
  createdAt: Date,
  isAdmin: Boolean
}

Product Model

{
  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
}

πŸ”§ Development

Available Scripts

# Start development server with auto-reload
pnpm run dev

# Start production server
pnpm start

# Run tests (when available)
pnpm test

Code Style Guidelines

  • 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

πŸš€ Deployment

Environment Variables for Production

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-secret

Deployment Platforms

  • Heroku Heroku
  • Railway Railway
  • Vercel Vercel
  • DigitalOcean DigitalOcean

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/AmazingFeature)
  3. πŸ’Ύ Commit your changes (git commit -m 'Add some AmazingFeature')
  4. πŸ“€ Push to the branch (git push origin feature/AmazingFeature)
  5. πŸ”ƒ Open a Pull Request

Development Guidelines

  • Write clear commit messages
  • Add tests for new features
  • Update documentation as needed
  • Follow the existing code style
  • Ensure all tests pass

πŸ™ Acknowledgments

  • 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

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published