# paulc4/microservices-demo architecture

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

- Interactive diagram: https://gitdiagram.com/paulc4/microservices-demo
- Repository: https://github.com/paulc4/microservices-demo

## Overview

##### Project Type and Purpose
- This is a Spring-based microservices demo application illustrating service registry/discovery with Eureka, three autonomous Spring Boot services (Registration, Accounts, Web), in-memory/configured database for accounts data, and a simple client-side UI.
- The README confirms it’s a demo of Spring Cloud microservices (RegistrationService as Eureka server, AccountsService for data, WebService acting as client and UI).

##### File Structure Analysis
- Top-level build files (pom.xml, build.gradle, Dockerfile) indicate Java/Spring Boot with both Maven and Gradle support.
- src/main/java/io/pivotal/microservices/services/Main.java: a “fat” JAR entry point that branches into three server modes (“registration”, “accounts”, “web”).
- services subpackages:
- services/registration – RegistrationServer (Eureka registry)
- services/accounts – AccountsServer (Spring Boot app exposing REST & JPA/H2)
- services/web – WebServer + WebAccountsService + Controllers for UI
- src/main/resources contains per-service YAML for ports and Eureka clients, HTML templates for UI, plus testdb scripts.
- Tests and configuration classes under accounts show Spring MVC and JPA pattern.

##### Key Architectural Insights from README
- There are three distinct Spring Boot applications, each launched via the same JAR with a mode argument.
- RegistrationService runs on port 1111, exposing Eureka dashboard.
- AccountsService registers itself, exposes account lookup REST API, backed by embedded database.
- WebService registers itself, serves HTML views on port 3333, uses client-side code (Ribbon) to discover/load-balance AccountsService.
- Docker support spins each service in its own container.

a. Main Components
- Service Registry (RegistrationService/Eureka)
- AccountsService (REST API + embedded DB)
- WebService (Spring MVC UI + discovery client)
- Database (H2 or configured RDBMS)
- End-user browser
- (Optional) Docker Host / Network
b. Relationships & Interactions
- On startup, AccountsService & WebService register with Eureka.
- Browser → HTTP GET to WebService (port 3333).
- WebService uses Eureka + Ribbon to call AccountsService REST endpoints.
- AccountsService reads/writes to embedded DB (testdb).
- Eureka dashboard viewable at RegistrationService (port 1111).
c. Architectural Patterns & Principles
- Microservices: each service isolated, independent deployable units.
- Service Registry/Discovery (Eureka) for loose coupling & dynamic endpoints.
- Client-side load balancing (Ribbon within WebService).
- Externalized configuration per-service via YAML.
- Fat JAR + embedded Tomcat pattern for cloud-native packaging.
d. Technologies & Frameworks
- Spring Boot & Spring MVC
- Spring Cloud Netflix Eureka (service registry)
- Ribbon (load balancing)
- Embedded H2 or configurable JDBC (data.sql/schema.sql)
- Thymeleaf/Spring Templates for HTML
- Maven/Gradle build, Docker containerization

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Actor
    Browser("End-User Browser"):::actor

    %% Docker Host Cluster
    subgraph "Docker Host" 
        direction TB

        %% Service Registry
        subgraph "Service Registry"
            direction TB
            Eureka(["Eureka Registry\n(port 1111)"]):::registry
        end

        %% Accounts Service
        subgraph "AccountsService (REST API)"
            direction TB
            AccountsApp(["AccountsServer"]):::service
            DB(["Embedded DB\n(H2)"]):::db
        end

        %% Web Service
        subgraph "WebService (UI)"
            direction TB
            WebApp(["WebServer"]):::service
        end
    end

    %% Interactions
    Browser -->|"HTTP GET /"| WebApp
    WebApp -->|"Service Discovery (Eureka)"| Eureka
    AccountsApp -->|"Service Registration"| Eureka
    WebApp -->|"REST Call /accounts"| AccountsApp
    AccountsApp -->|"JPA/H2 Query"| DB
    Browser -->|"View Eureka Dashboard (port 1111)"| Eureka

    %% Click Events
    click Eureka "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/services/registration/RegistrationServer.java"
    click Eureka "https://github.com/paulc4/microservices-demo/blob/master/src/main/resources/registration-server.yml"
    click AccountsApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/services/accounts/AccountsServer.java"
    click AccountsApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/resources/accounts-server.yml"
    click AccountsApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/accounts/Account.java"
    click AccountsApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/accounts/AccountRepository.java"
    click AccountsApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/accounts/AccountsConfiguration.java"
    click AccountsApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/accounts/AccountsController.java"
    click AccountsApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/accounts/HomeController.java"
    click AccountsApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/resources/testdb/schema.sql"
    click AccountsApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/resources/testdb/data.sql"
    click WebApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/services/web/WebServer.java"
    click WebApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/resources/web-server.yml"
    click WebApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/services/web/WebAccountsService.java"
    click WebApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/services/web/WebAccountsController.java"
    click WebApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/java/io/pivotal/microservices/services/web/HomeController.java"
    click WebApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/resources/web-server/templates/account.html"
    click WebApp "https://github.com/paulc4/microservices-demo/blob/master/src/main/resources/web-server/templates/accounts.html"
    click WebApp "https://github.com/paulc4/microservices-demo/tree/master/Dockerfile"
    click DockerHost "https://github.com/paulc4/microservices-demo/blob/master/pom.xml"

    %% Styles
    classDef registry fill:#ADD8E6,stroke:#036,stroke-width:2px
    classDef service fill:#90EE90,stroke:#070,stroke-width:2px
    classDef db fill:#FFA500,stroke:#a60,stroke-width:2px
    classDef actor fill:#D3D3D3,stroke:#666,stroke-width:2px
```
