Skip to content

MohamedElsayed002/microservices-kafka

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ Microservices E-commerce Platform

A modern, scalable e-commerce platform built with microservices architecture, featuring multiple backend frameworks, dual database systems, and real-time communication.

πŸ—οΈ Architecture Overview

This project implements a microservices architecture with 7 services:

  • 5 Backend Services (using different frameworks)
  • 2 Frontend Applications (client and admin)

πŸš€ Services

Backend Services

Service Framework Database Purpose
Auth Service Express.js - User authentication & authorization
Product Service Express.js PostgreSQL + Prisma Product & category management
Order Service Fastify MongoDB + Mongoose Order processing & management
Payment Service Hono - Stripe payment integration
Email Service Node.js - Email notifications via Kafka

Frontend Applications

Application Framework Purpose Port
Client Next.js 15 Customer-facing e-commerce store 3002
Admin Next.js 15 Administrative dashboard 3003

πŸ› οΈ Technology Stack

Backend Technologies

  • Frameworks: Express.js, Fastify, Hono
  • Databases: PostgreSQL (with Prisma ORM), MongoDB (with Mongoose)
  • Authentication: Clerk
  • Payment Processing: Stripe
  • Message Queue: Apache Kafka
  • Email: Nodemailer

Frontend Technologies

  • Framework: Next.js 15 with React 19
  • Styling: Tailwind CSS
  • UI Components: Radix UI, Lucide React
  • State Management: Zustand
  • Forms: React Hook Form + Zod validation
  • Charts: Recharts
  • Payment: Stripe React components

DevOps & Tools

  • Monorepo: Turborepo + pnpm workspaces
  • Containerization: Docker
  • TypeScript: Full type safety across all services
  • Linting: ESLint with custom configurations
  • Code Formatting: Prettier

πŸ“¦ Project Structure

micro/
β”œβ”€β”€ apps/                          # Applications
β”‚   β”œβ”€β”€ admin/                     # Admin dashboard (Next.js)
β”‚   β”œβ”€β”€ client/                    # Customer store (Next.js)
β”‚   β”œβ”€β”€ auth-service/              # Authentication service (Express)
β”‚   β”œβ”€β”€ product-service/           # Product management (Express)
β”‚   β”œβ”€β”€ order-service/             # Order processing (Fastify)
β”‚   β”œβ”€β”€ payment-service/           # Payment handling (Hono)
β”‚   └── email-service/             # Email notifications
β”œβ”€β”€ packages/                      # Shared packages
β”‚   β”œβ”€β”€ kafka/                     # Kafka client & configuration
β”‚   β”œβ”€β”€ product-db/                # PostgreSQL + Prisma
β”‚   β”œβ”€β”€ order-db/                  # MongoDB + Mongoose
β”‚   β”œβ”€β”€ types/                     # Shared TypeScript types
β”‚   β”œβ”€β”€ eslint-config/             # ESLint configurations
β”‚   └── typescript-config/         # TypeScript configurations
└── docker-compose.yml             # Kafka infrastructure

πŸš€ Getting Started

Prerequisites

  • Node.js >= 18
  • pnpm 9.0.0
  • Docker & Docker Compose
  • PostgreSQL database
  • MongoDB database

Installation

  1. Clone the repository

    git clone <your-repo-url>
    cd micro
  2. Install dependencies

    pnpm install
  3. Start Kafka infrastructure

    cd packages/kafka
    docker-compose up -d
  4. Set up environment variables Create .env files in each service directory with required environment variables:

    • Database URLs (PostgreSQL & MongoDB)
    • Clerk authentication keys
    • Stripe API keys
    • Email service credentials
  5. Run database migrations

    # For PostgreSQL (Product service)
    cd packages/product-db
    pnpm prisma migrate dev
  6. Start all services

    # From root directory
    pnpm dev

Individual Service Commands

# Start specific services
pnpm --filter client dev          # Client app (port 3002)
pnpm --filter admin dev           # Admin app (port 3003)
pnpm --filter auth-service dev    # Auth service
pnpm --filter product-service dev # Product service
pnpm --filter order-service dev   # Order service
pnpm --filter payment-service dev # Payment service
pnpm --filter email-service dev   # Email service

πŸ”§ Available Scripts

# Development
pnpm dev                    # Start all services in development mode
pnpm build                  # Build all applications
pnpm lint                   # Lint all packages
pnpm format                 # Format code with Prettier
pnpm check-types           # Type check all packages

# Database
pnpm db:generate           # Generate Prisma client
pnpm db:migrate            # Run database migrations
pnpm db:deploy             # Deploy database schema

🌐 Service Endpoints

Frontend Applications

Backend Services

  • Auth Service: Handles user authentication
  • Product Service: Manages products and categories
  • Order Service: Processes orders and order history
  • Payment Service: Handles Stripe payments
  • Email Service: Sends transactional emails

Infrastructure

πŸ”„ Inter-Service Communication

  • Synchronous: REST APIs for direct service communication
  • Asynchronous: Apache Kafka for event-driven communication
  • Authentication: Clerk for centralized auth across all services

πŸ—„οΈ Database Schema

PostgreSQL (Product Service)

  • Products: Product information, pricing, images, variants
  • Categories: Product categorization and organization

MongoDB (Order Service)

  • Orders: Order details, status, user information, product items

πŸ’³ Payment Integration

  • Stripe: Full payment processing with webhooks
  • Payment Methods: Credit cards, digital wallets
  • Order Management: Automatic order creation on successful payment

πŸ“§ Email System

  • Transactional Emails: Order confirmations, shipping updates
  • Event-Driven: Triggered via Kafka events
  • Template System: Customizable email templates

🐳 Docker Support

Kafka infrastructure is containerized with Docker Compose:

  • Zookeeper
  • Kafka broker
  • Kafka UI for management

πŸ” Security Features

  • Authentication: Clerk-based authentication
  • Authorization: Role-based access control
  • API Security: CORS, input validation
  • Payment Security: Stripe's secure payment processing

πŸ§ͺ Development Features

  • Hot Reload: All services support hot reloading
  • Type Safety: Full TypeScript coverage
  • Code Quality: ESLint, Prettier, and type checking
  • Monorepo: Efficient dependency management with pnpm workspaces

πŸ“ˆ Monitoring & Observability

  • Kafka UI: Real-time message monitoring
  • Service Health: Individual service health checks
  • Error Handling: Comprehensive error handling across services

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

πŸ“„ License

This project is licensed under the ISC License.

🎯 Future Enhancements

  • Add comprehensive testing suite
  • Implement service mesh (Istio)
  • Add monitoring and logging (Prometheus, Grafana)
  • Implement caching layer (Redis)
  • Add API documentation (Swagger/OpenAPI)
  • Implement CI/CD pipeline
  • Add performance monitoring
  • Implement rate limiting
  • Add comprehensive error tracking

Built with ❀️ using modern microservices architecture