# mploed/ddd-with-spring architecture

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

- Interactive diagram: https://gitdiagram.com/mploed/ddd-with-spring
- Repository: https://github.com/mploed/ddd-with-spring

## Overview

##### Main Components
- Assets Module – Acts as a web asset provider with static resources and a Spring Boot application (under the “assets” folder). It supports the presentation layer.
- Credit Agency – Implements a bounded context that handles credit agency functionalities. It includes event processing (incoming events like ApplicationSubmittedEvent) and messaging components. It connects to messaging channels and a repository for PersonRating data.
- Credit Sales Funnel – Responsible for handling credit sales aspects. It is a Spring Boot application with web controllers and templates (HTML pages) that provide the front-end for credit applications. It interacts with domain models such as CreditApplicationForm and related applicant, household, financing, and real estate entities.
- Scoring – The largest module, which is organized into several submodules (adapters-input, adapters-output, aggregates, application-services, microarchitecture, scoring-application, and sharedmodel). This module is responsible for processing scoring events and implementing the scoring business logic using event-based communication, domain aggregates, and application services.
- Infrastructure Components – There are Dockerfiles for several modules (credit-agency, credit-sales-funnel, scoring, and infrastructure_varnish) and a docker-compose file orchestrates their startup. The “infrastructure_varnish” folder indicates a reverse proxy or caching layer.
- External Services – Messaging systems (like RabbitMQ implied by the use of Spring Cloud Stream and message channels), databases (used via Spring Data JPA), and possibly HTTP feeds.

##### Relationships and Interactions
- Communication between bounded contexts is event driven. For example, credit agency and scoring modules communicate through domain events (e.g., ApplicationSubmittedEvent, AgencyResultArrivedEvent).
- Use of Spring Cloud Stream suggests asynchronous messaging, so include message brokers and channels showing inputs and outputs.
- The scoring module has clearly isolated input and output adapters along with internal aggregates. It processes incoming messages from credit agency or credit sales funnel and produces scoring results.
- The credit sales funnel includes web controllers and templates; thus, it is likely interfacing directly with end-users via HTTP, and it may push domain events downstream.
- Docker containers and docker-compose are being used to orchestrate the services. Varnish likely sits as an edge infrastructure component to route or cache incoming requests.

##### Architectural Patterns and Design Principles
- Domain-Driven Design – Separate bounded contexts (credit-agency, credit-sales-funnel, scoring) with their aggregates and domain events.
- Hexagonal/Ports & Adapters – Visible in the scoring module by the clear separation between adapters (input/output), application services, and the domain (aggregates).
- Event-Based Communication – Both through messaging channels (using Spring Cloud Stream) and Spring Application Events.
- Microservices/Modular Monolith – Although deployed via Docker, the modules are separated into dedicated subprojects which can run independently.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Container Orchestration
    subgraph "Container Orchestration"
        DC["Docker Compose (docker-compose.yml)"]:::infra
    end

    %% Frontend Services
    subgraph "Frontend Services"
        A["Assets Module (Spring Boot)"]:::frontend
        CSF["Credit Sales Funnel (Spring Boot)"]:::frontend
        T["Templates (HTML)"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
        CA["Credit Agency Service (Spring Boot)"]:::backend
        CAE["Event Processing"]:::backend
        CAM["Messaging Components"]:::backend

        %% Define Scoring Service as a subgraph
        subgraph "Scoring Service (Hexagonal Architecture)"
            SI["Adapters-Input"]:::backend
            DAS["Domain Aggregates & Application Services"]:::backend
            SO["Adapters-Output"]:::backend
            MA["Microarchitecture"]:::backend
            SA["Scoring Application"]:::backend
            SM["Shared Model"]:::backend
        end
    end

    %% Infrastructure Components
    subgraph "Infrastructure"
        MB["Messaging Broker (RabbitMQ)"]:::messaging
        VR["Varnish Reverse Proxy"]:::infra
    end

    %% Container Orchestration deploys all services
    DC --> A
    DC --> CSF
    DC --> CA
    DC --> SI
    DC --> VR

    %% Credit Sales Funnel publishes events to Messaging Broker
    CSF -->|"publishEvent"| MB

    %% Messaging delivers events to Credit Agency and Scoring Service
    MB -->|"deliverEvent"| CA
    MB -->|"deliverEvent"| SI

    %% Internal Credit Agency flow
    CA --> CAE
    CAE --> CAM

    %% Internal Scoring Service flow
    SI -->|"processEvent"| DAS
    DAS -->|"triggerScoring"| SO
    DAS -->|"uses"| MA
    DAS -->|"invokes"| SA
    DAS -->|"utilizes"| SM

    %% Credit Sales Funnel internal component
    CSF --> T

    %% Click Events
    click A "https://github.com/mploed/ddd-with-spring/blob/master/assets/src/main/java/com/mploed/dddwithspring/assets/AssetsApplication.java"
    click CSF "https://github.com/mploed/ddd-with-spring/tree/master/credit-sales-funnel/"
    click T "https://github.com/mploed/ddd-with-spring/tree/master/credit-sales-funnel/src/main/resources/templates/"
    click CA "https://github.com/mploed/ddd-with-spring/tree/master/credit-agency/"
    click CAE "https://github.com/mploed/ddd-with-spring/blob/master/credit-agency/src/main/java/com/mploed/dddwithspring/creditagency/events/incoming/ApplicationSubmittedEvent.java"
    click CAM "https://github.com/mploed/ddd-with-spring/tree/master/credit-agency/src/main/java/com/mploed/dddwithspring/creditagency/messaging/"
    click SI "https://github.com/mploed/ddd-with-spring/tree/master/scoring/adapters-input/"
    click SO "https://github.com/mploed/ddd-with-spring/tree/master/scoring/adapters-output/"
    click DAS "https://github.com/mploed/ddd-with-spring/tree/master/scoring/aggregates/"
    click MA "https://github.com/mploed/ddd-with-spring/tree/master/scoring/microarchitecture/"
    click SA "https://github.com/mploed/ddd-with-spring/blob/master/scoring/scoring-application/src/main/java/com/mploed/dddwithspring/scoring/ScoringApplication.java"
    click SM "https://github.com/mploed/ddd-with-spring/tree/master/scoring/sharedmodel/"
    click VR "https://github.com/mploed/ddd-with-spring/tree/master/infrastructure_varnish/"
    click DC "https://github.com/mploed/ddd-with-spring/blob/master/docker-compose.yml"

    %% Styles
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef backend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef messaging fill:#ffc,stroke:#333,stroke-width:2px;
    classDef infra fill:#cfc,stroke:#333,stroke-width:2px;
```
