# vartikajn07/codeslate architecture

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

- Interactive diagram: https://gitdiagram.com/vartikajn07/codeslate
- Repository: https://github.com/vartikajn07/codeslate

## Overview

##### Project type and purpose
- Codeslate is a full-stack, React-based web application built with Next.js 14.
- Its core purpose is to let users write or paste code, customize its appearance (theme, fonts, padding, backgrounds), and export/share high-quality snippet images.

##### File structure
- Top-level Next.js directories:
- app/ – Next.js App Router pages (layout.tsx, page.tsx) and global CSS
- public/ – static assets (fonts, videos, JSON)
- components/ & components/ui/ – reusable React UI components (shadcn/ui wrappers)
- hooks/ – custom React hooks (useToast, useDarkmode)
- store/ – Zustand global state (canvasStore.ts)
- services/ – API clients (supabaseClient.ts, imageService.ts)
- utils/ & lib/ – helper functions (supabaseUpload, utilities, utils.ts)
- config files: next.config.js, tsconfig.json, tailwind.config.ts, postcss.config.mjs

##### Key insights from the README
- Tech Stack: Next.js 14, TypeScript, Tailwind, shadcn/ui, Zustand, Supabase, Unsplash, Framer Motion
- Features: live code editor, theme selectors, background fetch (Unsplash), PNG export via html2canvas, upload to Supabase, shareable links

##### Main components and their relationships
a. Frontend (Client Browser)
- Renders pages & components (CodeEditor, ThemeSelector, etc.)
- Maintains UI state via Zustand (store/canvasStore.ts)
- Uses custom hooks (useToast, useDarkmode) for notifications and theme persistence
- Invokes html2canvas or imageService to generate PNG snapshots
b. Next.js Runtime (Server/Edge)
- Serves the React app, handles SSR/SSG if any, and environment variables
c. External Services
1. Unsplash API (via imageService.ts) – fetches random backgrounds
2. Supabase Storage (via supabaseClient.ts & supabaseUpload) – uploads generated images, returns shareable URLs
d. Utilities & Styling
- Tailwind CSS (tailwind.config.ts) for styling
- shadcn/ui components for dialogs, sliders, buttons
- Global CSS (app/globals.css) for base styles

##### Architectural patterns and design principles
- Component-based UI (React/Next.js with App Router)
- Single Page Application behavior for interactivity
- Global state management with Zustand for theme & canvas settings
- Separation of concerns: UI components ←→ services ←→ external APIs
- Utility modules for reusability (utils, lib)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Browser Layer
    subgraph "Client Browser" 
        direction TB
        Browser["Web Browser"]:::clientstyle
        subgraph "UI Components" 
            direction TB
            CodeEditor["CodeEditor"]:::clientstyle
            ThemeSelector["ThemeSelector"]:::clientstyle
            ColorSelector["ColorSelector"]:::clientstyle
            FontSize["FontSizeSelector"]:::clientstyle
            PaddingSelector["PaddingSelector"]:::clientstyle
            LanguageSelector["LanguageSelector"]:::clientstyle
            ImagesComp["BackgroundImage"]:::clientstyle
            LoaderComp["Loader/Animation"]:::clientstyle
            ShareComp["Share/Export"]:::clientstyle
            UI_Button["Button"]:::clientstyle
            UI_Dialog["Dialog"]:::clientstyle
            UI_Drawer["Drawer"]:::clientstyle
            UI_Dropdown["DropdownMenu"]:::clientstyle
            UI_Slider["Slider"]:::clientstyle
            UI_Toast["Toast"]:::clientstyle
            UI_Toaster["ToasterContainer"]:::clientstyle
        end
        subgraph "Custom Hooks & State" 
            direction TB
            ToastHook["useToast"]:::clientstyle
            DarkHook["useDarkmode"]:::clientstyle
            Store["Zustand Store"]:::storestyle
        end
    end

    %% Next.js Runtime Layer
    subgraph "Next.js Runtime" 
        direction TB
        Layout["App Router Layout"]:::serverstyle
        Page["App Router Page"]:::serverstyle
        GlobalsCSS["Global Styles"]:::serverstyle
    end

    %% Services Layer
    subgraph "Services & Utilities" 
        direction TB
        ImageService["ImageService"]:::servicestyle
        SupabaseClient["SupabaseClient"]:::servicestyle
        SupabaseUpload["Supabase Upload"]:::servicestyle
        UtilsLib["General Utilities"]:::utilstyle
        ReactUtils["React Utilities"]:::utilstyle
    end

    %% External APIs
    subgraph "External Services" 
        direction TB
        Unsplash["Unsplash API"]:::externalstyle
        SupabaseStorage["Supabase Storage"]:::externalstyle
    end

    %% Static Assets and Config
    subgraph "Static Assets & Config" 
        direction TB
        LoaderJSON["LoaderAnimation.json"]:::staticstyle
        BackgroundVid["Background Video"]:::staticstyle
        Fonts["Fonts"]:::staticstyle
        NextConfig["next.config.js"]:::staticstyle
        TailwindConf["tailwind.config.ts"]:::staticstyle
        PostCSSConf["postcss.config.mjs"]:::staticstyle
        TSConfig["tsconfig.json"]:::staticstyle
        ESLintConf["eslint.config.mjs"]:::staticstyle
    end

    %% Connections
    Browser -->|renders| Layout
    Layout -->|renders| Page
    Page -->|imports| CodeEditor
    Page -->|imports| ThemeSelector
    Page -->|imports| ColorSelector
    Page -->|imports| FontSize
    Page -->|imports| PaddingSelector
    Page -->|imports| LanguageSelector
    Page -->|imports| ImagesComp
    Page -->|imports| LoaderComp
    Page -->|imports| ShareComp

    CodeEditor -->|uses| Store
    ThemeSelector -->|uses| Store
    ColorSelector -->|uses| Store
    FontSize -->|uses| Store
    PaddingSelector -->|uses| Store
    LanguageSelector -->|uses| Store
    ImagesComp -->|uses| Store
    ShareComp -->|reads/writes| Store

    CodeEditor -->|hook| ToastHook
    ShareComp -->|hook| DarkHook

    ShareComp -->|invoke html2canvas| ImageService
    ShareComp -->|upload image| SupabaseClient
    ImageService -->|fetch background| Unsplash
    SupabaseClient -->|upload file| SupabaseStorage
    SupabaseUpload -->|helper| SupabaseClient

    UtilsLib -->|utility| CodeEditor
    ReactUtils -->|utility| ThemeSelector

    Browser -->|loads| LoaderJSON
    Browser -->|loads| BackgroundVid
    Browser -->|loads| Fonts

    Layout -->|imports| GlobalsCSS
    Layout -->|config| NextConfig
    Layout -->|config| TailwindConf
    Layout -->|config| PostCSSConf
    Layout -->|config| TSConfig
    Layout -->|config| ESLintConf

    %% Click Events
    click Layout "https://github.com/vartikajn07/codeslate/blob/main/app/layout.tsx"
    click Page "https://github.com/vartikajn07/codeslate/blob/main/app/page.tsx"
    click GlobalsCSS "https://github.com/vartikajn07/codeslate/blob/main/app/globals.css"
    click CodeEditor "https://github.com/vartikajn07/codeslate/blob/main/components/CodeEditor.tsx"
    click ThemeSelector "https://github.com/vartikajn07/codeslate/blob/main/components/ThemeSelector.tsx"
    click ColorSelector "https://github.com/vartikajn07/codeslate/blob/main/components/ColorSelector.tsx"
    click FontSize "https://github.com/vartikajn07/codeslate/blob/main/components/FontSize.tsx"
    click PaddingSelector "https://github.com/vartikajn07/codeslate/blob/main/components/PaddingSelector.tsx"
    click LanguageSelector "https://github.com/vartikajn07/codeslate/blob/main/components/LanguageSelector.tsx"
    click ImagesComp "https://github.com/vartikajn07/codeslate/blob/main/components/Images.tsx"
    click LoaderComp "https://github.com/vartikajn07/codeslate/blob/main/components/Loader.tsx"
    click ShareComp "https://github.com/vartikajn07/codeslate/blob/main/components/Share.tsx"
    click UI_Button "https://github.com/vartikajn07/codeslate/blob/main/components/ui/button.tsx"
    click UI_Dialog "https://github.com/vartikajn07/codeslate/blob/main/components/ui/dialog.tsx"
    click UI_Drawer "https://github.com/vartikajn07/codeslate/blob/main/components/ui/drawer.tsx"
    click UI_Dropdown "https://github.com/vartikajn07/codeslate/blob/main/components/ui/dropdown-menu.tsx"
    click UI_Slider "https://github.com/vartikajn07/codeslate/blob/main/components/ui/slider.tsx"
    click UI_Toast "https://github.com/vartikajn07/codeslate/blob/main/components/ui/toast.tsx"
    click UI_Toaster "https://github.com/vartikajn07/codeslate/blob/main/components/ui/toaster.tsx"
    click ToastHook "https://github.com/vartikajn07/codeslate/blob/main/hooks/use-toast.ts"
    click DarkHook "https://github.com/vartikajn07/codeslate/blob/main/hooks/useDarkmode.ts"
    click Store "https://github.com/vartikajn07/codeslate/blob/main/store/canvasStore.ts"
    click ImageService "https://github.com/vartikajn07/codeslate/blob/main/services/imageService.ts"
    click SupabaseClient "https://github.com/vartikajn07/codeslate/blob/main/services/supabaseClient.ts"
    click SupabaseUpload "https://github.com/vartikajn07/codeslate/blob/main/utils/supabaseUpload.ts"
    click UtilsLib "https://github.com/vartikajn07/codeslate/blob/main/lib/utils.ts"
    click ReactUtils "https://github.com/vartikajn07/codeslate/blob/main/utils/utilities.tsx"
    click LoaderJSON "https://github.com/vartikajn07/codeslate/blob/main/public/LoaderAnimation.json"
    click BackgroundVid "https://github.com/vartikajn07/codeslate/blob/main/public/UpdateFade_smaller.mp4"
    click Fonts "https://github.com/vartikajn07/codeslate/blob/main/public/fonts/Season-font-light.otf"
    click Fonts "https://github.com/vartikajn07/codeslate/blob/main/public/fonts/tropika-island-script-casual.otf"
    click NextConfig "https://github.com/vartikajn07/codeslate/blob/main/next.config.js"
    click TailwindConf "https://github.com/vartikajn07/codeslate/blob/main/tailwind.config.ts"
    click PostCSSConf "https://github.com/vartikajn07/codeslate/blob/main/postcss.config.mjs"
    click TSConfig "https://github.com/vartikajn07/codeslate/blob/main/tsconfig.json"
    click ESLintConf "https://github.com/vartikajn07/codeslate/blob/main/eslint.config.mjs"

    %% Styles
    classDef clientstyle fill:#e0f7fa,stroke:#006064,color:#000;
    classDef serverstyle fill:#e8f5e9,stroke:#2e7d32,color:#000;
    classDef storestyle fill:#fff9c4,stroke:#f9a825,color:#000;
    classDef servicestyle fill:#f3e5f5,stroke:#6a1b9a,color:#000;
    classDef externalstyle fill:#ffe0b2,stroke:#ef6c00,color:#000;
    classDef utilstyle fill:#eceff1,stroke:#607d8b,color:#000;
    classDef staticstyle fill:#f5f5f5,stroke:#9e9e9e,color:#000;
```
