# cargo-fob/rusty-react-flow architecture

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

- Interactive diagram: https://gitdiagram.com/cargo-fob/rusty-react-flow
- Repository: https://github.com/cargo-fob/rusty-react-flow

## Overview

##### Project type and purpose
- From the README and file tree, **rusty-react-flow** is a **dual-target CLI tool** for analyzing TypeScript/JavaScript modules.
- It ships as a **Rust binary** (`cargo install rusty-react-flow`) and as an **npm package** (`npm install -D rusty-react-flow`), offering both a pure-Rust engine and a Node.js/TSX-based interactive CLI (likely using a React-in-terminal library such as Ink).
- Its goal is to crawl `.ts/.tsx/.js/.jsx` files, parse imports/exports, produce a JSON report, and optionally run in an interactive mode.

##### File structure
- **Top-level binaries**
- `bin/rusty-react-flow` – the Cargo-built Rust CLI wrapper
- `package.json` + TSX files – the Node.js CLI entrypoint
- **Rust source** (`src/*.rs`)
- `lib.rs` – core library
- `cli.rs` + `main.rs` – Rust CLI glue (arg parsing via Clap)
- `analyzer/` – parsing & summary logic (modules: `summary.rs`, `typescript.rs`)
- `models/` – data types for imports, exports, and JSON output
- **TSX source** (`src/*.tsx` + `src/components/`)
- `main.tsx` – Node CLI entrypoint rendering the interactive UI
- `Category.tsx`, `components/Button.tsx` – UI building blocks for interactive mode
- **Configuration & metadata**
- `Cargo.toml`, `Cargo.lock` – Rust dependencies
- `.npmignore`, `package.json` – Node packaging

##### README for additional insights
- Emphasizes **features**: file-scanning, dependency stats, interactive mode, JSON export.

a. **Main components**
- **User Interface Layer**
– Rust CLI (`cli.rs`, `main.rs`)
– Node CLI + Ink-style UI (`main.tsx`, `components/`, `Category.tsx`)
- **Core Analyzer Engine** (`lib.rs`, `analyzer/`)
– File system walker
– AST parsers for TS/JS (`typescript.rs`)
– Dependency summarizer (`summary.rs`)
- **Data Model Layer** (`models/`)
– Import/Export record types
– Output JSON schema (`output.rs`)
- **Persistence / I/O**
– Reads source files from disk
– Writes JSON report or streams to console
b. **Relationships & Data Flow**
1. **User** invokes CLI (Rust or Node).
2. CLI parses **command-line arguments** (path, interactive flag, output file).
3. CLI calls into **Analyzer Engine**:
– Walks target directory
– Parses each file using TS/JS parser module
– Populates model objects (imports/exports)
4. Engine produces an **in-memory summary** + detailed file list.
5. CLI decides:
– **Non-interactive** → serializes models to JSON via Serde (Rust) or `JSON.stringify` (Node) → writes to stdout or file.
– **Interactive** → feeds summary + file list to UI components → renders via terminal UI.
c. **Architectural patterns & design principles**
- **Separation of concerns**:
- CLI layer (argument parsing & I/O) vs. Analyzer core vs. UI layer
- **Language-agnostic core**: Rust library reusable by both Rust and Node CLIs
- **Modular design**: distinct modules for parsing, summarizing, data modeling
d. **Key technologies / frameworks**
- Rust ecosystem: Cargo, Clap (CLI parsing), Serde (JSON), swc or a custom TS parser
- Node ecosystem: TypeScript, React-for-CLI (Ink), Node’s `child_process` (if calling Rust), or pure-JS analyzer

##### Elements
- CLI → Analyzer → Models → Output/UI
- File system → Analyzer
- UI events call back into Analyzer or CLI logic in interactive mode
- Rust-native components (e.g., red)
- Node/TS components (e.g., blue)
- Data model layer (e.g., green)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User
    User["User"]:::user

    %% CLI Layer
    subgraph "CLI Layer"
        RustCLI["Rust CLI Entrypoint\n(bin/rusty-react-flow)"]:::rust
        RustMain["Rust Main Function\n(src/main.rs)"]:::rust
        RustGlue["CLI Glue & Argument Parsing\n(src/cli.rs)"]:::rust
        NodeCLI["Node.js Interactive CLI\n(src/main.tsx)"]:::node
    end

    %% UI Layer
    subgraph "UI Layer"
        Category["Category Display\n(src/Category.tsx)"]:::node
        Button["Button Control\n(src/components/Button.tsx)"]:::node
    end

    %% Analyzer Engine
    subgraph "Analyzer Engine"
        AnalyzerRoot["Core Analyzer Engine\n(src/lib.rs)"]:::rust
        subgraph "Analyzer Modules"
            AnalyzerMod["Analyzer Module Root\n(src/analyzer/mod.rs)"]:::rust
            Summary["Summary Logic\n(src/analyzer/summary.rs)"]:::rust
            TSParser["TS/JS Parsing\n(src/analyzer/typescript.rs)"]:::rust
        end
    end

    %% Data Model Layer
    subgraph "Data Model Layer"
        ModelRoot["Data Models Root\n(src/models/mod.rs)"]:::model
        ImportRec["Import Record Definition\n(src/models/import.rs)"]:::model
        ExportRec["Export Record Definition\n(src/models/export.rs)"]:::model
        OutputSchema["JSON Output Schema\n(src/models/output.rs)"]:::model
    end

    %% Config & Metadata
    subgraph "Config & Metadata"
        CargoMeta["Cargo.toml\nCargo.lock"]:::io
        PackageMeta["package.json\n.npmignore"]:::io
    end

    %% I/O Externals
    InputFS["Source Files\n(File System)"]:::io
    OutputJSON["JSON Report\n(File/Stdout)"]:::io

    %% Connections
    User --> RustCLI
    User --> NodeCLI

    RustCLI --> RustMain
    RustMain --> RustGlue
    RustGlue --> AnalyzerRoot

    NodeCLI --> AnalyzerRoot
    AnalyzerRoot --> NodeCLI

    NodeCLI --> Category
    NodeCLI --> Button

    InputFS --> AnalyzerRoot
    AnalyzerRoot --> Digest{Decides Mode}

    Digest -->|Interactive| NodeCLI
    Digest -->|Non-interactive| OutputJSON

    AnalyzerRoot --> Summary
    AnalyzerRoot --> TSParser
    Summary --> ImportRec
    Summary --> ExportRec
    Summary --> ModelRoot
    AnalyzerRoot --> OutputSchema

    %% Metadata arrows
    CargoMeta --> RustCLI
    PackageMeta --> NodeCLI

    %% Click Events
    click RustCLI "https://github.com/cargo-fob/rusty-react-flow/tree/main/bin/rusty-react-flow"
    click RustMain "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/main.rs"
    click RustGlue "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/cli.rs"
    click NodeCLI "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/main.tsx"
    click Category "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/Category.tsx"
    click Button "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/components/Button.tsx"
    click AnalyzerRoot "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/lib.rs"
    click AnalyzerMod "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/analyzer/mod.rs"
    click Summary "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/analyzer/summary.rs"
    click TSParser "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/analyzer/typescript.rs"
    click ModelRoot "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/models/mod.rs"
    click ImportRec "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/models/import.rs"
    click ExportRec "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/models/export.rs"
    click OutputSchema "https://github.com/cargo-fob/rusty-react-flow/blob/main/src/models/output.rs"
    click CargoMeta "https://github.com/cargo-fob/rusty-react-flow/blob/main/Cargo.toml"
    click PackageMeta "https://github.com/cargo-fob/rusty-react-flow/blob/main/package.json"

    %% Styles
    classDef rust fill:#fdecea,stroke:#f44336,color:#000
    classDef node fill:#e8eaf6,stroke:#3f51b5,color:#000
    classDef model fill:#e8f5e9,stroke:#4caf50,color:#000
    classDef io fill:#fff3e0,stroke:#ff9800,color:#000
    classDef user fill:#ffffff,stroke:#000000,color:#000;font-weight:bold
```
