# philippstahlberggit/dat251_project_library_app architecture

> Architecture diagram of the GitHub repository philippstahlberggit/dat251_project_library_app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/philippstahlberggit/dat251_project_library_app
- Repository: https://github.com/philippstahlberggit/dat251_project_library_app

## Overview

##### What this project is (from tree + README)
**Project type:** Java **Spring Boot** application built with **Gradle (Kotlin DSL)**.
**Likely architecture style:** a **single deployable monolith** (one Spring Boot service) named `LibraryApp`.

**Signals in the repo:**
- `build.gradle.kts`, `settings.gradle.kts`, `gradlew*`, `gradle/wrapper/*` ⇒ Gradle-built JVM service.
- `src/main/java/.../LibraryAppApplication.java` ⇒ standard Spring Boot entrypoint class.
- `src/main/resources/application.yaml` ⇒ Spring Boot configuration (ports, DB, profiles, etc.).
- `src/test/java/...LibraryAppApplicationTests.java` ⇒ Spring Boot test harness.
- `.github/workflows/Java CI with Gradle.yaml` ⇒ CI pipeline for Java/Gradle.
- `.github/workflows/python-app.yml` ⇒ extra CI workflow (possibly for tooling/scripts); include it only if it actually runs something relevant.

##### Open `build.gradle.kts` and list key dependencies
- `spring-boot-starter-web` ⇒ REST controllers, HTTP endpoints.
- `spring-boot-starter-data-jpa` + DB driver ⇒ persistence layer + RDBMS.
- `spring-boot-starter-security` ⇒ authn/authz component.
- `spring-kafka`, `amqp`, etc. ⇒ async messaging components.
- `actuator`, `micrometer` ⇒ observability endpoints/metrics.
2. **Scan `src/main/java/app/main/LibraryApp` for packages** (even if not in the provided snippet):
- `controller` / `web` (API layer)
- `service` (domain/business logic)
- `repository` / `dao` (data access)
- `model` / `entity` / `domain`
- `config` (Spring config)
- `security`
- `integration` / `client` (calls to external systems)
##### Read `application.yaml` to identify external dependencies
- DB URL / host, credentials (or env var placeholders)
- server port/context path
- message broker endpoints
- third-party API base URLs
- profiles (dev/test/prod)
4. **Check `.github/workflows/*`** to understand build/test/release flow and include a lightweight CI/CD view if needed.

This is important: don’t guess components that are not backed by dependencies/config/packages. If a DB is not referenced anywhere, keep persistence as “TBD / not configured” rather than drawing PostgreSQL because it’s a “library app”.

##### Context (C4 Level 1) — “What is this system and who uses it?”
- **User / Admin** (actor)
- **LibraryApp (Spring Boot service)** (system)
- Any **external systems** discovered in `application.yaml` and `build.gradle.kts` (DB, identity provider, external book catalog APIs, etc.)

- User → LibraryApp (HTTP/HTTPS)
- LibraryApp → External dependencies (JDBC, REST, etc.)

##### Container (C4 Level 2) — “What deployables exist?”
Based on repo, at minimum:
- **Container: LibraryApp** (Java, Spring Boot, Gradle build)
- **Container: Database** (only if config/deps confirm it)
- **Container: CI pipeline** (GitHub Actions) as “build/test artifact” flow (optional, but often useful)

- **prod** branch → CI → deploy to Prod runtime
- **testing** branch → CI → deploy to Test runtime
(Your README explicitly defines `production` and `testing` branches, so including this pipeline view is justified.)

##### Component (C4 Level 3) — “Inside the Spring Boot app”

- **Web/API Layer**
- Controllers (REST endpoints)
- Request/response DTOs
- **Service Layer**
- Core domain services (e.g., `BookService`, `MemberService`, `LoanService`)
- Transaction boundaries
- **Persistence Layer**
- Repositories (Spring Data interfaces)
- Entities / ORM mappings
- **Cross-cutting**
- Security config / filters (if present)
- Exception handling / validation
- Observability (Actuator/Micrometer)
- Integration clients (if present)

- Controller → Service (method calls)
- Service → Repository (data access)
- Repository → DB (JDBC)
- Service → External API clients (REST/gRPC)
- Security filters wrap Controller entry

##### Relationships and interactions to make explicit
- “HTTP REST: /api/books”
- “JPA/Hibernate: CRUD on BOOK table”
- “OAuth2/JWT validation” (if security exists)
- “GitHub Actions: gradle test → build artifact”

Also distinguish:

##### Important architectural patterns to highlight (for this repo)
Given the Spring Boot structure, the most likely patterns to show are:
- **Layered architecture** (Controller → Service → Repository)
- **Configuration via `application.yaml`** (12-factor style; values via env vars in real deployments)
- **Branch-based release flow** (testing → production), enforced by protected branch PRs

- **Profile-based wiring** (test vs prod beans, different DBs, etc.)

From what’s certain:
- **Java**
- **Spring Boot**
- **Gradle**
- **GitHub Actions**
- **YAML config** (`application.yaml`)
- **JUnit/Spring Boot Test** (from `src/test`)

From what you must confirm (only label if present in Gradle/config):
- Spring Web (REST)
- Spring Data JPA + Hibernate
- PostgreSQL/MySQL/H2/etc.
- Spring Security
- Actuator/Micrometer
- Flyway/Liquibase migrations

##### Context
- Actor: Librarian/User
- System: LibraryApp (Spring Boot)
- External: “Database (TBD from config)”, “External APIs (TBD)”

##### Container
- GitHub Repo → GitHub Actions (Gradle build + tests) → Artifact
- Artifact → Deploy to Testing (from `testing` branch)
- Artifact → Deploy to Production (from `production` branch, PR gated)
- Runtime: LibraryApp container/VM + optional DB

##### Component
- LibraryAppApplication (bootstraps)
- Controllers (if present)
- Services (if present)
- Repositories (if present)
- application.yaml configuration feeding the app
- Tests (as a separate “verification” boundary, not runtime)

- `build.gradle.kts`: exact starters/drivers used
- `application.yaml`: external endpoints, profiles
- Any `Dockerfile`, `docker-compose.yml`, Helm charts, or deploy manifests (none shown—so deployment may be out-of-repo)
- Package structure under `src/main/java/...` beyond the main class

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =======================
  %% C4 Level 1 — Context
  %% =======================
  subgraph "Context (C4 L1) — Who uses the system?"
    direction TB
    User["User / Librarian"]:::actor
    Admin["Admin"]:::actor

    LibraryAppSys["LibraryApp (System)\nJava + Spring Boot"]:::system

    DBTBD[("Database (TBD)\nOnly if configured via deps/yaml")]:::datastore
    ExtAPIs["External Systems (TBD)\n3rd-party APIs, IdP, brokers"]:::external
  end

  User -->|"HTTP/HTTPS: uses UI/API"| LibraryAppSys
  Admin -->|"HTTP/HTTPS: admin operations"| LibraryAppSys
  LibraryAppSys -->|"JDBC (if configured)"| DBTBD
  LibraryAppSys -->|"REST/gRPC/AMQP/Kafka (if configured)"| ExtAPIs

  %% =======================
  %% C4 Level 2 — Containers
  %% =======================
  subgraph "Containers (C4 L2) — Deployables and build flow"
    direction TB

    subgraph "Source Control"
      direction TB
      Repo["Git Repository"]:::artifact
      Readme["README (branching rules:\nproduction/testing)"]:::artifact
    end

    subgraph "CI/CD (GitHub Actions)"
      direction TB
      GHA["GitHub Actions"]:::ci
      JavaCI["Workflow: Java CI with Gradle\n(build + test)"]:::ci
      PyCI["Workflow: Python workflow\n(tooling/scripts if used)"]:::ci
      Artifact["Build Artifact\n(JAR)"]:::artifact
    end

    subgraph "Runtime Environments"
      direction TB
      TestingEnv["Testing Runtime\n(deploy from testing branch)"]:::runtime
      ProdEnv["Production Runtime\n(deploy from production branch)"]:::runtime

      TestingApp["LibraryApp (Spring Boot)\nRunning service"]:::system
      ProdApp["LibraryApp (Spring Boot)\nRunning service"]:::system

      TestingDB[("Database (TBD)")]:::datastore
      ProdDB[("Database (TBD)")]:::datastore
    end
  end

  Repo -->|"contains"| Readme
  Repo -->|"triggers"| GHA
  GHA -->|"runs"| JavaCI
  GHA -.->|"runs (optional)"| PyCI
  JavaCI -->|"gradle build + test"| Artifact

  Artifact -->|"deploy (testing branch)"| TestingEnv
  Artifact -->|"deploy (production branch)"| ProdEnv

  TestingEnv -->|"starts"| TestingApp
  ProdEnv -->|"starts"| ProdApp

  TestingApp -->|"JDBC (if configured)"| TestingDB
  ProdApp -->|"JDBC (if configured)"| ProdDB

  %% =======================
  %% C4 Level 3 — Components
  %% =======================
  subgraph "Components (C4 L3) — Inside LibraryApp (Spring Boot)"
    direction TB

    subgraph "Bootstrap + Configuration"
      direction TB
      Entrypoint["LibraryAppApplication\n(Spring Boot entrypoint)"]:::component
      AppYaml["application.yaml\n(config: port/profiles/external endpoints)"]:::config
      GradleBuild["Gradle build config\n(deps define enabled modules)"]:::build
      GradleSettings["Gradle settings\n(project name/modules)"]:::build
      GradleWrapper["Gradle Wrapper\n(reproducible builds)"]:::build
      GradleWrapperProps["gradle-wrapper.properties"]:::build
      GradleWrapperJar["gradle-wrapper.jar"]:::build
    end

    subgraph "Web/API Layer (only if deps/packages exist)"
      direction TB
      Controllers["Controllers\n(REST endpoints)"]:::component
      DTOs["DTOs\n(request/response models)"]:::component
    end

    subgraph "Service Layer (only if packages exist)"
      direction TB
      Services["Domain Services\n(business logic, transactions)"]:::component
    end

    subgraph "Persistence Layer (only if deps/config exist)"
      direction TB
      Repos["Repositories / DAOs\n(Spring Data)"]:::component
      Entities["Entities / Domain Model\n(ORM mappings)"]:::component
      AppDB[("RDBMS (TBD)\nvia JPA/JDBC driver")]:::datastore
    end

    subgraph "Cross-cutting (only if deps exist)"
      direction TB
      Security["Security\n(filters/config, authn/authz)"]:::component
      Observability["Observability\n(Actuator/Metrics if enabled)"]:::component
      Integration["Integration Clients\n(external APIs/brokers if configured)"]:::component
      Errors["Validation + Exception Handling"]:::component
    end

    subgraph "Verification (non-runtime)"
      direction TB
      Tests["Spring Boot Test Harness\n(JUnit/SpringBootTest)"]:::test
    end
  end

  Entrypoint -->|"bootstraps"| Controllers
  Entrypoint -->|"loads"| AppYaml

  Controllers -->|"maps to"| DTOs
  Controllers -->|"calls"| Services
  Services -->|"CRUD via"| Repos
  Repos -->|"maps"| Entities
  Repos -->|"JPA/JDBC"| AppDB

  Security -.->|"wraps HTTP requests"| Controllers
  Errors -.->|"applies to"| Controllers
  Observability -.->|"exposes health/metrics"| LibraryAppSys
  Services -.->|"calls (if configured)"| Integration
  Integration -.->|"REST/gRPC/AMQP/Kafka"| ExtAPIs

  Tests -.->|"verifies"| Entrypoint
  Tests -.->|"verifies"| Controllers
  Tests -.->|"verifies"| Services

  GradleWrapperProps -->|"configures"| GradleWrapper
  GradleWrapperJar -->|"implements"| GradleWrapper

  %% =======================
  %% Click Events (from component_mapping)
  %% =======================
  click Entrypoint "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/src/main/java/app/main/LibraryApp/LibraryAppApplication.java"
  click AppYaml "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/src/main/resources/application.yaml"
  click GradleBuild "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/build.gradle.kts"
  click GradleSettings "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/settings.gradle.kts"

  click JavaCI "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/.github/workflows/Java CI with Gradle.yaml"
  click PyCI "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/.github/workflows/python-app.yml"
  click Tests "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/src/test/java/app/main/LibraryApp/LibraryAppApplicationTests.java"
  click Readme "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/README.md"

  click GradleWrapperProps "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/gradle/wrapper/gradle-wrapper.properties"
  click GradleWrapperJar "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/gradle/wrapper/gradle-wrapper.jar"

  %% Wrapper scripts (separate nodes to maximize click coverage)
  subgraph "Build Scripts"
    direction TB
    GradlewSh["gradlew (Unix script)"]:::build
    GradlewBat["gradlew.bat (Windows script)"]:::build
  end
  GradlewSh -->|"invokes"| GradleWrapper
  GradlewBat -->|"invokes"| GradleWrapper
  click GradlewSh "https://github.com/philippstahlberggit/dat251_project_library_app/tree/production/gradlew"
  click GradlewBat "https://github.com/philippstahlberggit/dat251_project_library_app/blob/production/gradlew.bat"

  %% =======================
  %% Styles
  %% =======================
  classDef actor fill:#ffffff,stroke:#2b2b2b,stroke-width:1px,color:#111
  classDef system fill:#cfe8ff,stroke:#1b66b3,stroke-width:1.5px,color:#0b2a44
  classDef component fill:#d8ecff,stroke:#1b66b3,stroke-width:1px,color:#0b2a44
  classDef datastore fill:#e6e6e6,stroke:#555,stroke-width:1px,color:#111
  classDef external fill:#ffe6c7,stroke:#c26b00,stroke-width:1px,color:#4a2a00
  classDef ci fill:#d7f7d7,stroke:#1b7f3a,stroke-width:1px,color:#0f3d1f
  classDef runtime fill:#eefbe8,stroke:#3d8b2a,stroke-width:1px,color:#103a0d
  classDef artifact fill:#f2f2f2,stroke:#666,stroke-width:1px,color:#111
  classDef config fill:#fff5cc,stroke:#b38b00,stroke-width:1px,color:#3d2f00
  classDef build fill:#eadcff,stroke:#6a3fb3,stroke-width:1px,color:#2b134d
  classDef test fill:#ffd6e7,stroke:#b31b5a,stroke-width:1px,color:#4d0f25
```
