# thejohndev/xerox architecture

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

- Interactive diagram: https://gitdiagram.com/thejohndev/xerox
- Repository: https://github.com/thejohndev/xerox

## Overview

Xerox is a WhatsApp file-management desktop app with a CLI entry point. Its main workflow starts the service, receives WhatsApp messages, associates senders with customer batches, saves media into dated folders, and exposes those files in the desktop UI for browsing and printing. The app also archives prior-day folders and reconstructs counters and batches after restart. Source excerpts show the core service and storage calls; the renderer implementation is not sampled, so UI-to-bridge interactions are left unverified.

Main entry points: [`electron-main.js`](https://github.com/thejohndev/xerox/blob/main/electron-main.js) (Electron main), [`src/filesystem.js`](https://github.com/thejohndev/xerox/blob/main/src/filesystem.js) (File management), [`src/whatsapp.js`](https://github.com/thejohndev/xerox/blob/main/src/whatsapp.js) (WhatsApp service), [`src/logger.js`](https://github.com/thejohndev/xerox/blob/main/src/logger.js) (Logs and dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop interface"]
  node_main["Electron main<br/>[electron-main.js]"]
  node_renderer["Main UI<br/>[index.html]"]
  node_bridge["UI bridge<br/>[preload.js]"]
  node_printview["Print preview<br/>[print.html]"]
  node_printbridge["Print bridge<br/>[print-preload.js]"]
  node_cli["CLI startup<br/>[index.js]"]
end

subgraph group_intake["WhatsApp intake"]
  node_wa["WhatsApp service<br/>[whatsapp.js]"]
end

subgraph group_storage["File lifecycle"]
  node_files["File management<br/>[filesystem.js]"]
  node_archive[("Dated file store")]
end

subgraph group_support["State and records"]
  node_config["Path and date config<br/>[config.js]"]
  node_state["Runtime counters<br/>[state.js]"]
  node_logger["Logs and dashboard<br/>[logger.js]"]
end

node_operator(("Operator"))
node_whatsapp(("WhatsApp network"))

node_operator -.->|"uses"| node_renderer
node_renderer -.->|"invokes APIs"| node_bridge
node_bridge -->|"invokes IPC"| node_main
node_main -->|"loads UI"| node_renderer
node_main -->|"starts and queries"| node_files
node_main -->|"starts and controls"| node_wa
node_main -->|"logs startup"| node_logger
node_main -->|"opens preview"| node_printview
node_printview -.->|"uses API"| node_printbridge
node_cli -->|"prepares folders"| node_files
node_cli -->|"starts service"| node_wa
node_cli -->|"logs startup"| node_logger
node_wa -.->|"connects and receives"| node_whatsapp
node_wa -->|"creates and saves"| node_files
node_wa -->|"tracks batches"| node_state
node_wa -->|"records events"| node_logger
node_files -->|"reads and writes"| node_archive
node_files -->|"recovers and updates"| node_state
node_files -->|"records archive events"| node_logger
node_files -->|"uses paths and dates"| node_config
node_logger -->|"gets dated paths"| node_config
node_main -->|"opens files"| node_archive
node_main -->|"provides batch data"| node_printview

click node_main "https://github.com/thejohndev/xerox/blob/main/electron-main.js"
click node_renderer "https://github.com/thejohndev/xerox/blob/main/index.html"
click node_bridge "https://github.com/thejohndev/xerox/blob/main/preload.js"
click node_printview "https://github.com/thejohndev/xerox/blob/main/print.html"
click node_printbridge "https://github.com/thejohndev/xerox/blob/main/print-preload.js"
click node_cli "https://github.com/thejohndev/xerox/blob/main/index.js"
click node_wa "https://github.com/thejohndev/xerox/blob/main/src/whatsapp.js"
click node_files "https://github.com/thejohndev/xerox/blob/main/src/filesystem.js"
click node_config "https://github.com/thejohndev/xerox/blob/main/src/config.js"
click node_state "https://github.com/thejohndev/xerox/blob/main/src/state.js"
click node_logger "https://github.com/thejohndev/xerox/blob/main/src/logger.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_main,node_renderer,node_bridge,node_printview,node_printbridge,node_cli toneBlue
class node_wa toneAmber
class node_files,node_archive toneMint
class node_config,node_state,node_logger toneRose
class node_operator,node_whatsapp toneIndigo
```

## Components

### Desktop interface

- [Electron main](https://github.com/thejohndev/xerox/blob/main/electron-main.js): `electron-main.js`
- [Main UI](https://github.com/thejohndev/xerox/blob/main/index.html): `index.html`
- [UI bridge](https://github.com/thejohndev/xerox/blob/main/preload.js): `preload.js`
- [Print preview](https://github.com/thejohndev/xerox/blob/main/print.html): `print.html`
- [Print bridge](https://github.com/thejohndev/xerox/blob/main/print-preload.js): `print-preload.js`
- [CLI startup](https://github.com/thejohndev/xerox/blob/main/index.js): `index.js`

### WhatsApp intake

- [WhatsApp service](https://github.com/thejohndev/xerox/blob/main/src/whatsapp.js): `src/whatsapp.js`

### File lifecycle

- [File management](https://github.com/thejohndev/xerox/blob/main/src/filesystem.js): `src/filesystem.js`
- **Dated file store**

### State and records

- [Path and date config](https://github.com/thejohndev/xerox/blob/main/src/config.js): `src/config.js`
- [Runtime counters](https://github.com/thejohndev/xerox/blob/main/src/state.js): `src/state.js`
- [Logs and dashboard](https://github.com/thejohndev/xerox/blob/main/src/logger.js): `src/logger.js`

### Other components

- **Operator**
- **WhatsApp network**

## Connections

- Operator → Main UI: uses
- Main UI → UI bridge: invokes APIs
- UI bridge → Electron main: invokes IPC (evidence: `preload.js`)
- Electron main → Main UI: loads UI (evidence: `electron-main.js`)
- Electron main → File management: starts and queries (evidence: `electron-main.js`)
- Electron main → WhatsApp service: starts and controls (evidence: `electron-main.js`)
- Electron main → Logs and dashboard: logs startup (evidence: `electron-main.js`)
- Electron main → Print preview: opens preview (evidence: `electron-main.js`)
- Print preview → Print bridge: uses API
- CLI startup → File management: prepares folders (evidence: `index.js`)
- CLI startup → WhatsApp service: starts service (evidence: `index.js`)
- CLI startup → Logs and dashboard: logs startup (evidence: `index.js`)
- WhatsApp service → WhatsApp network: connects and receives
- WhatsApp service → File management: creates and saves (evidence: `src/whatsapp.js`)
- WhatsApp service → Runtime counters: tracks batches (evidence: `src/whatsapp.js`)
- WhatsApp service → Logs and dashboard: records events (evidence: `src/whatsapp.js`)
- File management → Dated file store: reads and writes (evidence: `src/filesystem.js`)
- File management → Runtime counters: recovers and updates (evidence: `src/filesystem.js`)
- File management → Logs and dashboard: records archive events (evidence: `src/filesystem.js`)
- File management → Path and date config: uses paths and dates (evidence: `src/filesystem.js`)
- Logs and dashboard → Path and date config: gets dated paths (evidence: `src/logger.js`)
- Electron main → Dated file store: opens files (evidence: `electron-main.js`)
- Electron main → Print preview: provides batch data (evidence: `electron-main.js`)
