Open Valstorm Plugin System & Native Dual-Runtime PlatformContext Architecture
1. Executive Summary
Open Valstorm is designed to keep its core (apps/open-api in Python and apps/open-worker in Go) streamlined, fast, and database-strict on PostgreSQL + Valkey/Redis, while supporting an extensible ecosystem of modular integrations (Slack, AI, Telnyx, Twilio, Google Workspace, Microsoft 365, DigitalOcean, Azure, Campaigns, Booking, etc.) packaged under /plugins/*.
Crucially, Go integrations (like Telnyx, Twilio, Gmail sync, Campaigns, and AI Desktop Sync) must not proxy database CUD or schema operations over HTTP through the Python FastAPI server. Instead, both apps/open-api (Python) and apps/open-worker (Go) implement a Native PlatformContext Data Plane that communicates directly with PostgreSQL (asyncpg in Python, pgxpool in Go) and Valkey (redis), sharing the exact same Redis schema-invalidation signals, CUD WebSocket broadcast format, and asynchronous trigger queues.
2. Runtime Order of Operations (Unified Data Plane)
Every record mutation (whether initiated from Python PlatformContext or Go pkg/platform) executes the exact same 6-step order of operations:
[1. Ingress]
├── REST / GraphQL / OAuth / AI Chat ────────► open-api (Python)
└── High-Speed Webhooks / WS / Asynq / Cron ─► open-worker (Go)
│
▼
[2. Schema & Tenant Resolution (0ms RAM Cache + Redis Invalidation)]
• Checks Redis `org:{org_id}:schemas_updated_at`
• Loads SchemaDefinition + Postgres column types from local memory cache
• Resolves Tenant Postgres connection pool (`db_manager` in Python / `TenantPoolManager` in Go)
│
▼
[3. Record Preparation & Sanitization]
• Python: `sanitize_record_for_db` + `format_column_value`
• Go: `schema.PrepareRecord` / `schema.PrepareUpdate`
• Both: Generate Base62 ID (`prefix_...`), stamp `created_date`/`modified_date` (UTC),
stamp `created_by`/`modified_by`, strip lookup dicts to string IDs,
format phone objects, hydrate defaults, increment auto-number counters
│
▼
[4. Direct Parameterized PostgreSQL Execution]
• Executes `INSERT / UPDATE / DELETE ... RETURNING *` directly against Tenant DB
• Native Postgres enforces types (`TIMESTAMPTZ`, `JSONB`, `TEXT[]`) & foreign keys
│
▼
[5. Real-Time WebSocket CUD Broadcast (<0.1ms)]
• Publishes `cud_create` / `cud_update` / `cud_delete` envelope to Redis channel `{org_id}`
• `open-worker` WebSocket server streams immediately to all connected browsers/desktops
│
▼
[6. Asynchronous Trigger & Workflow Relay (<0.1ms)]
• Pushes `valstorm.core.execute_async_trigger` task payload into Redis (`valstorm:queue:default`)
• Python `ValstormBackgroundWorker` picks up and runs any tenant custom Python triggers in sandbox3. Classification of Existing Modules (worker-go & api)
Tier A: Core Engine & Data Plane (Lives in apps/open-worker & apps/open-api Core)
- Multi-Tenant DB Manager (
pkg/tenantdbin Go /db_router.pyin Python): Manages tenantpgxpool.Pool/asyncpgpools. - Dynamic Schema & Record Sanitizer (
pkg/schemain Go /record_service.pyin Python): In-memorysync.RWMutexschema cache invalidated by Redisorg:{org_id}:schemas_updated_at, Base62 ID generation, default value hydration, lookup string extraction, phone normalization, and Postgres column type coercion. - Native
PlatformContext(pkg/platformin Go /platform_context.pyin Python): Unified CUD, SQL query, credential decryption, CUD broadcast, and async trigger relay facade. - WebSocket & CUD Broadcast (
internal/websocket,internal/cud): Real-time pub/sub streaming to connected clients. - Dynamic Scheduler (
internal/scheduler): Cron ticker and Python/Asynq task relay. - Fleet App Deployment (
internal/deployment): Concurrent (errgroup) multi-tenant schema DDL and app bundle installer. - Telemetry & Logging (
internal/telemetry): High-throughput activity, error, and usage logging. - Core High-Speed Handlers (
internal/inbound,internal/vfs,internal/webhook,internal/notification,internal/scraper): Public form/webhook ingestion (/v1/inbound/submit), S3 batch purges/cascades, outbound webhook dispatch, and notification routing.
Tier B: Modular Plugins (Lives in /plugins/valstorm-plugin-<name>)
Each plugin can contain a /python package (FastAPI routers, background tasks, AI tools) and/or a /go module (Asynq handlers, high-speed HTTP/WebSocket handlers):
valstorm-plugin-slack(Python): Slack OAuth v2, workspace client, event webhooks, background tasks, AI tools.valstorm-plugin-telnyx(Python + Go): Number provisioning, Call Control state machine, Deepgram transcription, MMS S3 uploads, SMS webhooks.valstorm-plugin-twilio(Python + Go): Twilio Conversations state machine, bulk SMS, call ringing/queued alerts.valstorm-plugin-ai(Python + Go): Agentic chat orchestration, tool bridge, and Go sub-10ms/v1/ai/chat/{chat_id}/desktop-sync.valstorm-plugin-google(Python + Go): Google OAuth, Gmail Pub/Sub delta sync (pgx.Batch), Google Calendar sync, and Booking slot engine.valstorm-plugin-campaign(Python + Go): Bulk email/SMS campaign orchestrator and delivery status tracker.valstorm-plugin-m365/valstorm-plugin-digitalocean/valstorm-plugin-azure: Cloud & enterprise integrations.
4. Phased Implementation Roadmap
Step 1: Build the Native Go PlatformContext in apps/open-worker
apps/open-worker/pkg/id: Base62 ID generation and prefix inference matchingopen-api.apps/open-worker/pkg/tenantdb: Multi-tenantpgxpool.Poolmanager with thread-safe caching perorgID.apps/open-worker/pkg/schema: Portapps/worker-go/internal/schema(types.go,record.go,manager.go) from MongoDB to PostgreSQL (pgxpool), including table column type reflection (information_schema.columns) and atomic counter increments.apps/open-worker/pkg/platform: Native GoPlatformContext(ForOrg(orgID, userID)) providing:
Records.Create(ctx, apiName, data)&Records.CreateBatch(ctx, apiName, records)Records.Update(ctx, apiName, id, data)Records.Delete(ctx, apiName, id)Records.Get(ctx, apiName, id)&Records.Query(ctx, apiName, filters, limit)- Automatic
cud.PublishCUDbroadcast + Redisvalstorm.core.execute_async_triggerdispatch on mutations.
- Comprehensive Go Test Suite: Unit tests for
pkg/id,pkg/schema, andpkg/platformverifying schema hydration, Postgres SQL generation, CUD publishing, and async trigger relay.
Step 2: Build the Python & Go Plugin Registries + PlatformContext Extensions
- Extend Python
PlatformContextwithplatform.cache,platform.credentials,platform.tasks, andPlatformContext.for_external_account(...). - Create Python plugin loader (
apps/open-api/app/core/plugins.py) and Go plugin registry (apps/open-worker/pkg/plugin/registry.go) controlled byVALSTORM_PLUGINS. - Configure
/plugins,go.work, anddocker-compose.open.yamlvolume mounts for live hot-reloading.
Step 3: Vertical Slice #1 — Pure Python Plugin (valstorm-plugin-slack)
- Extract
apps/api/app/slackintoplugins/valstorm-plugin-slackusing purePlatformContext.
Step 4: Vertical Slice #2 — Hybrid Go + Python Plugins (valstorm-plugin-telnyx & twilio)
- Port Telnyx and Twilio handlers into
plugins/valstorm-plugin-telnyxandplugins/valstorm-plugin-twilioon top of Gopkg/platformand PythonPlatformContext.
Step 5: Vertical Slice #3 — AI, Google Workspace, Campaigns & Cloud Integrations
- Port
ai,google(gmail+calendar+booking), andcampaigninto/plugins/*.
