How rafaelsantana6/zapo-rest works
zapo-rest is a multi-session WhatsApp REST gateway: clients authenticate and operate named WhatsApp instances, while the service manages sessions, exposes messaging and operational APIs, and projects WhatsApp activity into durable stores and live integrations. The main runtime path is HTTP request through the Fastify app and routes to instance management and WhatsApp clients; inbound events are processed into chat, contact, message, and identity projections before webhook delivery or SSE. Media storage, VoIP, the dashboard, and API documentation are distinct product capabilities. Some route and boot wiring is unsampled, so only documented or indexed relationships are shown.
Main entry points: processor.ts Event processor · routes REST endpoints · app.ts Fastify application · manager.ts Instance lifecycle
Components 26
API and interfaces
- Fastify application
src/app.ts - API-key authentication
src/auth/plugin.ts - REST endpoints
src/routes
Sessions and identity
- Instance lifecycle
src/instances/manager.ts - Instance records
src/instances/repo.ts - WhatsApp client
src/instances/wa-client.ts
Events and projections
- Event processor
src/events/processor.ts - Chat projections
src/store/chats.ts - Message history
src/store/messages.ts - Contact projections
src/store/contacts.ts - LID-to-PN mapping
src/store/lid-map.ts - PostgreSQL
Media and integrations
- Live event stream
src/routes/events-sse.ts - Webhook delivery
src/webhooks/dispatcher.ts - Webhook outbox
src/webhooks/outbox.ts - Media endpoints
src/routes/media.ts - Media storage
src/media/storage.ts - S3-compatible storage
- VoIP control and audio
src/routes/voip-ws.ts - Call recording
src/voip/recording-manager.ts - Call records
src/store/calls.ts
Operator experience
- Operations dashboard
dashboard/src/App.tsx - Dashboard API client
dashboard/src/api/client.ts - Dashboard softphone
dashboard/src/components/Softphone.tsx - API guide and reference
docs-site/src
Other components
- API client
Connections 30
- API client → Fastify application: sends requests
README.md - Fastify application → API-key authentication: registers
src/app.ts - Fastify application → REST endpoints: registers
src/app.ts - REST endpoints → Instance lifecycle: uses sessions
src/app.ts - API-key authentication → Instance records: resolves keys
src/auth/plugin.ts - Instance lifecycle → Instance records: manages records
src/instances/manager.ts - Instance lifecycle → WhatsApp client: manages sessions
src/instances/manager.ts - WhatsApp client → Event processor: emits events
- Event processor → Chat projections: upserts chats
src/events/processor.ts - Event processor → Message history: projects messages
src/events/processor.ts - Event processor → Contact projections: updates contacts
src/events/processor.ts - Event processor → LID-to-PN mapping: records identity
src/events/processor.ts - Chat projections → PostgreSQL: reads and writes
src/store/chats.ts - Message history → PostgreSQL: persists history
README.md - Contact projections → PostgreSQL: persists contacts
README.md - LID-to-PN mapping → PostgreSQL: persists mappings
README.md - Event processor → Webhook delivery: dispatches events
src/events/processor.ts - Webhook delivery → Webhook outbox: queues delivery
src/webhooks/dispatcher.ts - Webhook outbox → API client: delivers retries
README.md - Event processor → Live event stream: publishes events
README.md - REST endpoints → Media endpoints: includes routes
README.md - Media endpoints → Media storage: serves media
README.md - Media storage → S3-compatible storage: stores objects
README.md - REST endpoints → VoIP control and audio: includes control
README.md - Call recording → Call records: updates recordings
src/voip/recording-manager.ts - Call recording → Media storage: stores recordings
src/voip/recording-manager.ts - Operations dashboard → Dashboard API client: calls API
dashboard/src/App.tsx - Operations dashboard → Dashboard softphone: renders
dashboard/src/App.tsx - Dashboard API client → Fastify application: calls REST API
README.md - API guide and reference → API client: documents API
README.md