# devdcores/bookstoreapp-distributed-application architecture

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

- Interactive diagram: https://gitdiagram.com/devdcores/bookstoreapp-distributed-application
- Repository: https://github.com/devdcores/bookstoreapp-distributed-application

## Overview

##### Project Overview and Type
- This is a distributed Ecommerce application for a bookstore, built with a microservices architecture using Java, Spring Boot, and React.
- The application is composed of multiple backend microservices (such as Account, Billing, Catalog, Order, and Payment) along with a frontend React app.
- It uses service discovery (Eureka for local development and Consul when running via Docker) and an API gateway (Zuul) to route requests.
- Additional support components include monitoring (Prometheus, Graphana, TICK stack), distributed tracing (Zipkin), and container orchestration via Docker-compose.

##### Analyzing the File Structure
- The project is organized into several distinct service modules – each represented by its own directory (e.g., bookstore-account-service, bookstore-billing-service, bookstore-catalog-service, bookstore-order-service, bookstore-payment-service).
- There is a common library (“bookstore-commons”) and a Feign client module (“bookstore-feign”) that consolidate shared code and facilitate inter-service communication.
- Other components include the API gateway (bookstore-api-gateway-service), service discovery modules (eureka and potentially consul configurations), and a React frontend (bookstore-frontend-react-app).
- Configuration files like “application.yml”, Dockerfiles, and migration SQL scripts clarify deployment, containerization, and database setups.
- Monitoring and tracing components are separately managed in directories such as bookstore-prometheus, bookstore-graphana, and others.

##### Main Components and Their Interactions
a. Frontend:
- React Application (“bookstore-frontend-react-app”): Acts as the public UI.
- Served behind an NGINX reverse proxy, which forwards requests to Zuul (API Gateway).

b. API Gateway:
- Zuul API Gateway routes frontend requests to appropriate backend services based on URL mappings.
- It also registers with the discovery services to dynamically resolve service endpoints.

c. Service Discovery:
- Eureka Discovery Service is used in local development mode.
- In Docker environments, Consul is used to dynamically manage service endpoints and targets.

d. Microservices:
- Account Service: Handles user accounts, authentication, and authorization.
- Billing Service: Manages billing and address information.
- Catalog Service: Manages products (books), categories, reviews, and image processing.
- Order Service: Manages cart, order processing, and order-related information.
- Payment Service: Handles payment methods and payment transactions.
- Each service is built as a Spring Boot project and communicates through REST APIs and potentially via Feign clients (as seen in “bookstore-feign”).

e. Shared Libraries:
- “bookstore-commons” provides common Spring configurations (security, exception handling, auditing) and utility methods across services.

f. Monitoring & Observability:
- Monitoring components include Prometheus, Graphana, Zipkin, and TICK stack tools (Telegraf, InfluxDB, Chronograf, Kapacitor).
- Each microservice is instrumented to provide metrics and traces which help in monitoring performance and overall health.

##### Architectural Patterns & Design Principles
- Microservices Architecture: Each domain of the application (account, catalog, etc.) is separated into modular, independent services.
- API Gateway: All client requests are funneled through a gateway that also handles dynamic routing using service discovery.
- Service Discovery: Utilizes Eureka or Consul for dynamic service endpoint registration and resolution.
- Containerization: Dockerfiles and docker-compose enable containerized deployments of microservices, monitoring tools, and reverse-proxy setups.
- Shared Code and Communication: The “bookstore-commons” module for cross-cutting concerns and “bookstore-feign” for inter-service communication.
- DevOps and Monitoring: Integrated monitoring and alerting systems with Prometheus, Graphana, and TICK.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["React Application"]:::frontend
        NGINX["NGINX Reverse Proxy"]:::proxy
    end

    %% API Gateway Layer
    subgraph "API Gateway"
        API["Zuul API Gateway"]:::gateway
    end

    %% Service Discovery
    subgraph "Service Discovery"
        DISC["Eureka/Consul Discovery"]:::discovery
    end

    %% Backend Microservices
    subgraph "Backend Microservices"
        ACC["Account Service"]:::service
        BILL["Billing Service"]:::service
        CAT["Catalog Service"]:::service
        ORD["Order Service"]:::service
        PAY["Payment Service"]:::service
    end

    %% Shared Modules
    subgraph "Shared Modules"
        COMMON["Shared Libraries"]:::library
        FEIGN["Feign Client Module"]:::library
    end

    %% Monitoring & Tracing
    subgraph "Monitoring & Tracing"
        PRO["Prometheus"]:::monitor
        GRAF["Grafana"]:::monitor
        TICK["TICK Stack"]:::monitor
        ZIP["Zipkin"]:::monitor
    end

    %% Connections - Frontend to API Gateway
    FE -->|"sendsRequest"| NGINX
    NGINX -->|"forwards"| API

    %% Connections - API Gateway to Microservices
    API -->|"routesTo"| ACC
    API -->|"routesTo"| BILL
    API -->|"routesTo"| CAT
    API -->|"routesTo"| ORD
    API -->|"routesTo"| PAY

    %% Service Discovery Registrations
    API -->|"registersWith"| DISC
    ACC -->|"registersWith"| DISC
    BILL -->|"registersWith"| DISC
    CAT -->|"registersWith"| DISC
    ORD -->|"registersWith"| DISC
    PAY -->|"registersWith"| DISC

    %% Shared Libraries usage in Microservices
    ACC ---|"uses"| COMMON
    BILL ---|"uses"| COMMON
    CAT ---|"uses"| COMMON
    ORD ---|"uses"| COMMON
    PAY ---|"uses"| COMMON

    ACC ---|"calls"| FEIGN
    BILL ---|"calls"| FEIGN
    CAT ---|"calls"| FEIGN
    ORD ---|"calls"| FEIGN
    PAY ---|"calls"| FEIGN

    %% Monitoring & Tracing connections
    ACC -->|"reportsMetrics"| PRO
    BILL -->|"reportsMetrics"| PRO
    CAT -->|"reportsMetrics"| PRO
    ORD -->|"reportsMetrics"| PRO
    PAY -->|"reportsMetrics"| PRO

    ACC -->|"traces"| ZIP
    BILL -->|"traces"| ZIP
    CAT -->|"traces"| ZIP
    ORD -->|"traces"| ZIP
    PAY -->|"traces"| ZIP

    PRO -->|"dashboards"| GRAF

    %% Click Events
    click FE "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-frontend-react-app"
    click API "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-api-gateway-service"
    click DISC "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-eureka-discovery-service"
    click ACC "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-account-service"
    click BILL "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-billing-service"
    click CAT "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-catalog-service"
    click ORD "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-order-service"
    click PAY "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-payment-service"
    click COMMON "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-commons"
    click FEIGN "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-feign"
    click PRO "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-prometheus"
    click GRAF "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-graphana"
    click TICK "https://github.com/devdcores/bookstoreapp-distributed-application/tree/master/bookstore-telegraph"

    %% Styles
    classDef frontend fill:#f9b,stroke:#333,stroke-width:2px;
    classDef proxy fill:#9cf,stroke:#333,stroke-width:2px;
    classDef gateway fill:#fc9,stroke:#333,stroke-width:2px;
    classDef discovery fill:#cff,stroke:#333,stroke-width:2px;
    classDef service fill:#cfc,stroke:#333,stroke-width:2px;
    classDef library fill:#fcf,stroke:#333,stroke-width:2px;
    classDef monitor fill:#ff9,stroke:#333,stroke-width:2px;
```
