# harunates/ecommerce architecture

> Architecture diagram of the GitHub repository harunates/ecommerce, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/harunates/ecommerce
- Repository: https://github.com/harunates/ecommerce

## Overview

##### Main Components
- API Gateway: Acts as the front door, routing client requests to the backend services.
- Discovery Server: Provides service registration and discovery (likely implemented with Netflix Eureka as indicated).
- Order Service: Manages order processing and business logic, has both REST endpoints and event handling (publishing OrderCreatedEvent).
- Product Service: Handles product-related operations, inventory checks, and similar functions.
- Notification Service: Responsible for sending notifications based on events (e.g., OrderCreatedEvent).
- Infrastructure Elements: Include databases (MySQL), a messaging system (Apache Kafka), and observability tools (Prometheus, Grafana, Zipkin, Micrometer).

##### Relationships and Interactions
- The API Gateway receives external client calls and forwards them to the appropriate microservice.
- Microservices register with the Discovery Server, allowing dynamic discovery of service endpoints.
- Order Service and Product Service, as primary commerce operation handlers, likely interact both synchronously (via REST calls) and asynchronously (using event-driven messaging, e.g., through Kafka).
- Notification Service consumes events (such as an order creation event) published by Order Service.
- Observability tools are integrated into each service to collect metrics, logs, and traces, feeding into Prometheus (with Grafana for dashboards) and Zipkin for distributed tracing.

##### Architectural Patterns
- Microservices Architecture: Clear separation into independent services.
- API Gateway Pattern: Centralized entry point for clients.
- Service Discovery Pattern: Letting services find one another dynamically (via Eureka).
- Event-driven Communication: Asynchronous messaging (using Apache Kafka) for decoupled interactions between services, especially for notifications.
- Containerization: Each service is containerized (Dockerfiles exist within each project directory) and managed via Docker Compose.
- Resilience Patterns: Use of circuit breakers (Resilience4J) for robust error handling.

##### Including Relevant Technologies
- Languages & Frameworks: Java, Spring Boot, Spring Cloud, Spring Cloud Gateway, Netflix Eureka.
- Database: MySQL (as seen from the technical stack and default application properties in each service).
- Messaging: Apache Kafka (for event-driven communication).
- Observability: Micrometer, Zipkin, Prometheus, Grafana.
- Build Tools: Maven, with containerization using Docker and Jib.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global entities
    Clients("Clients"):::external

    %% Microservices Layer
    subgraph "Microservices Layer"
        AG["API Gateway"]:::frontend
        DS["Discovery Server"]:::backend
        OS["Order Service"]:::backend
        PS["Product Service"]:::backend
        NS["Notification Service"]:::backend
    end

    %% Infrastructure Layer
    subgraph "Infrastructure"
        DB["MySQL Database"]:::infra
        K["Apache Kafka"]:::infra
        subgraph "Observability Tools"
            P["Prometheus"]:::observability
            G["Grafana"]:::observability
            Z["Zipkin"]:::observability
        end
    end

    %% Container Orchestration
    DC["Docker Compose"]:::container

    %% Connections from Clients
    Clients -->|"request"| AG

    %% API Gateway routing to Microservices
    AG -->|"serviceCall"| OS
    AG -->|"serviceCall"| PS
    AG -->|"serviceCall"| NS
    AG -->|"serviceCall"| DS

    %% Service Registration with Discovery Server (bidirectional)
    AG <-->|"register"| DS
    OS <-->|"register"| DS
    PS <-->|"register"| DS
    NS <-->|"register"| DS

    %% Event-driven Communication
    OS -->|"publishesEvent"| K
    K -->|"eventTrigger"| NS

    %% Database Access
    OS -->|"DBAccess"| DB
    PS -->|"DBAccess"| DB

    %% Observability Instrumentation from each Microservice
    AG -->|"instrument"| P
    AG -->|"instrument"| G
    AG -->|"instrument"| Z

    DS -->|"instrument"| P
    DS -->|"instrument"| G
    DS -->|"instrument"| Z

    OS -->|"instrument"| P
    OS -->|"instrument"| G
    OS -->|"instrument"| Z

    PS -->|"instrument"| P
    PS -->|"instrument"| G
    PS -->|"instrument"| Z

    NS -->|"instrument"| P
    NS -->|"instrument"| G
    NS -->|"instrument"| Z

    %% Docker Compose orchestrates all components
    DC --- AG
    DC --- DS
    DC --- OS
    DC --- PS
    DC --- NS
    DC --- DB
    DC --- K
    DC --- P
    DC --- G
    DC --- Z

    %% Click Events
    click AG "https://github.com/harunates/ecommerce/blob/master/api-gateway/src/main/java/tr/com/atessoft/apigateway/ApiGatewayApplication.java"
    click DS "https://github.com/harunates/ecommerce/blob/master/discovery-server/src/main/java/tr/com/atessoft/discoveryserver/DiscoveryServerApplication.java"
    click OS "https://github.com/harunates/ecommerce/blob/master/order-service/src/main/java/tr/com/atessoft/ordersrv/OrderServiceApplication.java"
    click PS "https://github.com/harunates/ecommerce/blob/master/product-service/src/main/java/tr/com/atessoft/productsrv/ProductServiceApplication.java"
    click NS "https://github.com/harunates/ecommerce/blob/master/notification-service/src/main/java/tr/com/atessoft/notificationsrv/NotificationServiceApplication.java"
    click DC "https://github.com/harunates/ecommerce/blob/master/docker-compose/docker-compose.yml"
    click P "https://github.com/harunates/ecommerce/blob/master/docker-compose/prometheus/prometheus.yml"
    click G "https://github.com/harunates/ecommerce/blob/master/assets/grafana-dashboard.json"

    %% Styles
    classDef external fill:#fce94f,stroke:#555,stroke-width:2px;
    classDef frontend fill:#66ccff,stroke:#333,stroke-width:2px;
    classDef backend fill:#99cc99,stroke:#333,stroke-width:2px;
    classDef infra fill:#ffcc66,stroke:#333,stroke-width:2px;
    classDef observability fill:#cc99ff,stroke:#333,stroke-width:2px;
    classDef container fill:#ff6666,stroke:#333,stroke-width:2px;
```
