# firas-b/microservices-full-code architecture

> Architecture diagram of the GitHub repository firas-b/microservices-full-code, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/firas-b/microservices-full-code
- Repository: https://github.com/firas-b/microservices-full-code

## Overview

##### Project type and purpose
- This is a Spring-Boot-based, cloud-native microservices e-commerce learning project.
- It uses Spring Cloud Config (config-server), Eureka discovery (discovery-service), API gateway (gateway-service), and a set of domain-specific microservices: customer, product, order, payment, notification.

##### File structure
- Top‐level folders:
- services/ : each subfolder is one Spring Boot microservice
- docker-compose.yml : orchestration of services plus dependencies
- resources/ : business/distributed patterns docs
- Each service has standard Maven layout, application.yml, tests.
- product-service uniquely includes Flyway migrations (db/migration).
- order and payment services include Kafka producer/consumer configs.
- notification service consumes Kafka events and sends emails.

##### README
- Confirms it is a “Spring boot microservice for learning”.
- No further architecture docs—so we infer interactions from code and files.

##### Main components & interactions
a. Config Server
- Centralized configuration: serves service-specific YAMLs
b. Service Registry (Discovery)
- Eureka for service registration & discovery
c. API Gateway
- Single entry point; routes incoming HTTP requests to domain services
d. Domain Microservices
- Customer Service – CRUD on customers
- Product Service – CRUD on products, backs onto a relational DB (Flyway migrations)
- Order Service – orchestrates order creation, calls Customer & Product via REST, publishes OrderConfirmation to Kafka
- Payment Service – processes payments, calls Order (or stub), publishes PaymentConfirmation to Kafka
- Notification Service – consumes Kafka topics for orders & payments, persists Notification entities, sends emails via templates
e. Messaging Infrastructure
- Kafka cluster or broker, topics: orders, payments
f. Databases
- Product Service DB (SQL via Flyway)
- Others may use in-memory H2 or external DB instances for persistence
g. External Email SMTP
- Used by Notification Service to send transactional emails

##### Architectural patterns & principles
- Microservices pattern: each bounded context is a separate deployable
- Centralized configuration via Spring Cloud Config
- Service discovery via Eureka
- API Gateway pattern for cross-cutting concerns (routing, security, rate-limit)
- Asynchronous communication via Kafka for decoupling order/payment/notification
- Database per service (product service shown)
- Resilience & fault handling via global exception handlers

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Platform Layer
    subgraph "Platform Layer"
        config["Config Server"]:::platform
        discovery["Service Registry (Eureka)"]:::platform
        kafka["Kafka Broker"]:::platform
    end

    %% External Entities
    client["External Client (Web/Mobile)"]:::external
    smtp["External SMTP Server"]:::external

    %% Domain Layer
    subgraph "Domain Layer"
        gateway["API Gateway"]:::platform
        cs["Customer Service"]:::domain
        ps["Product Service"]:::domain
        os["Order Service"]:::domain
        pms["Payment Service"]:::domain
        ns["Notification Service"]:::domain
    end

    %% Databases
    subgraph "Databases"
        psdb["Product DB (SQL)"]:::db
        nsdb["Notification DB"]:::db
    end

    %% Client to Gateway
    client -->|"HTTP/REST"| gateway

    %% Gateway to Services
    gateway -->|"/customers"| cs
    gateway -->|"/products"| ps
    gateway -->|"/orders"| os
    gateway -->|"/payments"| pms
    gateway -->|"/notifications"| ns

    %% Config & Discovery Registration
    gateway -->|config fetch| config
    cs -->|config fetch| config
    ps -->|config fetch| config
    os -->|config fetch| config
    pms -->|config fetch| config
    ns -->|config fetch| config

    gateway -->|service register/discovery| discovery
    cs -->|service register/discovery| discovery
    ps -->|service register/discovery| discovery
    os -->|service register/discovery| discovery
    pms -->|service register/discovery| discovery
    ns -->|service register/discovery| discovery

    %% Synchronous REST Calls
    os -->|"HTTP/REST"| cs
    os -->|"HTTP/REST"| ps
    pms -->|"HTTP/REST"| os

    %% Asynchronous Messaging
    os -->|"Kafka Topic: orders"| kafka
    pms -->|"Kafka Topic: payments"| kafka
    kafka -->|"subscribe orders & payments"| ns

    %% Databases Connections
    ps -->|Flyway migration<br>and SQL access| psdb
    ns -->|JPA persistence| nsdb

    %% Notification Sends Email
    ns -->|SMTP| smtp

    %% Click Events
    click config "https://github.com/firas-b/microservices-full-code/tree/main/services/config-server"
    click discovery "https://github.com/firas-b/microservices-full-code/tree/main/services/discovery"
    click gateway "https://github.com/firas-b/microservices-full-code/tree/main/services/gateway"
    click cs "https://github.com/firas-b/microservices-full-code/tree/main/services/customer"
    click ps "https://github.com/firas-b/microservices-full-code/tree/main/services/product"
    click os "https://github.com/firas-b/microservices-full-code/tree/main/services/order"
    click pms "https://github.com/firas-b/microservices-full-code/tree/main/services/payment"
    click ns "https://github.com/firas-b/microservices-full-code/tree/main/services/notification"

    %% Styles
    classDef platform fill:#cce5ff,stroke:#3399ff,color:#000
    classDef domain fill:#d4edda,stroke:#28a745,color:#000
    classDef db fill:#fff3cd,stroke:#ffcc00,color:#000
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#000
```
