# ayushsunny/brush-and-prompt architecture

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

- Interactive diagram: https://gitdiagram.com/ayushsunny/brush-and-prompt
- Repository: https://github.com/ayushsunny/brush-and-prompt

## Overview

##### Main Components
- Client/UI Layer: Since the project is entirely front-end with a rich user interface, show that the entire application runs in the browser.
- Image Upload Module: Illustrate how users upload images (via drag-and-drop or file selection) into the system.
- Editor Module: Represent the area where the image is displayed. Within this module, include sub-components such as:
- Canvas (src/components/editor/Canvas.tsx)
- Editor Controls for functions like brush tool and selection (src/components/editor/EditorControls.tsx)
- UI Components Library: Show that the project contains a comprehensive set of UI widgets (alert dialogs, buttons, input fields, etc.) which reside in the src/components/ui directory.
- Page Routing: Represent the pages (e.g., Gallery, Index, NotFound) found in src/pages that control overall navigation.
- Utility and Hook Layers: Indicate shared utilities (src/lib/utils.ts) and custom hooks (e.g., use-toast, use-mobile) that provide common functionality across components.
- External Services/API Calls: Although not explicitly shown as a separate backend service, mark an “API Layer” node that uses Axios for handling requests (likely for the AI transformation function), thus representing communication with the AI-powered backend service.

##### Relationships and Data Flow
- User Interaction: Start with the user uploading an image and interacting with the editor.
- UI Feedback: Show that components like Toast Notifications (via Sonner) and other UI feedback mechanisms update the user based on API responses.

##### Architectural Patterns and Design Principles
- Component-Based Architecture: Clearly indicate that the application is broken down into many self-contained reusable components.
- Separation of Concerns: Mark different layers (editor functionality vs. UI components vs. business logic in hooks and utilities).
- Declarative UI: Note that React’s component model helps keep UI representations separate from the application’s logic.
- API Integration: Although not full-stack, highlight the responsibilities of Axios in fetching data which might involve an external AI service.

##### Technologies and Frameworks
- Vite: Denote that Vite is used as the build tool for fast development and bundling.
- TailwindCSS & ShadCN: Represent the styling framework and component library used to style and standardize UI components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("User's Browser"):::user

    subgraph "Client/UI Layer"
        App("App Entry (React, TS, Vite)"):::entry
        Main("Main Entry"):::entry
        Upload("Image Upload Module"):::module
        subgraph "Editor Module"
            Canvas("Canvas (Editor)"):::editor
            EditorCtrl("Editor Controls"):::editor
        end
        UIC("UI Components Library"):::ui
        subgraph "Page Routing"
            Gallery("Gallery"):::page
            Home("Home/Index"):::page
            NotFound("NotFound"):::page
        end
        subgraph "Utility & Hook Layers"
            Util("Shared Utilities"):::utils
            subgraph "Custom Hooks"
                Toast("use-toast"):::hook
                Mobile("use-mobile"):::hook
            end
        end
    end

    API("AI Transformation API"):::api

    %% Data flow from user interaction to editor
    A -->|"opens"| App
    App -->|"initializes"| Upload
    App -->|"renders"| UIC
    App -->|"navigates"| Gallery
    App -->|"navigates"| Home
    App -->|"navigates"| NotFound

    %% Image upload and editing flow
    Upload -->|"loads image"| Canvas
    Canvas -->|"renders image"| EditorCtrl
    EditorCtrl -->|"submitPrompt"| API
    API -->|"APIResponse"| Toast
    Toast -->|"updateUI"| Canvas
    Mobile -->|"adjusts layout"| EditorCtrl

    %% Styling classes
    classDef user fill:#ffe6b3,stroke:#cc6600,stroke-width:2px;
    classDef entry fill:#cce6ff,stroke:#0066cc,stroke-width:2px;
    classDef module fill:#e6ffe6,stroke:#339933,stroke-width:2px;
    classDef editor fill:#f2e6ff,stroke:#9933cc,stroke-width:2px;
    classDef ui fill:#fff2e6,stroke:#cc3300,stroke-width:2px;
    classDef page fill:#e6f7ff,stroke:#006699,stroke-width:2px;
    classDef utils fill:#f9e6ff,stroke:#9900cc,stroke-width:2px;
    classDef hook fill:#e6ffff,stroke:#00cccc,stroke-width:2px;
    classDef api fill:#ffe6e6,stroke:#cc0000,stroke-width:2px;

    %% Click events for component mapping
    click App "https://github.com/ayushsunny/brush-and-prompt/blob/main/src/App.tsx"
    click Main "https://github.com/ayushsunny/brush-and-prompt/blob/main/src/main.tsx"
    click Canvas "https://github.com/ayushsunny/brush-and-prompt/blob/main/src/components/editor/Canvas.tsx"
    click EditorCtrl "https://github.com/ayushsunny/brush-and-prompt/blob/main/src/components/editor/EditorControls.tsx"
    click UIC "https://github.com/ayushsunny/brush-and-prompt/tree/main/src/components/ui"
    click Gallery "https://github.com/ayushsunny/brush-and-prompt/blob/main/src/pages/Gallery.tsx"
    click Home "https://github.com/ayushsunny/brush-and-prompt/blob/main/src/pages/Index.tsx"
    click NotFound "https://github.com/ayushsunny/brush-and-prompt/blob/main/src/pages/NotFound.tsx"
    click Util "https://github.com/ayushsunny/brush-and-prompt/blob/main/src/lib/utils.ts"
    click Toast "https://github.com/ayushsunny/brush-and-prompt/blob/main/src/hooks/use-toast.ts"
    click Mobile "https://github.com/ayushsunny/brush-and-prompt/blob/main/src/hooks/use-mobile.tsx"
```
