Skip to content

Latest commit

 

History

History
201 lines (156 loc) · 5.78 KB

File metadata and controls

201 lines (156 loc) · 5.78 KB

NodeShop - E-commerce MERN Application

A full-stack e-commerce application built with MongoDB, Express.js, React (Next.js), and Node.js.

🚀 Features

  • User Management: User registration, login, and profile management
  • Admin Panel: Admin authentication and user management
  • Product Management: CRUD operations for products
  • Shopping Cart: Add/remove products to/from cart
  • Checkout System: Complete purchase workflow
  • Authentication: JWT-based authentication for users and admins
  • Responsive Design: Built with Tailwind CSS for mobile-first design

🛠️ Tech Stack

Frontend (Client)

  • Next.js 16 - React framework with server-side rendering
  • TypeScript - Type-safe JavaScript
  • Tailwind CSS - Utility-first CSS framework
  • Axios - HTTP client for API requests
  • React 19 - Latest React version

Backend (Server)

  • Node.js - JavaScript runtime
  • Express.js - Web application framework
  • MongoDB - NoSQL database
  • Mongoose - MongoDB object modeling
  • JWT - JSON Web Tokens for authentication
  • CORS - Cross-origin resource sharing

📁 Project Structure

NodeShop/
├── client/                 # Next.js frontend application
│   ├── app/               # App router pages and components
│   │   ├── admin/         # Admin dashboard pages
│   │   ├── cart/          # Shopping cart functionality
│   │   ├── checkout/      # Checkout process
│   │   ├── components/    # Reusable UI components
│   │   ├── login/         # User authentication
│   │   ├── products/      # Product listing and details
│   │   └── register/      # User registration
│   ├── public/            # Static assets
│   └── package.json       # Frontend dependencies
└── server/                # Express.js backend application
    ├── controllers/       # Request handlers
    │   ├── adminlogin/    # Admin authentication logic
    │   ├── user/          # User management logic
    │   └── Products.js    # Product management logic
    ├── models/            # MongoDB schemas
    │   ├── Admin.js       # Admin model
    │   ├── User.js        # User model
    │   └── Products.js    # Product model
    ├── routes/            # API route definitions
    ├── middleware/        # Authentication middleware
    ├── service/           # Business logic services
    └── package.json       # Backend dependencies

🚀 Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • MongoDB (local installation or MongoDB Atlas)
  • npm or yarn package manager

Installation

  1. Clone the repository

    git clone <repository-url>
    cd NodeShop
  2. Install server dependencies

    cd server
    npm install
  3. Install client dependencies

    cd ../client
    npm install
  4. Environment Setup

    Create a .env file in the server directory:

    MONGODB_URI=mongodb://127.0.0.1:27017/NodeShopMern
    JWT_SECRET=your_jwt_secret_key
    PORT=5000
  5. Start MongoDB

    Make sure MongoDB is running on your system or configure MongoDB Atlas connection.

Running the Application

  1. Start the backend server

    cd server
    npm start

    Server will run on http://localhost:5000

  2. Start the frontend application

    cd client
    npm run dev

    Client will run on http://localhost:3000

📚 API Endpoints

Authentication

  • POST /admin/login - Admin login
  • POST /user/register - User registration
  • POST /user/login - User login

User Management

  • GET /user/all - Get all users (Admin only)
  • PUT /user/status/:id - Update user status (Admin only)

Products

  • GET /Products - Get all products
  • POST /Products - Create new product (Admin only)
  • PUT /Products/:id - Update product (Admin only)
  • DELETE /Products/:id - Delete product (Admin only)

🔐 Authentication

The application uses JWT (JSON Web Tokens) for authentication:

  • Users receive a token upon successful login
  • Protected routes require valid JWT token
  • Admin routes have additional role-based access control

🎨 Frontend Features

  • Responsive Design: Mobile-first approach with Tailwind CSS
  • TypeScript: Type safety throughout the application
  • Next.js App Router: Modern routing with server components
  • Toast Notifications: User feedback with nextjs-toast-notify
  • Form Validation: Client-side validation for better UX

🗄️ Database Models

User Model

  • Email, password, name
  • Status (active/inactive)
  • Role-based permissions

Admin Model

  • Admin credentials and permissions
  • User management capabilities

Product Model

  • Product details (name, price, description)
  • Inventory management
  • Category classification

🚀 Deployment

Backend Deployment

  1. Set environment variables for production
  2. Configure MongoDB connection string
  3. Deploy to platforms like Heroku, Railway, or DigitalOcean

Frontend Deployment

  1. Build the Next.js application: npm run build
  2. Deploy to Vercel, Netlify, or similar platforms
  3. Configure API endpoints for production

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Commit changes: git commit -m 'Add feature'
  4. Push to branch: git push origin feature-name
  5. Submit a pull request

📝 License

This project is licensed under the ISC License.

🐛 Issues

If you encounter any issues, please create an issue on the repository with:

  • Description of the problem
  • Steps to reproduce
  • Expected vs actual behavior
  • Environment details

📞 Support

For support and questions, please open an issue on the repository.