How cheerfulstoic/ecto_watch works
Main Components
a) Core Components:
• PostgreSQL Database (with triggers)
• EctoWatch Library Components
• Phoenix PubSub System
• Client Application Components
b) Key Process Components:
• WatcherSupervisor
• WatcherServer (multiple instances)
• Ecto Repo
• Subscribers (LiveView, GenServer, etc.)
┌─ Client Application ─────────────────────────┐
• ┌─ Subscribers ──┐ │
• LiveView │ │
• GenServer │ │
• Channels │ │
• ┘ │
• ▲ │
• ┌─ Phoenix.PubSub ─┐ │
• ┘ │
• ▲ │
• ┌─ EctoWatch ──────────────────────────┐ │
• ┌─ WatcherSupervisor ─┐ │ │
• ┌─ WatcherServer ─┐ │ │
• (per schema) │ │ │
• ┘ │ │
• ┘ │
• ┘ │
• ┼────────────────────────────────┘
┌───────────▼────────────────┐
• PostgreSQL Database │
• ┌─────────────────────┐ │
• Notification │ │
• Triggers │ │
• ┘ │
• ┘
Data Flow Indicators
1. Database triggers → WatcherServer
2. WatcherServer → Phoenix.PubSub
3. Phoenix.PubSub → Subscribers
4. Client Application → Database (for mutations)
Important Details
a) Configuration Components:
• WatcherOptions configuration
• Supported operations (inserted/updated/deleted)
• Subscription patterns (by ID, by association)
b) Process Architecture:
• Supervisor tree structure
• Multiple WatcherServer instances (one per schema/operation pair)
Additional Notes
• Notes about the trigger creation process
• Standardized message format
• Subscription patterns (full schema vs. individual record)
Technical Details to Highlight
• PostgreSQL LISTEN/NOTIFY mechanism
• Ecto integration points
• PubSub topic structure
• Message payload format