# fei-away/codex-dream-skin architecture

> Architecture diagram of the GitHub repository fei-away/codex-dream-skin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/fei-away/codex-dream-skin
- Repository: https://github.com/fei-away/codex-dream-skin

## Overview

#### Purpose and Boundaries
Codex Dream Skin is a local, external theming tool for the Codex desktop client on macOS and Windows. It injects styling through loopback-only Chrome DevTools Protocol (CDP), preserving official application binaries, packages, and signatures. It explicitly does not manage Codex API/provider configuration.

#### Platform Entry Points
macOS users install via `macos/Install Codex Dream Skin.command` or `macos/scripts/install-dream-skin-macos.sh`, then start/manage the skin through `macos/Start Codex Dream Skin.command` and related scripts. Windows uses PowerShell installation and startup: `windows/scripts/install-dream-skin.ps1` and `windows/scripts/start-dream-skin.ps1`. Platform-specific behavior is intentionally separated under `macos/` and `windows/`.

#### CDP Injection Runtime
The core runtime discovers/connects to the locally running Codex renderer and injects a bootstrap/renderer payload rather than modifying installed assets. Injection logic is implemented as Node modules in `macos/scripts/injector.mjs` and `windows/scripts/injector.mjs`; the browser-side payload is `macos/assets/renderer-inject.js` and `windows/assets/renderer-inject.js`. The principal trust boundary is local CDP bound to `127.0.0.1`.

#### Theme Rendering Layer
Injected code applies the shared visual system: CSS creates the background and native-control treatment, while a theme document supplies image and appearance settings. Key artifacts are `macos/assets/dream-skin.css`, `macos/assets/theme.json`, and their Windows counterparts under `windows/assets/`. The renderer maintains an interactive native Codex UI; it adds a background/theme layer rather than replacing the window with a mock UI.

#### Theme Lifecycle and Persistence
Themes are staged, validated, written, and switched as local assets/configuration. macOS has modular Node lifecycle operations in `macos/scripts/stage-theme.mjs`, `macos/scripts/theme-config.mjs`, and `macos/scripts/write-theme.mjs`, orchestrated by `macos/scripts/switch-theme-macos.sh` and `macos/scripts/customize-theme-macos.sh`. Windows centralizes equivalent user-facing theme operations in `windows/scripts/theme-windows.ps1`, with shared metadata processing in `windows/scripts/image-metadata.mjs`.

#### Presets and Image Inputs
macOS distributes named preset directories with per-preset `theme.json`, such as `macos/presets/preset-romantic-rose/theme.json`; a generator maintains preset material via `macos/presets/generate-presets.mjs`. Custom background handling derives metadata needed for display placement and safe presentation, using `macos/scripts/image-metadata.mjs` and `windows/scripts/image-metadata.mjs`. Documentation distinguishes valid clean backgrounds from UI-containing preview images.

#### Operational Control and Recovery
Install/start scripts establish the local runtime; pause, status, verification, and restore provide operational safety and reversibility. macOS control paths include `macos/scripts/start-dream-skin-macos.sh`, `macos/scripts/verify-dream-skin-macos.sh`, and `macos/scripts/restore-dream-skin-macos.sh`. Windows equivalents are `windows/scripts/start-dream-skin.ps1`, `windows/scripts/verify-dream-skin.ps1`, and `windows/scripts/restore-dream-skin.ps1`. macOS supports a menu-bar workflow through `macos/menubar/codex_dream_skin.10s.sh`; Windows provides tray integration in `windows/scripts/tray-dream-skin.ps1`.

#### Runtimes and External Dependencies
The system is shell/PowerShell orchestration plus Node `.mjs` utilities, targeting installed Codex desktop processes and their local Chromium CDP interface. It has no indicated backend service dependency. CI is defined in `.github/workflows/ci.yml`; behavioral guards focus on injection bootstrap, renderer behavior, theme staging, and image metadata under `macos/tests/` and `windows/tests/`.

Main entry points: [`macos/scripts/stage-theme.mjs`](https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/stage-theme.mjs) (Theme Lifecycle), [`macos/scripts/injector.mjs`](https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/injector.mjs) (CDP Injector), [`windows/scripts/injector.mjs`](https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/injector.mjs) (CDP Injector), [`macos/scripts/start-dream-skin-macos.sh`](https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/start-dream-skin-macos.sh) (Start, Verify & Restore)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_macos["macOS"]
  node_mac_install["Install<br/>shell entry point"]
  node_mac_control["Start, Verify &amp; Restore<br/>shell controls"]
  node_mac_menubar["Menu Bar Control<br/>10s workflow"]
  node_mac_injector["CDP Injector<br/>Node module<br/>[injector.mjs]"]
  node_mac_renderer["Renderer Payload<br/>browser script<br/>[renderer-inject.js]"]
  node_mac_theme_assets["Theme Assets<br/>CSS and theme document<br/>[dream-skin.css]"]
  node_mac_lifecycle["Theme Lifecycle<br/>Node operations<br/>[stage-theme.mjs]"]
  node_mac_switch["Switch &amp; Customize<br/>shell orchestration"]
  node_mac_presets["Preset Themes<br/>preset assets<br/>[theme.json]"]
  node_mac_metadata["Image Metadata<br/>Node utility<br/>[image-metadata.mjs]"]
end

subgraph group_windows["Windows"]
  node_win_install["Install<br/>PowerShell entry point"]
  node_win_control["Start, Verify &amp; Restore<br/>PowerShell controls"]
  node_win_tray["Tray Control<br/>PowerShell integration"]
  node_win_injector["CDP Injector<br/>Node module<br/>[injector.mjs]"]
  node_win_renderer["Renderer Payload<br/>browser script<br/>[renderer-inject.js]"]
  node_win_theme_ops["Theme Operations<br/>PowerShell workflow<br/>[theme-windows.ps1]"]
  node_win_metadata["Image Metadata<br/>Node utility<br/>[image-metadata.mjs]"]
end

subgraph group_runtime["Local Runtime"]
  node_codex["Codex Desktop<br/>external desktop client"]
  node_cdp{{"Loopback CDP<br/>trust boundary"}}
end

node_mac_install -->|"installs runtime"| node_mac_control
node_mac_control -->|"runs"| node_mac_injector
node_mac_menubar -->|"manages"| node_mac_control
node_mac_injector -->|"connects"| node_cdp
node_cdp -->|"renderer endpoint"| node_codex
node_mac_injector -->|"injects"| node_mac_renderer
node_mac_renderer -->|"applies"| node_mac_theme_assets
node_mac_switch -->|"orchestrates"| node_mac_lifecycle
node_mac_lifecycle -->|"stages"| node_mac_presets
node_mac_metadata -->|"supplies placement data"| node_mac_lifecycle
node_mac_lifecycle -->|"writes theme"| node_mac_theme_assets
node_win_install -->|"installs runtime"| node_win_control
node_win_control -->|"runs"| node_win_injector
node_win_tray -->|"manages"| node_win_control
node_win_injector -->|"connects"| node_cdp
node_win_injector -->|"injects"| node_win_renderer
node_win_theme_ops -->|"processes images"| node_win_metadata
node_win_theme_ops -->|"configures theme"| node_win_renderer

click node_mac_install "https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/install-dream-skin-macos.sh"
click node_mac_control "https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/start-dream-skin-macos.sh"
click node_mac_menubar "https://github.com/fei-away/codex-dream-skin/blob/main/macos/menubar/codex_dream_skin.10s.sh"
click node_mac_injector "https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/injector.mjs"
click node_mac_renderer "https://github.com/fei-away/codex-dream-skin/blob/main/macos/assets/renderer-inject.js"
click node_mac_theme_assets "https://github.com/fei-away/codex-dream-skin/blob/main/macos/assets/dream-skin.css"
click node_mac_lifecycle "https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/stage-theme.mjs"
click node_mac_switch "https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/switch-theme-macos.sh"
click node_mac_presets "https://github.com/fei-away/codex-dream-skin/blob/main/macos/presets/preset-romantic-rose/theme.json"
click node_mac_metadata "https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/image-metadata.mjs"
click node_win_install "https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/install-dream-skin.ps1"
click node_win_control "https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/start-dream-skin.ps1"
click node_win_tray "https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/tray-dream-skin.ps1"
click node_win_injector "https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/injector.mjs"
click node_win_renderer "https://github.com/fei-away/codex-dream-skin/blob/main/windows/assets/renderer-inject.js"
click node_win_theme_ops "https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/theme-windows.ps1"
click node_win_metadata "https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/image-metadata.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_mac_install,node_mac_control,node_mac_menubar,node_mac_injector,node_mac_renderer,node_mac_theme_assets,node_mac_lifecycle,node_mac_switch,node_mac_presets,node_mac_metadata toneBlue
class node_win_install,node_win_control,node_win_tray,node_win_injector,node_win_renderer,node_win_theme_ops,node_win_metadata toneAmber
class node_codex,node_cdp toneMint
```

## Components

### macOS

Platform-specific installation, control, and theme tooling.

- [Install](https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/install-dream-skin-macos.sh): shell entry point · `macos/scripts/install-dream-skin-macos.sh`
- [Start, Verify & Restore](https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/start-dream-skin-macos.sh): shell controls · Establishes, checks, pauses, or reverses the local skin runtime. · `macos/scripts/start-dream-skin-macos.sh`
- [Menu Bar Control](https://github.com/fei-away/codex-dream-skin/blob/main/macos/menubar/codex_dream_skin.10s.sh): 10s workflow · `macos/menubar/codex_dream_skin.10s.sh`
- [CDP Injector](https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/injector.mjs): Node module · Finds the Codex renderer and injects the browser payload. · `macos/scripts/injector.mjs`
- [Renderer Payload](https://github.com/fei-away/codex-dream-skin/blob/main/macos/assets/renderer-inject.js): browser script · Adds a theme layer to the native Codex UI. · `macos/assets/renderer-inject.js`
- [Theme Assets](https://github.com/fei-away/codex-dream-skin/blob/main/macos/assets/dream-skin.css): CSS and theme document · Defines background and native-control appearance. · `macos/assets/dream-skin.css`
- [Theme Lifecycle](https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/stage-theme.mjs): Node operations · Stages, validates, configures, and writes local themes. · `macos/scripts/stage-theme.mjs`
- [Switch & Customize](https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/switch-theme-macos.sh): shell orchestration · `macos/scripts/switch-theme-macos.sh`
- [Preset Themes](https://github.com/fei-away/codex-dream-skin/blob/main/macos/presets/preset-romantic-rose/theme.json): preset assets · Named themes with per-preset theme documents. · `macos/presets/preset-romantic-rose/theme.json`
- [Image Metadata](https://github.com/fei-away/codex-dream-skin/blob/main/macos/scripts/image-metadata.mjs): Node utility · Derives safe background placement metadata. · `macos/scripts/image-metadata.mjs`

### Windows

Platform-specific installation, control, and theme tooling.

- [Install](https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/install-dream-skin.ps1): PowerShell entry point · `windows/scripts/install-dream-skin.ps1`
- [Start, Verify & Restore](https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/start-dream-skin.ps1): PowerShell controls · Establishes, checks, or reverses the local skin runtime. · `windows/scripts/start-dream-skin.ps1`
- [Tray Control](https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/tray-dream-skin.ps1): PowerShell integration · `windows/scripts/tray-dream-skin.ps1`
- [CDP Injector](https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/injector.mjs): Node module · Connects to the local Codex renderer. · `windows/scripts/injector.mjs`
- [Renderer Payload](https://github.com/fei-away/codex-dream-skin/blob/main/windows/assets/renderer-inject.js): browser script · Applies the theme layer in the native UI. · `windows/assets/renderer-inject.js`
- [Theme Operations](https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/theme-windows.ps1): PowerShell workflow · Centralized user-facing staging and switching. · `windows/scripts/theme-windows.ps1`
- [Image Metadata](https://github.com/fei-away/codex-dream-skin/blob/main/windows/scripts/image-metadata.mjs): Node utility · Processes custom background metadata. · `windows/scripts/image-metadata.mjs`

### Local Runtime

Loopback injection into the installed Codex client.

- **Codex Desktop**: external desktop client · Installed client remains unmodified.
- **Loopback CDP**: trust boundary · Local Chromium DevTools connection on 127.0.0.1.

## Connections

- Install → Start, Verify & Restore: installs runtime
- Start, Verify & Restore → CDP Injector: runs
- Menu Bar Control → Start, Verify & Restore: manages
- CDP Injector → Loopback CDP: connects
- Loopback CDP → Codex Desktop: renderer endpoint
- CDP Injector → Renderer Payload: injects
- Renderer Payload → Theme Assets: applies
- Switch & Customize → Theme Lifecycle: orchestrates
- Theme Lifecycle → Preset Themes: stages
- Image Metadata → Theme Lifecycle: supplies placement data
- Theme Lifecycle → Theme Assets: writes theme
- Install → Start, Verify & Restore: installs runtime
- Start, Verify & Restore → CDP Injector: runs
- Tray Control → Start, Verify & Restore: manages
- CDP Injector → Loopback CDP: connects
- CDP Injector → Renderer Payload: injects
- Theme Operations → Image Metadata: processes images
- Theme Operations → Renderer Payload: configures theme
