# kilyinov/spring-petclinic architecture

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

- Interactive diagram: https://gitdiagram.com/kilyinov/spring-petclinic
- Repository: https://github.com/kilyinov/spring-petclinic

## Overview

##### Project Type and Purpose
- This is a Spring Boot full-stack web application that demonstrates a sample "Pet Clinic" system. It illustrates how to build a Spring-based application featuring layers such as web controllers, service logic, repositories, and persistence (with support for multiple databases: in-memory H2, MySQL, PostgreSQL).
- The application uses Thymeleaf templates for its UI and includes a CSS layer (built from SCSS combined with Bootstrap), making it an end-to-end demo both for backend and frontend concerns.

##### Analysis of the File Structure
- The top-level directories indicate a typical Java Maven/Gradle project layout:
- Files like pom.xml, build.gradle, settings.gradle, and wrapper scripts (mvnw/mvnw.cmd, gradlew/gradlew.bat) ensure that it can be built with both Maven and Gradle.
- The src/main directory holds the production code, including subfolders:
▪ Java packages under src/main/java/org/springframework/samples/petclinic that contain key application classes (e.g., PetClinicApplication, controllers, models).
▪ Resources, including configuration files (application.properties, db schemas and sample data for H2, MySQL, and PostgreSQL), static assets (CSS, images, fonts), and Thymeleaf templates.
- The src/test directory contains unit and integration tests for various components.
- Additional configuration folders like .devcontainer, .github/workflows, and Docker Compose files indicate support for containerized deployments and CI/CD pipelines.
- The presence of checkstyle configurations and the build scripts also highlight emphasis on code quality and convention enforcement.

##### Extracted Architectural Components
a. Main Application:
- PetClinicApplication.java acts as the entry point.
b. Web Layer (Presentation):
- Controllers (e.g., OwnerController, PetController, VetController, VisitController, WelcomeController, CrashController) handling HTTP requests, mapping URLs, and preparing responses (using Thymeleaf).
- Templates under src/main/resources/templates organize the UI views.
- Static assets (CSS, images, fonts) under src/main/resources/static.
c. Business Logic / Service Layer:
- Though services might not be explicitly in a separate package, the controllers and repository interactions (and possible service classes) represent the application’s core business logic.
d. Data Access Layer:
- Repositories (e.g., OwnerRepository, VetRepository) that interact with the underlying databases.
- Database configurations and SQL scripts under src/main/resources/db for H2, MySQL, and PostgreSQL.
- Models representing the domain (Owner, Person, Pet, Vet, etc.) in the petclinic/model and petclinic/owner packages.
e. Infrastructure and External Integrations:
- Cache configuration (CacheConfiguration.java) and integration with external databases.
- Build and containerization components (Docker-compose.yml, Maven/Gradle configuration files).
- Test applications leveraging Testcontainers and Docker Compose for integration tests.

##### Essential Elements
- For example, from "Browser" to "Controller" to "Service" to "Repository" and from "Repository" to "Database".
- Abbreviations (if any),
- Notes about profiles for different database configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
  B("Browser"):::client

  subgraph "Frontend Layer"
    FT("Thymeleaf Templates"):::frontend
    SA("Static Assets (CSS, images, fonts)"):::frontend
  end

  subgraph "Backend Layer"
    APP("PetClinicApplication"):::backend
    C1("OwnerController"):::controller
    C2("PetController"):::controller
    C3("VisitController"):::controller
    C4("VetController"):::controller
    C5("CrashController"):::controller
    C6("WelcomeController"):::controller
    S("Service Layer"):::service
    R1("OwnerRepository"):::repository
    R2("VetRepository"):::repository
    CACHE("Cache Configuration"):::infra
  end

  subgraph "Persistence Layer"
    DB1("H2 Database"):::database
    DB2("MySQL Database"):::database
    DB3("PostgreSQL Database"):::database
  end

  subgraph "Build & Deployment"
    MAVEN("Maven Build"):::cicd
    GRADLE("Gradle Build"):::cicd
    DOCKER("Docker / Containerization"):::cicd
    GHA("GitHub Actions"):::cicd
  end

  %% Main flow
  B --> FT
  FT --> APP
  APP --> C1
  C1 --> C2
  C2 --> C3
  C3 --> C4
  C4 --> C5
  C5 --> C6
  C6 --> S
  S --> R1
  S --> R2
  R1 --> DB1
  R2 --> DB2
  R2 --> DB3
  R1 --> CACHE
  CACHE --> DB1

  %% Build & Deployment dotted links
  APP -.-> MAVEN
  APP -.-> GRADLE
  APP -.-> DOCKER
  APP -.-> GHA

  %% Additional connection between UI assets
  FT --> SA

  %% Legend subgraph
  subgraph "Legend"
    L1["Browser (Client)"]:::client
    L2["UI / Presentation Layer (Thymeleaf Templates & Static Assets)"]:::frontend
    L3["Backend Application (Controllers, Service, Repositories)"]:::backend
    L4["Data Persistence (Databases)"]:::database
    L5["Build & Deployment (Maven, Gradle, Docker, GitHub Actions)"]:::cicd
  end

  %% Click events for component mapping
  click APP "https://github.com/kilyinov/spring-petclinic/blob/kosta/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java"
  click C1 "https://github.com/kilyinov/spring-petclinic/blob/kosta/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java"
  click C2 "https://github.com/kilyinov/spring-petclinic/blob/kosta/src/main/java/org/springframework/samples/petclinic/owner/PetController.java"
  click C3 "https://github.com/kilyinov/spring-petclinic/blob/kosta/src/main/java/org/springframework/samples/petclinic/owner/VisitController.java"
  click C4 "https://github.com/kilyinov/spring-petclinic/blob/kosta/src/main/java/org/springframework/samples/petclinic/vet/VetController.java"
  click C5 "https://github.com/kilyinov/spring-petclinic/blob/kosta/src/main/java/org/springframework/samples/petclinic/system/CrashController.java"
  click C6 "https://github.com/kilyinov/spring-petclinic/blob/kosta/src/main/java/org/springframework/samples/petclinic/system/WelcomeController.java"
  click FT "https://github.com/kilyinov/spring-petclinic/tree/kosta/src/main/resources/templates"
  click SA "https://github.com/kilyinov/spring-petclinic/tree/kosta/src/main/resources/static"
  click R1 "https://github.com/kilyinov/spring-petclinic/blob/kosta/src/main/java/org/springframework/samples/petclinic/owner/OwnerRepository.java"
  click R2 "https://github.com/kilyinov/spring-petclinic/blob/kosta/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java"
  click DB1 "https://github.com/kilyinov/spring-petclinic/tree/kosta/src/main/resources/db/h2"
  click DB2 "https://github.com/kilyinov/spring-petclinic/tree/kosta/src/main/resources/db/mysql"
  click DB3 "https://github.com/kilyinov/spring-petclinic/tree/kosta/src/main/resources/db/postgres"
  click CACHE "https://github.com/kilyinov/spring-petclinic/blob/kosta/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java"
  click MAVEN "https://github.com/kilyinov/spring-petclinic/blob/kosta/pom.xml"
  click GRADLE "https://github.com/kilyinov/spring-petclinic/blob/kosta/build.gradle"
  click DOCKER "https://github.com/kilyinov/spring-petclinic/blob/kosta/docker-compose.yml"
  click GHA "https://github.com/kilyinov/spring-petclinic/tree/kosta/.github/workflows"

  %% Class definitions for color coding
  classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
  classDef backend fill:#ccf,stroke:#333,stroke-width:2px;
  classDef controller fill:#9f9,stroke:#333,stroke-width:2px;
  classDef service fill:#fc9,stroke:#333,stroke-width:2px;
  classDef repository fill:#ff9,stroke:#333,stroke-width:2px;
  classDef database fill:#cfc,stroke:#333,stroke-width:2px;
  classDef infra fill:#fcc,stroke:#333,stroke-width:2px;
  classDef cicd fill:#cff,stroke:#333,stroke-width:2px;
  classDef client fill:#ffb,stroke:#333,stroke-width:2px;

  class APP backend;
  class C1,C2,C3,C4,C5,C6 controller;
  class S service;
  class R1,R2 repository;
  class DB1,DB2,DB3 database;
  class CACHE infra;
  class MAVEN,GRADLE,DOCKER,GHA cicd;
  class FT,SA frontend;
  class B client;
  class L1 client;
  class L2 frontend;
  class L3 backend;
  class L4 database;
  class L5 cicd;
```
