# zshn-dev/quarkus-flyway-demo architecture

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

- Interactive diagram: https://gitdiagram.com/zshn-dev/quarkus-flyway-demo
- Repository: https://github.com/zshn-dev/quarkus-flyway-demo

## Overview

##### Project Type and Purpose
- Type: A Java-based microservice (Quarkus) exposing REST endpoints
- Purpose: Demonstrate a Quarkus application with Flyway migrations on PostgreSQL, packaged for JVM or GraalVM native.

##### Main Components
a. Docker Compose Network
– postgres_db (PostgreSQL container)
– pgadmin (PgAdmin container)
– quarkus_app (our service, runs either in dev, JVM-jar, or native)
b. Quarkus Application
– REST Layer (GreetingResource.java)
– Flyway Migration (src/main/resources/db/migration/*.sql)
– JDBC Datasource (application.properties)
c. Database
– PostgreSQL instance
– flyway_schema_history table & author/book tables
d. External/Dev Tools
– Gradle Wrapper (build scripts, native container build)
– Dev UI (Quarkus Dev UI at /q/dev/)
– Native-test / Integration tests

##### Relationships & Data Flows
1. On `docker compose up`:
- Flyway (embedded in Quarkus startup) reads SQL files → applies migrations → updates PostgreSQL schema.
- PgAdmin connects to PostgreSQL for DB management.
2. At runtime:
- Client (e.g., browser, curl) → HTTP request → Quarkus REST endpoint (GreetingResource) → JDBC → PostgreSQL → result → back to client.
3. Build & Deploy:
- Developer runs `./gradlew build` → produces JAR/uber-jar/native binary → deployed as Docker image (Dockerfile.jvm or Dockerfile.native) → runs in container.

##### Architectural Patterns & Design Principles
– Layered Architecture:
- Controller/Resource layer (JAX-RS)
- Migration layer (Flyway) at startup
- Persistence layer (JDBC / DataSource)
– Infrastructure as Code: Dockerfiles + docker-compose
– Twelve-factor principles: externalize configs via env vars (`.env`)

##### Inside it, place three containers
– postgres_db (PostgreSQL, port 5432)
– pgadmin (PgAdmin UI, port 5050)
– quarkus_app (Quarkus service, port 8080)
##### Inside quarkus_app, subdivide into
– Dev UI (only in dev mode)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Docker Compose Network"
        postgres_db["postgres_db: PostgreSQL\nport 5432"]:::db
        pgadmin["pgadmin: PgAdmin UI\nport 5050"]:::container
        quarkus_app["quarkus_app: Quarkus Service\nport 8080"]:::container
        subgraph "Quarkus Application"
            flyway["Flyway Migration\n(src/main/resources/db/migration)"]:::module
            rest["REST Module\n(GreetingResource)"]:::module
            datasource["JDBC DataSource\n(application.properties)"]:::module
            devui["Dev UI (/q/dev)"]:::module
        end
    end

    client["Client\n(browser/curl)"]:::external
    subgraph "Build & Package"
        gradle["Gradle Build & Wrapper\n(build.gradle.kts, gradlew)"]:::tool
        jvmDocker["Dockerfile.jvm"]:::file
        nativeDocker["Dockerfile.native"]:::file
        legacyDocker["Dockerfile.legacy-jar"]:::file
        microDocker["Dockerfile.native-micro"]:::file
        dockerImage["quarkus_app Image"]:::container
    end

    subgraph "Tests"
        unitTest["Unit Tests"]:::test
        integTest["Native Integration Tests"]:::test
    end

    %% Runtime Flows
    client -->|"HTTP Request"| quarkus_app
    quarkus_app -->|"exposes /q/dev"| devui
    flyway -->|"applies migrations"| postgres_db
    rest -->|"calls JDBC"| datasource
    datasource -->|"queries"| postgres_db
    pgadmin -->|"admin UI"| postgres_db

    %% Build & Deploy Flows
    gradle -->|"builds"| jvmDocker
    gradle -->|"builds"| nativeDocker
    gradle -->|"builds"| legacyDocker
    gradle -->|"builds"| microDocker
    jvmDocker -->|"creates image"| dockerImage
    nativeDocker -->|"creates image"| dockerImage
    legacyDocker -->|"creates image"| dockerImage
    microDocker -->|"creates image"| dockerImage
    dockerImage -.->|"deploys"| quarkus_app

    %% Test Flows
    unitTest -.->|"calls"| quarkus_app
    integTest -.->|"calls"| quarkus_app

    %% Click Events
    click postgres_db "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/compose.yaml"
    click pgadmin "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/compose.yaml"
    click quarkus_app "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/compose.yaml"
    click jvmDocker "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/src/main/docker/Dockerfile.jvm"
    click nativeDocker "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/src/main/docker/Dockerfile.native"
    click legacyDocker "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/src/main/docker/Dockerfile.legacy-jar"
    click microDocker "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/src/main/docker/Dockerfile.native-micro"
    click rest "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/src/main/java/com/demo/GreetingResource.java"
    click datasource "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/src/main/resources/application.properties"
    click gradle "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/build.gradle.kts"
    click integTest "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/src/native-test/java/com/demo/GreetingResourceIT.java"
    click unitTest "https://github.com/zshn-dev/quarkus-flyway-demo/blob/main/src/test/java/com/demo/GreetingResourceTest.java"

    %% Styles
    classDef container fill:#f9f,stroke:#333,stroke-width:1px;
    classDef db fill:#ccf,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;
    classDef module fill:#cfc,stroke:#333,stroke-width:1px;
    classDef external fill:#ffc,stroke:#333,stroke-width:1px;
    classDef tool fill:#fcf,stroke:#333,stroke-width:1px;
    classDef file fill:#cff,stroke:#333,stroke-width:1px;
    classDef test fill:#fdd,stroke:#933,stroke-width:1px,stroke-dasharray: 2 2;
```
