Skip to content

Commit 40b590b

Browse files
committed
docs: add comprehensive API Worker documentation to CLAUDE.md
- Add dedicated API Worker subsection with: - Server features (REST API, admin UI, SSE, Swagger docs) - Authentication mechanisms (tokens, sessions, OAuth2/OKTA, TOTP) - Token scopes (api, metrics, smtp, imap-proxy) - API route categories - Configuration options (port, host, body size, timeout, proxy) - Key files (api.js, routes-ui.js, api-routes/*, tokens.js) - Update workers table to reference API Worker section
1 parent a0be341 commit 40b590b

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

CLAUDE.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ EmailEngine uses Node.js Worker Threads for isolated execution. Workers communic
100100

101101
| Worker | File | Count | Purpose |
102102
|--------|------|-------|---------|
103-
| API | `api.js` | 1 | REST API server (Hapi.js), handles all HTTP requests |
103+
| API | `api.js` | 1 | HTTP server for REST API and admin UI (see API Worker section below) |
104104
| IMAP | `imap.js` | 4* | Email sync engine (see IMAP Worker section below) |
105105
| Webhooks | `webhooks.js` | 1* | Webhook delivery processor (see Webhooks section below) |
106106
| Submit | `submit.js` | 1* | Email delivery processor (see Submit Worker section below) |
@@ -116,6 +116,44 @@ EmailEngine uses Node.js Worker Threads for isolated execution. Workers communic
116116
- Workers auto-restart on crash; accounts are reassigned to available workers
117117
- BullMQ queues distribute jobs to webhooks, submit, and documents workers
118118

119+
### API Worker
120+
121+
The API worker (`workers/api.js`) runs a Hapi.js HTTP server serving both the REST API (`/v1/*`) and admin web UI (`/admin/*`).
122+
123+
**Server features:**
124+
- REST API with OpenAPI/Swagger documentation (`/admin/swagger`)
125+
- Admin dashboard with Handlebars templates
126+
- Server-Sent Events (SSE) for real-time account updates (`/admin/changes`)
127+
- Static file serving, CSRF protection, i18n support (7 languages)
128+
129+
**Authentication:**
130+
- **API tokens**: Bearer token via `Authorization` header or `?access_token=` query param
131+
- **Sessions**: Cookie-based (`ee` cookie) for admin UI
132+
- **OAuth2**: Optional OKTA integration (`OKTA_OAUTH2_*` env vars)
133+
- **TOTP**: Optional two-factor authentication for admin login
134+
135+
**Token scopes:** `api`, `metrics`, `smtp`, `imap-proxy`, `*` (all)
136+
137+
**API route categories:**
138+
- `/v1/account/{account}/*` - Account and message operations
139+
- `/v1/token*` - API token management
140+
- `/v1/settings` - Global configuration
141+
- `/v1/oauth2*` - OAuth2 app management
142+
- `/v1/webhooks*`, `/v1/templates*`, `/v1/gateways*` - Resources
143+
144+
**Configuration:**
145+
- `EENGINE_PORT` / `PORT` - Listen port (default: 3000)
146+
- `EENGINE_HOST` - Bind address (default: 127.0.0.1)
147+
- `EENGINE_MAX_BODY_SIZE` - Max POST body (default: 25MB)
148+
- `EENGINE_TIMEOUT` - Request timeout (default: 10s), override with `X-EE-Timeout` header
149+
- `EENGINE_API_PROXY` - Enable X-Forwarded-For parsing
150+
151+
**Key files:**
152+
- `workers/api.js` - Hapi server setup and middleware
153+
- `lib/routes-ui.js` - Admin UI routes (88 routes)
154+
- `lib/api-routes/*.js` - REST API route modules
155+
- `lib/tokens.js` - Token validation and CRUD
156+
119157
### IMAP Worker
120158

121159
The IMAP worker (`workers/imap.js`) manages all email account connections and synchronization. Each worker handles multiple accounts via the `ConnectionHandler` class.

0 commit comments

Comments
 (0)