Skip to content

hmaach/Buy-01

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

205 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Buy-01

Overview

Buy-01 is a microservices-based e-commerce platform built with Spring Boot, providing product management, user authentication, and media handling capabilities.

Authors

  • Hamza Maach Github logo LinkedIn logo
  • Rachid Serraf Github logo LinkedIn logo

Table of Contents

  1. Architecture – System architecture and design
  2. API Endpoints – Complete API documentation
  3. Security – Security implementation details
  4. Kafka – Event-driven communication
  5. API Gateway Documentaion
  6. User Service Documentaion
  7. Product Service Documentaion
  8. Media Service Documentaion
  9. Discovery Server Documentaion

Quick Links

Services

Service Port Description
API Gateway 8080 Entry point for all client requests
Discovery Server 8761 Service registry (Eureka)
User Service 8081 Authentication & user management
Product Service 8082 Product catalog management
Media Service 8083 Media file storage

Databases

Service Port Database
MongoDB (Users) 27017 users
MongoDB (Products) 27018 products
MongoDB (Media) 27019 media

Message Broker

Service Port Purpose
Apache Kafka 9092 Event streaming

Architectural Style

  • Pattern: Microservices Architecture
  • Service Architecture: Hexagonal Architecture (Ports & Adapters)
  • Communication: REST APIs + Event-Driven (Kafka)
  • Service Discovery: Netflix Eureka
  • API Gateway: Spring Cloud Gateway

Project Structure

backend/
├── api-gateway/        # Spring Cloud Gateway
├── discovery-server/   # Eureka Service Registry
├── user-service/       # User authentication & management
├── product-service/    # Product catalog (Reactive)
└── media-service/      # Media file management (Reactive)

Technology Stack

  • Framework: Spring Boot 3.x
  • Language: Java 21
  • Databases: MongoDB
  • Message Broker: Apache Kafka
  • Service Registry: Netflix Eureka
  • API Gateway: Spring Cloud Gateway
  • Authentication: JWT (JSON Web Tokens)

High-Level Architecture

┌─────────────────────────────────────────────────────────────────┐
│                          Clients                                │
│                  (Web, Mobile, External APIs)                   │
└─────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────┐
│                       API Gateway (8080)                        │
│  • JWT Validation                                               │
│  • Rate Limiting                                                │
│  • Request Logging                                              │
│  • CORS                                                         │
│  • Route Management                                             │
└─────────────────────────────────────────────────────────────────┘
                                │
                ┌───────────────┼───────────────┐
                ▼               ▼               ▼
┌─────────────────────┐ ┌──────────────┐ ┌─────────────────────┐
│  User Service       │ │ Product      │ │ Media Service       │
│  (8081)             │ │ Service      │ │ (8083)              │
│                     │ │ (8082)       │ │                     │
│ • Authentication    │ │              │ │ • File Upload       │
│ • User Management   │ │ • Products   │ │ • File Storage      │
│ • Registration      │ │ • Inventory  │ │ • Image Retrieval   │
│ • Login/JWT         │ │              │ │                     │
└─────────────────────┘ └──────────────┘ └─────────────────────┘
                │               │               │
                └───────────────┼───────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────┐
│                    Discovery Server (8761)                      │
│                    Netflix Eureka Server                        │
│              Service Registration & Discovery                   │
└─────────────────────────────────────────────────────────────────┘
                                │
                                ▼
┌─────────────────────────────────────────────────────────────────┐
│                     Apache Kafka (9092)                         │
│              Event-Driven Communication                         │
└─────────────────────────────────────────────────────────────────┘
                                │
                ┌───────────────┴───────────────┐
                ▼                               ▼
┌──────────────────────────────┐   ┌─────────────────────────────┐
│     MongoDB Instances        │   │     Additional Services     │
├─────────────┬────────────────┤   │                             │
│ Users (27017)│Products(27018)│   │ • Logging                   │
│ Media (27019)│               │   │ • Monitoring                │
└─────────────┴────────────────┘   └─────────────────────────────┘

Service Details

1. API Gateway

  • Port: 8080
  • Technology: Spring Cloud Gateway
  • Responsibilities:
    • Centralized entry point for all requests
    • JWT token validation
    • Rate limiting (Bucket4j)
    • Request and response logging
    • CORS management
    • Dynamic route configuration

2. Discovery Server

  • Port: 8761
  • Technology: Netflix Eureka
  • Responsibilities:
    • Service registration and discovery
    • Load balancing support
    • Health monitoring

3. User Service

  • Port: 8081
  • Technology: Spring Boot (Servlet)
  • Database: MongoDB (27017)
  • Responsibilities:
    • User registration and authentication
    • JWT token generation
    • User profile and role management

4. Product Service

  • Port: 8082
  • Technology: Spring Boot WebFlux (Reactive)
  • Database: MongoDB (27018)
  • Responsibilities:
    • Product CRUD operations
    • Inventory management
    • Kafka event publishing
    • Image association

5. Media Service

  • Port: 8083
  • Technology: Spring Boot WebFlux (Reactive)
  • Database: MongoDB (27019)
  • Responsibilities:
    • Media upload and storage (GridFS)
    • Media retrieval
    • Kafka event consumption
    • Orphaned media cleanup

Design Patterns

  1. Hexagonal Architecture (Ports & Adapters)

    • Domain Layer: Core business logic
    • Ports: Interfaces for inbound (use cases) and outbound (repositories)
    • Adapters: Implementations for inbound (controllers) and outbound (MongoDB)
  2. Event-Driven Architecture

    • Kafka for asynchronous communication between services
    • Decouples Product and Media services
  3. API Gateway Pattern

    • Centralized entry point
    • Handles cross-cutting concerns (authentication, logging, rate limiting)
  4. Service Discovery

    • Dynamic service registration
    • Eliminates hard-coded service URLs

Getting Started

Clone the Repository

git clone https://github.com/hmaach/buy-01.git
cd buy-01

Requirements:

  • Git
  • Docker & Docker Compose
  • Java 21+
  • Maven (optional, mvnw included)

Generate the .env file

make env

Start the project with Docker

This starts all containers defined in docker-compose.yml in detached mode.

make docker-up

3. Stop the project

To stop and remove all running containers:

make docker-down

Actuator Health Endpoints

Service Endpoint
API Gateway http://localhost:8080/actuator/health
User Service http://localhost:8081/actuator/health
Product Service http://localhost:8082/actuator/health
Media Service http://localhost:8083/actuator/health

Use Cases:

  • Service monitoring
  • Readiness & liveness checks
  • Integration with service discovery
  • Observability (e.g., Prometheus)
  • Load balancer health checks

About

A microservices-based e-commerce platform built with Spring Boot, Angular and MongoDB

Topics

Resources

Security policy

Stars

Watchers

Forks

Contributors