# kojix2/libcall-cli architecture

> Architecture diagram of the GitHub repository kojix2/libcall-cli, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kojix2/libcall-cli
- Repository: https://github.com/kojix2/libcall-cli

## Overview

libcall is a command-line tool for invoking a focused set of C functions in shared libraries without libffi. Its main workflow accepts command-line or JSON-spec input, parses typed arguments, resolves and loads a library, finds a symbol, dispatches the native call, and formats the result. The graph also shows the documented Lua callback capability. Relationships are based on the provided excerpts, SOURCE INDEX references, and README; unsampled implementation details are not inferred.

Main entry points: [`src/main.rs`](https://github.com/kojix2/libcall-cli/blob/main/src/main.rs) (CLI Orchestrator), [`src/ffi.rs`](https://github.com/kojix2/libcall-cli/blob/main/src/ffi.rs) (FFI Dispatcher), [`src/output.rs`](https://github.com/kojix2/libcall-cli/blob/main/src/output.rs) (Result Formatter), [`src/types.rs`](https://github.com/kojix2/libcall-cli/blob/main/src/types.rs) (Value Types)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Call Input"]
  node_main["CLI Orchestrator<br/>[main.rs]"]
  node_spec["JSON Spec Loader<br/>[file_input.rs]"]
  node_parser["Call Parser<br/>[parser.rs]"]
end

subgraph group_runtime["Call Runtime"]
  node_library["Library Resolver<br/>[library.rs]"]
  node_ffi["FFI Dispatcher<br/>[ffi.rs]"]
end

subgraph group_support["Types And Callbacks"]
  node_types["Value Types<br/>[types.rs]"]
  node_callback["Lua Callback Bridge<br/>[callback.rs]"]
end

subgraph group_results["Results"]
  node_output["Result Formatter<br/>[output.rs]"]
end

node_user(("CLI User"))
node_c_library[("C Shared Library")]

node_user -->|"supplies arguments"| node_main
node_main -->|"loads spec"| node_spec
node_main -->|"parses arguments"| node_parser
node_main -->|"resolves and loads"| node_library
node_main -->|"dispatches call"| node_ffi
node_main -->|"prints result"| node_output
node_parser -->|"parses values"| node_types
node_ffi -->|"uses values"| node_types
node_ffi -->|"registers callback"| node_callback
node_library -->|"loads and finds symbols"| node_c_library
node_ffi -->|"invokes function"| node_c_library
node_output -->|"formats values"| node_types
node_output -->|"formats call result"| node_ffi

click node_main "https://github.com/kojix2/libcall-cli/blob/main/src/main.rs"
click node_spec "https://github.com/kojix2/libcall-cli/blob/main/src/file_input.rs"
click node_parser "https://github.com/kojix2/libcall-cli/blob/main/src/parser.rs"
click node_types "https://github.com/kojix2/libcall-cli/blob/main/src/types.rs"
click node_library "https://github.com/kojix2/libcall-cli/blob/main/src/library.rs"
click node_ffi "https://github.com/kojix2/libcall-cli/blob/main/src/ffi.rs"
click node_callback "https://github.com/kojix2/libcall-cli/blob/main/src/callback.rs"
click node_output "https://github.com/kojix2/libcall-cli/blob/main/src/output.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_spec,node_parser,node_user toneBlue
class node_library,node_ffi,node_c_library toneAmber
class node_types,node_callback toneMint
class node_output toneRose
```

## Components

### Call Input

- [CLI Orchestrator](https://github.com/kojix2/libcall-cli/blob/main/src/main.rs): `src/main.rs`
- [JSON Spec Loader](https://github.com/kojix2/libcall-cli/blob/main/src/file_input.rs): `src/file_input.rs`
- [Call Parser](https://github.com/kojix2/libcall-cli/blob/main/src/parser.rs): `src/parser.rs`

### Call Runtime

- [Library Resolver](https://github.com/kojix2/libcall-cli/blob/main/src/library.rs): `src/library.rs`
- [FFI Dispatcher](https://github.com/kojix2/libcall-cli/blob/main/src/ffi.rs): `src/ffi.rs`

### Types And Callbacks

- [Value Types](https://github.com/kojix2/libcall-cli/blob/main/src/types.rs): `src/types.rs`
- [Lua Callback Bridge](https://github.com/kojix2/libcall-cli/blob/main/src/callback.rs): `src/callback.rs`

### Results

- [Result Formatter](https://github.com/kojix2/libcall-cli/blob/main/src/output.rs): `src/output.rs`

### Other components

- **CLI User**
- **C Shared Library**

## Connections

- CLI User → CLI Orchestrator: supplies arguments (evidence: `README.md`)
- CLI Orchestrator → JSON Spec Loader: loads spec (evidence: `src/main.rs`)
- CLI Orchestrator → Call Parser: parses arguments (evidence: `src/main.rs`)
- CLI Orchestrator → Library Resolver: resolves and loads (evidence: `src/main.rs`)
- CLI Orchestrator → FFI Dispatcher: dispatches call (evidence: `src/main.rs`)
- CLI Orchestrator → Result Formatter: prints result (evidence: `src/main.rs`)
- Call Parser → Value Types: parses values (evidence: `src/parser.rs`)
- FFI Dispatcher → Value Types: uses values (evidence: `src/ffi.rs`)
- FFI Dispatcher → Lua Callback Bridge: registers callback (evidence: `src/ffi.rs`)
- Library Resolver → C Shared Library: loads and finds symbols (evidence: `src/library.rs`)
- FFI Dispatcher → C Shared Library: invokes function (evidence: `README.md`)
- Result Formatter → Value Types: formats values (evidence: `src/output.rs`)
- Result Formatter → FFI Dispatcher: formats call result (evidence: `src/output.rs`)
