# aadityageek/ai-image-generator architecture

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

- Interactive diagram: https://gitdiagram.com/aadityageek/ai-image-generator
- Repository: https://github.com/aadityageek/ai-image-generator

## Overview

##### Project type and purpose
- This is a single-page web application (frontend only in this repo) that provides a clean HTML/CSS/Vanilla JS interface for generating AI images.
- It relies on a custom backend API (hosted on Render.com) which in turn orchestrates calls to various AI model services (Stable Diffusion, FLUX.1, OpenJourney, etc.).

##### File structure
- index.html: the entry point. Contains the DOM skeleton for theme toggle, prompt input, model dropdown, aspect-ratio selector, gallery container and fullscreen overlay.
- style.css: global and component styles (responsive grid, light/dark theme, mobile breakpoints).
- script.js: all UI logic (event handlers, theme detection, prompt validation), network logic (fetch to BACKEND_URL), and DOM updates (loading spinner, error states, image rendering, zoom, download).

##### README for insights
- Confirms feature set (model support, aspect ratios, multiple images, responsive design, fullscreen/zoom/download).

##### Main components
a. Browser / Client (UI Layer)
– Theme Manager: system-pref light/dark switch
– Prompt & Settings Form: text area, model & ratio selectors, “Generate” button
– Gallery UI: grid layout, loading spinners, error messages, fullscreen & zoom handlers, download link generator
– Network Module: JS fetch wrapper calling the backend API
b. Static Asset Host (optional)
– GitHub Pages, Netlify or Render static site for serving index.html, style.css, script.js, and screenshots
– CDN for Font Awesome & Google Fonts
c. Backend API Endpoint (Render.com)
– Exposes RESTful POST /generate with payload { prompt, model, aspectRatio, count }
– Returns JSON with image URLs or error codes
d. AI Model Services (External)
– Calls to AI inference engines: Stable Diffusion variants, FLUX.1, OpenJourney, etc.
– Could be microservices or third-party hosted inference APIs

##### Relationships and data flows
1. User loads index.html → browser requests static assets from Hosting/CDN
2. Browser initializes UI & theme
3. User submits prompt → Network Module sends POST to Backend API
4. Backend API → orchestrates calls to AI Model Services → returns images (URLs or base64)
5. Browser receives JSON → Gallery UI renders images → User can fullscreen, zoom, download

##### Architectural patterns and design principles
- Client-Server separation: clear division between static frontend assets and dynamic AI orchestration in the backend
- Single-page application pattern: UI updates in place without full page reloads
- RESTful HTTP layer between front and back end
- Responsive design: mobile-first CSS grid and breakpoints
- Feature-slice decomposition in the frontend: theme, form, gallery, network modules

## Diagram (Mermaid)

```mermaid
graph TB
  S["Static Asset Host"]:::hosting
  CDN["CDN (Font Awesome & Google Fonts)"]:::external
  Browser["Browser (UI Layer)"]:::frontend
  API["Backend API (Render.com)"]:::backend
  AI["AI Model Services"]:::external

  subgraph "Browser (UI Layer)"
    direction TB
    B1["Theme Manager"]:::frontend
    B2["Prompt & Settings Form"]:::frontend
    B3["Gallery UI"]:::frontend
    B4["Network Module"]:::frontend
  end

  S -->|"serves assets (HTML/CSS/JS)"| Browser
  CDN -->|"provides fonts & icons"| Browser
  Browser -->|"POST /generate JSON"| API
  API -->|"orchestrates model calls"| AI
  AI -->|"returns image data"| API
  API -->|"returns JSON payload"| Browser

  Doc["Project Documentation"]:::external
  License["License Information"]:::external

  click B1 "https://github.com/aadityageek/ai-image-generator/blob/main/script.js"
  click B2 "https://github.com/aadityageek/ai-image-generator/blob/main/index.html"
  click B3 "https://github.com/aadityageek/ai-image-generator/blob/main/index.html"
  click B4 "https://github.com/aadityageek/ai-image-generator/blob/main/script.js"
  click S "https://github.com/aadityageek/ai-image-generator/tree/main/screenshots/"
  click CDN "https://github.com/aadityageek/ai-image-generator/blob/main/index.html"
  click Doc "https://github.com/aadityageek/ai-image-generator/blob/main/README.md"
  click License "https://github.com/aadityageek/ai-image-generator/tree/main/LICENSE"

  classDef frontend fill:#ADD8E6,stroke:#0000FF,color:#000
  classDef hosting fill:#F0F0F0,stroke:#AAAAAA,color:#000
  classDef backend fill:#90EE90,stroke:#008000,color:#000
  classDef external fill:#D8BFD8,stroke:#800080,color:#000
```
