# kazuki0824/recisdb-rs architecture

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

- Interactive diagram: https://gitdiagram.com/kazuki0824/recisdb-rs
- Repository: https://github.com/kazuki0824/recisdb-rs

## Overview

##### Project Type & Purpose
- This is a command‐line television tuner reader and ARIB STD-B25 decoder written in Rust. It is designed to read bitstreams from various tuner devices (Unix character devices and BonDriver on Windows) and decode them using a Rust wrapper (b25-sys) over libaribb25.
- The project is split into at least two main components: the command-line application (recisdb-rs) that provides various subcommands (checksignal, tune, decode) and a supporting library (b25-sys) that serves as an interface/wrapper to the external libaribb25.

##### Key Parts in the File Structure
- At the repository root you see cargo configurations, continuous integration workflows (GitHub Actions), and some configuration files.
- Two primary directories are present:
– b25-sys: Contains its own Cargo.toml, build.rs, and structured modules (e.g., ‘access_control’ and ‘bindings’) to wrap libaribb25. It includes external submodules in “externals/libaribb25”.
– recisdb-rs: Contains the main.rs and additional modules organizing “channels”, “commands”, “tuner” (with separate folders for linux and windows), and utility functions.
- This shows a clear separation where the “recisdb” CLI logic and device handling are implemented in recisdb-rs and the underlying ARIB STD-B25 decoding functionality is abstracted into the b25-sys library.

##### Components
a. User Interface / CLI:
– Represent the “CLI Application” (recisdb-rs) with its three subcommands:
- checksignal – for validating signal levels.
- tune – for selecting channels and streaming recorded TS data.
- decode – for taking scrambled input and producing a descrambled TS output.
b. Tuner Device Abstraction Layer:
– Break this out into platform-specific modules:
- Linux modules (chardev, DVBv5 support, tuner/linux).
- Windows modules (BonDriver and associated wrappers).
– Include “channels” and “commands” modules which parse command line input and coordinate between the CLI and underlying hardware.
c. Decoding Engine:
– Represent the b25-sys library as a distinct component that provides ARIB STD-B25 decoding.
– Under b25-sys, indicate several submodules:
- “access_control” handling control logic and structure.
- “bindings” which encapsulate the FFI layer to libaribb25.
- “externals/libaribb25” to show the native C library dependency.
d. External Dependencies:
– Illustrate dependencies such as libaribb25 and other system libraries (e.g., libdvbv5, libpcsclite) that are required for tuner operations.
– You might also show integration with build tools (Rust toolchain, build.rs) that help in building the FFI layer.

##### Relationships and Data Flow
– Parses and processes user commands.
– For tuner operations, directs requests to the platform-specific tuner modules.
– For decoding tasks, calls into the b25-sys decoding library.
- Then, b25-sys in turn invokes its “bindings” module that bridges the Rust code to the external libaribb25 library.
- Additionally, show that error/status information from tuner operations and decoding processes flows back to CLI for logging/debugging.

##### Important Architectural Patterns / Design Principles
- Modularity & separation of concerns:
– Clear isolation of CLI logic, hardware abstraction, and decoding functions.
- Cross-platform abstraction:
– Distinct handling of Linux (character devices, DVBv5) versus Windows (BonDriver) builds.
- FFI and wrapper usage:
– The b25-sys library wraps libaribb25 using Rust’s FFI capabilities, encapsulating native library interaction within a safe layer.
- Build script usage:
– Use of build.rs in both crates to handle custom build tasks (such as linking external libraries).

## Diagram (Mermaid)

```mermaid
flowchart TD
    U("User"):::external

    subgraph "CLI Application (recisdb-rs)"
        CLIApp["CLI Application (recisdb-rs)"]:::cli
        Commands["Commands Module (checksignal,tune,decode)"]:::cli
        Channels["Channels Module"]:::cli
        TunerModule["Tuner Module"]:::cli
        CLIApp -->|"handles"| Commands
        CLIApp -->|"manages"| Channels
        CLIApp -->|"delegates"| TunerModule
    end

    subgraph "Tuner Device Abstraction"
        Tuner_Linux["Tuner-Linux"]:::tuner
        Tuner_Windows["Tuner-Windows"]:::tuner
    end

    subgraph "Decoding Engine"
        DecLib["Decoding Library (b25-sys)"]:::lib
        AC["Access Control Module"]:::lib
        FFI["FFI Bindings"]:::lib
        DecLib -->|"includes"| AC
        DecLib -->|"includes"| FFI
    end

    subgraph "External Dependencies"
        Libaribb25["libaribb25"]:::external
        OtherLibs["OtherSystemLibraries"]:::external
    end

    U -->|"initiates"| CLIApp
    TunerModule -->|"platform_specific"| Tuner_Linux
    TunerModule -->|"platform_specific"| Tuner_Windows
    CLIApp -->|"command_for_decoding"| DecLib
    FFI -->|"calls"| Libaribb25
    Tuner_Linux -->|"status_msgs"| CLIApp
    Tuner_Windows -->|"status_msgs"| CLIApp
    DecLib -->|"error_msgs"| CLIApp

    click CLIApp "https://github.com/kazuki0824/recisdb-rs/blob/master/recisdb-rs/src/main.rs"
    click Tuner_Linux "https://github.com/kazuki0824/recisdb-rs/tree/master/recisdb-rs/src/tuner/linux"
    click Tuner_Windows "https://github.com/kazuki0824/recisdb-rs/tree/master/recisdb-rs/src/tuner/windows"
    click DecLib "https://github.com/kazuki0824/recisdb-rs/tree/master/b25-sys"
    click FFI "https://github.com/kazuki0824/recisdb-rs/tree/master/b25-sys/src/bindings"
    click Libaribb25 "https://github.com/kazuki0824/recisdb-rs/tree/master/b25-sys/externals/libaribb25"

    classDef cli fill:#f9f,stroke:#333,stroke-width:2px;
    classDef tuner fill:#ccf,stroke:#333,stroke-width:2px;
    classDef lib fill:#cfc,stroke:#333,stroke-width:2px;
    classDef external fill:#fc9,stroke:#333,stroke-width:2px;
```
