# pk-218/aegis-node architecture

> Architecture diagram of the GitHub repository pk-218/aegis-node, 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/pk-218/aegis-node
- Repository: https://github.com/pk-218/aegis-node

## Overview

##### Main System Components
- eBPF Program Component (aegis-node-ebpf)
- Userspace Program Component (aegis-node)
- Common Library Component (aegis-node-common)
- Build System Component (xtask)

**┌─ Userspace Layer ─────────────────────┐**

- aegis-node (Userspace Application)   │

- ┤

- aegis-node-common (Shared Library)   │

- ┤

- Kernel Layer                         │
- aegis-node-ebpf (eBPF Program)      │

- ┘

##### Component Relationships

- Data flow between userspace and kernel space
- Dependency relationships between components
- Build process flow

##### Specific Elements

a) eBPF Program Component (aegis-node-ebpf):
- Connection to kernel hooks
- Packet processing functionality (based on packet_info.rs)
- As running in kernel context

b) Userspace Component (aegis-node):
- EBPF program loading mechanism
- Communication channel with eBPF program
- As running in user context

c) Common Library (aegis-node-common):
- Shared structures and types
- Usage by both userspace and eBPF components

d) Build System (xtask):
- Build workflow
- Separate compilation paths for eBPF and userspace code

##### Additional Details

Technical specifications:
- Rust toolchain requirements (stable and nightly)
- BPF linker dependency
- Compilation targets
- Runtime configuration (RUST_LOG=info)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef userspace fill:#b3d1ff,stroke:#333,stroke-width:2px
    classDef kernel fill:#ffb3b3,stroke:#333,stroke-width:2px
    classDef common fill:#b3ffb3,stroke:#333,stroke-width:2px
    classDef build fill:#e6e6e6,stroke:#333,stroke-width:2px
    
    %% Subgraphs
    subgraph Userspace
        UserApp["Userspace Application"]
        UserMain["Main Program"]
        LoaderMech["eBPF Loader"]
    end
    
    subgraph Common
        SharedLib["Common Library"]
        PacketInfo["Packet Processing Types"]
        SharedTypes["Shared Structures"]
    end
    
    subgraph Kernel
        BPFProg["eBPF Program"]
        KernelHooks["Kernel Hooks"]
        PacketProc["Packet Processing"]
        BPFConst["eBPF Constants"]
    end
    
    subgraph BuildSystem
        XTask["Build System"]
        BPFBuild["eBPF Builder"]
        CodeGen["Code Generator"]
        RunConfig["Runtime Config"]
    end

    %% Relationships
    UserApp --> LoaderMech
    LoaderMech --> BPFProg
    BPFProg --> KernelHooks
    BPFProg --> PacketProc
    PacketProc --> PacketInfo
    SharedLib --> UserApp
    SharedLib --> BPFProg
    SharedTypes --> UserApp
    SharedTypes --> BPFProg
    XTask --> BPFBuild
    XTask --> CodeGen
    XTask --> RunConfig
    BPFBuild --> BPFProg
    BPFConst --> BPFProg

    %% Click Events
    click BPFProg "https://github.com/pk-218/aegis-node/blob/main/aegis-node-ebpf/src/main.rs"
    click BPFConst "https://github.com/pk-218/aegis-node/blob/main/aegis-node-ebpf/src/consts.rs"
    click UserMain "https://github.com/pk-218/aegis-node/blob/main/aegis-node/src/main.rs"
    click SharedLib "https://github.com/pk-218/aegis-node/blob/main/aegis-node-common/src/lib.rs"
    click PacketInfo "https://github.com/pk-218/aegis-node/blob/main/aegis-node-common/src/packet_info.rs"
    click XTask "https://github.com/pk-218/aegis-node/blob/main/xtask/src/main.rs"
    click BPFBuild "https://github.com/pk-218/aegis-node/blob/main/xtask/src/build_ebpf.rs"
    click RunConfig "https://github.com/pk-218/aegis-node/blob/main/xtask/src/run.rs"
    click CodeGen "https://github.com/pk-218/aegis-node/blob/main/xtask/src/codegen.rs"

    %% Style Applications
    class UserApp,UserMain,LoaderMech userspace
    class BPFProg,KernelHooks,PacketProc,BPFConst kernel
    class SharedLib,PacketInfo,SharedTypes common
    class XTask,BPFBuild,CodeGen,RunConfig build

    %% Legend
    subgraph Legend
        U[Userspace Component]:::userspace
        K[Kernel Component]:::kernel
        C[Common Library]:::common
        B[Build System]:::build
    end
```
