# gitkumi/snowflake architecture

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

- Interactive diagram: https://gitdiagram.com/gitkumi/snowflake
- Repository: https://github.com/gitkumi/snowflake

## Overview

##### Project type and purpose
- Snowflake is a Go‑based command‑line interface (CLI) application generator.
- It scaffolds new web‐service projects (Gin router, sqlc/goose for databases, templating for HTML, etc.), and can also run or inspect existing projects via subcommands.

##### File structure
- Top‐level entrypoint: main.go + cmd/cli/main.go (bootstraps the CLI).
- internal/commands: each subcommand (generate, run, tui, version) lives in its own package under internal/commands.
- internal/initialize: the scaffolding engine (file/directory creation, template management) and a rich directory of “base” + “fragments” templates.
- grammar & internal/parser: ANTLR grammar for SQLite + parser code to read SQL schemas/queries (used by generate).
- testdata: sample SQL + sqlc config used in parser tests.
- CI pipeline: .github/workflows (push, release).
- Configs: go.mod, Makefile, PUBLISH.md, LICENSE.

##### README for additional insights
- Snowflake supports sqlite3/postgres/mysql via sqlc + goose migrations.
- Uses third‐party libs: Gin router, air (dev watcher), templ (HTML templates), gotestsum.
- Two UX modes: TUI (“snowflake new”) and direct CLI (“snowflake run …”).

##### Essential details
- Template directory structure (base vs. fragments) under the Scaffold Engine.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Users
    User["User"]:::external

    %% CLI & UX Layer
    CLI["CLI Frontend"]:::cli
    click CLI "https://github.com/gitkumi/snowflake/blob/master/main.go"
    click CLI "https://github.com/gitkumi/snowflake/blob/master/cmd/cli/main.go"

    Generate["Generate Command"]:::core
    click Generate "https://github.com/gitkumi/snowflake/blob/master/internal/commands/generate/command.go"
    click Generate "https://github.com/gitkumi/snowflake/blob/master/internal/commands/generate/yaml.go"
    click Generate "https://github.com/gitkumi/snowflake/tree/master/internal/commands/generate/templates/"

    Run["Run Command"]:::core
    click Run "https://github.com/gitkumi/snowflake/blob/master/internal/commands/run/command.go"

    TUI["TUI Command"]:::core
    click TUI "https://github.com/gitkumi/snowflake/blob/master/internal/commands/tui/command.go"

    Version["Version Command"]:::core
    click Version "https://github.com/gitkumi/snowflake/blob/master/internal/commands/version/command.go"

    %% Core Engine Layer
    Initialize["Scaffold Engine"]:::core
    click Initialize "https://github.com/gitkumi/snowflake/blob/master/internal/initialize/initialize.go"
    click Initialize "https://github.com/gitkumi/snowflake/blob/master/internal/initialize/files.go"
    click Initialize "https://github.com/gitkumi/snowflake/blob/master/internal/initialize/operations.go"
    click Initialize "https://github.com/gitkumi/snowflake/blob/master/internal/initialize/types.go"
    click Initialize "https://github.com/gitkumi/snowflake/tree/master/internal/initialize/template/base/"
    click Initialize "https://github.com/gitkumi/snowflake/tree/master/internal/initialize/template/fragments/"

    %% Parser & Grammar Layer
    Grammar["ANTLR Grammar"]:::parser
    click Grammar "https://github.com/gitkumi/snowflake/blob/master/grammar/sqlite/SQLiteParser.g4"
    click Grammar "https://github.com/gitkumi/snowflake/blob/master/grammar/sqlite/SQLiteLexer.g4"

    ParserCode["Generated Parser Code"]:::parser
    click ParserCode "https://github.com/gitkumi/snowflake/blob/master/grammar/sqlite/sqliteparser_listener.go"
    click ParserCode "https://github.com/gitkumi/snowflake/blob/master/grammar/sqlite/sqlite_lexer.go"
    click ParserCode "https://github.com/gitkumi/snowflake/blob/master/grammar/sqlite/sqlite_parser.go"

    ParserLogic["Parser Logic"]:::parser
    click ParserLogic "https://github.com/gitkumi/snowflake/blob/master/internal/parser/sqlite/parse_table.go"
    click ParserLogic "https://github.com/gitkumi/snowflake/blob/master/internal/parser/sqlite/parse_queries.go"
    click ParserLogic "https://github.com/gitkumi/snowflake/blob/master/internal/parser/sqlite/testutil_test.go"

    %% Templates & I/O Layer
    Renderer["Template Renderer"]:::templates
    click Renderer "https://github.com/gitkumi/snowflake/tree/master/internal/commands/generate/templates/"
    click Renderer "https://github.com/gitkumi/snowflake/tree/master/internal/initialize/template/"

    FS["File System"]:::templates

    %% External Tools & CI/CD
    External["External Tools"]:::external
    CICD["CI/CD Pipelines"]:::external
    click CICD "https://github.com/gitkumi/snowflake/blob/master/.github/workflows/push.yml"
    click CICD "https://github.com/gitkumi/snowflake/blob/master/.github/workflows/release.yml"

    Config["Project Config & Build"]:::external
    click Config "https://github.com/gitkumi/snowflake/blob/master/go.mod"
    click Config "https://github.com/gitkumi/snowflake/blob/master/go.sum"
    click Config "https://github.com/gitkumi/snowflake/tree/master/Makefile"
    click Config "https://github.com/gitkumi/snowflake/tree/master/LICENSE"
    click Config "https://github.com/gitkumi/snowflake/blob/master/PUBLISH.md"
    click Config "https://github.com/gitkumi/snowflake/blob/master/README.md"

    %% Flows
    User -->|runs command| CLI
    CLI -->|routes to| Generate
    CLI -->|routes to| Run
    CLI -->|routes to| TUI
    CLI -->|routes to| Version

    Generate -->|uses| Renderer
    Generate -->|parses SQL via| ParserLogic
    Generate -->|writes files to| FS

    Initialize -->|renders templates via| Renderer
    Initialize -->|writes scaffolding to| FS
    TUI -->|invokes| Initialize
    TUI -->|invokes| Generate

    Grammar --> ParserCode --> ParserLogic

    Run -->|calls| External

    CICD -->|tests/build/releases| CLI

    %% Styles
    classDef cli fill:#D0E6FF,stroke:#0366d6,color:#0366d6
    classDef core fill:#E6FFED,stroke:#28A745,color:#28A745
    classDef parser fill:#FFF5E6,stroke:#FF8C00,color:#FF8C00
    classDef templates fill:#FFFBCC,stroke:#D4A017,color:#D4A017
    classDef external fill:#F0F0F0,stroke:#6A737D,color:#6A737D
```
