Skip to content

Latest commit

Β 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TechStore Backend

TypeScript Node.js Express MongoDB License

A production-ready, scalable e-commerce backend API built with modern TypeScript, Express, and MongoDB

Features β€’ API Documentation β€’ Tech Stack β€’ Getting Started β€’ Project Structure


πŸ“– Overview

TechStore Backend is a full-featured REST API designed to power modern e-commerce applications. It provides comprehensive functionality for product management, order processing, user authentication, analytics, and more. Built with industry-standard technologies and following best practices for security, scalability, and maintainability.

Key Highlights

  • πŸ” Secure Authentication - JWT-based auth with refresh tokens and role-based access control
  • βœ… Input Validation - Comprehensive Zod schemas for all endpoints
  • πŸ—οΈ Modular Architecture - Clean MVC pattern with separated business logic
  • πŸ“Š Analytics Dashboard - Built-in analytics for business insights
  • πŸ›’ Complete Order Management - Full order lifecycle with status tracking
  • πŸ“¦ Product Catalog - Categories, subcategories, and rich product management
  • πŸ‘₯ User Management - Admin/user roles with profile management

πŸš€ Key Features

Authentication & Authorization

  • User Registration - Secure signup with email validation
  • JWT Authentication - Access and refresh token mechanism
  • Role-Based Access Control - Admin and user roles with granular permissions
  • Password Security - Bcrypt hashing with configurable salt rounds
  • Token Refresh - Seamless token renewal without re-login

Product Management

  • CRUD Operations - Create, read, update, delete products
  • Category System - Hierarchical categories and subcategories
  • Rich Product Data - Support for images, specifications, features
  • Pricing - Regular price and discount price support
  • Search & Filter - Pagination and search capabilities

Order Processing

  • Order Creation - Cash on delivery support
  • Order Status Updates - Admin can update order statuses
  • Order History - Users can view their order history
  • Order Validation - Complete input validation for order data

Analytics

  • Sales Analytics - Revenue and order statistics
  • User Analytics - User growth and engagement metrics
  • Product Analytics - Popular products and inventory insights

User Management

  • Profile Management - Update user profiles
  • Admin Operations - User CRUD by admin
  • Password Reset - Secure password reset functionality
  • Soft Delete - Safe user deletion with recovery option

Newsletter Subscriptions

  • Subscribe/Unsubscribe - Email subscription management
  • Status Updates - Manage subscriber status
  • Delete Subscribers - Clean subscriber list

πŸ›  Tech Stack

Technology Version Purpose
TypeScript 5.7 Type-safe development
Node.js 18+ Runtime environment
Express.js 4.21 Web framework
MongoDB Latest NoSQL database
Mongoose 8.10 ODM for MongoDB
Zod 3.24 Schema validation
JWT 9.0 Authentication tokens
Bcrypt 5.1 Password hashing
date-fns 4.1 Date utilities

πŸ“‘ API Endpoints

Base URL

http://localhost:5000/api/v1

Authentication (/auth)

Method Endpoint Description Auth Required
POST /signup Register new user ❌ No
POST /login Login user ❌ No
POST /refresh-token Get new access token ❌ No

Products (/products)

Method Endpoint Description Auth Required
POST /create-product Create new product βœ… Admin
PATCH /edit-product/:id Update product βœ… Admin
DELETE /delete-product/:id Delete product βœ… Admin
GET /get-all-product Get all products ❌ No
GET /:id Get product by ID ❌ No

Categories (/category)

Method Endpoint Description Auth Required
POST /create-category Create category βœ… Admin
GET /get-all-category Get all categories (paginated) ❌ No
GET /:id Get category by ID ❌ No
PATCH /update-category/:id Update category βœ… Admin
DELETE /delete-category/:id Delete category βœ… Admin

Subcategories (/subcategory)

Method Endpoint Description Auth Required
POST /create-subcategory Create subcategory βœ… Admin
GET /get-all-subcategory Get all subcategories ❌ No
GET /:id Get subcategory by ID ❌ No
PATCH /update-subcategory/:id Update subcategory βœ… Admin
DELETE /delete-subcategory/:id Delete subcategory βœ… Admin

Orders (/orders)

Method Endpoint Description Auth Required
POST /create-order Create new order βœ… User/Admin
GET /get-orders Get user orders βœ… User/Admin
PATCH /update-status/:id Update order status βœ… Admin

Users (/users)

Method Endpoint Description Auth Required
POST /create-user Create user βœ… Admin
GET /get-all-user Get all users βœ… Admin
GET /get-single-user/:id Get user by ID βœ… Admin
PATCH /update-user/:id Update user βœ… Admin
DELETE /delete-user/:id Delete user βœ… Admin
PATCH /reset-user Reset user password βœ… Admin

Analytics (/analytics)

Method Endpoint Description Auth Required
GET /get-analytics Get analytics data βœ… User/Admin

Subscribers (/subscribers)

Method Endpoint Description Auth Required
POST /create-subscriber Add subscriber ❌ No
GET /get-all-subscriber Get all subscribers βœ… Admin
DELETE /delete-subscriber/:id Delete subscriber βœ… Admin
PATCH /update-status/:id Update status βœ… Admin

πŸ— Project Structure

TechStore-Server/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.ts                      # Express app configuration
β”‚   β”œβ”€β”€ server.ts                   # Server entry point
β”‚   └── app/
β”‚       β”œβ”€β”€ config/
β”‚       β”‚   └── index.ts           # Environment configuration
β”‚       β”œβ”€β”€ middlewares/
β”‚       β”‚   β”œβ”€β”€ authMiddleware.ts  # JWT authentication
β”‚       β”‚   └── validateRequest.ts # Request validation
β”‚       β”œβ”€β”€ modules/              # Feature modules (MVC)
β”‚       β”‚   β”œβ”€β”€ analytics/        # Analytics controller, service, routes
β”‚       β”‚   β”œβ”€β”€ auth/             # Authentication logic
β”‚       β”‚   β”œβ”€β”€ category/         # Category management
β”‚       β”‚   β”œβ”€β”€ order/            # Order processing
β”‚       β”‚   β”œβ”€β”€ product/          # Product CRUD
β”‚       β”‚   β”œβ”€β”€ subcategory/      # Subcategory management
β”‚       β”‚   β”œβ”€β”€ subscriber/       # Newsletter subscriptions
β”‚       β”‚   └── user/             # User management
β”‚       β”œβ”€β”€ routes/
β”‚       β”‚   └── index.ts          # Main router
β”‚       β”œβ”€β”€ utils/
β”‚       β”‚   └── parseDate.ts      # Utility functions
β”‚       β”œβ”€β”€ validation/           # Zod schemas
β”‚       └── interfaces/           # TypeScript declarations
β”œβ”€β”€ .env                          # Environment variables
β”œβ”€β”€ package.json                  # Dependencies
β”œβ”€β”€ tsconfig.json                 # TypeScript config
└── README.md                     # This file

Module Pattern (MVC)

Each module follows a clean, scalable architecture:

module/
β”œβ”€β”€ module.model.ts      # Mongoose schema & model
β”œβ”€β”€ module.interface.ts  # TypeScript interfaces
β”œβ”€β”€ module.service.ts   # Business logic layer
β”œβ”€β”€ module.controller.ts # Request handlers
└── module.route.ts     # Route definitions

πŸ”§ Getting Started

Prerequisites

  • Node.js 18 or higher
  • MongoDB (local or cloud instance)
  • npm or yarn package manager

Installation

  1. Clone the repository

    git clone https://github.com/ahad1033/TechStore-Server
    cd TechStore-Server
  2. Install dependencies

    npm install
  3. Environment setup

    Create a .env file in the root directory:

    PORT=5000
    DATABASE_URL=mongodb://localhost:27017/techstore
    BCRYPT_SALT_ROUNDS=3
    JWT_ACCESS_SECRET=your-super-secret-access-key
    JWT_ACCESS_EXPIRES_IN=10d
    JWT_REFRESH_SECRET=your-super-secret-refresh-key
    JWT_REFRESH_EXPIRES_IN=10d
    SUPER_ADMIN_PASSWORD=your-admin-password
    NODE_ENV=development
  4. Start the server

    # Development mode (with hot reload)
    npm run start:dev
    
    # Production mode
    npm run build
    npm start
  5. Verify the server

    The server will start on http://localhost:5000


πŸ“¦ Environment Variables

Variable Description Default
PORT Server port 5000
DATABASE_URL MongoDB connection string -
BCRYPT_SALT_ROUNDS Password hashing rounds 9
JWT_ACCESS_SECRET Access token secret -
JWT_ACCESS_EXPIRES_IN Access token expiry 10d
JWT_REFRESH_SECRET Refresh token secret -
JWT_REFRESH_EXPIRES_IN Refresh token expiry 10d
SUPER_ADMIN_PASSWORD Default admin password -
NODE_ENV Environment (dev/prod) development

πŸ” Authentication Flow

  1. Sign Up

    POST /api/v1/auth/signup
    {
      "name": "John Doe",
      "email": "john@example.com",
      "password": "securePassword123",
      "gender": "male",
      "phone": "1234567890",
      "address": "123 Main St"
    }
  2. Login

    POST /api/v1/auth/login
    {
      "email": "john@example.com",
      "password": "securePassword123"
    }
  3. Access Protected Routes

    GET /api/v1/orders/get-orders
    Authorization: Bearer <access_token>
  4. Refresh Token

    POST /api/v1/auth/refresh-token
    Cookie: refreshToken=<refresh_token>

🎨 Code Quality & Best Practices

  • Type Safety - Full TypeScript coverage with strict mode
  • Validation - Zod schemas for all input validation
  • Error Handling - Consistent error response format
  • Security - Bcrypt password hashing, JWT tokens, CORS configured
  • Clean Code - Modular architecture, separated concerns
  • Scalability - Ready for horizontal scaling
  • Maintainability - Clear code structure and documentation

πŸ“„ License

This project is licensed under the MIT License.


πŸ‘¨β€πŸ’» Author

Ahad Ahammad Akash


🀝 Contributing

Contributions, issues, and feature requests are welcome!

  1. Fork the repository
  2. Create your 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

πŸ“ž Support

For support, email ahadahamedakash@gmail.com or open an issue in the repository.


Built with ❀️ for the e-commerce community

⭐ Star this repo if it helped you!

About

This is the backend service for TechStore, a full-featured ecommerce web application built using TypeScript, Node.js, Express, and MongoDB. The backend handles all business logic, user roles, data validation, and secure API interactions to support the frontend system.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages