# akiidjk/styx architecture

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

- Interactive diagram: https://gitdiagram.com/akiidjk/styx
- Repository: https://github.com/akiidjk/styx

## Overview

##### Main Components Identification

The system can be broken down into these major components:

a) Core Firewall Components:
- eBPF/XDP Module (kernel-level filtering)
- Redis Datastore
- API Server
- Configuration Management

b) User Interface Components:
- Web Interface
- Log Viewer
- Management API

##### Component Relationships

Key interactions:

a) Data Flow:
- Network traffic → eBPF/XDP programs
- eBPF programs ↔ Userspace program
- Core service ↔ Redis datastore
- API server ↔ Web UI
- Log collection → Log viewer

b) Control Flow:
- Configuration changes → Core service
- API requests → Core service
- Monitoring data → Log viewer

##### Specific Implementation Details

Technical elements:

a) eBPF Components:
- Counter program (counter.c)
- IP filtering program (filter_ip.c)
- eBPF maps for state sharing

b) Service Components:
- Redis for state management
- HTTP/API server
- Configuration management

c) User Interface:
- Web interface with Tailwind CSS
- Python-based log viewer
- API endpoints

##### Critical Relationships to Highlight

- Separation between kernel space and user space
- Real-time nature of packet filtering
- Configuration deployment flow
- Monitoring and logging paths

##### Technical Details

a) Kernel Space:
- eBPF programs (counter.c, filter_ip.c)
- XDP hooks
- eBPF maps

b) User Space:
- Go-based main service
- Redis integration
- Web interface
- Python log viewer

c) APIs and Interfaces:
- Management API
- Monitoring endpoints
- Configuration interfaces

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Infrastructure
        Kernel[Linux Kernel]:::kernel
        XDP[XDP Hook]:::kernel
        eBPF_Programs[eBPF Programs]:::kernel
        click eBPF_Programs "https://github.com/akiidjk/styx/tree/master/internal/ebpf/ebpf_module_kernel"
        Counter[Counter Program]:::kernel
        click Counter "https://github.com/akiidjk/styx/blob/master/internal/ebpf/ebpf_module_kernel/counter.c"
        FilterIP[IP Filter Program]:::kernel
        click FilterIP "https://github.com/akiidjk/styx/blob/master/internal/ebpf/ebpf_module_kernel/filter_ip.c"
        Redis[(Redis Datastore)]:::storage
        click Redis "https://github.com/akiidjk/styx/blob/master/internal/datastore/redis.go"
    end

    subgraph Core_Services
        MainService[Main Styx Service]:::service
        click MainService "https://github.com/akiidjk/styx/blob/master/cmd/root.go"
        APIServer[API Server]:::service
        click APIServer "https://github.com/akiidjk/styx/blob/master/internal/api/server.go"
        ConfigMgmt[Configuration Management]:::service
        click ConfigMgmt "https://github.com/akiidjk/styx/blob/master/internal/utils/config.go"
        Logger[Logging System]:::service
        click Logger "https://github.com/akiidjk/styx/blob/master/internal/utils/logger/logger.go"
        NetworkUtils[Network Utilities]:::service
        click NetworkUtils "https://github.com/akiidjk/styx/blob/master/internal/utils/network.go"
    end

    subgraph User_Interface
        WebUI[Web Interface]:::ui
        click WebUI "https://github.com/akiidjk/styx/tree/master/internal/web"
        LogViewer[Log Viewer]:::ui
        click LogViewer "https://github.com/akiidjk/styx/tree/master/log-viewer"
        APIEndpoints[API Endpoints]:::ui
    end

    %% Kernel Space Connections
    Kernel --> XDP
    XDP --> eBPF_Programs
    eBPF_Programs --> Counter
    eBPF_Programs --> FilterIP

    %% Core Service Connections
    MainService <--> Redis
    MainService <--> eBPF_Programs
    MainService --> Logger
    MainService --> NetworkUtils
    APIServer --> MainService
    ConfigMgmt --> MainService

    %% UI Connections
    WebUI --> APIServer
    LogViewer --> Logger
    APIEndpoints --> APIServer

    %% Styling
    classDef kernel fill:#1e40af,color:white
    classDef storage fill:#7e22ce,color:white
    classDef service fill:#15803d,color:white
    classDef ui fill:#c2410c,color:white

    %% Legend
    subgraph Legend
        K[Kernel Components]:::kernel
        S[Services]:::service
        ST[(Storage)]:::storage
        U[User Interface]:::ui
    end
```
