# sdeleuze/petclinic-efficient-container architecture

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

- Interactive diagram: https://gitdiagram.com/sdeleuze/petclinic-efficient-container
- Repository: https://github.com/sdeleuze/petclinic-efficient-container

## Overview

##### Project type and purpose
- This is a full-stack, monolithic Spring Boot web application (“Spring Petclinic”) repurposed to demonstrate containerization and runtime-efficiency improvements when migrating from Spring Boot 2/Java 8 to Spring Boot 3/Java 21.
- It includes a traditional MVC web UI (Thymeleaf), REST endpoints, a persistence layer with Spring Data JDBC and caching, all packaged and deployed via Docker & Docker Compose.

##### Main components
a. Client layer
- Browser – renders Thymeleaf pages and consumes JSON endpoints
- Benchmark tool (Oha) – external load-testing client
b. Application layer (single Spring Boot container)
- Controllers (e.g., OwnerController, VetController, VisitController, CrashController)
- View engine (Thymeleaf templates + static resources)
- Service & caching (annotated @Cacheable on VetRepository)
- Persistence (Spring Data JDBC repositories connecting over JDBC)
- Configuration (application.properties, CacheConfiguration)
c. Data layer
- PostgreSQL container – initialized via sql/1-schema-postgres.sql & sql/2-data-postgres.sql
d. Build & deployment pipeline
- Maven wrapper & pom.xml – compile, test, package
- Dockerfile & build-container-image.sh – multi-stage image build using self-extracting JAR
- Docker Compose – orchestrates Petclinic and Postgres services

##### Relationships and interactions
- Browser → (HTTP/HTTPS) → Spring Boot App: requests for HTML (Thymeleaf) or JSON
- Spring Boot App → (JDBC) → PostgreSQL: CRUD operations
- Spring Boot App → (in-memory cache) → cached Vet data
- Maven → builds → JAR → Docker image → run by Docker Compose
- Oha → (HTTP) → endpoints for benchmarking

##### Architectural patterns & principles
- Layered MVC: presentation (controllers + views), business/validation, persistence
- Container-first deployment: immutable build artifacts, self-extracting executable JAR
- Infrastructure as Code: docker-compose defines networking, resource limits (2 CPU, 2 GB RAM)
- Cache-aside pattern for frequently accessed data (vets)

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Clients
    subgraph "External Clients"
        Browser["Browser"]:::external
        Oha["Oha Load Tester (Oha)"]:::external
    end

    %% Build & Deployment Pipeline
    subgraph "Build & Deployment Pipeline"
        Maven["Maven Wrapper & pom.xml"]:::build
        Dockerfile["Dockerfile"]:::build
        BuildSh["build-container-image.sh"]:::build
        Compose["docker-compose.yml"]:::build
    end

    %% Runtime Environment
    subgraph "Runtime Environment"
        subgraph "Docker Network"
            subgraph "Spring Boot App (Container)"
                Entry["PetClinicApplication"]:::runtime

                subgraph "Controllers Layer"
                    OwnerCtrl["OwnerController"]:::runtime
                    PetCtrl["PetController"]:::runtime
                    VisitCtrl["VisitController"]:::runtime
                    VetCtrl["VetController"]:::runtime
                    CrashCtrl["CrashController"]:::runtime
                    WelcomeCtrl["WelcomeController"]:::runtime
                end

                subgraph "Service & Cache Layer"
                    Service["Service Layer"]:::runtime
                    CacheConfig["CacheConfiguration"]:::runtime
                end

                subgraph "Repositories Layer"
                    OwnerRepo["OwnerRepository"]:::runtime
                    PetRepo["PetRepository"]:::runtime
                    VisitRepo["VisitRepository"]:::runtime
                    VetRepo["VetRepository"]:::runtime
                    SpecRepo["SpecialtyRepository"]:::runtime
                end

                subgraph "View Layer"
                    Templates["Thymeleaf Templates"]:::runtime
                    Static["Static Resources"]:::runtime
                end
            end

            subgraph "PostgreSQL Container"
                DB["PostgreSQL"]:::db
            end
        end
    end

    %% Build Flow
    Maven -->|"builds JAR"| Dockerfile
    Dockerfile -->|creates image| BuildSh
    BuildSh -->|used by| Compose

    %% Runtime Interactions
    Browser -->|"HTTP/HTTPS"| Entry
    Oha -->|"HTTP"| Entry
    Entry -->|"JDBC"| DB
    Entry -->|"cache-aside"| CacheConfig
    Entry -->|"invokes"| OwnerCtrl
    Entry -->|"invokes"| PetCtrl
    Entry -->|"invokes"| VisitCtrl
    Entry -->|"invokes"| VetCtrl
    Entry -->|"invokes"| CrashCtrl
    Entry -->|"invokes"| WelcomeCtrl
    OwnerCtrl -->|calls| OwnerRepo
    PetCtrl -->|calls| PetRepo
    VisitCtrl -->|calls| VisitRepo
    VetCtrl -->|calls| VetRepo
    VetRepo -->|uses| CacheConfig
    Entry -->|renders| Templates
    Entry -->|serves| Static

    %% Click Events
    click Entry "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java"
    click OwnerCtrl "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java"
    click PetCtrl "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/owner/PetController.java"
    click VisitCtrl "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java"
    click VetCtrl "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/vet/VetController.java"
    click CrashCtrl "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/system/CrashController.java"
    click WelcomeCtrl "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/system/WelcomeController.java"
    click OwnerRepo "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java"
    click PetRepo "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/owner/PetRepository.java"
    click VisitRepo "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java"
    click VetRepo "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java"
    click SpecRepo "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/vet/SpecialtyRepository.java"
    click CacheConfig "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java"
    click Templates "https://github.com/sdeleuze/petclinic-efficient-container/tree/main/src/main/resources/templates"
    click Static "https://github.com/sdeleuze/petclinic-efficient-container/tree/main/src/main/resources/static/resources"
    click Maven "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/pom.xml"
    click Dockerfile "https://github.com/sdeleuze/petclinic-efficient-container/tree/main/Dockerfile"
    click BuildSh "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/build-container-image.sh"
    click Compose "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/docker-compose.yml"
    click DB "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/sql/1-schema-postgres.sql"
    click DB "https://github.com/sdeleuze/petclinic-efficient-container/blob/main/sql/2-data-postgres.sql"

    %% Styles
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef build fill:#90EE90,stroke:#333,stroke-width:1px
    classDef runtime fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef db fill:#DDA0DD,stroke:#333,stroke-width:1px
```
