# alegrey91/harpoon architecture

> Architecture diagram of the GitHub repository alegrey91/harpoon, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/alegrey91/harpoon
- Repository: https://github.com/alegrey91/harpoon

## Overview

##### Main Components

a) Core Components:
- CLI Interface (cmd/ directory)
- eBPF Program (ebpf/ directory)
- Internal Services Layer (internal/ directory)
- Analysis Engine (internal/analyzer)
- System Call Capture System (internal/ebpf/probesfacade)

b) Supporting Components:
- ELF Reader (internal/elfreader)
- Archive Management (internal/archiver)
- Seccomp Profile Generation (internal/seccomputils)

**┌─ User Interface Layer ─────────────────────┐**
- CLI Commands (analyze, build, capture, etc)│
- ┬───────────────────────┘
- ↓
**┌─ Core Services Layer ──────────────────────┐**
- ┌─────────────┐  ┌──────────┐ ┌─────────┐ │
- eBPF Program │←→│ Analyzer │ │ Archive │ │
- ┘  └──────────┘ └─────────┘ │
- ┬───────────────────────┘
- ↓
**┌─ System Integration Layer ─────────────────┐**
- ┌──────────┐ ┌────────────┐ ┌──────────┐  │
- ELF Reader│ │Probe Facade│ │Seccomp   │  │
- ┘ └────────────┘ └──────────┘  │
- ┬───────────────────────┘
- ↓
**┌─ Kernel Interface Layer ───────────────────┐**
- System Calls & eBPF Hooks           │
- ┘

##### Important Relationships

a) Data Flow:
- Command flow from CLI to core services
- eBPF program interaction with kernel
- Syscall capture flow from kernel to analysis
- Output generation path

b) Component Dependencies:
- eBPF program dependency on kernel hooks
- Analyzer dependency on eBPF program output
- CLI commands' dependencies on internal services

##### Technical Details to Highlight

- eBPF program compilation and loading process
- Syscall capture mechanism
- Security profile generation
- Archive management for captured data

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef core fill:#2ecc71,stroke:#27ae60,color:white
    classDef system fill:#f1c40f,stroke:#f39c12,color:black
    classDef kernel fill:#e74c3c,stroke:#c0392b,color:white
    classDef support fill:#95a5a6,stroke:#7f8c8d,color:white

    %% User Interface Layer
    subgraph UI
        CLI["CLI Interface"]
        ANALYZE["Analyze Command"]
        BUILD["Build Command"]
        CAPTURE["Capture Command"]
        HUNT["Hunt Command"]
    end

    %% Core Services Layer
    subgraph Core
        EBPF["eBPF Program"]
        ANALYZER["Analysis Engine"]
        ARCHIVE["Archive Management"]
        WRITER["Output Writer"]
        EXECUTOR["Execution Manager"]
        METADATA["Metadata Manager"]
        EMBEDDED["Embedded Resources"]
    end

    %% System Integration Layer
    subgraph System
        ELF["ELF Reader"]
        PROBE["Probe Facade"]
        SECCOMP["Seccomp Utils"]
        PRIV["Privileged Operations"]
    end

    %% Kernel Interface Layer
    subgraph Kernel
        SYSCALLS["System Calls & eBPF Hooks"]
    end

    %% Relationships
    CLI --> ANALYZE & BUILD & CAPTURE & HUNT
    ANALYZE & BUILD & CAPTURE & HUNT --> ANALYZER
    ANALYZER --> EBPF
    EBPF --> SYSCALLS
    PROBE --> SYSCALLS
    ANALYZER --> ARCHIVE
    ANALYZER --> WRITER
    ANALYZER --> SECCOMP
    EBPF --> PROBE
    PROBE --> ELF
    EXECUTOR --> PRIV
    METADATA --> EMBEDDED

    %% Click Events
    click CLI "https://github.com/alegrey91/harpoon/blob/main/cmd/root.go"
    click ANALYZE "https://github.com/alegrey91/harpoon/blob/main/cmd/analyze.go"
    click BUILD "https://github.com/alegrey91/harpoon/blob/main/cmd/build.go"
    click CAPTURE "https://github.com/alegrey91/harpoon/blob/main/cmd/capture.go"
    click HUNT "https://github.com/alegrey91/harpoon/blob/main/cmd/hunt.go"
    click EBPF "https://github.com/alegrey91/harpoon/blob/main/ebpf/ebpf.c"
    click ANALYZER "https://github.com/alegrey91/harpoon/blob/main/internal/analyzer/analyze.go"
    click PROBE "https://github.com/alegrey91/harpoon/blob/main/internal/ebpf/probesfacade/probesfacade.go"
    click ELF "https://github.com/alegrey91/harpoon/blob/main/internal/elfreader/retoffsets.go"
    click ARCHIVE "https://github.com/alegrey91/harpoon/blob/main/internal/archiver/archive.go"
    click SECCOMP "https://github.com/alegrey91/harpoon/blob/main/internal/seccomputils/seccomputils.go"
    click PRIV "https://github.com/alegrey91/harpoon/blob/main/internal/privileged/privileged.go"
    click WRITER "https://github.com/alegrey91/harpoon/blob/main/internal/writer/write.go"
    click EXECUTOR "https://github.com/alegrey91/harpoon/blob/main/internal/executor/exec.go"
    click METADATA "https://github.com/alegrey91/harpoon/blob/main/internal/metadata/metadata.go"
    click EMBEDDED "https://github.com/alegrey91/harpoon/blob/main/internal/embeddable/ebpf.go"

    %% Style Applications
    class CLI,ANALYZE,BUILD,CAPTURE,HUNT ui
    class EBPF,ANALYZER,ARCHIVE,WRITER,EXECUTOR,METADATA,EMBEDDED core
    class ELF,PROBE,SECCOMP,PRIV system
    class SYSCALLS kernel

    %% Legend
    subgraph Legend
        L1["User Interface"]:::ui
        L2["Core Services"]:::core
        L3["System Integration"]:::system
        L4["Kernel Interface"]:::kernel
    end
```
