# harshaislive/ai_image_gen architecture

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

- Interactive diagram: https://gitdiagram.com/harshaislive/ai_image_gen
- Repository: https://github.com/harshaislive/ai_image_gen

## Overview

##### Project Type and Purpose
- This is a full-stack, monorepo web application for text-to-image and image-to-image generation using the OpenAI API.
- The frontend is a minimalist React + Tailwind UI; the backend is a Node.js proxy server that secures the OpenAI API key.

##### File-Structure Analysis
- Top level:
- backend/ – Node.js service (index.js, package.json, .env)
- frontend/ – React app (src/, Vite config, Tailwind config)
- package.json + scripts for monorepo install/dev
- Patterns: clear separation of UI and API layers; no direct API calls in the frontend.
- Key config: frontend/vite.config.js, tailwind.config.js, backend/.env.example.

##### README Insights
- Describes a proxy pattern: frontend → backend → OpenAI API.
- Local development ports: 5173 (frontend), 5000 (backend).
- Emphasizes security: API key never exposed.

##### Essential Architectural Elements to Capture
- Monorepo structure: shared root scripts (`npm run dev`, `install-all`).
- Build & serve steps for frontend and backend.
- Security boundary (backend holds secrets).
- UI components handling text prompts and mask uploads.
- Data flow from user input → AI service → rendered output.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Root files
    RootPkg["Root package.json"]:::root
    Readme["README.md"]:::root

    %% External
    Browser["Client Browser"]:::external

    subgraph "Frontend Layer"
        FrontendApp["Frontend Application (React + Tailwind UI)"]:::frontend
        ViteConfig["Vite Config (vite.config.js)"]:::frontend
        TailwindConfig["Tailwind Config (tailwind.config.js)"]:::frontend
        MainEntry["Entry Point (src/main.jsx)"]:::frontend
        HTMLTemplate["HTML Template (index.html)"]:::frontend
        GlobalCSS["Global Stylesheet (main.css)"]:::frontend
        FlowiseChatbot["FlowiseChatbot.jsx"]:::frontend
        MaskEditor["MaskEditor.jsx"]:::frontend
        ImageSettings["ImageSettings.jsx"]:::frontend
        Fonts["Fonts Assets"]:::frontend
    end

    subgraph "Backend Layer"
        BackendProxy["Backend Proxy Server (index.js)"]:::backend
        BackendPkg["Backend package.json"]:::backend
        TempStorage["Temporary Storage (backend/tmp/)"]:::storage
    end

    subgraph "External Services"
        OpenAI["OpenAI API"]:::external
    end

    %% Data Flow
    Browser -->|"Interacts with UI"| FrontendApp
    FrontendApp -->|"POST /generate-image<br/>multipart/form-data"| BackendProxy
    BackendProxy -->|"Forward to OpenAI API"| OpenAI
    OpenAI -->|"Image data response"| BackendProxy
    BackendProxy -->|"Return image data"| FrontendApp
    FrontendApp -->|"Render generated image"| Browser

    BackendProxy -->|"Writes temp files/logs"| TempStorage

    %% Click Events
    click FrontendApp "https://github.com/harshaislive/ai_image_gen/tree/master/frontend/"
    click ViteConfig "https://github.com/harshaislive/ai_image_gen/blob/master/frontend/vite.config.js"
    click TailwindConfig "https://github.com/harshaislive/ai_image_gen/blob/master/frontend/tailwind.config.js"
    click MainEntry "https://github.com/harshaislive/ai_image_gen/blob/master/frontend/src/main.jsx"
    click HTMLTemplate "https://github.com/harshaislive/ai_image_gen/blob/master/frontend/index.html"
    click GlobalCSS "https://github.com/harshaislive/ai_image_gen/blob/master/frontend/src/main.css"
    click FlowiseChatbot "https://github.com/harshaislive/ai_image_gen/blob/master/frontend/src/components/FlowiseChatbot.jsx"
    click MaskEditor "https://github.com/harshaislive/ai_image_gen/blob/master/frontend/src/components/MaskEditor.jsx"
    click ImageSettings "https://github.com/harshaislive/ai_image_gen/blob/master/frontend/src/components/ImageSettings.jsx"
    click Fonts "https://github.com/harshaislive/ai_image_gen/tree/master/frontend/fonts/"
    click BackendProxy "https://github.com/harshaislive/ai_image_gen/blob/master/backend/index.js"
    click BackendPkg "https://github.com/harshaislive/ai_image_gen/blob/master/backend/package.json"
    click TempStorage "https://github.com/harshaislive/ai_image_gen/tree/master/backend/tmp/"
    click RootPkg "https://github.com/harshaislive/ai_image_gen/blob/master/package.json"
    click Readme "https://github.com/harshaislive/ai_image_gen/blob/master/README.md"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#000;
    classDef backend fill:#D0FFD6,stroke:#22863a,color:#000;
    classDef external fill:#FFE0B2,stroke:#e36209,color:#000;
    classDef storage fill:#E0E0E0,stroke:#6a737d,color:#000;
    classDef root fill:#F0F0F0,stroke:#586069,color:#000;
```
