# bsgip/envoy architecture

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

- Interactive diagram: https://gitdiagram.com/bsgip/envoy
- Repository: https://github.com/bsgip/envoy

## Overview

##### Main Components

a) Core Services (3 main applications):
- Server Application (Primary API Service)
- Admin Application
- Notification Service

b) External Dependencies:
- PostgreSQL Database
- RabbitMQ (Optional, for notifications)
- Azure AD (Optional, for authentication)

c) Client Integration Points:
- Smart Devices (CSIP-Aus compliant)
- Admin Clients
- Monitoring Systems

##### Client Layer (Top)
- Smart Devices (2030.5/CSIP/CSIP-Aus)
- Admin Clients
- Monitoring Systems

##### API Gateway Layer
- TLS Termination
- Certificate Validation
- Azure AD Authentication (if enabled)

##### Application Layer (Core Services)
- Server Application
- API Modules (sep2, csip_aus)
- CRUD Operations
- Managers
- Mappers
- Admin Application
- API Endpoints
- CRUD Operations
- Notification Service
- Task Workers
- Notification Handlers

##### Message Queue Layer
- RabbitMQ (for async notifications)

##### Data Layer
- PostgreSQL Database
- Cache System

##### Connection Types

- Double lines: Database connections

##### Key Elements to Highlight

a) Security Features:
- TLS Termination
- Certificate-based Authentication
- Azure AD Integration
- HTTP Basic Auth for Admin

b) Data Flows:
- Smart Device Communications
- Notification Paths
- Admin Operations
- Database Interactions

c) Scalability Points:
- Worker Pools
- Message Queue
- Database Connections

##### Additional Details

Annotations for:
- Supported Standards (2030.5, CSIP, CSIP-Aus)
- Configuration Options
- Database Migration Paths
- Environment Variables

##### Implementation Notes

- FastAPI-based Implementation
- Async Nature of Operations
- Multiple Service Integration
- Extensibility Points

This system design should reflect the modular nature of the project while highlighting its core functionality as a CSIP-Aus compliant utility server with multiple integration points and optional features.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        SD[Smart Devices]:::client
        AC[Admin Clients]:::client
        MS[Monitoring Systems]:::client
    end

    %% API Gateway Layer
    subgraph Gateway
        TLS[TLS Termination]:::security
        click TLS "https://github.com/bsgip/envoy/tree/main/demo/tls-termination/"
        CERT[Certificate Validation]:::security
        click CERT "https://github.com/bsgip/envoy/blob/main/src/envoy/server/api/depends/lfdi_auth.py"
        AAD[Azure AD Auth]:::security
        click AAD "https://github.com/bsgip/envoy/blob/main/src/envoy/server/api/auth/azure.py"
    end

    %% Application Layer
    subgraph CoreServices
        subgraph Server
            SA[Server Application]:::core
            click SA "https://github.com/bsgip/envoy/blob/main/src/envoy/server/main.py"
            
            subgraph APIModules
                SEP["SEP2 API"]:::api
                click SEP "https://github.com/bsgip/envoy/tree/main/src/envoy/server/api/sep2/"
                CSIP["CSIP-Aus API"]:::api
                click CSIP "https://github.com/bsgip/envoy/tree/main/src/envoy/server/api/csip_aus/"
                AUTH["Authentication"]:::api
                click AUTH "https://github.com/bsgip/envoy/tree/main/src/envoy/server/api/auth/"
            end

            subgraph ServerComponents
                SCRUD["Server CRUD"]:::component
                click SCRUD "https://github.com/bsgip/envoy/tree/main/src/envoy/server/crud/"
                SMAN["Server Managers"]:::component
                click SMAN "https://github.com/bsgip/envoy/tree/main/src/envoy/server/manager/"
                SMAP["Server Mappers"]:::component
                click SMAP "https://github.com/bsgip/envoy/tree/main/src/envoy/server/mapper/"
            end
        end

        subgraph Admin
            AA[Admin Application]:::core
            click AA "https://github.com/bsgip/envoy/blob/main/src/envoy/admin/main.py"
            ACRUD["Admin CRUD"]:::component
            click ACRUD "https://github.com/bsgip/envoy/tree/main/src/envoy/admin/crud/"
            AMAN["Admin Managers"]:::component
            click AMAN "https://github.com/bsgip/envoy/tree/main/src/envoy/admin/manager/"
            AMAP["Admin Mappers"]:::component
            click AMAP "https://github.com/bsgip/envoy/tree/main/src/envoy/admin/mapper/"
        end

        subgraph Notification
            NS[Notification Service]:::core
            click NS "https://github.com/bsgip/envoy/blob/main/src/envoy/notification/main.py"
            NCRUD["Notification CRUD"]:::component
            click NCRUD "https://github.com/bsgip/envoy/tree/main/src/envoy/notification/crud/"
            NMAN["Notification Managers"]:::component
            click NMAN "https://github.com/bsgip/envoy/tree/main/src/envoy/notification/manager/"
            TW["Task Workers"]:::component
            click TW "https://github.com/bsgip/envoy/tree/main/src/envoy/notification/task/"
        end
    end

    %% Message Queue Layer
    MQ[RabbitMQ]:::queue

    %% Data Layer
    subgraph Data
        DB[(PostgreSQL)]:::database
        CACHE[Cache System]:::database
        click CACHE "https://github.com/bsgip/envoy/blob/main/src/envoy/server/cache.py"
        MIGRATIONS["Database Migrations"]:::database
        click MIGRATIONS "https://github.com/bsgip/envoy/tree/main/src/envoy/server/alembic/"
        MODELS["Database Models"]:::database
        click MODELS "https://github.com/bsgip/envoy/tree/main/src/envoy/server/model/"
    end

    %% Connections
    SD --> TLS
    AC --> TLS
    MS --> TLS
    TLS --> CERT
    CERT --> AAD
    AAD --> SA
    AAD --> AA

    SA --> DB
    AA --> DB
    NS --> DB
    
    SA --> CACHE
    AA --> CACHE
    
    SA --> MQ
    NS --> MQ
    
    %% Styles
    classDef client fill:#90EE90
    classDef security fill:#FFD700
    classDef core fill:#87CEEB
    classDef api fill:#DDA0DD
    classDef component fill:#B0C4DE
    classDef queue fill:#FFA500
    classDef database fill:#9370DB

    %% Legend
    subgraph Legend
        C1[Client]:::client
        S1[Security]:::security
        CO1[Core Service]:::core
        A1[API]:::api
        CM1[Component]:::component
        Q1[Queue]:::queue
        D1[Database]:::database
    end
```
