@@ -14,7 +14,7 @@ EmailEngine is an email sync platform that provides REST API access to email acc
1414- ` /lib/ui-routes ` - Web UI route handlers
1515- ` /lib/lua ` - Redis Lua scripts for atomic operations
1616- ` /lib/oauth ` - OAuth provider implementations
17- - ` /workers ` - Worker thread modules (API, IMAP, webhooks, submit )
17+ - ` /workers ` - Worker thread modules (7 worker types, see Workers section )
1818- ` /test ` - Unit and integration tests
1919- ` /config ` - TOML configuration files
2020- ` /views ` - Handlebars templates for web UI
@@ -61,9 +61,31 @@ npm run single # Single-worker debug mode with Inspector
6161- Uses Redis database 9 for test isolation
6262- Run ` npm test ` for full test suite with linting
6363
64+ ## Workers
65+
66+ EmailEngine uses Node.js Worker Threads for isolated execution. Workers communicate via message passing with the main thread (` server.js ` ).
67+
68+ | Worker | File | Count | Purpose |
69+ | --------| ------| -------| ---------|
70+ | API | ` api.js ` | 1 | REST API server (Hapi.js), handles all HTTP requests |
71+ | IMAP | ` imap.js ` | 4* | Email sync engine, manages IMAP/Gmail/Outlook connections per account |
72+ | Webhooks | ` webhooks.js ` | 1* | Delivers webhook notifications for email events |
73+ | Submit | ` submit.js ` | 1* | Processes queued emails for SMTP submission |
74+ | Documents | ` documents.js ` | 1 | ** Deprecated.** Indexes emails in Elasticsearch (legacy feature) |
75+ | SMTP | ` smtp.js ` | 1 | Optional SMTP server for local email submission (port 2525) |
76+ | IMAP Proxy | ` imap-proxy.js ` | 1 | Optional IMAP proxy server for local IMAP access (port 2993) |
77+
78+ * Configurable via environment variables (` EENGINE_WORKERS ` , ` EENGINE_WORKERS_WEBHOOKS ` , ` EENGINE_WORKERS_SUBMIT ` )
79+
80+ ** Worker Lifecycle:**
81+ - Main thread spawns workers at startup and monitors health via heartbeats (every 10s)
82+ - IMAP workers receive account assignments from main thread
83+ - Workers auto-restart on crash; accounts are reassigned to available workers
84+ - BullMQ queues distribute jobs to webhooks, submit, and documents workers
85+
6486## Architecture Notes
6587
66- - ** Multi-threaded** : Separate workers for API, IMAP sync , webhooks, email submission
88+ - ** Multi-threaded** : 7 worker types ( API, IMAP, webhooks, submit, documents, SMTP server, IMAP proxy)
6789- ** Redis-backed** : Primary data store with Lua scripts for atomic operations
6890- ** Encrypted** : All credentials encrypted at rest (AES-256-GCM)
6991- ** State machine** : Account states (init, connecting, syncing, connected, authenticationError, connectError, unset)
0 commit comments