# icedynamix/reliquary-archiver architecture

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

- Interactive diagram: https://gitdiagram.com/icedynamix/reliquary-archiver
- Repository: https://github.com/icedynamix/reliquary-archiver

## Overview

##### Project type and purpose
- This is a Rust‑based CLI tool (an open‑source packet‑capture archiver) called “reliquary‑archiver”.
- Purpose: capture network packets from a turn‑based anime game (live via libpcap or from a .pcap file), parse game‑specific data, and export it to a JSON format compatible with downstream tools (e.g., fribbels hsr optimizer).

##### File structure
- Top‑level files:
- Cargo.toml / Cargo.lock (Rust package config)
- build.rs (build‑time resource downloader & embedder)
- src/main.rs (CLI entrypoint)
- src/lib.rs (core library definitions)
- src/export/ (exporter modules: database.rs, fribbels.rs)
- .github/workflows/release.yml (CI/CD pipeline for releases)
- README.md / LICENSE / .gitignore

##### Extract insights from the README
- Dependencies: libpcap (Linux) or npcap (Windows), Rust pcap crate
- Supports live capture (CAP_NET_RAW) or offline .pcap input
- CLI options: output path, timeout, verbosity, log path, update‑check flags, exit behavior
- Build script pulls in static resource files at compile time
- Outputs JSON and optionally log files
- Integrates with external services (GitHub for update checks)

a. Main components
- CLI & Configuration Layer (src/main.rs)
- Layer (pcap live capture or file reader via pcap crate)
- Parser / Core Library (src/lib.rs + underlying reliquary library)
- Exporter Modules (src/export/database.rs & fribbels.rs)
- Output Writer (JSON file sink + optional log file)
- Build Script (build.rs, invoked at compile time)
- External Dependencies / Services
- libpcap / npcap
- GitHub API (update‑check on Windows)

b. Relationships & data flow
1. User invokes CLI → parses arguments & config
2. CLI initializes Capture Layer → binds to live interface or opens .pcap file
3. Raw packets flow into the Parser / Core Library → extracts game‑specific events
4. Parsed events feed into appropriate Exporter(s) → transform into JSON structures
5. Output Writer writes JSON to disk; logs get emitted via tracing‑subscriber
6. (Windows only) CLI optionally queries GitHub API for updates
7. build.rs runs at build time to fetch & embed resource files

c. Architectural patterns & principles
- Layered, pipeline architecture (capture → parse → export → write)
- Modular exporter plugins (database vs. fribbels)
- Clear separation between CLI, core logic, and I/O
- Build‑time codegen (via build.rs) for embedding static assets

d. Key technologies & libraries
- Rust (Cargo, build.rs)
- pcap crate (libpcap/npcap binding)
- tracing + tracing‑subscriber (logging)
- serde_json (JSON serialization)
- reliquary (underlying packet decode library)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build-time
    Build["Build Script (build.rs)"]:::build

    %% Core Pipeline
    CLI["CLI & Configuration Layer\n(src/main.rs)"]:::internal
    subgraph "Capture Layer"
        direction TB
        Live["Live Capture\n(pcap crate\nlibpcap/npcap)"]:::internal
        FileReader["File Reader\n(.pcap input)"]:::internal
    end
    Parser["Parser / Core Library\n(src/lib.rs)"]:::internal
    ExportReg["Exporter Module Registry\n(src/export/mod.rs)"]:::internal
    subgraph "Exporter Modules"
        direction TB
        ExportDB["Database Plugin\n(src/export/database.rs)"]:::internal
        ExportFribbels["Fribbels Plugin\n(src/export/fribbels.rs)"]:::internal
    end
    Writer["Output Writer\n(JSON & Logs)"]:::io

    %% External Dependencies
    PcapLib["libpcap / npcap"]:::external
    GitHub["GitHub API\n(update-check)"]:::external
    FS["File System"]:::io

    %% CI/CD & Docs
    CargoToml["Cargo.toml"]:::build
    CargoLock["Cargo.lock"]:::build
    CI["CI/CD Workflow\n(.github/workflows/release.yml)"]:::external
    README["README.md"]:::external
    LICENSE["LICENSE"]:::external

    %% Data Flow
    Build --> CLI
    CLI --> Live
    CLI --> FileReader
    Live --> Parser
    FileReader --> Parser
    Parser --> ExportReg
    ExportReg --> ExportDB
    ExportReg --> ExportFribbels
    ExportDB --> Writer
    ExportFribbels --> Writer
    Writer --> FS
    CLI -->|"optional update-check"| GitHub
    Live --> PcapLib
    FileReader --> PcapLib

    %% Click Events
    click CLI "https://github.com/icedynamix/reliquary-archiver/blob/main/src/main.rs"
    click Build "https://github.com/icedynamix/reliquary-archiver/blob/main/build.rs"
    click Parser "https://github.com/icedynamix/reliquary-archiver/blob/main/src/lib.rs"
    click ExportDB "https://github.com/icedynamix/reliquary-archiver/blob/main/src/export/database.rs"
    click ExportFribbels "https://github.com/icedynamix/reliquary-archiver/blob/main/src/export/fribbels.rs"
    click ExportReg "https://github.com/icedynamix/reliquary-archiver/blob/main/src/export/mod.rs"
    click CargoToml "https://github.com/icedynamix/reliquary-archiver/blob/main/Cargo.toml"
    click CargoLock "https://github.com/icedynamix/reliquary-archiver/blob/main/Cargo.lock"
    click CI "https://github.com/icedynamix/reliquary-archiver/blob/main/.github/workflows/release.yml"
    click README "https://github.com/icedynamix/reliquary-archiver/blob/main/README.md"
    click LICENSE "https://github.com/icedynamix/reliquary-archiver/tree/main/LICENSE"

    %% Styles
    classDef internal fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef external fill:#ABEBC6,stroke:#1D8348,color:#1B2631
    classDef io fill:#F9E79F,stroke:#B7950B,color:#1B2631
    classDef build fill:#D5DBDB,stroke:#839192,color:#1B2631
```
