# pagopa/io-backend architecture

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

- Interactive diagram: https://gitdiagram.com/pagopa/io-backend
- Repository: https://github.com/pagopa/io-backend

## Overview

a. Authentication Flow:
- Mobile App → Authentication Endpoints
- Bearer Token Validation
- Session Management

b. API Flows:
- Mobile App → API Gateway
- API Gateway → Controllers
- Controllers → Services
- Services → External APIs

##### Infrastructure Components

a. Docker Containers:
- Backend Node.js Application
- Redis Instance
- Nginx Reverse Proxy

b. Azure Services:
- Azure App Service
- Azure Storage
- Application Insights

##### Security Layer (Highlight with a distinct border)
- API Key Authentication
- Bearer Token Validation
- IP Whitelisting
- CIDR Range Restrictions

##### Monitoring & Logging
- Application Insights Integration
- Logging System
- API Monitoring

Important Elements to Include:

##### Clear separation of concerns between
- API Routes
- Business Logic (Services)
- Data Storage
- External Service Integration

##### Key architectural patterns
- Dependency Injection Container
- Multiple Instance Deployment
- Cache Layer
- Message Queue System

##### Version Compatibility
- Mobile App Version Check
- PagoPA Version Compatibility

Use the following visual conventions:

- Blue: Core application components
- Green: External services
- Yellow: Security components
- Red: Critical infrastructure
- Gray: Supporting services

##### Lines
- Solid: Synchronous communications

- Line styles and their meanings
- Any abbreviations or technical terms
- Version compatibility indicators

Keep the abstraction level balanced:
- Enough detail to understand the system's architecture
- Avoid cluttering with implementation details
- Interactions and data flows
- Critical security and scaling components

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Mobile["Mobile Application"]
        MobileApp[Mobile App Client]
    end

    subgraph Core["Core Application Layer"]
        Express["Express.js Server"]:::core
        Controllers["Controllers Layer"]:::core
        Services["Services Layer"]:::core
        Auth["Authentication Strategies"]:::core
        APIClient["API Client Factory"]:::core
    end

    subgraph External["External Services"]
        PagoPA["PagoPA Integration"]:::external
        SPID["SPID Authentication"]:::external
        IOFunc["IO Functions"]:::external
        CGN["CGN Services"]:::external
        Trial["Trial System"]:::external
        Notif["Notification Services"]:::external
        IOSign["IO Sign Services"]:::external
        FIMS["IO FIMS Services"]:::external
        Lollipop["Lollipop Services"]:::external
    end

    subgraph Storage["Storage Layer"]
        Redis[(Redis Session Storage)]:::storage
        AzureStorage[(Azure Storage)]:::storage
        TableStorage[(Azure Table Storage)]:::storage
    end

    subgraph Monitor["Monitoring & Logging"]
        AppInsights["Application Insights"]:::monitoring
        Logging["Logging System"]:::monitoring
    end

    subgraph Security["Security Layer"]
        APIKey["API Key Auth"]:::security
        Bearer["Bearer Token"]:::security
        IPWhitelist["IP Whitelist"]:::security
        CIDR["CIDR Restrictions"]:::security
    end

    MobileApp --> Express
    Express --> Controllers
    Controllers --> Services
    Services --> APIClient
    APIClient --> External
    Services --> Storage
    Core --> AppInsights
    Security --> Core

    %% Click Events
    click Express "https://github.com/pagopa/io-backend/blob/master/src/app.ts"
    click Controllers "https://github.com/pagopa/io-backend/tree/master/src/controllers/"
    click Services "https://github.com/pagopa/io-backend/tree/master/src/services/"
    click Auth "https://github.com/pagopa/io-backend/tree/master/src/strategies/"
    click PagoPA "https://github.com/pagopa/io-backend/blob/master/src/services/pagoPAProxyService.ts"
    click CGN "https://github.com/pagopa/io-backend/blob/master/src/services/cgnService.ts"
    click Trial "https://github.com/pagopa/io-backend/blob/master/src/services/trialService.ts"
    click FIMS "https://github.com/pagopa/io-backend/blob/master/src/services/fimsService.ts"
    click Lollipop "https://github.com/pagopa/io-backend/blob/master/src/services/lollipopService.ts"
    click Redis "https://github.com/pagopa/io-backend/blob/master/src/services/redisSessionStorage.ts"
    click Notif "https://github.com/pagopa/io-backend/blob/master/src/services/notificationService.ts"
    click IOSign "https://github.com/pagopa/io-backend/blob/master/src/services/ioSignService.ts"
    click APIClient "https://github.com/pagopa/io-backend/blob/master/src/services/apiClientFactory.ts"
    click AppInsights "https://github.com/pagopa/io-backend/blob/master/src/utils/appinsights.ts"

    classDef core fill:#2374ab
    classDef external fill:#57a773
    classDef storage fill:#484d6d
    classDef security fill:#f7d794
    classDef monitoring fill:#95a5a6

    %% Legend
    subgraph Legend
        CoreL["Core Components"]:::core
        ExtL["External Services"]:::external
        StorL["Storage Systems"]:::storage
        SecL["Security Components"]:::security
        MonL["Monitoring"]:::monitoring
    end
```
