# ihozaifazia/chatgpt-image-genration-browser-automation architecture

> Architecture diagram of the GitHub repository ihozaifazia/chatgpt-image-genration-browser-automation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ihozaifazia/chatgpt-image-genration-browser-automation
- Repository: https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation

## Overview

This service accepts image prompts over HTTP, automates ChatGPT in a persistent Chrome profile, and returns PNG bytes while archiving each result for later retrieval. The main path is n8n → server validation and single-task control → browser generation and download → response and archive. Health and API documentation are separate service capabilities. Source excerpts show the server’s calls into the queue, generator, session manager, and OpenAPI spec; README documents ChatGPT automation and archive behavior. The automation’s detailed intermediate UI steps are only partly sampled.

Main entry points: [`server.js`](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/server.js) (HTTP server), [`scripts/generateImage.js`](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/generateImage.js) (Prompt automation), [`scripts/queue.js`](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/queue.js) (Single-task lock), [`scripts/sessionManager.js`](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/sessionManager.js) (Persistent browser session)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_server["HTTP server<br/>[server.js]"]
  node_health["Health endpoint<br/>[server.js]"]
  node_api_docs["API specification<br/>[openapi.js]"]
  node_last_image["Last-image endpoint<br/>[server.js]"]
end

subgraph group_generation["Image generation"]
  node_generator["Prompt automation<br/>[generateImage.js]"]
  node_archive[("PNG archive<br/>[generateImage.js]")]
end

subgraph group_runtime["Browser runtime"]
  node_queue["Single-task lock<br/>[queue.js]"]
  node_session["Persistent browser session<br/>[sessionManager.js]"]
end

node_n8n(("n8n caller"))
node_chatgpt["ChatGPT web UI"]
node_chrome["Automation Chrome"]

node_n8n -->|"sends prompt"| node_server
node_server -->|"checks and enqueues"| node_queue
node_server -->|"invokes"| node_generator
node_queue -->|"runs task"| node_generator
node_generator -->|"gets context"| node_session
node_session -->|"launches context"| node_chrome
node_generator -->|"automates UI"| node_chatgpt
node_chatgpt -->|"provides image"| node_generator
node_generator -->|"saves PNG"| node_archive
node_server -->|"returns PNG"| node_n8n
node_server -->|"routes retrieval"| node_last_image
node_last_image -->|"reads latest PNG"| node_archive
node_server -->|"serves status"| node_health
node_server -->|"serves specification"| node_api_docs

click node_server "https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/server.js"
click node_health "https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/server.js"
click node_api_docs "https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/openapi.js"
click node_queue "https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/queue.js"
click node_generator "https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/generateImage.js"
click node_session "https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/sessionManager.js"
click node_archive "https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/generateImage.js"
click node_last_image "https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/server.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_health,node_api_docs,node_last_image,node_chatgpt toneBlue
class node_generator,node_archive toneAmber
class node_queue,node_session toneMint
class node_n8n,node_chrome toneIndigo
```

## Components

### HTTP API

- [HTTP server](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/server.js): `server.js`
- [Health endpoint](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/server.js): `server.js`
- [API specification](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/openapi.js): `openapi.js`
- [Last-image endpoint](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/server.js): `server.js`

### Image generation

- [Prompt automation](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/generateImage.js): `scripts/generateImage.js`
- [PNG archive](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/generateImage.js): `scripts/generateImage.js`

### Browser runtime

- [Single-task lock](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/queue.js): `scripts/queue.js`
- [Persistent browser session](https://github.com/ihozaifazia/chatgpt-image-genration-browser-automation/blob/main/scripts/sessionManager.js): `scripts/sessionManager.js`

### Other components

- **n8n caller**
- **ChatGPT web UI**
- **Automation Chrome**

## Connections

- n8n caller → HTTP server: sends prompt (evidence: `README.md`)
- HTTP server → Single-task lock: checks and enqueues (evidence: `server.js`)
- HTTP server → Prompt automation: invokes (evidence: `server.js`)
- Single-task lock → Prompt automation: runs task (evidence: `server.js`)
- Prompt automation → Persistent browser session: gets context (evidence: `scripts/generateImage.js`)
- Persistent browser session → Automation Chrome: launches context (evidence: `scripts/sessionManager.js`)
- Prompt automation → ChatGPT web UI: automates UI (evidence: `README.md`)
- ChatGPT web UI → Prompt automation: provides image (evidence: `README.md`)
- Prompt automation → PNG archive: saves PNG (evidence: `README.md`)
- HTTP server → n8n caller: returns PNG (evidence: `README.md`)
- HTTP server → Last-image endpoint: routes retrieval (evidence: `server.js`)
- Last-image endpoint → PNG archive: reads latest PNG (evidence: `server.js`)
- HTTP server → Health endpoint: serves status (evidence: `server.js`)
- HTTP server → API specification: serves specification (evidence: `server.js`)
