SYSTEM TOPOLOGY & DEPLOYMENT

Full-Stack Architecture & Container / Edge Boundaries

Strict-TypeScript monorepo combining Next.js 15 App Router, Express REST + WebSockets, Go 1.23 concurrent ML workers, and PostgreSQL 16.

REFERENCE GUIDEUse this page to verify which components execute inside Vercel Serverless Functions versus inside long-lived Docker containers.

1. Vercel Edge & Serverless Layer (`vercel.json`)

  • Next.js App Router SSR (`apps/web`): Server Components pre-render the initial 4-signal forecasting benchmark on the server for immediate first paint.
  • Serverless API Bridge (`/api/v1/[...path]`): Executes stateless REST requests, Zod validation, and @google/genai Gemma 4 API calls (`gemma-4-31b-it` / `gemini-4-argon`) within Vercel Function execution limits.

2. Containerized Backend Layer (`docker-compose.yml`)

  • Go Signal Engine (`services/go-signal-engine`): Concurrent goroutine pool executing multi-signal synthesis, lag/rolling window feature engineering, and 4 ML models with 200-iteration bootstrap confidence intervals.
  • Node.js + Express + `ws` (`apps/api`): Persistent WebSocket server (`/ws/signals`) pushing 1.2s real-time signal ticks, plus validated REST endpoints and PostgreSQL connection pooling.
  • PostgreSQL 16 (`postgres`): Relational storage for `signal_experiments`, `model_evaluations`, and `ai_predictions`.
ARCHITECTURAL DECISIONS

Explicit Stack Tradeoffs & Mitigations

Tradeoff 1: Vercel Serverless Functions vs. Persistent WebSockets

Vercel Serverless Functions are stateless and terminate after each HTTP response cycle, meaning they cannot host persistent ws:// connections. SignalForge hosts the stateful WebSocket server in the Node/Express container (`apps/api`), while the Next.js client automatically degrades to an edge stream feed when deployed serverless-only.

Tradeoff 2: Go Worker Concurrency vs. HTTP Serialization Hop

Training Random Forest, Gradient Boosting, and 200-iteration bootstrap confidence intervals is CPU-bound and would block Node.js's single-threaded event loop under concurrent load. Offloading `/v1/forecast` to Go goroutines keeps Express responsive at the cost of a ~1–2ms internal HTTP serialization hop.