# as400671/server-config architecture

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

- Interactive diagram: https://gitdiagram.com/as400671/server-config
- Repository: https://github.com/as400671/server-config

## Overview

##### Main Components
- BIRD Routing Service:
- The “bird” directory holds multiple configuration files (inside basic and bgp) for controlling BGP connections and various routing policies.
- It includes configuration for standard Bird operation plus support for RPKI checks and BGP Large Communities.
- GRETP Tunneling:
- Found in the “gretap” folder, these scripts are used to manage GRE tunneling connections (critical for interconnect stability).
- API/Web Interface:
- The “html” folder contains PHP scripts (api.php) and the front-facing web pages (index.html, robots.txt) that serve as an interface for the network dashboard.
- Technologies include PHP and a recommended webserver (Caddy or alternatives).
- Cron / Scheduled Tasks:
- The “cron” folder holds Python scripts for connectivity checks and likely other periodic checks regarding IXP connectivity and BGP status.
- Network and Environment:
- The README emphasizes that all inbound/outbound network connections use WireGuard (wg0 interface) and that several external tools (stayrtr, rpki-client, bgpq4, tcpdump/Wireshark) are important for proper operation and debugging.

##### Relationships and Interactions
- The BIRD daemon is the core component handling BGP routing. It interacts with various configuration files that define routing rules, filters, constants, and environment variables.
- Before or after (re)starting the Bird daemon, GRETP scripts are executed to reset and establish GRE tunnel connections, ensuring link stability.
- The API layer (PHP in the “html” directory) serves external requests by interfacing with Bird’s configuration data. This API feeds data to a network dashboard, effectively bridging the configuration layer and the monitoring/visualization components.
- Cron jobs (Python scripts in the “cron” folder) periodically perform connectivity checks and potentially crawl interconnected IXPs and peers, feeding back data into the system.
- Overall, the system is governed by network layer rules – particularly enforced via WireGuard for all traffic routing, ensuring secure and reliable operations.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- Each folder targets a different aspect of the system (routing, tunneling, API, scheduling).
- Modular Design:
- By having all configuration files modularly placed within “basic” and “bgp” subdirectories and separate tooling (a dedicated scripts folder for upgrades and GRETP tunneling), the system facilitates easy updates and extensions.
- Interaction via Well-Defined Interfaces:
- For example, the web API serves as an interface between the Bird daemon’s operations and an external system (the dashboard).

##### Additional Notes
- Even though the overall system isn’t overly large, break it down into distinct parts (configuration for BIRD, cron operations, web API) to better reflect modularity and design.

## Diagram (Mermaid)

```mermaid
graph TD
    %% BIRD Routing Service Subgraph
    subgraph "BIRD Routing Service"
        BIRD_Config["Main Config"]:::routing
        BIRD_Basic["Basic Config"]:::routing
        BIRD_BGP["BGP Config"]:::routing
        BIRD_Env["Environment Variables"]:::routing
        BIRD_Upgrade["Upgrade Script"]:::routing
        BIRD_Config --> BIRD_Basic
        BIRD_Config --> BIRD_BGP
    end

    %% GRETP Tunneling Subgraph
    subgraph "GRETP Tunneling"
        GRETP["GRETP Tunneling Scripts"]:::tunneling
    end

    %% API/Web Interface Subgraph
    subgraph "API/Web Interface"
        API_PHP["API (PHP)"]:::api
        INDEX["Index Page"]:::api
        ROBOTS["Robots.txt"]:::api
        API_PHP -->|"serves"| INDEX
        API_PHP -->|"serves"| ROBOTS
    end

    %% Cron / Scheduled Tasks Subgraph
    subgraph "Cron/Scheduled Tasks"
        CRON_CONNECT["Connectivity Check"]:::cron
        CRON_CONFIG["Config Check"]:::cron
    end

    %% External Dependencies
    WIREGUARD["WireGuard (wg0)"]:::external
    EXTERNAL_UTILS["External Tools (stayrtr, rpki-client, bgpq4, tcpdump/Wireshark)"]:::external

    %% Relationships between components
    BIRD_Config -->|"triggers"| GRETP
    BIRD_Config -->|"exposes"| API_PHP
    CRON_CONNECT -->|"checks"| BIRD_Config
    CRON_CONFIG -->|"checks"| BIRD_Config
    WIREGUARD -->|"secures"| BIRD_Config
    WIREGUARD -->|"secures"| API_PHP
    EXTERNAL_UTILS -->|"supports"| BIRD_Config
    EXTERNAL_UTILS -->|"supports"| API_PHP
    EXTERNAL_UTILS -->|"supports"| CRON_CONNECT
    EXTERNAL_UTILS -->|"supports"| CRON_CONFIG

    %% Click Events for BIRD Routing Service
    click BIRD_Config "https://github.com/as400671/server-config/tree/main/bird/config/"
    click BIRD_Basic "https://github.com/as400671/server-config/tree/main/bird/config/basic/"
    click BIRD_BGP "https://github.com/as400671/server-config/tree/main/bird/config/bgp/"
    click BIRD_Env "https://github.com/as400671/server-config/tree/main/bird/config/envvars"
    click BIRD_Upgrade "https://github.com/as400671/server-config/blob/main/bird/scripts/upgrade-latest.sh"

    %% Click Events for GRETP Tunneling
    click GRETP "https://github.com/as400671/server-config/tree/main/gretap/"

    %% Click Events for API/Web Interface
    click API_PHP "https://github.com/as400671/server-config/blob/main/html/api.php"
    click INDEX "https://github.com/as400671/server-config/blob/main/html/index.html"
    click ROBOTS "https://github.com/as400671/server-config/blob/main/html/robots.txt"

    %% Click Events for Cron / Scheduled Tasks
    click CRON_CONNECT "https://github.com/as400671/server-config/blob/main/cron/connectivity_check.py"
    click CRON_CONFIG "https://github.com/as400671/server-config/blob/main/cron/config.py"

    %% Styles
    classDef routing fill:#f9c,stroke:#333,stroke-width:2px;
    classDef tunneling fill:#cfc,stroke:#333,stroke-width:2px;
    classDef api fill:#ccf,stroke:#333,stroke-width:2px;
    classDef cron fill:#fc9,stroke:#333,stroke-width:2px;
    classDef external fill:#ccc,stroke:#333,stroke-width:2px;
```
