# thatonetoast/sand architecture

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

- Interactive diagram: https://gitdiagram.com/thatonetoast/sand
- Repository: https://github.com/thatonetoast/sand

## Overview

##### Main Components

a) Input Processing Layer:
- Tree-sitter Parser (from tree-sitter-sand directory)
- Grammar definitions (grammar.js)
- Source file handling (.sand files)
- Configuration handling (Sand.toml)

b) Language Processing Layer:
- Language Handles (/src/lang/handles)
- Structure definitions (/src/lang/structure.rs)
- Execute handlers (execute_h.rs)

c) Datapack Generation Layer:
- Datapack Builder (/src/datapack/builder)
- Minecraft-specific components:
- Advancements (advancements.rs)
- Enchantments (enchantments.rs)
- Entities (mc_entities.rs)

##### Flow and Relationships

**[Input Files (.sand, .toml)] → [Tree-sitter Parser] → [AST]**
- ↓
**[Language Processing Layer] ← → [Structure Definitions]**
- ↓
**[Datapack Builder] → [Minecraft Datapack Components]**
- ↓
**[Output: Generated Datapack]**

##### Important Details to Highlight

a) Parser Pipeline:
- How the tree-sitter grammar feeds into the parsing process
- Transformation from Sand syntax to Minecraft commands

b) Language Features:
- Function handling (as shown in the example code)
- Command translation process
- Effect command processing

c) Build Process:
- Build.rs integration
- Test framework connection

##### Additional Elements

- Version information
- Notes about development status
- Extension points for future features

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        SandFiles[".sand Source Files"]
        Config["Sand.toml Config"]
        TreeSitter["Tree-sitter Parser"]:::parser
        Grammar["Grammar Definitions"]:::grammar
    end

    subgraph "Language Processing"
        LangCore["Language Processing Core"]:::lang
        StructDef["Structure Definitions"]:::struct
        LangHandles["Language Handles"]:::handles
        ExecHandles["Execute Handlers"]:::exec
    end

    subgraph "Datapack Generation"
        DPBuilder["Datapack Builder"]:::builder
        subgraph "Minecraft Components"
            Adv["Advancements"]:::mc
            Ench["Enchantments"]:::mc
            Ent["Entities"]:::mc
        end
        Output["Generated Datapack"]
    end

    subgraph "Build System"
        BuildProc["Build Process"]:::build
        Tests["Test Framework"]:::test
        Main["Main Entry Point"]:::main
    end

    %% Connections
    SandFiles --> TreeSitter
    Config --> TreeSitter
    Grammar --> TreeSitter
    TreeSitter --> LangCore
    LangCore <--> StructDef
    LangCore <--> LangHandles
    LangHandles <--> ExecHandles
    LangCore --> DPBuilder
    DPBuilder --> Adv
    DPBuilder --> Ench
    DPBuilder --> Ent
    Adv & Ench & Ent --> Output
    BuildProc --> Main
    Main --> Tests

    %% Click Events
    click TreeSitter "https://github.com/ThatOneToast/sand/tree/main/tree-sitter-sand/"
    click Grammar "https://github.com/ThatOneToast/sand/blob/main/tree-sitter-sand/grammar.js"
    click LangCore "https://github.com/ThatOneToast/sand/blob/main/src/lang/mod.rs"
    click StructDef "https://github.com/ThatOneToast/sand/blob/main/src/lang/structure.rs"
    click ExecHandles "https://github.com/ThatOneToast/sand/blob/main/src/lang/handles/execute_h.rs"
    click LangHandles "https://github.com/ThatOneToast/sand/blob/main/src/lang/handles/mod.rs"
    click DPBuilder "https://github.com/ThatOneToast/sand/blob/main/src/datapack/builder/mod.rs"
    click Adv "https://github.com/ThatOneToast/sand/blob/main/src/datapack/advancements.rs"
    click Ench "https://github.com/ThatOneToast/sand/blob/main/src/datapack/enchantments.rs"
    click Ent "https://github.com/ThatOneToast/sand/blob/main/src/datapack/mc_entities.rs"
    click BuildProc "https://github.com/ThatOneToast/sand/blob/main/src/build.rs"
    click Main "https://github.com/ThatOneToast/sand/blob/main/src/main.rs"
    click Tests "https://github.com/ThatOneToast/sand/blob/main/src/tests.rs"

    %% Styles
    classDef parser fill:#90caf9,stroke:#000
    classDef grammar fill:#80cbc4,stroke:#000
    classDef lang fill:#ce93d8,stroke:#000
    classDef struct fill:#fff59d,stroke:#000
    classDef handles fill:#ffcc80,stroke:#000
    classDef exec fill:#ef9a9a,stroke:#000
    classDef builder fill:#a5d6a7,stroke:#000
    classDef mc fill:#ffab91,stroke:#000
    classDef build fill:#b39ddb,stroke:#000
    classDef test fill:#81d4fa,stroke:#000
    classDef main fill:#f48fb1,stroke:#000

    %% Legend
    subgraph Legend
        L1["Parser Component"]:::parser
        L2["Grammar Component"]:::grammar
        L3["Language Component"]:::lang
        L4["Structure Component"]:::struct
        L5["Handles Component"]:::handles
        L6["Execute Component"]:::exec
        L7["Builder Component"]:::builder
        L8["Minecraft Component"]:::mc
        L9["Build Component"]:::build
        L10["Test Component"]:::test
        L11["Main Component"]:::main
    end
```
