[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 EngineLocationExternal DepsCloud Sync / RLSRecommended Use Case
1. SQLite./data/zenth.dbNONE (Node 22 built-in)Local File OnlyZero-setup default for single-machine trading
2. PostgreSQLlocalhost:5432pg (Connection Pool)SupportedEnterprise relational queries and Docker stacks
3. MongoDBlocalhost:27017mongodb driverAtlas SupportedHigh-throughput document storage with compound indexes
4. SupabaseCloud PostgreSQL@supabase/supabase-jsRow-Level SecurityMulti-device cloud synchronization & remote telemetry
5. In-MemoryRAM EphemeralZERO dependenciesIn-Memory OnlyEphemeral 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 2026Maintained by Zenth Core