# kojix2/c2ffi4rb architecture

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

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

## Overview

c2ffi4rb converts c2ffi-generated JSON specifications into Ruby FFI binding code: users run the CLI with one or more specs, optionally supplying a type-conversion table, and receive generated Ruby on standard output for manual completion. The CLI delegates generation to BindGen, which dispatches declaration forms and resolves their types. The library entry point loads BindGen and version metadata. CLI internals and the type-table file format were not sampled, so those details are limited to README-documented behavior.

Main entry points: [`exe/c2ffi4rb`](https://github.com/kojix2/c2ffi4rb/blob/main/exe/c2ffi4rb) (Command-line tool), [`lib/c2ffi4rb/bind_gen.rb`](https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb/bind_gen.rb) (Binding generator), [`lib/c2ffi4rb.rb`](https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb.rb) (Library entry point), [`lib/c2ffi4rb/version.rb`](https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb/version.rb) (Version metadata)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_cli["Command-line tool"]
  node_library["Library entry point<br/>[c2ffi4rb.rb]"]
  node_version["Version metadata<br/>[version.rb]"]
end

subgraph group_generation["Binding generation"]
  node_generator["Binding generator<br/>[bind_gen.rb]"]
  node_type_table["Type table"]
  node_type_resolution["Type resolution<br/>[bind_gen.rb]"]
end

node_user(("Binding author"))
node_c2ffi["c2ffi compiler"]
node_spec["JSON spec"]
node_ruby_output["Generated Ruby"]

node_user -->|"invokes"| node_c2ffi
node_c2ffi -->|"produces"| node_spec
node_user -->|"invokes"| node_cli
node_spec -->|"supplies input"| node_cli
node_type_table -->|"optional input"| node_cli
node_cli -->|"generates with"| node_generator
node_cli -->|"writes output"| node_ruby_output
node_library -->|"loads"| node_generator
node_library -->|"loads"| node_version
node_generator -->|"resolves types"| node_type_resolution
node_type_resolution -->|"emits declarations"| node_ruby_output

click node_cli "https://github.com/kojix2/c2ffi4rb/blob/main/exe/c2ffi4rb"
click node_library "https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb.rb"
click node_version "https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb/version.rb"
click node_generator "https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb/bind_gen.rb"
click node_type_resolution "https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb/bind_gen.rb"

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_cli,node_library,node_version toneBlue
class node_generator,node_type_table,node_type_resolution toneAmber
class node_user,node_c2ffi,node_spec,node_ruby_output toneIndigo
```

## Components

### User interface

- [Command-line tool](https://github.com/kojix2/c2ffi4rb/blob/main/exe/c2ffi4rb): `exe/c2ffi4rb`
- [Library entry point](https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb.rb): `lib/c2ffi4rb.rb`
- [Version metadata](https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb/version.rb): `lib/c2ffi4rb/version.rb`

### Binding generation

- [Binding generator](https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb/bind_gen.rb): `lib/c2ffi4rb/bind_gen.rb`
- **Type table**
- [Type resolution](https://github.com/kojix2/c2ffi4rb/blob/main/lib/c2ffi4rb/bind_gen.rb): `lib/c2ffi4rb/bind_gen.rb`

### Other components

- **Binding author**
- **c2ffi compiler**
- **JSON spec**
- **Generated Ruby**

## Connections

- Binding author → c2ffi compiler: invokes (evidence: `README.md`)
- c2ffi compiler → JSON spec: produces (evidence: `README.md`)
- Binding author → Command-line tool: invokes (evidence: `README.md`)
- JSON spec → Command-line tool: supplies input (evidence: `README.md`)
- Type table → Command-line tool: optional input (evidence: `README.md`)
- Command-line tool → Binding generator: generates with (evidence: `README.md`)
- Command-line tool → Generated Ruby: writes output (evidence: `README.md`)
- Library entry point → Binding generator: loads (evidence: `lib/c2ffi4rb.rb`)
- Library entry point → Version metadata: loads (evidence: `lib/c2ffi4rb.rb`)
- Binding generator → Type resolution: resolves types (evidence: `lib/c2ffi4rb/bind_gen.rb`)
- Type resolution → Generated Ruby: emits declarations (evidence: `lib/c2ffi4rb/bind_gen.rb`)
