# anubhav1206/ai-image-generator architecture

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

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

## Overview

##### Project Type and Purpose
- The project is a full-stack web application built to generate 1024x1024 images from user-provided text prompts using the OpenAI API.
- The frontend is built with React (using Vite as the build tool and Tailwind CSS for styling) and the backend is built with Node/Express. It also interfaces with external services like OpenAI and Cloudinary for image generation and storage.
- Key interactions include user input of prompts, image generation via an external API, and displaying a home feed of generated images.

##### File Structure
- The top-level directories (“client” and “server”) clearly separate the frontend and backend components.
– Configuration files (.eslintrc, tailwind.config.js, vite.config.js) that set up code quality and styling.
– A React-based structure with organized components, pages, assets, constants, and utility files.
– Express server setup including index.js.
– A “mongodb” folder handling database connectivity and Mongoose models (specifically the “post” model for storing image or creator details).
– Routing files (dalleRoutes.js and postRoutes.js) that map URL endpoints to controllers, facilitating communication between the client and backend.
- Both directories contain their own dependency configuration files (package.json and package-lock.json).

##### README for Additional Insights
- The README explains the core functionalities of the app and outlines how to run both the client and server.
- It highlights user interactions (text prompts, surprise prompts, image generation, image display in the home feed, and image downloading).
- External services like the OpenAI API (for image generation) and Cloudinary (for hosting images) are mentioned.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Client (Frontend)"
        A1["React Frontend (Vite)"]:::frontend
        A2["UI Components"]:::frontendComp
        A3["Frontend Pages (Home & CreatePost)"]:::frontendComp
        A1 -->|"renders"| A2
        A1 -->|"navigatesTo"| A3
    end

    %% Backend Subgraph
    subgraph "Server (Backend)"
        B1["Express Server Setup"]:::backend
        B2["Image Generation API (dalleRoutes)"]:::backendApi
        B3["Posts API (postRoutes)"]:::backendApi
        B1 -->|"routesTo"| B2
        B1 -->|"routesTo"| B3

        %% External Services
        B4["OpenAI API"]:::external
        B5["Cloudinary"]:::external
        B1 -->|"calls"| B4
        B1 -->|"uploadsTo"| B5

        %% Database Subgraph
        subgraph "Database"
            C1["MongoDB Connectivity"]:::db
            C2["Post Model"]:::db
            C1 -->|"defines"| C2
        end
        B1 -->|"storesDataIn"| C1
        C1 -->|"retrievesDataFor"| B1
    end

    %% Interaction between Client and Server
    A1 -->|"HTTP_Request"| B1
    B1 -->|"returnsData"| A1

    %% Click Events
    click A1 "https://github.com/anubhav1206/ai-image-generator/tree/main/client/"
    click A2 "https://github.com/anubhav1206/ai-image-generator/tree/main/client/src/components/"
    click A3 "https://github.com/anubhav1206/ai-image-generator/tree/main/client/src/pages/"
    click B1 "https://github.com/anubhav1206/ai-image-generator/blob/main/server/index.js"
    click B2 "https://github.com/anubhav1206/ai-image-generator/blob/main/server/routes/dalleRoutes.js"
    click B3 "https://github.com/anubhav1206/ai-image-generator/blob/main/server/routes/postRoutes.js"
    click C1 "https://github.com/anubhav1206/ai-image-generator/blob/main/server/mongodb/connect.js"
    click C2 "https://github.com/anubhav1206/ai-image-generator/blob/main/server/mongodb/models/post.js"

    %% Styles
    classDef frontend fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef frontendComp fill:#C6E2FF,stroke:#333,stroke-width:2px;
    classDef backend fill:#F7CBA7,stroke:#333,stroke-width:2px;
    classDef backendApi fill:#F7D6A0,stroke:#333,stroke-width:2px;
    classDef db fill:#D5F5E3,stroke:#333,stroke-width:2px;
    classDef external fill:#F9E79F,stroke:#333,stroke-width:2px;
```
