# it-at-m/dave-backend architecture

> Architecture diagram of the GitHub repository it-at-m/dave-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/it-at-m/dave-backend
- Repository: https://github.com/it-at-m/dave-backend

## Overview

##### Project Type and Purpose
- This repository is the “Backend (Datenportal)” component for DAVe – a core Spring Boot service providing business logic for several frontends (Datenportal, Adminportal, Selfserviceportal) and an EAI interface.
- It handles data access, search functionality (using Elasticsearch for “Stammdaten”), relational database storage (for Zähldaten), integrated PDF generation, data processing (including KI-based Hochrechnung), and external service integration (email, SSO, etc.).
- Technologies include Java 21, Spring Boot 3.3, and Elasticsearch 8.15, with deployment support via Docker and Maven.

##### File Structure to Identify Main Components
- Presentation/API Layer: Located in the “src/main/java/de/muenchen/dave/controller” folder. These controllers expose REST endpoints for frontends and other integrated systems.
- Business Logic / Service Layer: Numerous services in “src/main/java/de/muenchen/dave/services” (including specialized subdirectories for messstelle, email, pdfgeneration, etc.) implement the core application logic.
- Persistence/Repository Layer: Found in “src/main/java/de/muenchen/dave/repositories” (both relational and Elasticsearch repositories) for data access and storage. This separates data retrieval logic for both types of data.
- Domain Model: Under “src/main/java/de/muenchen/dave/domain”, showing how various business entities (e.g., Zaehlung, Zaehlstelle, Messstelle) are modeled.
- Configuration & Infrastructure: The “src/main/java/de/muenchen/dave/configuration” folder provides configuration classes (caching, security, Flyway migration, aspect logging, etc.), while additional files (application.yml, Dockerfile, and migration scripts) support environment settings and deployment.
- Additional Utilities: Supporting functionality like PDF generation templates (and helper classes), file templates with Mustache, email integration, and data processing utilities.
- Security & SSO: Classes in “src/main/java/de/muenchen/dave/security” and related “sso-config” files indicate integration with SSO/authorization mechanisms.

##### Architectural Patterns and Key Relationships
- Layered Architecture: The system follows a clear separation of concerns – Controllers (API) call Services (business logic), which in turn interact with Repositories (database and search engines) and Domain models.
- Integration with External Systems:
– Relational Database (e.g., Oracle) for transactional data storage.
– Elasticsearch for indexing and searching “Stammdaten”.
– External services for PDF generation (using Mustache templates) and email handling.
- Use of Aspect-oriented programming and caching configurations indicates performance optimizations and modular cross-cutting concerns.
- Security configurations demonstrating server-to-server security alongside possible SSO integration.
- The project also contains build and deployment automation via Maven, Docker, and CI/CD configurations (.github, .gitlab-ci.yml).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "External Systems"
        ext1["Datenportal"]:::external
        ext2["Adminportal"]:::external
        ext3["Selfserviceportal"]:::external
        ext4["EAI"]:::external
    end

    SG["Service Gateway"]:::integration
    ext1 --> SG
    ext2 --> SG
    ext3 --> SG
    ext4 --> SG

    RC["REST Controllers"]:::controller
    SG --> RC

    subgraph "Business Logic / Service Layer"
        BS["Business Services"]:::service
        MESS["Messstelle Service"]:::service
        PDFService["PDF Generation Service"]:::service
        BS --> MESS
        BS --> PDFService
    end
    RC --> BS

    subgraph "Persistence Layer"
        RelDB["Relational Repository"]:::repository
        EsRepo["Elasticsearch Repository"]:::repository
    end
    BS --> RelDB
    BS --> EsRepo

    DM["Domain Model"]:::domain
    BS --> DM

    UTIL["Additional Utilities"]:::utility
    BS --> UTIL

    CONF["Configuration & Infrastructure"]:::config
    BS --> CONF

    subgraph "Security & SSO"
        SEC["Security Module"]:::security
        SSO["SSO Integration"]:::security
    end
    RC --> SEC

    subgraph "PDF Components"
        PDFDomain["Domain PDF Components"]:::pdf
        PDFTemplates["PDF Templates"]:::pdf
    end
    PDFService --> PDFDomain
    PDFService --> PDFTemplates

    %% Click Events
    click RC "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/controller"
    click BS "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/services"
    click MESS "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/services/messstelle"
    click PDFService "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/services/pdfgenerator"
    click RelDB "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/repositories/relationaldb"
    click EsRepo "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/repositories/elasticsearch"
    click DM "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/domain"
    click CONF "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/configuration"
    click SEC "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/security"
    click SSO "https://github.com/it-at-m/dave-backend/tree/sprint/sso-config folder"
    click UTIL "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/util"
    click PDFDomain "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/java/de/muenchen/dave/domain/pdf"
    click PDFTemplates "https://github.com/it-at-m/dave-backend/tree/sprint/src/main/resources/pdf/templates"

    %% Styles
    classDef external fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef integration fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef controller fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef service fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef repository fill:#ABEBC6,stroke:#333,stroke-width:2px;
    classDef domain fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef config fill:#D2B4DE,stroke:#333,stroke-width:2px;
    classDef security fill:#F9E79F,stroke:#333,stroke-width:2px;
    classDef utility fill:#D5F5E3,stroke:#333,stroke-width:2px;
    classDef pdf fill:#FCF3CF,stroke:#333,stroke-width:2px;
```
