How cargo-fob/rusty-react-flow works
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)