How julien-cpsn/atac works
Project type and purpose
• This is “ATAC”, a terminal-based API client written in Rust. It is a monolithic CLI/TUI application, combining:
• A command-line interface for scripting and batch use
• An interactive text-user-interface (TUI) for real-time exploration
• File-based persistence of collections, environments, themes, key-bindings, etc.
• An HTTP engine with scripting (JavaScript) support
File structure
• Top-level Cargo configuration and Dockerfile
• example_resources: sample collections, themes, key-bindings for import
• src/cli: argument parsing & command dispatch → “commands” & “cli_logic” modules
• src/app: core application startup, business logic, file I/O, configuration
• src/models: data structures (collections, requests, environments, scripts)
• src/tui: TUI state management, UI widgets, event handling
• src/main.rs: bootstraps CLI or TUI based on user input
• Dependencies & build workflows reside in .github and Cargo.toml
README insights
• Describes features: collections, environments, HTTP methods, scripting, export/import
• Technical precisions: ratatui for UI, reqwest for HTTP, boa_engine for JS scripting, serde for serialization, tokio for async
• No separate service processes—everything runs in a single process
Main components
a. CLI Layer
• clap CLI parser → CLI command handlers (src/cli/commands & cli_logic)
b. Core Application Layer
• Startup & configuration loader (src/app/startup)
• Business Logic (src/app/business_logic): constructs and processes requests
• Data Persistence (src/app/files): reads/writes JSON/TOML/YAML collections, envs, themes, key-bindings
• Models (src/models): domain objects shared between layers
c. HTTP & Scripting
• Async HTTP client (reqwest + reqwest_cookie_store)
• JavaScript runtime (boa_engine) for pre/post request scripts
d. TUI Layer
• Event loop & state machine (src/tui/app_states, tui_logic)
• UI rendering (ratatui) components (src/tui/ui)
• Key-bindings & input handling (crokey, tui_utils)
e. External Entities
• File system (collections, env files, themes)
• Remote HTTP servers / APIs
Interactions & data flow
1. User invokes “atac” binary → main.rs
2. Clap parses arguments → selects CLI mode or TUI interactive mode
3. In CLI mode: command handlers in src/cli invoke business logic → file I/O, HTTP, scripts → output to stdout or clipboard
4. In TUI mode:
• Startup loads config & data into memory
• Event loop listens for keypresses → updates application state
• UI renderer draws views based on current state
• Actions (e.g. “send request”) trigger business logic: build request → run pre-script → send via reqwest → run post-script → update result state → TUI updates view
5. File persistence: changes to collections, environments, settings trigger writes to disk
Architectural patterns & design principles
• Layered architecture: separation of concerns (CLI, core logic, persistence, UI)
• Modular Rust crates/modules: each directory is a cohesive feature set
• Async reactor model for HTTP (tokio)
• Stateful TUI rendering loop
• Plugin-style scripting via embedded JS engine