# kiwi-520/palette-snap architecture

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

- Interactive diagram: https://gitdiagram.com/kiwi-520/palette-snap
- Repository: https://github.com/kiwi-520/palette-snap

## Overview

##### Project type and purpose
- From the README and file tree, this is a full-stack Next.js web application (“Palette-Snap”) deployed on Firebase.

##### File structure
- Top-level:
- next.config.ts, tailwind.config.ts, tsconfig.json → build & styling config
- apphosting.yaml → Firebase hosting config
- src/ai → server-side AI utilities (genkit.ts, dev.ts)
- src/app → Next.js App Router entrypoints (layout.tsx, page.tsx, actions.ts)
- src/components
– layout (navbar, footer, theme)
– palette-snap (camera capture, image handler, generated palette, save button, saved palettes)
– ui (reusable primitives: button, dialog, slider, etc.)
- Configuration files and scripts show a serverless, component-driven architecture, styled with Tailwind.

##### README for additional insights
- Minimal—“NextJS starter in Firebase Studio.”
- Key takeaway: it uses Firebase for hosting, auth, and database.

##### Detail is key
- React sub-component grouping (layout vs. ui vs. feature).
- Web worker as a separate component.
- Firebase services individually (Auth, Firestore, Hosting).
- Don’t omit the npm scripts or configuration files—they drive deployment and build.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Browser" 
        direction TB
        Browser[/"Web Browser (Client)"/]:::client
        subgraph "Next.js App Router" 
            direction TB
            AppRouter["App Router (src/app)"]:::client
        end
        subgraph "UI Components" 
            direction TB
            LayoutComponents["Layout Components"]:::client
            PaletteSnapComponents["Palette-Snap Components"]:::client
            UIPrimitives["UI Primitives"]:::client
        end
        Worker["Color-Processing Worker"]:::client
    end

    %% Serverless/API Layer
    subgraph "Serverless/API" 
        direction TB
        ServerlessAI["AI Utilities (src/ai)"]:::server
        Actions["Next.js Actions (src/app/actions.ts)"]:::server
    end

    %% Firebase Services
    subgraph "Firebase Services"
        direction TB
        Auth["Authentication"]:::firebase
        Firestore["Firestore Database"]:::firebase
        Hosting["Hosting & Storage"]:::firebase
    end

    %% Utilities and Helpers
    subgraph "Helpers & Utilities"
        direction TB
        FirebaseInit["Firebase Init (src/lib/firebase.ts)"]:::server
        Quantizer["Color Quantizer (src/lib/color-quantizer.ts)"]:::server
        Converter["Color Converter (src/lib/color-converter.ts)"]:::server
        AuthHook["use-auth Hook (src/hooks/use-auth.ts)"]:::server
        MiscLib["Misc Utilities (src/lib)"]:::server
    end

    %% External AI
    ExternalAI["External AI Service"]:::external

    %% Configuration
    Config["Firebase Hosting Config (apphosting.yaml)"]:::server

    %% Connections
    Browser -->|"Loads App Router"| AppRouter
    AppRouter -->|"Renders Layout"| LayoutComponents
    AppRouter -->|"Renders Palette UI"| PaletteSnapComponents
    AppRouter -->|"Uses Primitives"| UIPrimitives

    PaletteSnapComponents -->|"Posts image"| ServerlessAI
    PaletteSnapComponents -->|"Calls action"| Actions
    PaletteSnapComponents -->|"Spawns worker"| Worker

    Worker -->|"Runs quantization"| Quantizer
    Worker -->|"Runs conversion"| Converter

    ServerlessAI -->|"Optional AI gen"| ExternalAI
    ServerlessAI -->|"Verifies user"| Auth
    ServerlessAI -->|"Reads/Writes palettes"| Firestore

    Actions -->|"Initializes Firebase"| FirebaseInit
    Actions -->|"Reads/Writes palettes"| Firestore
    Actions -->|"Verifies user"| Auth

    Browser -->|"Real-time SDK"| Firestore

    Browser -->|"Uses Auth Hook"| AuthHook
    Browser -->|"Uses utils"| MiscLib

    Config --> Hosting
    Hosting --> Browser

    %% Click Events
    click AppRouter "https://github.com/kiwi-520/palette-snap/tree/main/src/app"
    click LayoutComponents "https://github.com/kiwi-520/palette-snap/tree/main/src/components/layout"
    click PaletteSnapComponents "https://github.com/kiwi-520/palette-snap/tree/main/src/components/palette-snap"
    click UIPrimitives "https://github.com/kiwi-520/palette-snap/tree/main/src/components/ui"
    click Worker "https://github.com/kiwi-520/palette-snap/blob/main/public/color-worker.js"
    click ServerlessAI "https://github.com/kiwi-520/palette-snap/tree/main/src/ai"
    click Actions "https://github.com/kiwi-520/palette-snap/blob/main/src/app/actions.ts"
    click Config "https://github.com/kiwi-520/palette-snap/blob/main/apphosting.yaml"
    click FirebaseInit "https://github.com/kiwi-520/palette-snap/blob/main/src/lib/firebase.ts"
    click Quantizer "https://github.com/kiwi-520/palette-snap/blob/main/src/lib/color-quantizer.ts"
    click Converter "https://github.com/kiwi-520/palette-snap/blob/main/src/lib/color-converter.ts"
    click AuthHook "https://github.com/kiwi-520/palette-snap/blob/main/src/hooks/use-auth.ts"
    click MiscLib "https://github.com/kiwi-520/palette-snap/tree/main/src/lib"

    %% Styles
    classDef client fill:#E0F7FA,stroke:#00ACC1,color:#006064
    classDef server fill:#E8F5E9,stroke:#43A047,color:#1B5E20
    classDef firebase fill:#FFF3E0,stroke:#FB8C00,color:#E65100
    classDef external fill:#F3E5F5,stroke:#8E24AA,color:#4A148C
```
