# inksha/rust-tutorial architecture

> Architecture diagram of the GitHub repository inksha/rust-tutorial, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/inksha/rust-tutorial
- Repository: https://github.com/inksha/rust-tutorial

## Overview

##### Project type and purpose
- This is a standalone command-line Todo-management tool written in Rust.
- It uses Cargo to pull in two major third-party crates: clap (for CLI argument parsing) and serde/serde_json (for JSON serialization).
- Users can run commands like `create` and `list` to manage their tasks; data is persisted in a local JSON file (`todo.json`).

##### File structure
- Top level:
– Cargo.toml and Cargo.lock define dependencies and build targets.
– README.md and docs/ explain usage and host the tutorial.
– todo.json is the runtime persistence file.
- src/ directory:
– main.rs: program entrypoint. Reads CLI args via clap, reads existing todos, dispatches to commands, then saves.
– todo.rs: module root; declares three submodules.
– todo/core.rs: domain definitions: TodoItem struct, TodoCommand enum, serialization/deserialization logic.
– todo/create.rs: interactive or flag-driven creation logic.
– todo/list.rs: listing and filtering logic.
– todo/storage.rs: file I/O; read/write JSON.

##### README for additional insights
- Highlights layering: parsing → domain → commands → persistence.
- Shows evolution from a monolithic main.rs to a modular layout.
- Emphasizes use of patterns like generics (Option, Into), traits (Serializer), and error handling (Result, ? operator).

##### Elements
– Presentation layer (terminal & clap)
– Application layer (command modules)
– Domain layer (core structs & enums)
– Infrastructure layer (storage & file system)
– External dependencies (clap, serde, std::fs)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interaction
    User["Terminal I/O"]:::external

    %% Presentation Layer
    subgraph "Presentation Layer"
        CLI["CLI Interface (main.rs)"]:::presentation
        Clap["Argument Parser (clap)"]:::external
    end

    %% Application Layer
    subgraph "Application Layer"
        Dispatcher["Command Dispatcher (main.rs)"]:::application
        Create["CreateTodo Module (create.rs)"]:::application
        List["ListTodo Module (list.rs)"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        Core["Domain Model (core.rs)"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        StorageLayer["Storage Layer (storage.rs)"]:::infrastructure
        Persistence["Persistence Store (todo.json)"]:::infrastructure
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Serde["serde / serde_json"]:::external
    end

    %% Documentation & Build
    subgraph "Docs & Build"
        Cargo["Cargo.toml"]:::external
        Docs["README.md & docs/"]:::external
    end

    %% Connections
    User -->|"input"| CLI
    CLI -->|"parse args"| Clap
    Clap -->|"Program struct with TodoCommand"| Dispatcher
    CLI -->|"entrypoint"| Dispatcher
    Dispatcher -->|"match command"| Create
    Dispatcher -->|"match command"| List
    Dispatcher -->|"on startup call"| StorageLayer
    Create -->|"uses types"| Core
    List -->|"uses types & filtering"| Core
    Create -->|"modify Vec<TodoItem>"| StorageLayer
    List -->|"read Vec<TodoItem>"| StorageLayer
    StorageLayer -->|"read_todo_list()"| Persistence
    StorageLayer -->|"save_todo_list()"| Persistence
    Core -->|"derive Serialize/Deserialize"| Serde

    %% Click Events
    click CLI "https://github.com/inksha/rust-tutorial/blob/main/src/main.rs"
    click Dispatcher "https://github.com/inksha/rust-tutorial/blob/main/src/main.rs"
    click Core "https://github.com/inksha/rust-tutorial/blob/main/src/todo/core.rs"
    click Create "https://github.com/inksha/rust-tutorial/blob/main/src/todo/create.rs"
    click List "https://github.com/inksha/rust-tutorial/blob/main/src/todo/list.rs"
    click StorageLayer "https://github.com/inksha/rust-tutorial/blob/main/src/todo/storage.rs"
    click Persistence "https://github.com/inksha/rust-tutorial/blob/main/todo.json"
    click Cargo "https://github.com/inksha/rust-tutorial/blob/main/Cargo.toml"
    click Docs "https://github.com/inksha/rust-tutorial/blob/main/README.md"

    %% Styles
    classDef presentation fill:#D6E9F8,stroke:#31708F,color:#31708F;
    classDef application fill:#DFF0D8,stroke:#3C763D,color:#3C763D;
    classDef domain fill:#FCF8E3,stroke:#8A6D3B,color:#8A6D3B;
    classDef infrastructure fill:#F2DEDE,stroke:#A94442,color:#A94442;
    classDef external fill:#EEEEEE,stroke:#333333,color:#333333;
```
