# esnet-security/scram architecture

> Architecture diagram of the GitHub repository esnet-security/scram, 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/esnet-security/scram
- Repository: https://github.com/esnet-security/scram

## Overview

##### Main Components

a) Frontend Layer:
- Nginx Web Server (reverse proxy)
- Static Assets
- Web Interface (Django Templates)

b) Application Layer:
- Django Application Server
- REST API
- WebSocket Handlers
- Celery Workers (for async tasks)
- Celery Beat (for scheduled tasks)
- Celery Flower (monitoring)

c) Data Layer:
- PostgreSQL Database
- Redis (for channel layers)

d) Network Control Layer:
- GoBGP Container
- Translator Service

##### Component Relationships

**Client Tier -> Nginx -> Django -> Data Stores**
- > Static Assets

**WebSocket Clients <-> Django Channels <-> Redis**

- v
- Translator

- v
- GoBGP

- v
- Network Infrastructure

##### Key Elements to Highlight

a) Authentication Flow:
- Both OIDC and local authentication paths
- Authentication middleware

b) Data Flow:
- REST API endpoints
- WebSocket connections
- Database interactions
- BGP route management

c) Security Boundaries:
- Docker container isolation
- Network segmentation
- Authentication boundaries

##### Specific Implementation Details

Key features:
- Action Types system
- IP/CIDR management
- BGP null routing capability
- WebSocket-based real-time updates
- Historical tracking system

##### Environment Separation

Different configurations for:
- Development environment
- Production environment
- Test environment

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
        WSClient["WebSocket Client"]
    end

    subgraph "Web Layer"
        Nginx["Nginx Reverse Proxy"]
        Static["Static Assets"]:::static
        Templates["Web Templates"]:::templates
    end

    subgraph "Application Layer"
        Django["Django Server"]:::django
        API["REST API"]:::api
        WSHandler["WebSocket Handlers"]:::wshandler
        Auth["Authentication System"]:::auth
        Users["User Management"]:::users
        APIRouter["API Router"]:::apirouter
        WSRouter["WebSocket Router"]:::wsrouter
    end

    subgraph "Task Processing"
        Celery["Celery Workers"]:::celery
        CeleryBeat["Celery Beat"]:::celery
        CeleryFlower["Celery Flower"]:::celery
    end

    subgraph "Data Layer"
        Postgres[(PostgreSQL)]:::postgres
        Redis[(Redis)]:::redis
    end

    subgraph "Network Control"
        RouteManager["Route Manager"]:::routemanager
        Translator["Translator Service"]:::translator
        GoBGP["GoBGP Service"]:::gobgp
    end

    subgraph "Network Infrastructure"
        BGPPeers["BGP Peers"]
    end

    %% Client to Web Layer
    Browser --> Nginx
    WSClient --> Nginx

    %% Web Layer Connections
    Nginx --> Static
    Nginx --> Django
    Nginx --> Templates

    %% Application Layer Internal
    Django --> API
    Django --> WSHandler
    Django --> Auth
    Django --> Users
    Django --> APIRouter
    Django --> WSRouter

    %% Data Connections
    Django --> Postgres
    WSHandler --> Redis
    Celery --> Redis
    Celery --> Postgres

    %% Task Processing
    Django -.-> Celery
    CeleryBeat -.-> Celery
    CeleryFlower -.-> Celery

    %% Network Control Flow
    API --> RouteManager
    WSHandler --> RouteManager
    RouteManager --> Translator
    Translator --> GoBGP
    GoBGP --> BGPPeers

    %% Click Events
    click Static "https://github.com/esnet-security/SCRAM/tree/develop/scram/static/"
    click Templates "https://github.com/esnet-security/SCRAM/tree/develop/scram/templates/"
    click Django "https://github.com/esnet-security/SCRAM/tree/develop/config/"
    click API "https://github.com/esnet-security/SCRAM/tree/develop/scram/route_manager/api/"
    click WSHandler "https://github.com/esnet-security/SCRAM/blob/develop/config/consumers.py"
    click Celery "https://github.com/esnet-security/SCRAM/tree/develop/compose/production/django/celery/"
    click Postgres "https://github.com/esnet-security/SCRAM/tree/develop/compose/production/postgres/"
    click GoBGP "https://github.com/esnet-security/SCRAM/blob/develop/gobgp_config/gobgp.toml"
    click Translator "https://github.com/esnet-security/SCRAM/blob/develop/translator/translator.py"
    click RouteManager "https://github.com/esnet-security/SCRAM/tree/develop/scram/route_manager/"
    click Auth "https://github.com/esnet-security/SCRAM/tree/develop/scram/local_auth/"
    click Users "https://github.com/esnet-security/SCRAM/tree/develop/scram/users/"
    click APIRouter "https://github.com/esnet-security/SCRAM/blob/develop/config/api_router.py"
    click WSRouter "https://github.com/esnet-security/SCRAM/blob/develop/config/routing.py"

    %% Styling
    classDef static fill:#f9f,stroke:#333
    classDef templates fill:#f9f,stroke:#333
    classDef django fill:#3498db,stroke:#333
    classDef api fill:#2ecc71,stroke:#333
    classDef wshandler fill:#e74c3c,stroke:#333
    classDef auth fill:#95a5a6,stroke:#333
    classDef users fill:#95a5a6,stroke:#333
    classDef celery fill:#9b59b6,stroke:#333
    classDef postgres fill:#f1c40f,stroke:#333
    classDef redis fill:#e67e22,stroke:#333
    classDef routemanager fill:#1abc9c,stroke:#333
    classDef translator fill:#34495e,stroke:#333
    classDef gobgp fill:#34495e,stroke:#333
    classDef apirouter fill:#2ecc71,stroke:#333
    classDef wsrouter fill:#e74c3c,stroke:#333
```
