# sharpedmimishee/gi architecture

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

- Interactive diagram: https://gitdiagram.com/sharpedmimishee/gi
- Repository: https://github.com/sharpedmimishee/gi

## Overview

1. **Project shape**
   - This is a single Rust command-line binary named `gi` (“Get Integer”), focused on 2FA code generation and management.
   - The repository is small and modular: `src/main.rs` is the entrypoint, and `src/commands.rs` plus `src/commands/*` contain the CLI subcommands.

2. **Top-level execution flow**
   - The program starts in `main`, parses the user’s command, and dispatches into one of the command handlers.
   - The available user-facing actions are `run/get`, `list`, `add`, `delete`, plus help-oriented handling.

3. **Command routing layer**
   - `src/commands.rs` is the command orchestration layer.
   - It likely centralizes shared command definitions, argument parsing, and dispatch to the concrete modules in `src/commands/`.
   - The subcommand files indicate a clean separation between command parsing and command behavior.

4. **Core command modules**
   - `add.rs` handles creating a new 2FA entry.
   - `delete.rs` removes an entry.
   - `delline.rs` suggests deletion may be implemented by line-based editing of a local storage file.
   - `list.rs` enumerates stored accounts/secrets.
   - `get.rs` retrieves or generates the current integer/token for a selected entry.
   - `help.rs` provides usage output and command guidance.

5. **Primary data flow**
   - User invokes a subcommand.
   - The command layer locates the relevant stored 2FA record.
   - For `get/run`, the secret is used to compute a one-time integer.
   - For `add/delete/list`, the command layer reads and updates the local registry of entries.

6. **State and persistence boundary**
   - The presence of `delline.rs` strongly suggests the app stores 2FA entries in a local file rather than in a database or remote service.
   - The app’s persistence boundary is therefore local filesystem state, with command modules acting on that file directly or through a small helper layer.

7. **Cryptography and token generation**
   - The README lists `sha1`, `hmac`, and `byteorder` as dependencies.
   - That combination is consistent with standard OTP generation, likely HMAC-SHA1-based code computation with binary/byte-order handling.
   - In architecture terms, this is the core “token engine” used by `get/run`, separate from the CLI plumbing.

8. **Dependency boundaries**
   - The app has no visible backend service, network client, or UI framework.
   - External crates are used only for cryptographic/token logic and low-level byte handling, not for infrastructure integration.

9. **Operational model**
   - This is an offline local utility: users build it with Cargo and run commands directly in the terminal.
   - There is no evidence of background daemon behavior, scheduler, or server process.

10. **Likely diagram boundaries**
   - One boundary is the CLI interface: terminal input/output and help text.
   - A second boundary is command processing: routing and validation.
   - A third boundary is data/crypto: local storage of secrets plus OTP generation from HMAC-SHA1.

11. **What to emphasize in an architecture diagram**
   - Draw the binary as one process with a command dispatcher in the center.
   - Show four functional areas around it: add/update, list, delete, and token generation.
   - Show a local file/store as the persistence target, and a crypto component feeding the token-generation path.

12. **Overall architectural summary**
   - `gi` is a compact Rust CLI for managing local 2FA entries and generating integer OTP codes.
   - Its architecture is primarily command-driven, with a small shared command layer and a cryptographic token-generation core, backed by local file-based state.

Main entry points: [`src/commands.rs`](https://github.com/sharpedmimishee/gi/blob/main/src/commands.rs) (Commands), [`src/commands/delete.rs`](https://github.com/sharpedmimishee/gi/blob/main/src/commands/delete.rs) (Delete), [`src/commands/get.rs`](https://github.com/sharpedmimishee/gi/blob/main/src/commands/get.rs) (Get), [`src/commands/list.rs`](https://github.com/sharpedmimishee/gi/blob/main/src/commands/list.rs) (List)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_cli["CLI surface"]
  node_main["gi<br/>binary entrypoint<br/>[main.rs]"]
  node_help_cmd["Help<br/>usage output<br/>[help.rs]"]
  node_list_cmd["List<br/>enumeration command<br/>[list.rs]"]
  node_add_cmd["Add<br/>insert command<br/>[add.rs]"]
  node_delete_cmd["Delete<br/>remove command<br/>[delete.rs]"]
  node_get_cmd["Get<br/>otp command<br/>[get.rs]"]
end

subgraph group_grp_core["Command core"]
  node_cmd_router["Commands<br/>dispatcher<br/>[commands.rs]"]
  node_delline_cmd["Del line<br/>file edit helper<br/>[delline.rs]"]
  node_otp_engine{{"OTP engine<br/>token generator"}}
  node_hmac_sha1{{"HMAC-SHA1<br/>crypto primitive"}}
  node_byte_order["Byte order<br/>encoding helper"]
end

subgraph group_grp_state["Local state"]
  node_entry_store[("Registry<br/>local file store")]
  node_secret_record["Secret data<br/>2FA entry"]
end

node_main -->|"dispatches"| node_cmd_router
node_cmd_router -->|"help"| node_help_cmd
node_cmd_router -->|"list"| node_list_cmd
node_cmd_router -->|"add"| node_add_cmd
node_cmd_router -->|"delete"| node_delete_cmd
node_cmd_router -->|"get/run"| node_get_cmd
node_add_cmd -->|"append"| node_entry_store
node_list_cmd -->|"read"| node_entry_store
node_delete_cmd -->|"uses"| node_delline_cmd
node_delline_cmd -->|"edit"| node_entry_store
node_delete_cmd -->|"remove"| node_entry_store
node_get_cmd -->|"lookup"| node_entry_store
node_get_cmd -->|"uses"| node_secret_record
node_secret_record -->|"feeds"| node_otp_engine
node_otp_engine -->|"depends on"| node_hmac_sha1
node_otp_engine -->|"depends on"| node_byte_order

click node_main "https://github.com/sharpedmimishee/gi/blob/main/src/main.rs"
click node_cmd_router "https://github.com/sharpedmimishee/gi/blob/main/src/commands.rs"
click node_help_cmd "https://github.com/sharpedmimishee/gi/blob/main/src/commands/help.rs"
click node_list_cmd "https://github.com/sharpedmimishee/gi/blob/main/src/commands/list.rs"
click node_add_cmd "https://github.com/sharpedmimishee/gi/blob/main/src/commands/add.rs"
click node_delete_cmd "https://github.com/sharpedmimishee/gi/blob/main/src/commands/delete.rs"
click node_get_cmd "https://github.com/sharpedmimishee/gi/blob/main/src/commands/get.rs"
click node_delline_cmd "https://github.com/sharpedmimishee/gi/blob/main/src/commands/delline.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_help_cmd,node_list_cmd,node_add_cmd,node_delete_cmd,node_get_cmd toneBlue
class node_cmd_router,node_delline_cmd,node_otp_engine,node_hmac_sha1,node_byte_order toneAmber
class node_entry_store,node_secret_record toneMint
```

## Components

### CLI surface

Terminal entrypoint and user-facing commands

- [gi](https://github.com/sharpedmimishee/gi/blob/main/src/main.rs): binary entrypoint · Starts the CLI and hands off to command routing · `src/main.rs`
- [Help](https://github.com/sharpedmimishee/gi/blob/main/src/commands/help.rs): usage output · Prints usage and command guidance · `src/commands/help.rs`
- [List](https://github.com/sharpedmimishee/gi/blob/main/src/commands/list.rs): enumeration command · Shows stored 2FA entries · `src/commands/list.rs`
- [Add](https://github.com/sharpedmimishee/gi/blob/main/src/commands/add.rs): insert command · Creates a new 2FA entry · `src/commands/add.rs`
- [Delete](https://github.com/sharpedmimishee/gi/blob/main/src/commands/delete.rs): remove command · Deletes an existing entry · `src/commands/delete.rs`
- [Get](https://github.com/sharpedmimishee/gi/blob/main/src/commands/get.rs): otp command · Retrieves or generates the current integer token · `src/commands/get.rs`

### Command core

Routing, subcommands, and token generation

- [Commands](https://github.com/sharpedmimishee/gi/blob/main/src/commands.rs): dispatcher · Shared command parsing and subcommand dispatch · `src/commands.rs`
- [Del line](https://github.com/sharpedmimishee/gi/blob/main/src/commands/delline.rs): file edit helper · Line-based deletion helper for storage updates · `src/commands/delline.rs`
- **OTP engine**: token generator · Computes one-time integers from stored secrets
- **HMAC-SHA1**: crypto primitive · Core hash/MAC used by token generation
- **Byte order**: encoding helper · Handles binary layout for OTP inputs and counters

### Local state

Filesystem-backed entry storage

- **Registry**: local file store · Filesystem-backed 2FA entry records
- **Secret data**: 2FA entry · Stored account identifier and secret material

## Connections

- gi → Commands: dispatches · Program startup routes into shared command handling
- Commands → Help: help · Resolves help-oriented requests
- Commands → List: list · Routes listing requests
- Commands → Add: add · Routes creation requests
- Commands → Delete: delete · Routes removal requests
- Commands → Get: get/run · Routes token-generation requests
- Add → Registry: append · Adds a new entry to local storage
- List → Registry: read · Reads stored entries for display
- Delete → Del line: uses · Delegates line-based storage removal
- Del line → Registry: edit · Updates the registry file in place
- Delete → Registry: remove · Deletes an entry from local storage
- Get → Registry: lookup · Finds the selected record before generating a token
- Get → Secret data: uses · Consumes stored secret material
- Secret data → OTP engine: feeds · Secret data is transformed into an OTP value
- OTP engine → HMAC-SHA1: depends on · Token generation is based on HMAC-SHA1
- OTP engine → Byte order: depends on · Binary encoding is handled during token computation
