# nhsdigital/mesh-client architecture

> Architecture diagram of the GitHub repository nhsdigital/mesh-client, 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/nhsdigital/mesh-client
- Repository: https://github.com/nhsdigital/mesh-client

## Overview

##### Main Components

a) Core Components:
- MESH Client Library
- NHS MESH API Service (External)
- SSL Certificate Management
- Message Handling System

b) Integration Points:
- Client Applications
- MESH Sandbox (for testing)
- NHS Digital Endpoints (INT/LIVE)

**[Client Applications]**
- ↓
**[MESH Client Library]**
- ↙     ↓      ↘
**[Auth] [IO]  [Message Handling]**
- ↓
**[SSL/Certificates]**
- ↓
**[NHS MESH API]**

##### Key Elements to Highlight

a) Client Library Components:
- Authentication Module (mesh_auth.py)
- I/O Helpers (io_helpers.py)
- Key Management (key_helper.py)
- Type Definitions (types.py)

b) Security Layer:
- SSL Certificate Management
- CA Bundles for different environments (DEP/INT/LIVE)
- Authentication mechanisms

c) Message Flow:
- Message Sending
- Message Retrieval
- Message Acknowledgment
- Handshake Process

##### Specific Implementation Details

- Rectangles: Core components
- Blue: Core MESH client components
- Green: External NHS Digital services
- Yellow: Security components
- Gray: Testing/Development components

##### Testing Infrastructure
- MESH Sandbox connection
- Test certificates
- Docker environment (Squid proxy)

Top Section:
**[Client Application Layer]**
- Shows how applications integrate with the library

Middle Section:
**[MESH Client Core]**
- Authentication
- Message Operations
- Certificate Management

Bottom Section:
**[External Services]**
- NHS MESH API
- Different environments (INT/LIVE)

##### Important Flows

- Authentication flow
- Message sending flow
- Message retrieval flow
- Handshake process
- Error handling and retries

##### Technical Details

- SSL/TLS connection points
- API endpoint variations (INT/LIVE)
- Certificate paths and requirements
- Message acknowledgment flow

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application Layer"]
        APP[Client Applications]
    end

    subgraph Core["MESH Client Core"]
        MESH["MESH Client Library"]:::core
        click MESH "https://github.com/NHSDigital/mesh-client/blob/develop/mesh_client/__init__.py"
        
        subgraph Components["Core Components"]
            AUTH["Authentication Module"]:::component
            click AUTH "https://github.com/NHSDigital/mesh-client/blob/develop/mesh_client/mesh_auth.py"
            IO["I/O Operations"]:::component
            click IO "https://github.com/NHSDigital/mesh-client/blob/develop/mesh_client/io_helpers.py"
            KEY["Key Management"]:::component
            click KEY "https://github.com/NHSDigital/mesh-client/blob/develop/mesh_client/key_helper.py"
            TYPES["Type Definitions"]:::component
            click TYPES "https://github.com/NHSDigital/mesh-client/blob/develop/mesh_client/types.py"
        end
        
        subgraph Security["Security Layer"]
            CERT["SSL Certificate Management"]:::security
            LIVE["Live CA Bundle"]:::cert
            click LIVE "https://github.com/NHSDigital/mesh-client/blob/develop/mesh_client/nhs-live-ca-bundle.pem"
            INT["Integration CA Bundle"]:::cert
            click INT "https://github.com/NHSDigital/mesh-client/blob/develop/mesh_client/nhs-int-ca-bundle.pem"
            DEP["Development CA Bundle"]:::cert
            click DEP "https://github.com/NHSDigital/mesh-client/blob/develop/mesh_client/nhs-dep-ca-bundle.pem"
        end
    end

    subgraph Testing["Testing Infrastructure"]
        SANDBOX["MESH Sandbox"]:::test
        click SANDBOX "https://github.com/NHSDigital/mesh-client/blob/develop/tests/mesh_sandbox_tests.py"
        PROXY["Squid Proxy"]:::test
        click PROXY "https://github.com/NHSDigital/mesh-client/blob/develop/docker/squid/squid.conf"
        TEST_CERT["Test Certificates"]:::test
        click TEST_CERT "https://github.com/NHSDigital/mesh-client/blob/develop/tests/ca.cert.pem"
        MSG_TEST["Message Tests"]:::test
        click MSG_TEST "https://github.com/NHSDigital/mesh-client/blob/develop/tests/mesh_retry_send_chunk_tests.py"
        CONN_TEST["Connectivity Tests"]:::test
        click CONN_TEST "https://github.com/NHSDigital/mesh-client/blob/develop/tests/mesh_endpoint_connectivity_tests.py"
    end

    subgraph External["External Services"]
        NHS["NHS MESH API"]:::external
        INT_ENV["Integration Environment"]:::environment
        LIVE_ENV["Live Environment"]:::environment
    end

    %% Relationships
    APP --> MESH
    MESH --> AUTH & IO & KEY & TYPES
    AUTH & IO & KEY --> CERT
    CERT --> LIVE & INT & DEP
    MESH --> NHS
    NHS --> INT_ENV & LIVE_ENV
    MESH -.-> SANDBOX
    SANDBOX --> PROXY
    SANDBOX --> TEST_CERT
    SANDBOX --> MSG_TEST & CONN_TEST

    %% Styling
    classDef core fill:#2374ab
    classDef component fill:#4a90e2
    classDef security fill:#f39c12
    classDef cert fill:#f1c40f
    classDef test fill:#95a5a6
    classDef external fill:#27ae60
    classDef environment fill:#2ecc71

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Library Components"]:::component
        L3["Security Components"]:::security
        L4["Certificates"]:::cert
        L5["Testing Components"]:::test
        L6["External Services"]:::external
        L7["Environments"]:::environment
    end
```
