TERRANOETIS

Platform architecture

Platform v3.0.0 Docs v3.0.0 MEASURED — topology read from the measured server boot order

Full description: Read the full narrative

Terranoetis is a three-tier application: a React 19 + CesiumJS single-page client (Vite 7), a Node.js + Express 4 API (TypeScript run via tsx), and SQLite (primary store) with Redis as an optional cache/memory hot path. The client talks REST + SSE + WebSocket to the API; the API orchestrates live-data fetchers, the 150-equation analytical engine, the hazard-simulation runners and the cognitive pipeline.

Server assembly

Middleware/service order in server/index.ts (line cites are the app.use/startup sequence; boot observed on port 3399)
OrderComponentDetailSource
1helmet CSP + Permissions-Policyexplicit CSP incl. Cesium/WS allowances; HSTS 1 yr in prodserver/index.ts:233-272
2corsstatic allowlist origin = CLIENT_ORIGIN, credentials onserver/index.ts:273
3body limits 5 mb, x-powered-by offserver/index.ts:274-276
4pino request logger → prom-client metricsbefore auth so all traffic is meteredserver/index.ts:279-280
5auth endpoints pre-guardlogin rate-limited 5/15 min; refresh; dev-login non-prod onlyserver/index.ts:306-314
6global /api guardpublic allow-list: health/metrics/config/OpenAPI + rate-limited read-only data routes (300/min/IP) + unthrottled public non-data routes (tiles, pulse, share-token reads); everything else requires JWTserver/index.ts:373-487
7routersfoundation-models, fork, pulse, /api/kaggle, analytical-models, openapiserver/index.ts:489-494
8DynamicToolRegistry (DB-persisted; 210 tools loaded at boot) + Omninet init + local GGUF spawnllama-server :11436 when model file presentserver/index.ts:513-817
9listen() background enginessentinel, monitors, forecast ledger, reflex, forks, entropy, discovery, dream, memory system, power saverserver/index.ts:14448-14488
10graceful shutdownstop engines → close HTTP → queue shutdown 10 s → close DBserver/index.ts:14519-14573

Request flow (chat)

  1. POST /api/agent/ask (authGuard, 30/min, zod-validated ≤ 10k chars + ≤ 4 images) — server/index.ts:9749,9167 server/middleware/validate.ts:3-41
  2. Intent classification: deterministic keyword router; embedding path if conf < 0.85; LLM deep-path only if conf < 0.7 — server/agent.ts:389-800 server/index.ts:9835-9851
  3. Cognitive orchestration: System 1 fast path (similarity ≥ 0.92), S1 + 10 s S2 verification (0.70–0.92), full System 2 with 45 s hard cap (< 0.70) — server/cognition/cognitiveOrchestrator.ts:251-295,386-388
  4. Tool execution: live-data fetchers, analytical tools, sandbox, simulation jobs; ≤ 3 tool rounds; SSE streamed with 15 s heartbeats and a hard 150 s run cap — server/index.ts:9801-9811,10966-10983
  5. Write-through to the chat knowledge graph and reasoning traces — server/index.ts:11237 server/kgV2/chatKgBridge.ts:28

Module inventory

LOC per directory and each module’s purpose are tabulated in the prose document (BACKEND.md), verified against the tree. Highlights of interest to researchers: analytical-models/ (23,866 LOC), kaggle/ (3,105), cognition/ (2,760), sentinel/ (3,191), memoryV2/ (2,091).

Persistence and realtime plumbing

SubsystemImplementationSource
Primary storeSQLite server/realtime.db, WAL + busy_timeout 5000, FKs on; 47 schema tables + runtime tables (provider_stats, system1_cache, job_queue…)server/db/index.ts:6-18 server/db/schema.sql:47 tables (counted)
Cache/hot pathRedis via ioredis when reachable; graceful SQLite fallbackserver/infrastructure/redis.ts:degradation
Event busIn-process EventEmitter pub/sub (server/pubsub.ts) — not Redis pub/sub; WebSocket fan-out runs through this busserver/pubsub.ts:1-21
Realtime transportsWebSocket only on /ws/agent + /ws/voice; SSE for chat and job statusserver/websocket.ts:74-80 server/kaggle/routes.ts:225
Job queueSQLite-backed SimpleQueue, 10 concurrent, max 3 attempts, recurring timers (MVC refresh 60 s, plugin scan 30 s…)server/queue/simple-queue.ts:22-60 server/index.ts:1006-1039