# find-xposed-magisk/chatgpt-web architecture

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

- Interactive diagram: https://gitdiagram.com/find-xposed-magisk/chatgpt-web
- Repository: https://github.com/find-xposed-magisk/chatgpt-web

## Overview

##### Project type and purpose
- This is a full-stack web application (“ChatGPT Web”) split into a Vue3-based frontend (under `/src`) and a Node.js/TypeScript backend service (under `/service`).
- It serves a single-page application that lets users chat with ChatGPT via two interchangeable methods: the official OpenAI API or an unofficial proxy.

##### File structure
- Top-level:
- `src/` – Vue3 SPA (Vite, Pinia, Router, NaiveUI)
- `service/` – Node.js HTTP service (TS entry, middleware for auth & rate limiting, ChatGPT adapter modules)
- `docker-compose/`, `kubernetes/` – deployment manifests and reverse-proxy (Nginx) configs
- CI/CD: `.github/workflows/*.yml`
- Config & tooling: Dockerfile, tsconfig.json, Vite config, eslint, husky, pnpm lockfiles
- No traditional database directory: session/context state is managed in-memory or client-side (localStorage).

##### README for additional insights
- Dual-model support (official vs proxy API)
- ENV‐driven configuration for OpenAI keys, proxies, rate limits, auth secret
- Packaging targets: standalone Docker image, Docker Compose with optional Nginx anti-crawler, Railway, Sealos, or manual build.

##### Essential architectural elements
- Don’t omit middleware (auth, rate limiter) – they enforce security & quotas.
- Both API methods to ChatGPT (official vs proxy) as parallel or conditional flows.
- CI/CD and deployment infra to show how changes propagate from code to running service.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Main User Flow
    User["User"]:::external
    Browser["Browser (JS Runtime)"]:::ui
    User -->|"interacts with"| Browser
    Browser -->|"loads SPA"| Frontend
    
    %% Frontend Subsystem
    subgraph "Frontend SPA" 
        direction TB
        Frontend["Vue3 SPA"]:::ui
        Entry["main.ts"]:::ui
        Router["router/index.ts<br/>permission.ts"]:::ui
        Store["store/index.ts<br/>modules/**"]:::ui
        APIClient["api/index.ts"]:::ui
        Views["views/**<br/>components/**"]:::ui
        Styles["styles/**<br/>tailwind.config.js<br/>vite.config.ts"]:::ui
        Frontend --> Entry
        Entry --> Router
        Entry --> Store
        Entry --> APIClient
        Entry --> Views
        Entry --> Styles
    end
    click Entry "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/src/main.ts"
    click Router "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/src/router/index.ts"
    click Store "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/src/store/index.ts"
    click APIClient "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/src/api/index.ts"
    click Views "https://github.com/find-xposed-magisk/chatgpt-web/tree/main/src/views/"
    click Styles "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/tailwind.config.js"
    
    Frontend -->|"HTTP API requests"| API_Gateway
    
    %% Infrastructure / Gateway
    subgraph "Infrastructure" 
        direction TB
        API_Gateway["Reverse Proxy / API Gateway"]:::infra
        NginxCompose["docker-compose/nginx/nginx.conf"]:::infra
        K8sIngress["kubernetes/ingress.yaml"]:::infra
        API_Gateway --> Backend
        API_Gateway -->|"ingress rules"| K8sIngress
    end
    click NginxCompose "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/docker-compose/nginx/nginx.conf"
    click K8sIngress "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/kubernetes/ingress.yaml"
    
    %% Backend Subsystem
    subgraph "Backend Service" 
        direction TB
        Backend["Node.js API Service<br/>(TS, Koa/Express)"]:::backend
        BEEntry["index.ts"]:::backend
        MiddlewareAuth["middleware/auth.ts"]:::backend
        MiddlewareLimiter["middleware/limiter.ts"]:::backend
        Adapters["chatgpt/index.ts"]:::backend
        AdapterTypes["chatgpt/types.ts"]:::backend
        Utils["utils/index.ts<br/>utils/is.ts"]:::backend
        Types["types.ts"]:::backend
        BEEntry --> MiddlewareAuth
        BEEntry --> MiddlewareLimiter
        MiddlewareAuth --> Adapters
        MiddlewareLimiter --> Adapters
        Adapters --> AdapterTypes
        Adapters --> Utils
        BEEntry --> Types
    end
    click BEEntry "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/service/src/index.ts"
    click MiddlewareAuth "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/service/src/middleware/auth.ts"
    click MiddlewareLimiter "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/service/src/middleware/limiter.ts"
    click Adapters "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/service/src/chatgpt/index.ts"
    click AdapterTypes "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/service/src/chatgpt/types.ts"
    click Utils "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/service/src/utils/index.ts"
    click Types "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/service/src/types.ts"
    
    %% External ChatGPT APIs
    subgraph "External ChatGPT Endpoints"
        direction TB
        OfficialAPI["OpenAI Official API"]:::external
        ProxyAPI["Unofficial Proxy API"]:::external
    end
    Adapters -->|"official flow"| OfficialAPI
    Adapters -->|"proxy flow"| ProxyAPI
    OfficialAPI -->|"response"| Adapters
    ProxyAPI -->|"response"| Adapters
    
    %% Deployment & CI/CD
    subgraph "CI/CD & Deployment" 
        direction TB
        GitHubActions["GitHub Actions"]:::ci
        CI_CI["ci.yml"]:::ci
        CI_Build["build_docker.yml"]:::ci
        CI_Issues["issues_close.yml"]:::ci
        DockerfileNode["Dockerfile"]:::infra
        DockerCompose["docker-compose.yml"]:::infra
        DockerIgnore[".dockerignore"]:::infra
        K8sDeploy["kubernetes/deploy.yaml"]:::infra
        Registry["Container Registry"]:::infra
        Cluster["Kubernetes Cluster<br/>Docker Hosts"]:::infra
        GitHubActions --> CI_CI
        GitHubActions --> CI_Build
        GitHubActions --> CI_Issues
        CI_Build -->|"build image"| DockerfileNode
        CI_Build --> DockerCompose
        CI_Build --> DockerIgnore
        CI_Build --> K8sDeploy
        CI_Build --> Registry
        Registry --> Cluster
        Cluster --> API_Gateway
    end
    click CI_CI "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/.github/workflows/ci.yml"
    click CI_Build "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/.github/workflows/build_docker.yml"
    click CI_Issues "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/.github/workflows/issues_close.yml"
    click DockerfileNode "https://github.com/find-xposed-magisk/chatgpt-web/tree/main/Dockerfile"
    click DockerCompose "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/docker-compose/docker-compose.yml"
    click DockerIgnore "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/.dockerignore"
    click K8sDeploy "https://github.com/find-xposed-magisk/chatgpt-web/blob/main/kubernetes/deploy.yaml"
    
    %% Styles
    classDef ui fill:#cce5ff,stroke:#4da3ff
    classDef backend fill:#d4edda,stroke:#28a745
    classDef infra fill:#e2e3e5,stroke:#6c757d
    classDef external fill:#f8d7da,stroke:#dc3545
    classDef ci fill:#fff3cd,stroke:#e0a800
```
