# liuzhengming/ccswitch-deepseek architecture

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

- Interactive diagram: https://gitdiagram.com/liuzhengming/ccswitch-deepseek
- Repository: https://github.com/liuzhengming/ccswitch-deepseek

## Overview

ccswitch-deepseek is a local HTTP protocol proxy that lets Codex CLI use DeepSeek: it accepts Responses API requests, translates them to Chat Completions, forwards them upstream, and returns Responses-format output. The principal workflow also restores reasoning across turns and supports both streaming SSE and non-streaming replies. The README documents image/file/audio input handling and broader event coverage; source sampling confirms translation and streaming components, but not every documented behavior in detail.

Main entry points: [`index.js`](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/index.js) (HTTP proxy), [`lib/sse.js`](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/sse.js) (SSE translation), [`lib/log.js`](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/log.js) (Request logging), [`lib/translate.js`](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/translate.js) (Request translation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Proxy gateway"]
  node_proxy["HTTP proxy<br/>[index.js]"]
  node_health["Health endpoint<br/>[index.js]"]
  node_logging["Request logging<br/>[log.js]"]
end

subgraph group_translation["Protocol translation"]
  node_request_translation["Request translation<br/>[translate.js]"]
  node_sse_translation["SSE translation<br/>[sse.js]"]
  node_nonstream_response["JSON response mapping<br/>[index.js]"]
end

subgraph group_state["Response state"]
  node_reasoning_recovery["Reasoning recovery<br/>[recover.js]"]
end

node_codex(("Codex CLI"))
node_deepseek["DeepSeek API"]

node_codex -->|"sends request"| node_proxy
node_codex -->|"checks status"| node_health
node_proxy -->|"translates input"| node_request_translation
node_proxy -->|"restores reasoning"| node_reasoning_recovery
node_proxy -->|"posts completions"| node_deepseek
node_deepseek -->|"returns completion"| node_proxy
node_proxy -->|"feeds stream"| node_sse_translation
node_sse_translation -->|"emits SSE"| node_codex
node_proxy -->|"maps completion"| node_nonstream_response
node_nonstream_response -->|"returns JSON"| node_codex
node_proxy -->|"stores reasoning"| node_reasoning_recovery
node_proxy -->|"logs activity"| node_logging
node_request_translation -->|"logs skips"| node_logging
node_sse_translation -->|"logs events"| node_logging

click node_proxy "https://github.com/liuzhengming/ccswitch-deepseek/blob/main/index.js"
click node_health "https://github.com/liuzhengming/ccswitch-deepseek/blob/main/index.js"
click node_request_translation "https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/translate.js"
click node_reasoning_recovery "https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/recover.js"
click node_sse_translation "https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/sse.js"
click node_nonstream_response "https://github.com/liuzhengming/ccswitch-deepseek/blob/main/index.js"
click node_logging "https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/log.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_proxy,node_health,node_logging toneBlue
class node_request_translation,node_sse_translation,node_nonstream_response toneAmber
class node_reasoning_recovery,node_deepseek toneMint
class node_codex toneIndigo
```

## Components

### Proxy gateway

- [HTTP proxy](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/index.js): `index.js`
- [Health endpoint](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/index.js): `index.js`
- [Request logging](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/log.js): `lib/log.js`

### Protocol translation

- [Request translation](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/translate.js): `lib/translate.js`
- [SSE translation](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/sse.js): `lib/sse.js`
- [JSON response mapping](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/index.js): `index.js`

### Response state

- [Reasoning recovery](https://github.com/liuzhengming/ccswitch-deepseek/blob/main/lib/recover.js): `lib/recover.js`

### Other components

- **Codex CLI**
- **DeepSeek API**

## Connections

- Codex CLI → HTTP proxy: sends request
- Codex CLI → Health endpoint: checks status
- HTTP proxy → Request translation: translates input
- HTTP proxy → Reasoning recovery: restores reasoning
- HTTP proxy → DeepSeek API: posts completions
- DeepSeek API → HTTP proxy: returns completion
- HTTP proxy → SSE translation: feeds stream
- SSE translation → Codex CLI: emits SSE
- HTTP proxy → JSON response mapping: maps completion
- JSON response mapping → Codex CLI: returns JSON
- HTTP proxy → Reasoning recovery: stores reasoning
- HTTP proxy → Request logging: logs activity
- Request translation → Request logging: logs skips
- SSE translation → Request logging: logs events
