# rybarix/snaptail architecture

> Architecture diagram of the GitHub repository rybarix/snaptail, 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/rybarix/snaptail
- Repository: https://github.com/rybarix/snaptail

## Overview

Key Components to Include:

##### Core Components
- CLI Interface (Entry Point)
- Builder System
- Templating Engine
- Framework Adapters
- Kit Manager

##### External Dependencies
- Next.js
- React
- Tailwind CSS
- Shadcn UI (Optional Integration)

##### Component Details

a. Input Section:
- Single file entry point (*.tsx/*.jsx)
- Configuration options (--ui shadcn flag)

b. Processing Section (Core):
- CLI Handler (src/cli.ts)
- Builder System (src/builder.ts)
- Templator (src/templator.ts)
- Framework Adapter (src/frameworks/nextjs.ts)
- Kit Manager (src/kits/*)

c. Output Section:
- Generated Next.js Application
- Hidden Build System (.snaptail directory)
- Generated API Routes
- Final Bundle

##### It to the CLI handler which branches into
- Init command flow
- Run command flow
##### Builder system's interaction with
- Template selection
- Framework adaptation
- Kit integration
##### Templator's role in
- Injecting necessary code
- Managing CSS (globals.css, shadcn.css)
- Handling TypeScript configuration
##### Output structure with
- Generated Next.js application
- API routes derived from the single file
- Hidden build system (.snaptail)

Important Notes:
- Keep the focus on the single-file-to-full-app transformation
- Hidden complexity management
- Auto-detection and package management flow
- Template system's role in maintaining consistency

- Component Types (Core, Generated, External)
- Special States (Optional Features, Auto-detected Elements)
- Build Phases (Init, Run, Build)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        SF["Single File (*.tsx/*.jsx)"]:::input
        Config["Configuration Options"]:::input
    end

    subgraph "Core Processing"
        CLI["CLI Handler"]:::core
        Builder["Builder System"]:::core
        Templator["Templating Engine"]:::core
        Framework["Framework Adapter"]:::core
        KitMgr["Kit Manager"]:::core
        CoreLib["Core Library"]:::core
    end

    subgraph "Template System"
        BaseTemp["Base Template"]:::template
        NextTemp["Next.js Templates"]:::template
        Layout["Layout System"]:::template
        Page["Page System"]:::template
        Style["Styling System"]:::template
        TSConfig["TypeScript Config"]:::template
        Meta["Metadata Handler"]:::template
    end

    subgraph "External Dependencies"
        Next["Next.js"]:::external
        React["React"]:::external
        Tailwind["Tailwind CSS"]:::external
        Shadcn["Shadcn UI"]:::external
    end

    subgraph "Output"
        GenApp["Generated Next.js App"]:::output
        Hidden[".snaptail Directory"]:::output
        APIRoutes["Generated API Routes"]:::output
        Bundle["Final Bundle"]:::output
    end

    SF --> CLI
    Config --> CLI
    CLI --> Builder
    Builder --> Templator
    Builder --> Framework
    Builder --> KitMgr
    Templator --> BaseTemp
    Framework --> NextTemp
    KitMgr --> Style
    CoreLib --> Builder

    NextTemp --> Layout
    NextTemp --> Page
    NextTemp --> Style
    NextTemp --> TSConfig
    NextTemp --> Meta

    Templator --> GenApp
    Framework --> Hidden
    Builder --> APIRoutes
    APIRoutes --> Bundle
    GenApp --> Bundle
    Hidden --> Bundle

    Next -.-> Framework
    React -.-> Framework
    Tailwind -.-> Style
    Shadcn -.-> Style

    %% Styling
    classDef core fill:#2563eb,color:white
    classDef input fill:#22c55e,color:white
    classDef output fill:#22c55e,color:white
    classDef external fill:#f97316,color:white
    classDef template fill:#a855f7,color:white

    %% Click Events
    click CLI "https://github.com/rybarix/snaptail/blob/main/src/cli.ts"
    click Builder "https://github.com/rybarix/snaptail/blob/main/src/builder.ts"
    click Templator "https://github.com/rybarix/snaptail/blob/main/src/templator.ts"
    click Framework "https://github.com/rybarix/snaptail/blob/main/src/frameworks/nextjs.ts"
    click KitMgr "https://github.com/rybarix/snaptail/tree/main/src/kits/"
    click CoreLib "https://github.com/rybarix/snaptail/blob/main/src/lib.ts"
    click NextTemp "https://github.com/rybarix/snaptail/tree/main/templates/next/"
    click BaseTemp "https://github.com/rybarix/snaptail/blob/main/templates/starter.jsx"
    click Layout "https://github.com/rybarix/snaptail/blob/main/templates/next/layout.tsx"
    click Page "https://github.com/rybarix/snaptail/blob/main/templates/next/page.tsx"
    click Style "https://github.com/rybarix/snaptail/blob/main/templates/next/globals.css"
    click TSConfig "https://github.com/rybarix/snaptail/blob/main/templates/next/tsconfig.json"
    click Meta "https://github.com/rybarix/snaptail/blob/main/templates/next/metadata.js"

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["Input/Output"]:::input
        L3["External Dependency"]:::external
        L4["Template Component"]:::template
    end
```
