# ugase/nspm-rs architecture

> Architecture diagram of the GitHub repository ugase/nspm-rs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ugase/nspm-rs
- Repository: https://github.com/ugase/nspm-rs

## Overview

##### Project Type and Purpose
- This is a Rust-based command-line tool (an open-source package manager rewrite of “nspm”).

##### File Structure Analysis
- src/main.rs: entry point, parses arguments, orchestrates workflow.
- src/storage.rs: abstracts local persistent storage (file I/O, config directory, caching).
- src/cryptography.rs: provides signing, verification, hashing.

##### Special Focus on storage.rs
- **Responsibilities**:
- Locate or create the application’s config/cache directory (e.g. `$HOME/.config/nspm`).
- Serialize and deserialize state objects (using JSON, TOML or binary formats).
- Provide high-level APIs: `load_state()`, `save_state()`, `clear_cache()`.
- Handle I/O errors and propagate them to main.rs for user feedback.
- **Interactions**:
- Exposed functions are called by main.rs before performing operations (e.g., install, uninstall).
- May invoke cryptography.rs to encrypt/decrypt stored credentials.
- Uses Rust’s `std::fs` and `std::path` under the hood.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CLI Entry
    Main["CLI Entry\n(main.rs)"]:::cli
    click Main "https://github.com/ugase/nspm-rs/blob/master/src/main.rs"

    %% UI Layer
    subgraph "UI Layer"
        UI["UI Module\n(ui.rs)"]:::ui
        click UI "https://github.com/ugase/nspm-rs/blob/master/src/ui.rs"
        subgraph "ANSI Styling"
            ModAnsi["mod.rs"]:::ansi
            Colors["colors.rs"]:::ansi
            Const["constants.rs"]:::ansi
            click ModAnsi "https://github.com/ugase/nspm-rs/blob/master/src/ansi/mod.rs"
            click Colors "https://github.com/ugase/nspm-rs/blob/master/src/ansi/colors.rs"
            click Const "https://github.com/ugase/nspm-rs/blob/master/src/ansi/constants.rs"
        end
        UI -->|"renders using"| ModAnsi
        UI --> Colors
        UI --> Const
    end

    %% Storage Module
    subgraph "Storage Module"
        Loader["State Loader"]:::storage
        Writer["State Writer"]:::storage
        Handler["Error Handler"]:::storage
        click Loader "https://github.com/ugase/nspm-rs/blob/master/src/storage.rs"
        click Writer "https://github.com/ugase/nspm-rs/blob/master/src/storage.rs"
        click Handler "https://github.com/ugase/nspm-rs/blob/master/src/storage.rs"
        Loader --> Handler
        Writer --> Handler
    end

    %% Crypto Module
    Crypto["Crypto Module\n(cryptography.rs)"]:::crypto
    click Crypto "https://github.com/ugase/nspm-rs/blob/master/src/cryptography.rs"

    %% File System
    FileSys["File System\n($HOME/.config/nspm)"]:::fs
    click FileSys "https://github.com/ugase/nspm-rs/tree/master/$HOME/.config/nspm"

    %% Interactions
    Main -->|"parses commands"| UI
    Main -->|"calls storage APIs"| Loader
    Loader -->|"reads/writes state"| FileSys
    Writer -->|"persists state"| FileSys
    Main -->|"uses crypto for signing/verification"| Crypto
    Handler -->|"propagates errors"| Main

    %% Styling
    classDef cli fill:#e3f2fd,stroke:#2196f3,stroke-width:2px,shape:roundrect;
    classDef ui fill:#fce4ec,stroke:#ec407a,stroke-width:2px;
    classDef ansi fill:#fff3e0,stroke:#fb8c00,stroke-width:2px;
    classDef storage fill:#e8f5e9,stroke:#43a047,stroke-width:2px;
    classDef crypto fill:#ede7f6,stroke:#7e57c2,stroke-width:2px;
    classDef fs fill:#f3e5f5,stroke:#ab47bc,stroke-width:2px,shape:cylinder;
```
