Skip to content

DevDad-Main/Ecommerce-Microservices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

61 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ecommerce Microservices

A modern, scalable e-commerce platform built with microservices architecture using Turborepo for monorepo management. This project demonstrates best practices for building distributed systems with separate concerns for products, orders, payments, and administration.

πŸ—οΈ Architecture

This monorepo consists of multiple services and applications, each handling specific business domains:

Applications

  • Client (apps/client): Customer-facing Next.js application for browsing products, managing cart, and checkout
  • Admin (apps/admin): Administrative dashboard for managing products, categories, and orders

Microservices

  • Product Service (apps/product-service): REST API for product and category management using Express.js
  • Order Service (apps/order-service): Order processing service using Fastify
  • Payment Service (apps/payment-service): Stripe payment processing with webhooks using Hono

Shared Packages

  • Types (packages/types): Shared TypeScript interfaces and schemas
  • BullMQ (packages/bullmq): Background job processing for Stripe operations
  • Product DB (packages/product-db): Prisma ORM for PostgreSQL product database
  • Order DB (packages/order-db): Mongoose ODM for MongoDB order database
  • ESLint Config (packages/eslint-config): Shared linting configuration
  • TypeScript Config (packages/typescript-config): Shared TypeScript configuration

πŸš€ Features

Customer Features

  • Product catalog with categories, sizes, colors, and images
  • Shopping cart with persistent state
  • Secure checkout with Stripe integration
  • User authentication via Clerk
  • Order history and tracking
  • Responsive design with Tailwind CSS

Admin Features

  • Product management (CRUD operations)
  • Category management
  • Order overview and management
  • Dashboard with analytics
  • Image upload and management
  • Real-time data updates

Technical Features

  • Asynchronous job processing with BullMQ
  • Stripe webhook handling for payment confirmations
  • Database migrations with Prisma
  • Type-safe APIs with Zod validation
  • Background job queues for Stripe product sync
  • Monorepo tooling with Turborepo
  • Comprehensive backend testing with Vitest

πŸ› οΈ Tech Stack

Frontend

  • Next.js 15 - React framework with App Router
  • React 19 - UI library
  • TypeScript - Type safety
  • Tailwind CSS - Styling
  • Zustand - State management
  • React Hook Form - Form handling
  • Clerk - Authentication
  • Stripe Elements - Payment UI

Backend Services

  • Express.js - REST API framework
  • Fastify - High-performance web framework
  • Hono - Lightweight web framework for payments
  • Prisma - Database ORM
  • Mongoose - MongoDB ODM
  • BullMQ - Job queue system

Testing

  • Vitest - Fast unit and integration testing
  • Supertest - API endpoint testing
  • Mocked dependencies - Isolated testing for databases, auth, and external services

Infrastructure

  • PostgreSQL - Primary database for products
  • MongoDB - Document database for orders
  • Redis - Queue storage
  • Stripe - Payment processing
  • Turborepo - Monorepo build system

πŸ“‹ Prerequisites

  • Node.js >= 18
  • pnpm package manager
  • PostgreSQL database
  • MongoDB database
  • Redis instance
  • Stripe account

πŸš€ Getting Started

  1. Clone the repository

    git clone https://github.com/Devdad-Main/Ecommerce-Microservices.git
    cd Ecommerce-Microservices/
  2. Install dependencies

    pnpm install
  3. Set up environment variables

    Copy the example environment files and configure:

    • Database URLs (PostgreSQL, MongoDB)
    • Redis connection
    • Stripe API keys
    • Clerk authentication keys
  4. Set up databases

    # Generate Prisma client and run migrations
    pnpm run db:generate
    pnpm run db:migrate
  5. Start development servers

    pnpm run dev

    This will start all services concurrently:

πŸ§ͺ Testing

The project includes comprehensive backend testing:

  • Unit tests for controllers, middleware, and utilities
  • Integration tests for API endpoints
  • Mocked dependencies for databases, authentication, and external services
  • Run pnpm test in individual service directories to execute tests
  • Current test coverage includes product-service auth middleware and category controllers

πŸ“ Project Structure

ecommerce-microservices/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ admin/          # Admin dashboard (Next.js)
β”‚   β”œβ”€β”€ client/         # Customer frontend (Next.js)
β”‚   β”œβ”€β”€ order-service/  # Order processing (Fastify)
β”‚   β”œβ”€β”€ payment-service/# Payment processing (Hono)
β”‚   └── product-service/# Product management (Express)
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ bullmq/         # Job queue system
β”‚   β”œβ”€β”€ eslint-config/  # Shared ESLint config
β”‚   β”œβ”€β”€ order-db/       # Order database models
β”‚   β”œβ”€β”€ product-db/     # Product database schema
β”‚   β”œβ”€β”€ types/          # Shared TypeScript types
β”‚   └── typescript-config/ # Shared TS config
β”œβ”€β”€ package.json
β”œβ”€β”€ turbo.json
└── pnpm-workspace.yaml

πŸ”§ Available Scripts

  • pnpm run dev - Start all services in development mode
  • pnpm run build - Build all applications and packages
  • pnpm run lint - Run ESLint across the monorepo
  • pnpm run check-types - Run TypeScript type checking
  • pnpm run db:generate - Generate Prisma client
  • pnpm run db:migrate - Run database migrations
  • pnpm run test - Run tests across all services
  • pnpm run test:watch - Run tests in watch mode

πŸ”’ Authentication

The application uses Clerk for authentication with role-based access:

  • Customers: Can browse products, manage cart, place orders
  • Admins: Full access to product and order management

πŸ’³ Payment Processing

Stripe handles all payment processing with:

  • Secure checkout sessions
  • Webhook handling for payment confirmations
  • Asynchronous order creation via job queues
  • Support for multiple currencies

πŸ”„ Background Jobs

BullMQ manages asynchronous operations:

  • Stripe product creation/deletion
  • Order processing after successful payments
  • Image processing and optimization

πŸ“Š Database Schema

Products (PostgreSQL)

  • Products with variants (sizes, colors)
  • Categories with slug-based routing
  • Image storage with color-specific images

Orders (MongoDB)

  • Order history with user association
  • Product snapshots at time of purchase
  • Payment status tracking

🀝 Contributing

  1. Follow the existing code style and conventions
  2. Use TypeScript for all new code
  3. Add tests for new features
  4. Update documentation as needed
  5. Use conventional commits

πŸ“„ License

This project is licensed under the ISC License.

πŸ™ Acknowledgments

  • Built with modern web technologies and best practices
  • Inspired by scalable e-commerce architectures
  • Uses open-source tools and frameworks

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors