# kioubit/flapalerted architecture

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

## Overview

##### Main Components

a) Core BGP Processing Layer:
- BGP listener component (port 1790)
- Main BGP message types (Open, Update, KeepAlive) processing
- Path change detection system

b) Monitoring and Analysis Layer:
- Route change counter
- Path analysis component
- Flap detection logic
- State management for prefix tracking

c) Module System:
- HTTP API Module (default enabled)
- Logging Module (default enabled)
- ROA Filter Module (optional)

##### Component Relationships

**External BGP Peer -> BGP Listener -> Message Processing -> Analysis Engine -> Modules**

##### Specific Implementation Details

- BGP Session Handler (port 1790)
- Message Parser (showing Open/Update/KeepAlive flows)
- Route Change Analyzer
- State Manager
- Module System

##### Important Elements to Highlight

a) Data Flows:
- BGP message flow
- Route update processing
- Flap detection pipeline
- Module communication

b) External Interfaces:
- BGP peer connection (port 1790)
- HTTP API endpoints (port 8699)
- Web Dashboard
- Metrics endpoints

##### Technical Details

Key configurations:
- ASN handling
- AddPath support
- Route change counter
- Minimum age tracking
- Period window

##### Architectural Patterns

Emphasize:
- Modular design pattern
- Event-driven architecture
- Pipeline processing
- State management

**[External Layer]**
**BGP Peers -> BGP Daemon Connection**

**[Core Processing Layer]**
**BGP Session Handler -> Message Parser -> Route Processor**

**[Analysis Layer]**
**Path Analyzer -> Flap Detector -> State Manager**

**[Module Layer]**
**HTTP API -> Logging -> ROA Filter**

**[External Interfaces]**
**Web Dashboard -> Metrics Endpoints -> API Endpoints**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External
        BGPPeer[BGP Peer]
    end

    subgraph CoreProcessing["Core BGP Processing Layer"]
        BGPListener[BGP Listener\nPort 1790]
        
        subgraph MessageProcessing["Message Processing"]
            direction TB
            OpenMsg["Open Messages"]:::core
            UpdateMsg["Update Messages"]:::core
            KeepAliveMsg["KeepAlive Messages"]:::core
            CommonBGP["Common BGP Functions"]:::core
        end
    end

    subgraph Analysis["Analysis Layer"]
        RouteAnalyzer["Route Analyzer"]:::analysis
        FlapDetector["Flap Detector"]:::analysis
        StateManager["State Manager"]:::analysis
        Notifier["Notification System"]:::analysis
    end

    subgraph ModuleSystem["Module Layer"]
        ModuleManager["Module Manager"]:::module
        HTTPAPI["HTTP API Module"]:::module
        LoggingMod["Logging Module"]:::module
        ROAFilter["ROA Filter Module\n(Optional)"]:::module
    end

    subgraph WebInterface["External Interfaces"]
        Dashboard["Web Dashboard"]:::interface
        MetricsEndpoint["Metrics Endpoint"]:::interface
        APIEndpoint["API Endpoint\nPort 8699"]:::interface
        StateStream["State Streaming"]:::interface
    end

    subgraph Config["Configuration"]
        ConfigMgr["Configuration Manager"]:::config
    end

    %% Connections
    BGPPeer --> BGPListener
    BGPListener --> MessageProcessing
    MessageProcessing --> RouteAnalyzer
    RouteAnalyzer --> FlapDetector
    FlapDetector --> StateManager
    StateManager --> Notifier
    
    ModuleManager --> HTTPAPI
    ModuleManager --> LoggingMod
    ModuleManager --> ROAFilter
    
    HTTPAPI --> Dashboard
    HTTPAPI --> MetricsEndpoint
    HTTPAPI --> APIEndpoint
    HTTPAPI --> StateStream
    
    ConfigMgr --> ModuleManager
    ConfigMgr --> CoreProcessing

    %% Styling
    classDef core fill:#2374ab
    classDef analysis fill:#47a025
    classDef module fill:#ff8c42
    classDef interface fill:#848484
    classDef config fill:#574ae2

    %% Click events
    click OpenMsg "https://github.com/Kioubit/FlapAlerted/tree/master//bgp/open"
    click UpdateMsg "https://github.com/Kioubit/FlapAlerted/tree/master//bgp/update"
    click KeepAliveMsg "https://github.com/Kioubit/FlapAlerted/blob/master//bgp/keepAlive.go"
    click CommonBGP "https://github.com/Kioubit/FlapAlerted/tree/master//bgp/common"
    click RouteAnalyzer "https://github.com/Kioubit/FlapAlerted/blob/master//monitor/analyze.go"
    click Notifier "https://github.com/Kioubit/FlapAlerted/blob/master//monitor/notifier.go"
    click HTTPAPI "https://github.com/Kioubit/FlapAlerted/blob/master//modules/httpAPI/mod_httpAPI.go"
    click LoggingMod "https://github.com/Kioubit/FlapAlerted/blob/master//modules/log/mod_log.go"
    click ROAFilter "https://github.com/Kioubit/FlapAlerted/blob/master//modules/roaFilter/mod_roaFilter.go"
    click Dashboard "https://github.com/Kioubit/FlapAlerted/tree/master//modules/httpAPI/dashboard"
    click ConfigMgr "https://github.com/Kioubit/FlapAlerted/blob/master//config/config.go"
    click ModuleManager "https://github.com/Kioubit/FlapAlerted/blob/master//modules/modules.go"
    click StateStream "https://github.com/Kioubit/FlapAlerted/blob/master//modules/httpAPI/statstream.go"
```
