[node:sqlite][PostgreSQL_16][MongoDB_7][Supabase_RLS][LocalStore]
Pluggable Multi-Database Storage
Unified DatabaseAdapter interface with polymorphic support for SQLite, PostgreSQL, MongoDB, Supabase Cloud RLS, and In-Memory RAM.
Storage Engine Feature Matrix
Zenth features a pluggable database architecture supporting 5 persistence backends configured via `STORAGE_BACKEND`:
| Storage Engine | Location | External Deps | Cloud Sync / RLS | Recommended Use Case |
|---|---|---|---|---|
| 1. SQLite | ./data/zenth.db | NONE (Node 22 built-in) | Local File Only | Zero-setup default for single-machine trading |
| 2. PostgreSQL | localhost:5432 | pg (Connection Pool) | Supported | Enterprise relational queries and Docker stacks |
| 3. MongoDB | localhost:27017 | mongodb driver | Atlas Supported | High-throughput document storage with compound indexes |
| 4. Supabase | Cloud PostgreSQL | @supabase/supabase-js | Row-Level Security | Multi-device cloud synchronization & remote telemetry |
| 5. In-Memory | RAM Ephemeral | ZERO dependencies | In-Memory Only | Ephemeral simulation, CI tests, zero disk footprint |
Database DDL Schema Definition
All database backends persist 3 core tables: `trade_ledger`, `adaptive_learnings`, and `session_metrics`:
PostgreSQL / Supabase DDL
sql
CREATE TABLE IF NOT EXISTS public.trade_ledger ( id TEXT PRIMARY KEY, timestamp TIMESTAMPTZ NOT NULL DEFAULT now(), symbol TEXT NOT NULL, action TEXT NOT NULL, price NUMERIC(18, 8) NOT NULL, quantity NUMERIC(18, 8) NOT NULL, notional_value NUMERIC(18, 4), outcome TEXT NOT NULL DEFAULT 'PENDING', pnl NUMERIC(18, 4)); CREATE TABLE IF NOT EXISTS public.adaptive_learnings ( id TEXT PRIMARY KEY, created_at TIMESTAMPTZ NOT NULL DEFAULT now(), symbol TEXT NOT NULL, pattern_condition TEXT NOT NULL, loss_reason TEXT NOT NULL, trading_rule TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'ACTIVE', trigger_count INTEGER NOT NULL DEFAULT 0);Supabase Row-Level Security (RLS)
Cloud persistence is locked down with cryptographic Row-Level Security policies:
Supabase RLS Policies
sql
ALTER TABLE public.trade_ledger ENABLE ROW LEVEL SECURITY;ALTER TABLE public.adaptive_learnings ENABLE ROW LEVEL SECURITY; CREATE POLICY "Allow authenticated read/write" ON public.trade_ledger FOR ALL TO authenticated USING (true) WITH CHECK (true);Last verified: August 2026•Maintained by Zenth Core