How pratikpandey994-dotcom/fx-terminal works
1. Overall shape
This repo is a multi-runtime intelligence platform, not a single web app. The architecture is split across a Next.js 14 frontend/API layer, a Node.js worker for ingestion and computation, and a Python FastAPI pattern service for technical analog matching. Persistent state lives in PostgreSQL with pgvector and Redis.
2. User-facing application
The app/ and components/ trees implement the terminal-style UI and dashboard surfaces. The main experience is the research terminal under app/(dashboard)/terminal, with supporting dashboard panels and reusable terminal widgets in components/terminal and components/dashboard. This layer is primarily presentation, orchestration, and live data fetching.
3. API boundary
The app/api/ tree is the primary HTTP contract. It groups endpoints by domain: market, intelligence, bias, pattern, feed, knowledge, public, v1, plus health/ready and terminal bootstrap. These routes act as the boundary between the UI and the backend engines, normalizing responses and shielding the frontend from direct provider complexity.
4. Fundamental intelligence engine
The Node worker is the core computation plane for the “Engine 1” side of the product. Its jobs ingest and synthesize news, macro releases, central-bank communications, COT, positioning, sentiment, event risk, and narrative structure. The worker’s engine modules cover things like market structure, regime detection, funding stress, intermarket chains, positioning, risk sentiment, daily brief generation, and forecast/recommendation combining.
5. Technical pattern engine
“Engine 2” is isolated in services/pattern/, a separate Python service built around candle encoding, motif discovery, similarity search, and probability estimation. It stores and queries historical analogs using pgvector-backed similarity. The worker also contains pattern-related jobs for encoding, resolving, and backfilling candle episodes, which suggests a pipeline from raw price history to analog-based predictions.
6. Data ingestion layer
The worker is responsible for pulling from many external sources via provider adapters and scrapers: Alpha Vantage, BLS, CFTC, EIA, FRED, Finnhub, OANDA, Twelve Data, World Bank, ForexFactory, GDELT, SEC, RSS, Google News proxy, and others. There are dedicated jobs for macro, news, earnings, politician trades, source discovery, staleness checks, and feed promotion. This is the main ingress path into the platform.
7. Persistence and indexing
prisma/schema.prisma and the large migration history show that PostgreSQL is the system of record for users, layouts, market snapshots, intelligence artifacts, knowledge documents, alerts, and pattern data. pgvector is used for semantic or analog retrieval. Redis is used as a shared cache/tiered-speed layer for worker and API paths, with additional edge/cache helpers in the app code.
8. Knowledge and retrieval subsystem
The platform has a separate knowledge-corpus pipeline: embeddings, chunking, hybrid retrieval, taxonomy classification, entity linking, and search. The services/search/ microservice handles discovery and retrieval across sources using DuckDuckGo/SearxNG-style engines plus LLM-assisted ranking. This subsystem feeds the intelligence layer rather than serving as a user-facing search product.
9. Alerts and external delivery
The system is not a trading bot, but it does produce outbound intelligence via Telegram and automation hooks. lib/telegram and worker/src/telegram-notify.ts indicate alert generation, while services/telegram/ and app/api/n8n/ingest connect to external ingestion/automation flows. A Google Drive cold-storage path is also part of the operational data lifecycle.
10. AI and model integration
Both app and worker have AI client wrappers for Gemini and Groq. These are used for enrichment, summarization, narrative synthesis, and likely retrieval-augmented reasoning. The AI layer sits above raw data ingestion and below the UI, and is used to turn market facts into explainable intelligence outputs.
11. Operational architecture
Deployment is centered on Railway for the app and worker, with a separate Oracle Cloud n8n automation environment. Dockerfiles, GitHub Actions, Sentry configs, health/ready routes, and docker-compose.yml show that the repo is designed for containerized deployment with explicit observability and environment separation. There is also a strong runbook/docs culture around operations.
12. Primary data flow
The typical flow is: external providers and scrapers → worker jobs → Postgres/Redis → API routes → terminal/dashboard UI. For pattern analysis, the flow is: historical candles → Python pattern service and/or worker encoding jobs → vector similarity/probability outputs → API/UI panels. The platform’s architecture is therefore a two-engine intelligence pipeline with shared storage and a thin presentation layer on top.
Main entry points: index.ts Job Suite · schema.prisma PostgreSQL · page.tsx Research Terminal · route.ts Intel API
Components 21
Frontend + API
Next.js terminal UI and HTTP boundary
- Research Terminal · Main terminal workspace and dashboard experience
app/(dashboard)/terminal/page.tsx - Dashboard Panels · Reusable terminal and dashboard widgets
components/terminal/TerminalMainView.tsx - Market API · Market data, quotes, candles, and session endpoints
app/api/market/candles/route.ts - Intel API · Core intelligence endpoints for briefs, regimes, narratives, and signals
app/api/intelligence/daily-brief/route.ts - Pattern API · Analog analysis and event-study endpoints
app/api/pattern/analyze/route.ts - Knowledge API · Corpus search and retrieval boundary
app/api/knowledge/search/route.ts - Bootstrap API · Terminal bootstrap and readiness checks
app/api/terminal/bootstrap/route.ts
Node Worker
Primary ingestion and intelligence compute plane
- Worker Core · Main Node worker entrypoint and job scheduler
worker/src/index.ts - Job Suite · Coordinates ingestion, analysis, and backfill jobs
worker/src/jobs/index.ts - Providers · External market, macro, and news connectors
worker/src/providers/alphaVantage.ts - Ingestion Flow · Pulls and normalizes external feeds into the platform
worker/src/jobs/newsIngestion.ts - Market Engines · Market structure, regime, positioning, funding stress, and risk sentiment
worker/src/engines/market-structure.ts - Narrative Synthesis · Daily briefs, narratives, convergence, and recommendations
worker/src/engines/narrative-engine.ts - Knowledge Pipeline · Embedding, ingest, taxonomy, and retrieval preparation
worker/src/engines/knowledge-ingest.ts - Pattern Jobs · Candle encoding, pattern resolution, and backfill jobs
worker/src/jobs/pattern-encode-worker.ts
Python Services
Standalone pattern and search runtimes
- Pattern Service · Standalone technical analog matching and probability service
services/pattern/main.py - Search Service · Multi-engine discovery and ranked retrieval service
services/search/main.py
Storage
Persistent state and shared caches
- PostgreSQL · Primary database for users, layouts, intelligence, knowledge, and patterns
prisma/schema.prisma - Redis · Shared cache and speed tier for API and worker flows
lib/redis.ts
Delivery + Ops
Outbound channels and automation
- Telegram Alerts · Outbound alerting and intelligence delivery
lib/telegram/alerts.ts - Automation Ingest · Automation and external workflow ingestion entrypoint
app/api/n8n/ingest/route.ts
Connections 32
- Research Terminal → Bootstrap API: bootstraps · Terminal loads initial state and health before rendering
- Research Terminal → Market API: fetches market · UI requests quotes, candles, sessions, and market summaries
- Research Terminal → Intel API: renders intel · UI consumes intelligence panels, briefs, and regime views
- Research Terminal → Pattern API: shows analogs · UI requests pattern analysis and analog outputs
- Research Terminal → Knowledge API: searches corpus · UI queries knowledge retrieval
- Dashboard Panels → Market API: drives views · Dashboard widgets consume market endpoints
- Dashboard Panels → Intel API: drives views · Dashboard widgets consume intelligence endpoints
- Market API → Redis: caches · Market responses are accelerated through shared cache
- Market API → PostgreSQL: reads state · Market views read persisted snapshots and metadata
- Intel API → Market Engines: serves signals · Intel routes surface engine outputs from the worker plane
- Intel API → Narrative Synthesis: serves briefs · Daily brief, narratives, and synthesis are exposed via API
- Intel API → Knowledge Pipeline: uses corpus · Intel routes can incorporate knowledge and embeddings
- Pattern API → Pattern Service: analogs · Pattern endpoints call the Python analog matching service
- Knowledge API → Search Service: retrieves · Knowledge search delegates to the retrieval service
- Bootstrap API → PostgreSQL: hydrates · Bootstrap pulls persisted workspace and user state
- Worker Core → Job Suite: starts · Worker runtime launches the job suite
- Job Suite → Providers: orchestrates · Job runner coordinates provider-backed ingestion tasks
- Providers → Ingestion Flow: feeds · Adapters supply raw market and news data to ingestion jobs
- Ingestion Flow → PostgreSQL: writes · Ingested artifacts and snapshots are persisted
- Ingestion Flow → Redis: hot cache · Recent data is staged in cache for fast reads
- Job Suite → Market Engines: computes · Worker executes core market intelligence engines
- Job Suite → Narrative Synthesis: synthesizes · Worker generates briefs, narratives, and combined recommendations
- Job Suite → Knowledge Pipeline: builds corpus · Worker maintains knowledge embeddings and retrieval data
- Job Suite → Pattern Jobs: encodes patterns · Worker runs candle and episode processing for analog workflows
- Pattern Jobs → Pattern Service: syncs analogs · Worker pattern jobs complement the standalone pattern runtime
- Knowledge Pipeline → Search Service: indexes · Knowledge assets are prepared for cross-source search
- Pattern Service → PostgreSQL: vector store · Pattern service stores and queries analog history in Postgres pgvector
- Search Service → PostgreSQL: reads corpus · Search runtime queries stored documents and metadata
- Narrative Synthesis → Telegram Alerts: notifies · Narrative and risk outputs can be pushed as alerts
- Telegram Alerts → PostgreSQL: records alerts · Alert lifecycle and delivery state are persisted
- Automation Ingest → Ingestion Flow: ingests · Automation flows can inject external data into ingestion paths
- Automation Ingest → PostgreSQL: writes external · Automation can persist imported records and artifacts