# billyevans/tst architecture

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

- Interactive diagram: https://gitdiagram.com/billyevans/tst
- Repository: https://github.com/billyevans/tst

## Overview

##### Project type and purpose
- This is a Rust library crate (“tst”) implementing a ternary search tree (TST) data structure, with two public types: TSTMap and TSTSet.
- It provides insertion, lookup, prefix‐search, wildcard search, and longest‐prefix operations, with an API modeled after Rust’s standard collections.

##### File structure
- Top-level project files: Cargo.toml, README.md, LICENSE, CI configs (.travis.yml, .github/…/rust.yml), deployment scripts (deploy-docs.sh, deploy.sh), coverage setup (install-kcov.sh).
- benches/: benchmark driver (bench.rs)
- examples/: sample programs demonstrating usage (callback.rs, dict.rs)
- src/: core library modules
- lib.rs – crate root (public API exports, pub mod declarations)
- .rs – TSTMap implementation
- set.rs – TSTSet implementation (wraps TSTMap or uses same internals)
- node.rs – internal Node struct, children pointers (low, eq, high)
- traverse.rs – iterator implementations (prefix_iter, wildcard_iter)
- tests/: unit tests for map and set modules

##### README for additional insights
- It confirms core functionality (map and set, wildcard/prefix iterators, longest_prefix).
- References Wikipedia’s TST design.
- Shows code snippets of public API usage.

- User Application (examples, benchmarks, client code)
- tst Crate Public API
– TSTMap
– TSTSet
- Internal Library Modules
– Node (ternary node data structure)
– Traverse (iterator logic for wildcard and prefix)
- External Dependencies
– Rust std::collections (for trait definitions, but minimal external crates)
- CI/CD Pipeline
– GitHub Actions (.github/workflows/rust.yml)
– Travis CI (.travis.yml)
– Coverage (install-kcov.sh, Coveralls)
– Docs Deployment (deploy-docs.sh)
– Crates.io Publishing (deploy.sh)

- User code → calls → Public API (TSTMap / TSTSet)
- Public API → delegates to → Internal Modules (map.rs uses node.rs; map.rs and set.rs call traverse.rs for iterators)
- Node ↔ children pointers → forms the tree data structure
- CI pipeline → triggers → build → tests → benchmarks → documentation → deploy

c. Important architectural patterns
- Modular separation: public API vs. internal implementation
- Iterator pattern: traverse.rs defines Iterator traits for prefix and wildcard searches
- Encapsulation: node.rs is not exposed; only accessed by map/set/traverse
- Layered design: Data storage (node) at the bottom, data structures (map, set) in the middle, user API at the top

d. Technologies, frameworks, libraries
- Rust language and Cargo build system
- GitHub Actions and Travis CI for continuous integration
- Kcov and Coveralls for coverage reporting
- docs.rs/GitHub Pages for documentation

##### Detailed capturing of essential architectural elements
- Do not omit tests, benchmarks, and CI—they form part of the project’s delivery pipeline.
- How node.rs underpins map.rs and set.rs, and how traverse.rs wraps traversal logic.
- Crate root (lib.rs) exports, and how the public macros (tstmap!) connect to the API.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Application Layer
    subgraph "User Application" 
        direction TB
        EX1["callback.rs"]:::external
        EX2["dict.rs"]:::external
        BENCH["bench.rs"]:::external
    end

    %% Public API Layer
    subgraph "Public API" 
        direction TB
        LIB["lib.rs"]:::publicapi
        MAP["TSTMap (map.rs)"]:::publicapi
        SET["TSTSet (set.rs)"]:::publicapi
    end

    %% Internal Modules Layer
    subgraph "Internal Modules" 
        direction TB
        NODE["Node (node.rs)"]:::internal
        TRAV["Traverse (traverse.rs)"]:::internal
    end

    %% Unit Tests
    subgraph "Unit Tests"
        direction TB
        TM["map_ut.rs"]:::test
        TS["set_ut.rs"]:::test
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        direction TB
        GH["GitHub Actions"]:::ci
        TRAVCI["Travis CI"]:::ci
        KCOV["install-kcov.sh"]:::ci
        DOCSDEP["deploy-docs.sh"]:::ci
        PUBLISH["deploy.sh"]:::ci
    end

    %% Project Files
    subgraph "Project Files"
        direction TB
        CARGO["Cargo.toml"]:::external
        README["README.md"]:::external
        LICENSE["LICENSE"]:::external
    end

    %% Connections
    EX1 -->|"uses"| LIB
    EX2 -->|"uses"| LIB
    BENCH -->|"benchmarks"| LIB

    LIB -->|"exports"| MAP
    LIB -->|"exports"| SET

    MAP -->|"uses"| NODE
    SET -->|"wraps/map internals"| MAP
    SET -->|"uses"| NODE

    MAP -->|"iterator calls"| TRAV
    SET -->|"iterator calls"| TRAV
    TRAV -->|"accesses"| NODE

    MAP -->|"tested by"| TM
    SET -->|"tested by"| TS

    GH -->|"runs tests"| TM
    GH -->|"runs tests"| TS
    TRAVCI -->|"runs tests"| TM
    TRAVCI -->|"runs tests"| TS
    GH -->|"runs benchmarks"| BENCH
    GH -->|"coverage setup"| KCOV
    GH -->|"deploy docs"| DOCSDEP
    GH -->|"publish crate"| PUBLISH

    %% Project Files to crate root
    CARGO -->|"defines crate"| LIB
    README -->|"documentation"| LIB
    LICENSE -->|"license"| LIB

    %% Click Events
    click EX1 "https://github.com/billyevans/tst/blob/master/examples/callback.rs"
    click EX2 "https://github.com/billyevans/tst/blob/master/examples/dict.rs"
    click BENCH "https://github.com/billyevans/tst/blob/master/benches/bench.rs"
    click LIB "https://github.com/billyevans/tst/blob/master/src/lib.rs"
    click MAP "https://github.com/billyevans/tst/blob/master/src/map.rs"
    click SET "https://github.com/billyevans/tst/blob/master/src/set.rs"
    click NODE "https://github.com/billyevans/tst/blob/master/src/node.rs"
    click TRAV "https://github.com/billyevans/tst/blob/master/src/traverse.rs"
    click TM "https://github.com/billyevans/tst/blob/master/tests/map_ut.rs"
    click TS "https://github.com/billyevans/tst/blob/master/tests/set_ut.rs"
    click GH "https://github.com/billyevans/tst/blob/master/.github/workflows/rust.yml"
    click TRAVCI "https://github.com/billyevans/tst/blob/master/.travis.yml"
    click KCOV "https://github.com/billyevans/tst/blob/master/install-kcov.sh"
    click DOCSDEP "https://github.com/billyevans/tst/blob/master/deploy-docs.sh"
    click PUBLISH "https://github.com/billyevans/tst/blob/master/deploy.sh"
    click CARGO "https://github.com/billyevans/tst/blob/master/Cargo.toml"
    click README "https://github.com/billyevans/tst/blob/master/README.md"
    click LICENSE "https://github.com/billyevans/tst/tree/master/LICENSE"

    %% Styles
    classDef publicapi fill:#cce5ff,stroke:#0366d6;
    classDef internal fill:#ccffcc,stroke:#28a745;
    classDef external fill:#ffd,stroke:#735c0f;
    classDef ci fill:#f0e68c,stroke:#b58900;
    classDef test fill:#ffe4e1,stroke:#ff1493;
```
