# puravparab/gptanime architecture

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

- Interactive diagram: https://gitdiagram.com/puravparab/gptanime
- Repository: https://github.com/puravparab/gptanime

## Overview

##### Main Components
- Frontend (User Interface)
- Represented by the pages and components in the /src/app and /src/components directories. This includes dynamic project pages (e.g., /project/[id]) and sections like “how-it-works” and “home”.
- Layout files (layout.tsx), error and not-found handling (error.tsx, not-found.tsx), and global styles (globals.css).
- API Layer/Backend Endpoints
- Found in /src/app/api, especially the transform route (src/app/api/transform/route.ts) which likely handles image transformation requests.
- This layer bridges frontend requests with the image processing logic.
- Service Integrations
- External services such as FAL (configured via .env.local for FAL_KEY).
- The Gemini integration exists inside /src/services/gemini.ts, representing the connection to the Gemini Flash Edit model.
- Shared Utilities and Hooks
- Utilities for image uploading (src/utils/imageUpload.ts) and custom hooks like useProjects (src/hooks/useProjects.ts) serve as building blocks across the app.
- Static Assets
- Located under /src/public/assets (images and a background video) which are used to enrich the UI.

##### Relationships and Data Flow
- The User Interface (UI) interacts with the API endpoints through HTTP requests (or internal API calls provided by Next.js).
- The API endpoints are responsible for receiving user inputs (uploaded images, project requests) and then orchestrating image transformation by calling service functions, like those in the Gemini integration or FAL-based processing.
- Results from the external services are sent back through the API to the UI components, which then update the view accordingly.
- Utility functions and hooks support both front and back ends without being tied to specific UI or service concerns.

##### Architectural Patterns and Technologies
- The project follows a Next.js App Router pattern with clearly separated client-side pages (with dynamic routing using brackets as seen in /src/app/project/[id]) and API routes.
- There is a division of concerns: UI and layout components are decoupled from API logic, while service integrations (for image transformation) are self-contained.
- External integrations, like FAL for API key-based image processing and the Gemini module, emphasize modularity.
- Bun is used for running and managing the project (noted by bun.lock and bun run dev).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Initiation
    User["User (Client)"]:::external

    %% Frontend: Pages & Layout Subgraph
    subgraph "Frontend Pages & Layout"
        FP1["Home Page"]:::frontend
        FP2["Layout"]:::frontend
        FP3["How-it-works Page"]:::frontend
        FP4["Project Page (Dynamic)"]:::frontend
        FP5["Project History Page"]:::frontend
        FP6["Error Page"]:::frontend
        FP7["Not Found Page"]:::frontend
        FP8["Global Styles"]:::frontend
    end

    %% Frontend: Components Subgraph
    subgraph "Frontend Components"
        FC1["Header (Common)"]:::frontend
        FC2["Background Video"]:::frontend
        FC3["Home Header"]:::frontend
        FC4["Project Card"]:::frontend
        FC5["Status Indicator"]:::frontend
        FC6["Image Dropzone"]:::frontend
        FC7["Model Selector"]:::frontend
        FC8["Prompt Section"]:::frontend
    end

    %% API Layer Subgraph
    subgraph "API Layer"
        API["Transform API Route"]:::api
    end

    %% Service Integrations Subgraph
    subgraph "Service Integrations"
        SVC1["Gemini Flash Edit"]:::service
        SVC2["FAL Image Processing"]:::external
    end

    %% Shared Utilities Subgraph
    subgraph "Shared Utilities"
        UT1["Image Upload Utility"]:::utility
        UT2["useProjects Hook"]:::utility
    end

    %% Static Assets Subgraph
    subgraph "Static Assets"
        AS["Public Assets"]:::assets
    end

    %% Connections: User interacting with Frontend
    User --> FP1
    User --> FC1

    %% Frontend Pages & Components interact internally
    FP1 --> FP2
    FP2 --> FC1
    FC1 --> FC2
    FC2 --> FC3
    FC3 --> FC4
    FC4 --> FC5
    FC5 --> FC6
    FC6 --> FC7
    FC7 --> FC8

    %% UI sends requests to API
    FC8 -->|"submitImage"| API
    FP4 -->|"navigate"| API

    %% API interacts with External Services
    API -->|"processImage"| SVC1
    API -->|"callFAL"| SVC2
    SVC1 -->|"result"| API
    SVC2 -->|"result"| API

    %% API returns data to UI
    API -->|"updateUI"| FP1
    API -->|"updateUI"| FC8

    %% Shared Utilities support Frontend Components
    UT1 --> FC6
    UT2 --> FC4

    %% API and UI both use Static Assets
    AS --> FP1
    AS --> FC2

    %% Click Events for Frontend Pages & Layout
    click FP1 "https://github.com/puravparab/gptanime/blob/main/src/app/page.tsx"
    click FP2 "https://github.com/puravparab/gptanime/blob/main/src/app/layout.tsx"
    click FP3 "https://github.com/puravparab/gptanime/blob/main/src/app/how-it-works/page.tsx"
    click FP4 "https://github.com/puravparab/gptanime/blob/main/src/app/project/[id]/page.tsx"
    click FP5 "https://github.com/puravparab/gptanime/blob/main/src/app/project/[id]/history/page.tsx"
    click FP6 "https://github.com/puravparab/gptanime/blob/main/src/app/error.tsx"
    click FP7 "https://github.com/puravparab/gptanime/blob/main/src/app/not-found.tsx"
    click FP8 "https://github.com/puravparab/gptanime/blob/main/src/app/globals.css"

    %% Click Events for Frontend Components
    click FC1 "https://github.com/puravparab/gptanime/blob/main/src/components/header.tsx"
    click FC2 "https://github.com/puravparab/gptanime/blob/main/src/components/home/BackgroundVideo.tsx"
    click FC3 "https://github.com/puravparab/gptanime/blob/main/src/components/home/Header.tsx"
    click FC4 "https://github.com/puravparab/gptanime/blob/main/src/components/home/ProjectCard.tsx"
    click FC5 "https://github.com/puravparab/gptanime/blob/main/src/components/common/StatusIndicator.tsx"
    click FC6 "https://github.com/puravparab/gptanime/blob/main/src/components/project/ImageDropzone.tsx"
    click FC7 "https://github.com/puravparab/gptanime/blob/main/src/components/project/ModelSelector.tsx"
    click FC8 "https://github.com/puravparab/gptanime/blob/main/src/components/project/PromptSection.tsx"

    %% Click Event for API Layer
    click API "https://github.com/puravparab/gptanime/blob/main/src/app/api/transform/route.ts"

    %% Click Event for Service Integration
    click SVC1 "https://github.com/puravparab/gptanime/blob/main/src/services/gemini.ts"

    %% Click Events for Shared Utilities
    click UT1 "https://github.com/puravparab/gptanime/blob/main/src/utils/imageUpload.ts"
    click UT2 "https://github.com/puravparab/gptanime/blob/main/src/hooks/useProjects.ts"

    %% Click Event for Static Assets
    click AS "https://github.com/puravparab/gptanime/tree/main/src/public/assets"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef api fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef service fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef utility fill:#F5CBA7,stroke:#943126,stroke-width:2px;
    classDef assets fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef external fill:#FAD7A0,stroke:#9A7D0A,stroke-width:2px;
```
