# nethajinirmal13/worldmonitor architecture

> Architecture diagram of the GitHub repository nethajinirmal13/worldmonitor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nethajinirmal13/worldmonitor
- Repository: https://github.com/nethajinirmal13/worldmonitor

## Overview

#### Purpose and Entry Points
World Monitor is a TypeScript situational-awareness dashboard combining geospatial intelligence, news, market, infrastructure, and AI analysis. It produces World, Tech, and Finance variants from one codebase, deployable as a Vite SPA/PWA, Vercel API deployment, or Tauri desktop application.

Browser startup flows through `index.html`, `src/main.ts`, and `src/App.ts`. Variant-specific composition is configured under `src/config/variants/base.ts`, `src/config/variants/tech.ts`, and `src/config/variants/finance.ts`.

#### Frontend Intelligence Workspace
The application is centered on a MapLibre/deck.gl map plus independently polling panels. Map interactions, overlays, clusters, popups, and country navigation are implemented in `src/components/MapContainer.ts`, `src/components/DeckGLMap.ts`, and `src/components/CountryBriefPage.ts`.

Panels consume normalized service outputs and static domain data rather than directly owning most upstream integration. Feature selection, panel visibility, feed sets, and map layers vary by build/runtime variant through `src/config/panels.ts`, `src/config/feeds.ts`, and `src/config/variant.ts`.

#### Client Data and Analysis Pipeline
Domain services are grouped by vertical (`src/services/conflict/index.ts`, `src/services/market/index.ts`, `src/services/intelligence/index.ts`) and combine API data with browser-resident analysis. The central fusion layer is `src/services/signal-aggregator.ts`; downstream correlation and convergence logic live in `src/services/correlation.ts` and `src/services/geo-convergence.ts`.

News follows an immediate-render then enrichment model: ingestion and clustering use `src/services/live-news.ts`, `src/services/clustering.ts`, and `src/services/entity-extraction.ts`. Browser workers provide asynchronous ML/analysis without blocking rendering: `src/workers/analysis.worker.ts`, `src/workers/ml.worker.ts`, and `src/services/ml-worker.ts`.

#### Contract-First RPC Boundary
New API functionality is defined as Proto services, then generated into typed client/server bindings and OpenAPI artifacts. Contracts are under `proto/worldmonitor/*/v1/service.proto`; representative RPC definitions include `proto/worldmonitor/intelligence/v1/classify_event.proto` and `proto/worldmonitor/market/v1/list_market_quotes.proto`.

Generated browser clients reside in `src/generated/client/worldmonitor/`, while server interfaces are in `src/generated/server/worldmonitor/`. The Edge gateway entry point, `api/[domain]/v1/[rpc].ts`, dispatches requests to the common router in `server/router.ts` and domain handlers such as `server/worldmonitor/intelligence/v1/handler.ts`.

#### Backend Adapters, Resilience, and Security
The backend normalizes external providers into RPC responses. Domain operations are implemented as focused handlers, e.g. `server/worldmonitor/conflict/v1/list-acled-events.ts`, `server/worldmonitor/maritime/v1/get-vessel-snapshot.ts`, and `server/worldmonitor/infrastructure/v1/get-cable-health.ts`.

Caching and resilience are shared concerns: Redis access is centralized in `server/_shared/redis.ts`, while API error translation and CORS are bounded by `server/error-mapper.ts` and `server/cors.ts`. Legacy Vercel functions coexist for specialized/proxy behavior, notably `api/rss-proxy.js`, `api/youtube/embed.js`, and `api/story.js`. Edge access is additionally screened by `middleware.ts`.

#### Deployment Topology and External Services
The primary hosted runtime is Vercel: static SPA plus Edge endpoints configured by `vercel.json`. Upstash Redis supports shared caching/deduplication. Upstreams span RSS, geopolitical, market, aviation, maritime, AI, and mapping providers; provider calls are deliberately isolated behind server handlers so browser clients do not receive most credentials.

Railway is an optional relay runtime launched via `scripts/ais-relay.cjs`, supporting persistent AIS/WebSocket traffic and alternate-origin proxying for blocked upstreams. Nginx compression/proxy deployment support is in `deploy/nginx/brotli-api-proxy.conf`.

#### Desktop and Local-First Runtime
Tauri packages the same frontend for macOS, Windows, and Linux. Native startup, keychain/session-token handling, and desktop commands originate in `src-tauri/src/main.rs`; product variants are described by `src-tauri/tauri.conf.json`, `src-tauri/tauri.tech.conf.json`, and `src-tauri/tauri.finance.conf.json`.

The desktop process starts a local Node sidecar at `src-tauri/sidecar/local-api-server.mjs`. Frontend requests route through `src/services/tauri-bridge.ts`; the sidecar executes local handlers first, applies local authentication/compression, and can fall back to the cloud API. This establishes the main trust boundary: OS-managed desktop secrets and localhost API execution versus hosted Vercel services.

Main entry points: [`src/services/intelligence/index.ts`](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/services/intelligence/index.ts) (Domain services), [`src/App.ts`](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/App.ts) (Variant application shell), [`server/worldmonitor/intelligence/v1/handler.ts`](https://github.com/nethajinirmal13/worldmonitor/blob/main/server/worldmonitor/intelligence/v1/handler.ts) (Domain handlers), [`src/components/MapContainer.ts`](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/components/MapContainer.ts) (Map and country workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser workspace"]
  node_bootstrap["SPA bootstrap<br/>TypeScript entry<br/>[main.ts]"]
  node_app["Variant application shell<br/>React composition<br/>[App.ts]"]
  node_variants["Build variants<br/>variant config<br/>[base.ts]"]
  node_workspace["Map and country workspace<br/>MapLibre/deck.gl UI<br/>[MapContainer.ts]"]
  node_panel_config["Panels, feeds, and layers<br/>feature config<br/>[panels.ts]"]
  node_domain_services["Domain services<br/>client service layer<br/>[index.ts]"]
  node_news_pipeline["News ingestion and enrichment<br/>client pipeline<br/>[live-news.ts]"]
  node_fusion["Signal fusion and correlation<br/>analysis layer"]
  node_workers["Browser analysis workers<br/>Web Workers<br/>[analysis.worker.ts]"]
end

subgraph group_contracts["RPC contracts"]
  node_proto["Proto RPC definitions<br/>contract source"]
  node_generated_clients["Generated browser clients<br/>typed RPC client"]
end

subgraph group_hosted["Hosted API"]
  node_edge_gateway["Edge RPC gateway<br/>Vercel API entry<br/>[&#91;rpc&#93;.ts]"]
  node_router["Common RPC router<br/>server dispatch<br/>[router.ts]"]
  node_handlers["Domain handlers<br/>provider adapter layer<br/>[handler.ts]"]
  node_cache[("Shared Redis cache<br/>Upstash Redis access<br/>[redis.ts]")]
  node_legacy_api["Specialized legacy functions<br/>Vercel functions<br/>[rss-proxy.js]"]
end

subgraph group_desktop["Desktop runtime"]
  node_tauri["Tauri native host<br/>desktop shell<br/>[main.rs]"]
  node_tauri_bridge["Desktop request bridge<br/>client transport<br/>[tauri-bridge.ts]"]
  node_local_sidecar["Local API sidecar<br/>Node localhost API"]
end

subgraph group_platform["Deployment &amp; upstreams"]
  node_vercel{{"Vercel hosted runtime<br/>SPA and Edge deployment<br/>[vercel.json]"}}
  node_upstreams(("External data providers"))
  node_railway["Optional AIS relay<br/>persistent relay runtime<br/>[ais-relay.cjs]"]
end

node_bootstrap -->|"mounts"| node_app
node_app -->|"selects"| node_variants
node_app -->|"composes"| node_workspace
node_variants -->|"configures"| node_panel_config
node_panel_config -->|"controls"| node_workspace
node_workspace -->|"polls data"| node_domain_services
node_domain_services -->|"uses news"| node_news_pipeline
node_domain_services -->|"feeds signals"| node_fusion
node_news_pipeline -->|"enriches"| node_fusion
node_fusion -->|"offloads analysis"| node_workers
node_domain_services -->|"calls"| node_generated_clients
node_proto -->|"generates"| node_generated_clients
node_generated_clients -->|"typed RPC"| node_edge_gateway
node_edge_gateway -->|"dispatches"| node_router
node_router -->|"routes domain calls"| node_handlers
node_handlers -->|"caches and deduplicates"| node_cache
node_handlers -->|"adapts"| node_upstreams
node_legacy_api -->|"proxies"| node_upstreams
node_vercel -->|"hosts"| node_edge_gateway
node_tauri -->|"packages frontend"| node_app
node_tauri -->|"starts"| node_local_sidecar
node_domain_services -.->|"desktop transport"| node_tauri_bridge
node_tauri_bridge -->|"localhost requests"| node_local_sidecar
node_local_sidecar -.->|"local-first / cloud fallback"| node_handlers
node_railway -->|"relays persistent traffic"| node_upstreams

click node_bootstrap "https://github.com/nethajinirmal13/worldmonitor/blob/main/src/main.ts"
click node_app "https://github.com/nethajinirmal13/worldmonitor/blob/main/src/App.ts"
click node_variants "https://github.com/nethajinirmal13/worldmonitor/blob/main/src/config/variants/base.ts"
click node_workspace "https://github.com/nethajinirmal13/worldmonitor/blob/main/src/components/MapContainer.ts"
click node_panel_config "https://github.com/nethajinirmal13/worldmonitor/blob/main/src/config/panels.ts"
click node_domain_services "https://github.com/nethajinirmal13/worldmonitor/blob/main/src/services/intelligence/index.ts"
click node_news_pipeline "https://github.com/nethajinirmal13/worldmonitor/blob/main/src/services/live-news.ts"
click node_fusion "https://github.com/nethajinirmal13/worldmonitor/blob/main/src/services/signal-aggregator.ts"
click node_workers "https://github.com/nethajinirmal13/worldmonitor/blob/main/src/workers/analysis.worker.ts"
click node_proto "https://github.com/nethajinirmal13/worldmonitor/blob/main/proto/worldmonitor/intelligence/v1/classify_event.proto"
click node_edge_gateway "https://github.com/nethajinirmal13/worldmonitor/blob/main/api/%5Bdomain%5D/v1/%5Brpc%5D.ts"
click node_router "https://github.com/nethajinirmal13/worldmonitor/blob/main/server/router.ts"
click node_handlers "https://github.com/nethajinirmal13/worldmonitor/blob/main/server/worldmonitor/intelligence/v1/handler.ts"
click node_cache "https://github.com/nethajinirmal13/worldmonitor/blob/main/server/_shared/redis.ts"
click node_legacy_api "https://github.com/nethajinirmal13/worldmonitor/blob/main/api/rss-proxy.js"
click node_tauri "https://github.com/nethajinirmal13/worldmonitor/blob/main/src-tauri/src/main.rs"
click node_tauri_bridge "https://github.com/nethajinirmal13/worldmonitor/blob/main/src/services/tauri-bridge.ts"
click node_local_sidecar "https://github.com/nethajinirmal13/worldmonitor/blob/main/src-tauri/sidecar/local-api-server.mjs"
click node_vercel "https://github.com/nethajinirmal13/worldmonitor/blob/main/vercel.json"
click node_railway "https://github.com/nethajinirmal13/worldmonitor/blob/main/scripts/ais-relay.cjs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bootstrap,node_app,node_variants,node_workspace,node_panel_config,node_domain_services,node_news_pipeline,node_fusion,node_workers toneBlue
class node_proto,node_generated_clients toneAmber
class node_edge_gateway,node_router,node_handlers,node_cache,node_legacy_api toneMint
class node_tauri,node_tauri_bridge,node_local_sidecar toneRose
class node_vercel,node_upstreams,node_railway toneIndigo
```

## Components

### Browser workspace

- [SPA bootstrap](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/main.ts): TypeScript entry · `src/main.ts`
- [Variant application shell](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/App.ts): React composition · `src/App.ts`
- [Build variants](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/config/variants/base.ts): variant config · Selects World, Tech, and Finance composition. · `src/config/variants/base.ts`
- [Map and country workspace](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/components/MapContainer.ts): MapLibre/deck.gl UI · Renders map layers, interactions, clusters, and country views. · `src/components/MapContainer.ts`
- [Panels, feeds, and layers](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/config/panels.ts): feature config · `src/config/panels.ts`
- [Domain services](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/services/intelligence/index.ts): client service layer · Normalizes vertical conflict, market, and intelligence data. · `src/services/intelligence/index.ts`
- [News ingestion and enrichment](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/services/live-news.ts): client pipeline · Immediate rendering followed by clustering and entity enrichment. · `src/services/live-news.ts`
- [Signal fusion and correlation](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/services/signal-aggregator.ts): analysis layer · Aggregates signals and derives correlation and geo-convergence. · `src/services/signal-aggregator.ts`
- [Browser analysis workers](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/workers/analysis.worker.ts): Web Workers · Runs ML and analysis off the rendering thread. · `src/workers/analysis.worker.ts`

### RPC contracts

- [Proto RPC definitions](https://github.com/nethajinirmal13/worldmonitor/blob/main/proto/worldmonitor/intelligence/v1/classify_event.proto): contract source · `proto/worldmonitor/intelligence/v1/classify_event.proto`
- **Generated browser clients**: typed RPC client

### Hosted API

- [Edge RPC gateway](https://github.com/nethajinirmal13/worldmonitor/blob/main/api/%5Bdomain%5D/v1/%5Brpc%5D.ts): Vercel API entry · Routes domain/RPC requests into the common server router. · `api/[domain]/v1/[rpc].ts`
- [Common RPC router](https://github.com/nethajinirmal13/worldmonitor/blob/main/server/router.ts): server dispatch · `server/router.ts`
- [Domain handlers](https://github.com/nethajinirmal13/worldmonitor/blob/main/server/worldmonitor/intelligence/v1/handler.ts): provider adapter layer · Normalizes upstream domain operations into RPC responses. · `server/worldmonitor/intelligence/v1/handler.ts`
- [Shared Redis cache](https://github.com/nethajinirmal13/worldmonitor/blob/main/server/_shared/redis.ts): Upstash Redis access · Supports caching and deduplication. · `server/_shared/redis.ts`
- [Specialized legacy functions](https://github.com/nethajinirmal13/worldmonitor/blob/main/api/rss-proxy.js): Vercel functions · Provides RSS, embed, and story proxy behavior. · `api/rss-proxy.js`

### Desktop runtime

- [Tauri native host](https://github.com/nethajinirmal13/worldmonitor/blob/main/src-tauri/src/main.rs): desktop shell · Owns native startup, keychain/session tokens, and commands. · `src-tauri/src/main.rs`
- [Desktop request bridge](https://github.com/nethajinirmal13/worldmonitor/blob/main/src/services/tauri-bridge.ts): client transport · `src/services/tauri-bridge.ts`
- [Local API sidecar](https://github.com/nethajinirmal13/worldmonitor/blob/main/src-tauri/sidecar/local-api-server.mjs): Node localhost API · Runs local handlers and falls back to the cloud API. · `src-tauri/sidecar/local-api-server.mjs`

### Deployment & upstreams

- [Vercel hosted runtime](https://github.com/nethajinirmal13/worldmonitor/blob/main/vercel.json): SPA and Edge deployment · `vercel.json`
- **External data providers**: RSS, intelligence, market, AI, mapping · Credentials remain behind server-side adapters.
- [Optional AIS relay](https://github.com/nethajinirmal13/worldmonitor/blob/main/scripts/ais-relay.cjs): persistent relay runtime · Handles AIS/WebSocket traffic and alternate-origin proxying. · `scripts/ais-relay.cjs`

## Connections

- SPA bootstrap → Variant application shell: mounts
- Variant application shell → Build variants: selects
- Variant application shell → Map and country workspace: composes
- Build variants → Panels, feeds, and layers: configures
- Panels, feeds, and layers → Map and country workspace: controls
- Map and country workspace → Domain services: polls data
- Domain services → News ingestion and enrichment: uses news
- Domain services → Signal fusion and correlation: feeds signals
- News ingestion and enrichment → Signal fusion and correlation: enriches
- Signal fusion and correlation → Browser analysis workers: offloads analysis
- Domain services → Generated browser clients: calls
- Proto RPC definitions → Generated browser clients: generates
- Generated browser clients → Edge RPC gateway: typed RPC
- Edge RPC gateway → Common RPC router: dispatches
- Common RPC router → Domain handlers: routes domain calls
- Domain handlers → Shared Redis cache: caches and deduplicates
- Domain handlers → External data providers: adapts
- Specialized legacy functions → External data providers: proxies
- Vercel hosted runtime → Edge RPC gateway: hosts
- Tauri native host → Variant application shell: packages frontend
- Tauri native host → Local API sidecar: starts
- Domain services → Desktop request bridge: desktop transport
- Desktop request bridge → Local API sidecar: localhost requests
- Local API sidecar → Domain handlers: local-first / cloud fallback
- Optional AIS relay → External data providers: relays persistent traffic
