# kartikchaudharygit/microservices-new architecture

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

- Interactive diagram: https://gitdiagram.com/kartikchaudharygit/microservices-new
- Repository: https://github.com/kartikchaudharygit/microservices-new

## Overview

##### Project Type and Purpose
- This is a Spring Boot microservices reference implementation. It demonstrates API Gateway, service discovery (Eureka), loosely coupled RESTful services, event-driven communication (Apache Kafka), and observability (Prometheus + Grafana).

##### File Structure Analysis
- Top-level modules (Maven multimodule project):
- api-gateway (Spring Cloud Gateway/Zuul)
- discovery-server (Eureka)
- inventory-service, order-service, product-service, notification-service (business microservices)
- prometheus (Prometheus config)
- Grafana_Dashboard.json
- docker-compose.yml (service orchestration)
- Each microservice follows standard packages: controller, service, repository, model, dto, config.
- Common patterns: OpenAPIConfig (Swagger), WebClientConfig (inter-service REST), KafkaConsumer (in notification), application.properties for external endpoints, banner, tests.

##### README Insights
- Core technologies: Spring Boot, Spring Cloud (Gateway, Eureka), Apache Kafka, Swagger/OpenAPI, Spring Boot Actuator, Prometheus, Grafana.
- Architectural patterns:
- API Gateway for routing and cross-cutting concerns
- Eureka for dynamic service discovery and client-side load balancing
- Event-driven microservices via Kafka (publish/subscribe)
- Separate databases per service implied by repository layers
- Observability via Actuator → Prometheus → Grafana

##### Main Components
a. External Clients (e.g., Web UI, Mobile App)
b. API Gateway
c. Eureka Discovery Server
d. Microservices (Inventory, Order, Product, Notification)
e. Message Broker (Kafka Cluster)
f. Databases (one per microservice)
g. Monitoring Stack (Spring Actuator endpoints, Prometheus, Grafana)
h. Orchestration (Docker Compose network)

##### Relationships & Interactions
- Clients → API Gateway: all HTTP traffic enters here.
- API Gateway ↔ Eureka: at startup and for routing lookup.
- API Gateway → Target Microservices: dynamic routing via service IDs registered in Eureka.
- Order Service → Inventory Service (“check stock”) via synchronous WebClient call.
- Order Service publishes OrderPlacedEvent → Kafka topic.
- Notification Service consumes OrderPlacedEvent from Kafka and sends notifications.
- Each microservice persists state in its own database (JPA repository).
- Spring Boot Actuator on each service exposes /actuator/prometheus metrics.
- Prometheus scrapes those endpoints.
- Grafana visualizes metrics via Prometheus data source.

##### Architectural Patterns & Principles
- Loose coupling: each service is autonomous, communicates over HTTP or Kafka.
- Single Responsibility: each microservice owns one business domain.
- Service Discovery: Eureka eliminates hard-coded service locations.
- API Composition: API Gateway centralizes routing, security, rate limiting, etc.
- Event-Driven: Kafka decouples producers and consumers for async processing.
- Observability: metrics, logs, dashboards ensure runtime visibility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client["External Client\n(Web UI/Mobile App)"]:::external

    subgraph "Infrastructure Layer"
        direction TB
        APIGW["API Gateway\n(Spring Cloud Gateway)"]:::gateway
        Eureka["Eureka Discovery Server"]:::discovery
    end

    subgraph "Business Layer"
        direction TB
        subgraph "Inventory Service"
            direction TB
            Inventory_Service["inventory-service\n(port 8081)\nSpring Boot"]:::microservice
            Inventory_DB["Inventory DB\n(Spring Data JPA)"]:::database
        end
        subgraph "Order Service"
            direction TB
            Order_Service["order-service\n(port 8082)\nSpring Boot"]:::microservice
            Order_DB["Order DB\n(Spring Data JPA)"]:::database
        end
        subgraph "Product Service"
            direction TB
            Product_Service["product-service\n(port 8083)\nSpring Boot"]:::microservice
            Product_DB["Product DB\n(Spring Data JPA)"]:::database
        end
        subgraph "Notification Service"
            direction TB
            Notification_Service["notification-service\n(port 8084)\nSpring Boot"]:::microservice
        end
    end

    subgraph "Messaging Layer"
        direction TB
        Kafka["Kafka Cluster"]:::kafka
    end

    subgraph "Monitoring Layer"
        direction TB
        Prometheus["Prometheus"]:::monitoring
        Grafana["Grafana"]:::monitoring
    end

    subgraph "Deployment"
        direction TB
        DockerCompose["Docker Compose"]:::external
    end

    %% Relationships
    Client -->|"HTTP Request"| APIGW
    APIGW -->|"Service Lookup"| Eureka
    APIGW -->|"Proxy Request"| Inventory_Service
    APIGW -->|"Proxy Request"| Order_Service
    APIGW -->|"Proxy Request"| Product_Service
    APIGW -->|"Proxy Request"| Notification_Service

    Order_Service -->|"check stock (WebClient)"| Inventory_Service
    Order_Service -->|"persist order"| Order_DB
    Inventory_Service -->|"persist inventory"| Inventory_DB
    Product_Service -->|"persist product"| Product_DB

    Order_Service -->|"publish OrderPlacedEvent"| Kafka
    Kafka -->|"consume OrderPlacedEvent"| Notification_Service

    %% Databases
    Inventory_Service --> Inventory_DB
    Product_Service --> Product_DB

    %% Observability
    Inventory_Service -->|"metrics /actuator/prometheus"| Prometheus
    Order_Service -->|"metrics /actuator/prometheus"| Prometheus
    Product_Service -->|"metrics /actuator/prometheus"| Prometheus
    Notification_Service -->|"metrics /actuator/prometheus"| Prometheus
    APIGW -->|"metrics /actuator/prometheus"| Prometheus
    Eureka -->|"metrics /actuator/prometheus"| Prometheus

    Prometheus -->|"data source"| Grafana

    %% Deployment orchestration
    DockerCompose --> APIGW
    DockerCompose --> Eureka
    DockerCompose --> Inventory_Service
    DockerCompose --> Order_Service
    DockerCompose --> Product_Service
    DockerCompose --> Notification_Service
    DockerCompose --> Kafka
    DockerCompose --> Prometheus
    DockerCompose --> Grafana

    %% Click Events
    click APIGW "https://github.com/kartikchaudharygit/microservices-new/blob/master/api-gateway/src/main/java/com/example/microservices/ApiGatewayApplication.java"
    click Eureka "https://github.com/kartikchaudharygit/microservices-new/blob/master/discovery-server/src/main/java/com/example/discoveryserver/DiscoveryServerApplication.java"
    click Inventory_Service "https://github.com/kartikchaudharygit/microservices-new/blob/master/inventory-service/src/main/java/com/example/inventoryservice/InventoryServiceApplication.java"
    click Order_Service "https://github.com/kartikchaudharygit/microservices-new/blob/master/order-service/src/main/java/com/microservices/orderservice/OrderServiceApplication.java"
    click Product_Service "https://github.com/kartikchaudharygit/microservices-new/blob/master/product-service/src/main/java/com/microservices/productservice/ProductServiceApplication.java"
    click Notification_Service "https://github.com/kartikchaudharygit/microservices-new/blob/master/notification-service/src/main/java/com/example/microservices/NotificationServiceApplication.java"
    click Prometheus "https://github.com/kartikchaudharygit/microservices-new/blob/master/prometheus/prometheus.yml"
    click Grafana "https://github.com/kartikchaudharygit/microservices-new/blob/master/Grafana_Dashboard.json"
    click DockerCompose "https://github.com/kartikchaudharygit/microservices-new/blob/master/docker-compose.yml"

    %% Styles
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px
    classDef gateway fill:#DDEBF7,stroke:#2F75B5,stroke-width:1px
    classDef discovery fill:#FFF2CC,stroke:#BF9000,stroke-width:1px
    classDef microservice fill:#E2EFDA,stroke:#548235,stroke-width:1px
    classDef database fill:#FCE4D6,stroke:#B45F06,stroke-width:1px
    classDef kafka fill:#F4CCCC,stroke:#CC0000,stroke-width:1px
    classDef monitoring fill:#D9D2E9,stroke:#7030A0,stroke-width:1px
```
