# sivaprasadreddy/spring-boot-application-template architecture

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

- Interactive diagram: https://gitdiagram.com/sivaprasadreddy/spring-boot-application-template
- Repository: https://github.com/sivaprasadreddy/spring-boot-application-template

## Overview

##### Project Type and Purpose
- This is a **monolithic, backend-only** Spring Boot application template.
- It provides REST endpoints, persistence via Spring Data JPA/PostgreSQL, Flyway migrations, OpenAPI docs, test automation, CI/CD pipelines, and Docker deployment.

##### Main Architectural Components
a. Client / Consumer
- Any HTTP client (e.g., browser, Postman, another microservice) calling the REST API.
b. Spring Boot Application
- Web layer (Spring MVC controller package `users/web/controller`)
- Service layer (`users/domain/UserService`)
- Repository layer (`users/domain/UserRepository`, Spring Data JPA)
- Flyway migration (runs at startup, scripts under `resources/db/migration`)
- Springdoc OpenAPI (auto-generated API docs)
c. Database
- PostgreSQL instance (used in production via Docker Compose and in tests via Testcontainers)
- Flyway-managed schema migrations
d. CI/CD & Quality Gates
- GitHub Actions (Maven and Gradle workflows under `.github/workflows/`)
- SonarCloud scan (configured via `sonar-project.properties`)
- OWASP Dependency Check
- JaCoCo code coverage
e. Containerization & Deployment
- Cloud Native Buildpacks (Spring Boot Maven/Gradle plugin builds OCI image)
- Docker registry (push built image)
- Docker Compose setup (`deployment/docker-compose/docker-compose.yml`)
- Local dev/test containers (Testcontainers)

##### Relationships & Data Flows
1. Client → HTTP request → Spring MVC Controller (UserController)
2. Controller → invokes → UserService
3. Service → uses → UserRepository (Spring Data JPA)
4. Repository → executes SQL → PostgreSQL DB
5. On app startup → Flyway runs migrations against DB
6. Springdoc generates OpenAPI docs accessible at `/v3/api-docs` and Swagger UI
7. Git push → triggers GitHub Actions → runs build/format-test-coverage → Sonar scan → builds Docker image → publishes to registry
8. Docker Compose pulls application image + postgres image → starts two containers → binds ports (8080 → app, 5432 → db)

##### Architectural Patterns & Principles
- **Layered Architecture**: clear separation of concerns (Web → Service → Persistence).
- **Domain-driven package structure**: `com.sivalabs.myapp.users.domain` vs. `users.web`.
- **12-Factor Apps**: externalize config in `application.properties`.
- **Shift-left testing**: Testcontainers for integration tests (see `TestcontainersConfig.java`).
- **Infrastructure as Code**: Docker Compose for local/dev deployment, Cloud Native Buildpacks for image creation.

## Diagram (Mermaid)

```mermaid
flowchart TD
  classDef web fill:#add8e6;
  classDef service fill:#90ee90;
  classDef infra fill:#ffcc99;
  classDef external fill:#d3d3d3;

  Client["HTTP Client"]:::external

  subgraph "Spring Boot Application"
    direction TB
    Entry["Application.java"]:::service
    MVCConfig["WebMvcConfig"]:::service
    UC["UserController"]:::web
    US["UserService"]:::service
    UR["UserRepository"]:::service
    UE["User"]:::service
    Flyway["Flyway Migration"]:::infra
    AppProps["application.properties"]:::infra
    OpenAPI["Springdoc OpenAPI"]:::infra
    Entry -->|starts up| Flyway
    Client -->|HTTP request| UC
    UC -->|calls| US
    US -->|uses| UR
    UR -->|queries| Db["PostgreSQL"]:::infra
  end

  subgraph "CI/CD Pipeline"
    direction TB
    GH["GitHub Actions"]:::infra
    CI_Maven["ci-maven.yml"]:::infra
    CI_Gradle["ci-gradle.yml"]:::infra
    Sonar["SonarCloud"]:::infra
    OWASP["OWASP DepCheck"]:::infra
    JaCoCo["JaCoCo"]:::infra
    GH --> CI_Maven
    GH --> CI_Gradle
    GH --> Sonar
    GH --> OWASP
    GH --> JaCoCo
    CI_Maven -->|build| POM["pom.xml"]:::infra
    CI_Gradle -->|build| GRADLE["build.gradle.kts"]:::infra
  end

  subgraph "Deployment & Testing"
    direction TB
    Reg["Docker Registry"]:::infra
    Compose["Docker Compose"]:::infra
    Testcont["Testcontainers"]:::infra
    CI_Maven -->|push image| Reg
    CI_Gradle -->|push image| Reg
    Compose -->|pull image| Reg
    Compose -->|start containers| Entry
    Compose -->|start containers| Db
    Testcont -->|integration tests| URTest["UserControllerTest"]:::service
    TestcontConfig["TestcontainersConfig"]:::infra
    AppTests["ApplicationTests"]:::service
    Testcont --> TestcontConfig
    Testcont --> AppTests
  end

  class Client external;
  click Entry "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/main/java/com/sivalabs/myapp/Application.java"
  click MVCConfig "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/main/java/com/sivalabs/myapp/users/config/WebMvcConfig.java"
  click UC "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/main/java/com/sivalabs/myapp/users/web/controller/UserController.java"
  click US "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/main/java/com/sivalabs/myapp/users/domain/UserService.java"
  click UR "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/main/java/com/sivalabs/myapp/users/domain/UserRepository.java"
  click UE "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/main/java/com/sivalabs/myapp/users/domain/User.java"
  click Flyway "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/main/resources/db/migration/V1__Init.sql"
  click AppProps "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/main/resources/application.properties"
  click Compose "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/deployment/docker-compose/docker-compose.yml"
  click CI_Maven "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/.github/workflows/ci-maven.yml"
  click CI_Gradle "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/.github/workflows/ci-gradle.yml"
  click Sonar "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/sonar-project.properties"
  click POM "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/pom.xml"
  click GRADLE "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/build.gradle.kts"
  click TestcontConfig "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/test/java/com/sivalabs/myapp/TestcontainersConfig.java"
  click URTest "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/test/java/com/sivalabs/myapp/users/web/controller/UserControllerTest.java"
  click AppTests "https://github.com/sivaprasadreddy/spring-boot-application-template/blob/main/src/test/java/com/sivalabs/myapp/ApplicationTests.java"
```
