How design0r/rust-aoc-cli works
Project Type and Purpose
• This is a Rust-based command-line interface (CLI) tool for working with Advent of Code puzzles.
• It handles three primary user workflows: setting a session cookie, downloading puzzles (and scaffolding projects), and submitting solutions.
File Structure Analysis
• Top-level files: Cargo.toml (project metadata/dependencies), README.md, LICENSE, .gitignore.
• src/ directory with five modules plus main.rs:
• args.rs – command-line parsing
• cookie.rs – session cookie storage and retrieval
• aoc.rs – core logic for download/submit commands
• utils.rs – HTTP client wrappers, file system operations, templating/scaffolding
• main.rs – entry point and command dispatch
Key Components
a. User CLI (stdin/stdout)
b. Argument Parser layer (args.rs, likely using Clap)
c. Command Dispatcher / Core Library (aoc.rs)
d. Services invoked by core:
• HTTP Client (e.g., reqwest) to interact with the Advent of Code website (download input, submit answers)
• File System (utils) for:
• Storing session cookie (e.g., in a config file)
• Creating project directories and template files for new puzzles
• Saving downloaded puzzle inputs
e. External Service: Advent of Code web server (HTTPS API)
Relationships and Data Flows
1. User invokes aoc <command> [options].
2. CLI layer passes raw args → Argument Parser.
3. Parsed command → Core (aoc.rs):
• If cookie: write session token via FS service.
• If download: call HTTP service to fetch puzzle → pass response to FS templating.
• If submit: read solution & cookie from FS → send HTTP POST → parse response.
4. Core receives results → returns status → CLI prints output.
Architectural Patterns and Design Principles
• Layered separation:
• Presentation (CLI / args.rs)
• Application Logic (command dispatcher in aoc.rs)
• Infrastructure Services (HTTP + FS in utils.rs + cookie.rs)
• Single Responsibility per module—clear boundaries between parsing, logic, and side-effects.
• Dependency injection style: core logic should accept HTTP/FS clients as abstractions (if implemented).
• Rust / Cargo
• Clap (or structopt) in args.rs for argument parsing
• reqwest or hyper inside utils.rs for HTTP
• serde_json or HTML parsing if needed (implicit by HTTP API)
• std::fs or fs-extra in utils.rs for file operations
2. In the center, stack three horizontal layers:
• Top: “CLI & Argument Parser”
• Middle: “Core Command Dispatcher”
• Bottom: “Infrastructure Services” (split into HTTP Client and FS/Cookie Store)
• Rectangles for modules (args.rs, aoc.rs, utils.rs, cookie.rs)
• Stick figure for the “User”
6. Label everything clearly—module names, data passed, protocols (HTTP), file paths.