# pagopa/pn-delivery-push architecture

> Architecture diagram of the GitHub repository pagopa/pn-delivery-push, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pagopa/pn-delivery-push
- Repository: https://github.com/pagopa/pn-delivery-push

## Overview

##### Main Components

a. Core Service Components:
- Delivery Push Service (Main Application)
- Action Handlers
- Timeline Service
- Notification Service
- Webhook Service
- Legal Facts Service

b. External Integrations:
- Address Manager Client
- Data Vault Client
- External Channel Client
- Paper Channel Client
- Safe Storage Client
- National Registries Client
- Mandate Client
- F24 Client

c. Data Stores:
- DynamoDB Tables (for actions, timeline, documents, webhooks)
- Safe Storage (for documents/attachments)

d. Message Queues:
- SQS Queues (for actions and webhooks)
- Event Bridge
- Kinesis Streams

##### Architecture Layers

a. API Layer:
- REST Controllers (PnCancellationController, PnDocumentsController, etc.)
- Webhook Controllers
- API Versioning Support

b. Service Layer:
- Business Logic Services
- Workflow Handlers
- Event Handlers

c. Data Access Layer:
- DAO Implementations
- External Client Integrations

##### Key Workflows to Highlight

a. Notification Processing:
- Digital Workflow
- Analog Workflow
- Mixed Workflow

b. Document Management:
- Legal Facts Generation
- Document Creation
- Attachment Handling

##### Implementation Details

Create sections showing:
- AWS Infrastructure components
- Spring Boot application structure
- External service integration points
- Data persistence layer
- Event processing flow

##### Specific Recommendations

- Main service entry points (REST APIs)
- Core business logic components
- External service integrations
- Storage solutions
- Message queues

- Notification workflow processing
- Document handling flow
- Webhook event processing
- Timeline management

##### Cross-cutting concerns
- Security
- Logging
- Monitoring
- Error handling

- The event-driven nature of the system
- The separation between synchronous and asynchronous operations
- The integration points with external services
- The data flow between components
- The scalability aspects of the system

- Core services (blue)
- External integrations (green)
- Storage components (yellow)
- Message queues (purple)
- API endpoints (orange)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph API_Layer
        RC1["Notification Controller"]:::api
        RC2["Timeline Controller"]:::api
        RC3["Webhook Controller"]:::api
        RC4["Legal Facts Controller"]:::api
    end

    subgraph Core_Services
        MA["Delivery Push Service"]:::core
        AH["Action Handlers"]:::core
        TS["Timeline Service"]:::core
        NS["Notification Service"]:::core
        WS["Webhook Service"]:::core
        LFS["Legal Facts Service"]:::core
    end

    subgraph Data_Access
        AD["Action DAO"]:::dao
        TD["Timeline DAO"]:::dao
        DD["Document DAO"]:::dao
        WD["Webhook DAO"]:::dao
    end

    subgraph Message_Queues
        QC["Queue Consumer"]:::queue
        QP["Queue Producer"]:::queue
        SQS[("SQS Queues")]:::queue
        EB[("Event Bridge")]:::queue
        KS[("Kinesis Streams")]:::queue
    end

    subgraph External_Clients
        AMC["Address Manager Client"]:::external
        DVC["Data Vault Client"]:::external
        ECC["External Channel Client"]:::external
        PCC["Paper Channel Client"]:::external
        SSC["Safe Storage Client"]:::external
        NRC["National Registries Client"]:::external
        MC["Mandate Client"]:::external
        F24["F24 Client"]:::external
    end

    subgraph Storage
        DDB[(DynamoDB)]:::storage
        SS[(Safe Storage)]:::storage
    end

    %% API Layer Connections
    RC1 --> NS
    RC2 --> TS
    RC3 --> WS
    RC4 --> LFS

    %% Core Service Connections
    MA --> AH
    MA --> TS
    MA --> NS
    MA --> WS
    MA --> LFS

    %% Data Access Connections
    AH --> AD
    TS --> TD
    NS --> DD
    WS --> WD

    %% Queue Connections
    QC --> MA
    MA --> QP
    QP --> SQS
    QP --> EB
    QP --> KS

    %% Storage Connections
    AD --> DDB
    TD --> DDB
    DD --> DDB
    WD --> DDB
    LFS --> SS

    %% External Client Connections
    NS --> AMC
    NS --> DVC
    NS --> ECC
    NS --> PCC
    NS --> SSC
    NS --> NRC
    NS --> MC
    NS --> F24

    %% Styles
    classDef core fill:#2374ab
    classDef api fill:#ff7f50
    classDef dao fill:#ffd700
    classDef queue fill:#9370db
    classDef external fill:#98fb98
    classDef storage fill:#f4a460

    %% Click Events
    click MA "https://github.com/pagopa/pn-delivery-push/blob/develop/src/main/java/it/pagopa/pn/deliverypush/PnDeliveryPushApplication.java"
    click AH "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/action/"
    click TS "https://github.com/pagopa/pn-delivery-push/blob/develop/src/main/java/it/pagopa/pn/deliverypush/service/TimelineService.java"
    click NS "https://github.com/pagopa/pn-delivery-push/blob/develop/src/main/java/it/pagopa/pn/deliverypush/service/NotificationService.java"
    click WS "https://github.com/pagopa/pn-delivery-push/blob/develop/src/main/java/it/pagopa/pn/deliverypush/service/WebhookStreamsService.java"
    click LFS "https://github.com/pagopa/pn-delivery-push/blob/develop/src/main/java/it/pagopa/pn/deliverypush/service/GetLegalFactService.java"
    click AMC "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/externalclient/pnclient/addressmanager/"
    click DVC "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/externalclient/pnclient/datavault/"
    click ECC "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/externalclient/pnclient/externalchannel/"
    click PCC "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/externalclient/pnclient/paperchannel/"
    click SSC "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/externalclient/pnclient/safestorage/"
    click NRC "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/externalclient/pnclient/nationalregistries/"
    click MC "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/externalclient/pnclient/mandate/"
    click F24 "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/externalclient/pnclient/f24/"
    click AD "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/dao/actiondao/"
    click TD "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/dao/timelinedao/"
    click DD "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/dao/documentcreationdao/"
    click WD "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/dao/webhook/"
    click QC "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/queue/consumer/"
    click QP "https://github.com/pagopa/pn-delivery-push/tree/develop/src/main/java/it/pagopa/pn/deliverypush/middleware/queue/producer/"
    click RC1 "https://github.com/pagopa/pn-delivery-push/blob/develop/src/main/java/it/pagopa/pn/deliverypush/rest/PnNotificationViewController.java"
    click RC2 "https://github.com/pagopa/pn-delivery-push/blob/develop/src/main/java/it/pagopa/pn/deliverypush/rest/PnTimelineController.java"
    click RC3 "https://github.com/pagopa/pn-delivery-push/blob/develop/src/main/java/it/pagopa/pn/deliverypush/rest/PnWebhookStreamsController.java"
    click RC4 "https://github.com/pagopa/pn-delivery-push/blob/develop/src/main/java/it/pagopa/pn/deliverypush/rest/PnLegalFactsController.java"
```
