# niawjunior/aipass-bridge architecture

> Architecture diagram of the GitHub repository niawjunior/aipass-bridge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/niawjunior/aipass-bridge
- Repository: https://github.com/niawjunior/aipass-bridge

## Overview

AiPASS Bridge exposes a local OpenAI-compatible API and CLI tools; a Chrome extension dispatches work into a logged-in AiPASS page, which performs credentialed requests. The principal flow is a client request through the bridge and extension to AiPASS, with streamed results returned to the client. README capabilities also include model/conversation/credit access, media generation, and a local-file agent. Some subsystem links are documented rather than visible in the sampled excerpts, so uncertain internal wiring is omitted.

Main entry points: [`aipass-bridge/bridge/server.mjs`](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/bridge/server.mjs) (HTTP bridge), [`aipass-bridge/agent.mjs`](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/agent.mjs) (Coding agent), [`aipass-bridge/extension/background.js`](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/extension/background.js) (Service worker), [`aipass-bridge/extension/page.js`](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/extension/page.js) (Page requester)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Local API"]
  node_server["HTTP bridge<br/>[server.mjs]"]
  node_job["Job dispatch<br/>[server.mjs]"]
  node_models["Models and account<br/>[server.mjs]"]
end

subgraph group_browser["Browser Bridge"]
  node_extension["Service worker<br/>[background.js]"]
  node_content["Content script<br/>[content.js]"]
  node_page["Page requester<br/>[page.js]"]
  node_popup["Extension popup<br/>[popup.js]"]
end

subgraph group_cli["CLI Workflows"]
  node_chat["Chat CLI<br/>[chat.mjs]"]
  node_listing["Account commands<br/>[list.mjs]"]
  node_doctor["Connection checks<br/>[doctor.mjs]"]
  node_setup["Assistant setup"]
end

subgraph group_agent["Local Agent"]
  node_agent["Coding agent<br/>[agent.mjs]"]
  node_files[("Project files")]
  node_diff["Diff formatter<br/>[difflib.mjs]"]
end

node_client(("API client"))
node_terminal(("Terminal user"))
node_aipass["Logged-in AiPASS"]

node_client -->|"sends API requests"| node_server
node_chat -->|"posts chat"| node_server
node_agent -->|"requests model turns"| node_server
node_listing -->|"queries account"| node_server
node_doctor -->|"checks endpoints"| node_server
node_setup -->|"requests assistant actions"| node_server
node_popup -->|"reads status and configures"| node_server
node_server -->|"creates and dispatches"| node_job
node_server -->|"serves account data"| node_models
node_server -->|"sends jobs by SSE"| node_extension
node_extension -->|"posts job results"| node_server
node_extension -->|"sends run requests"| node_content
node_content -->|"forwards page messages"| node_page
node_page -->|"makes credentialed requests"| node_aipass
node_aipass -->|"returns replies and media"| node_page
node_agent -->|"reads and edits"| node_files
node_agent -->|"formats fallback diffs"| node_diff

click node_server "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/bridge/server.mjs"
click node_job "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/bridge/server.mjs"
click node_models "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/bridge/server.mjs"
click node_extension "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/extension/background.js"
click node_content "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/extension/content.js"
click node_page "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/extension/page.js"
click node_popup "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/extension/popup.js"
click node_chat "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/chat.mjs"
click node_listing "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/list.mjs"
click node_doctor "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/doctor.mjs"
click node_setup "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/setup-assistant.mjs"
click node_agent "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/agent.mjs"
click node_diff "https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/difflib.mjs"

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_job,node_models,node_client,node_terminal toneBlue
class node_extension,node_content,node_page,node_popup toneAmber
class node_chat,node_listing,node_doctor,node_setup toneMint
class node_agent,node_files,node_diff toneRose
class node_aipass toneIndigo
```

## Components

### Local API

- [HTTP bridge](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/bridge/server.mjs): `aipass-bridge/bridge/server.mjs`
- [Job dispatch](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/bridge/server.mjs): `aipass-bridge/bridge/server.mjs`
- [Models and account](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/bridge/server.mjs): `aipass-bridge/bridge/server.mjs`

### Browser Bridge

- [Service worker](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/extension/background.js): `aipass-bridge/extension/background.js`
- [Content script](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/extension/content.js): `aipass-bridge/extension/content.js`
- [Page requester](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/extension/page.js): `aipass-bridge/extension/page.js`
- [Extension popup](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/extension/popup.js): `aipass-bridge/extension/popup.js`

### CLI Workflows

- [Chat CLI](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/chat.mjs): `aipass-bridge/chat.mjs`
- [Account commands](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/list.mjs): `aipass-bridge/list.mjs`
- [Connection checks](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/doctor.mjs): `aipass-bridge/doctor.mjs`
- [Assistant setup](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/setup-assistant.mjs): `aipass-bridge/setup-assistant.mjs`

### Local Agent

- [Coding agent](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/agent.mjs): `aipass-bridge/agent.mjs`
- **Project files**
- [Diff formatter](https://github.com/niawjunior/aipass-bridge/blob/main/aipass-bridge/difflib.mjs): `aipass-bridge/difflib.mjs`

### Other components

- **API client**
- **Terminal user**
- **Logged-in AiPASS**

## Connections

- API client → HTTP bridge: sends API requests
- Chat CLI → HTTP bridge: posts chat
- Coding agent → HTTP bridge: requests model turns
- Account commands → HTTP bridge: queries account
- Connection checks → HTTP bridge: checks endpoints
- Assistant setup → HTTP bridge: requests assistant actions
- Extension popup → HTTP bridge: reads status and configures
- HTTP bridge → Job dispatch: creates and dispatches
- HTTP bridge → Models and account: serves account data
- HTTP bridge → Service worker: sends jobs by SSE
- Service worker → HTTP bridge: posts job results
- Service worker → Content script: sends run requests
- Content script → Page requester: forwards page messages
- Page requester → Logged-in AiPASS: makes credentialed requests
- Logged-in AiPASS → Page requester: returns replies and media
- Coding agent → Project files: reads and edits
- Coding agent → Diff formatter: formats fallback diffs
