# snyk/broker architecture

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

- Interactive diagram: https://gitdiagram.com/snyk/broker
- Repository: https://github.com/snyk/broker

## Overview

##### Main Components

a. External Systems:
- Snyk.io (Cloud Service)
- Git Providers (GitHub Enterprise, GitHub.com, Bitbucket Server)
- Jira (On-premise)
- Container Registries

b. Core Components:
- Broker Server
- Broker Client
- Applicative Tunnel
- Authentication/Authorization Layer
- Filter Rules Engine
- WebSocket Connection Manager
- HTTP/HTTPS Request Handler

##### Architecture Pattern

**[External Zone (Snyk.io)] <---> [Broker Server] <---> [Secure Tunnel] <---> [Broker Client] <---> [Internal Zone (Git/Jira)]**

##### Key Relationships to Highlight

a. Communication Flows:
- Bidirectional secure tunnel between Broker Server and Client
- Filtered requests from Snyk.io to internal systems
- Webhook events from internal systems to Snyk.io
- Authentication flows for different providers

b. Security Layers:
- Filter rules and validation
- Token-based authentication
- Request/Response scanning
- Connection pooling

##### Component Details

Client Side (Internal Network):
- Client configuration system (/lib/client)
- Connection management (/lib/client/connectionsManager)
- Filtering system (/lib/common/filter)
- Plugin architecture (/lib/client/brokerClientPlugins)

Server Side:
- Dispatcher system (/lib/server/infra)
- Route handlers (/lib/server/routesHandlers)
- Socket management (/lib/server/socket)

##### Additional Elements

Specialized components for:
- Health checking system
- Metrics collection
- Plugin system
- Certificate management
- PGP signing capabilities

##### Implementation Details to Note

- WebSocket-based communication
- HTTP/HTTPS proxying
- Filter rule application
- Authentication mechanisms
- Plugin extensibility

**[External Services Layer]**
- ↕
**[Security/Authentication Layer]**
- ↕
**[Broker Server Layer]**
- ↕
**[Secure Tunnel Layer]**
- ↕
**[Broker Client Layer]**
- ↕
**[Internal Services Layer]**

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Systems
    subgraph External["External Zone"]
        direction TB
        Snyk["Snyk.io"]:::external
        GitProviders["Git Providers"]:::external
        Jira["Jira"]:::external
        Containers["Container Registries"]:::external
    end

    %% Broker Server Components
    subgraph ServerZone["Broker Server Zone"]
        direction TB
        BrokerServer["Broker Server"]:::server
        ServerSocket["Server Socket Manager"]:::server
        Dispatcher["Request Dispatcher"]:::server
        ServerRoutes["HTTP Request Handler"]:::server
    end

    %% Secure Tunnel Components
    subgraph TunnelZone["Secure Tunnel"]
        direction TB
        WSConnection["WebSocket Connection"]:::tunnel
    end

    %% Broker Client Components
    subgraph ClientZone["Broker Client Zone"]
        direction TB
        BrokerClient["Broker Client"]:::client
        ClientSocket["Client Socket Manager"]:::client
        FilterEngine["Filter Rules Engine"]:::security
        AuthLayer["Authentication Layer"]:::security
        PluginSystem["Plugin System"]:::client
        HealthCheck["Health Check System"]:::client
    end

    %% Internal Systems
    subgraph Internal["Internal Zone"]
        direction TB
        InternalGit["Internal Git"]:::internal
        InternalJira["Internal Jira"]:::internal
        InternalRegistry["Internal Registry"]:::internal
    end

    %% Connections
    Snyk --> BrokerServer
    GitProviders --> BrokerServer
    Jira --> BrokerServer
    Containers --> BrokerServer

    BrokerServer --> ServerSocket
    ServerSocket --> WSConnection
    ServerSocket --> Dispatcher
    Dispatcher --> ServerRoutes

    WSConnection --> ClientSocket
    ClientSocket --> BrokerClient
    BrokerClient --> FilterEngine
    BrokerClient --> AuthLayer
    BrokerClient --> PluginSystem
    BrokerClient --> HealthCheck

    BrokerClient --> InternalGit
    BrokerClient --> InternalJira
    BrokerClient --> InternalRegistry

    %% Styles
    classDef external fill:#2374AB
    classDef server fill:#FF8C42
    classDef tunnel fill:#939597
    classDef client fill:#45B7D1
    classDef security fill:#FF4365
    classDef internal fill:#4CAF50

    %% Click Events
    click BrokerServer "https://github.com/snyk/broker/tree/master/lib/server/"
    click ServerSocket "https://github.com/snyk/broker/blob/master/lib/server/socket.ts"
    click Dispatcher "https://github.com/snyk/broker/blob/master/lib/server/infra/dispatcher.ts"
    click ServerRoutes "https://github.com/snyk/broker/blob/master/lib/server/routesHandlers/httpRequestHandler.ts"
    click BrokerClient "https://github.com/snyk/broker/tree/master/lib/client/"
    click ClientSocket "https://github.com/snyk/broker/blob/master/lib/client/socket.ts"
    click FilterEngine "https://github.com/snyk/broker/tree/master/lib/common/filter/"
    click AuthLayer "https://github.com/snyk/broker/blob/master/lib/client/auth/oauth.ts"
    click PluginSystem "https://github.com/snyk/broker/blob/master/lib/client/brokerClientPlugins/pluginManager.ts"
    click HealthCheck "https://github.com/snyk/broker/tree/master/lib/client/checks/"
```
