Montis.icu Unified Prefetch Architecture β v5.1 Design
The Montis.icu Coach App operates on an authority-driven architecture separating
measurement, interpretation, prescription,
and interface.
Data integrity originates from Intervals.icu,
computation executes in Railway (python), and conversational rendering
never alters canonical truth.
π§ Strategy β’ π’ Technical β’ π Coaching β’ π΅ Tool & LLM
The system is intentionally divided into independent architectural layers, each with a single responsibility and defined authority.
- π§ Strategy & Philosophy β Governing architectural doctrine. Defines authority boundaries and non-negotiable contracts for interpretation.
- π’ Technical Pipeline - Operational Architecture β Cloudflare Services handle identity resolution, OAuth facades, sessions, grants, routing, and policy. Railway performs deterministic data ingestion, validation, aggregation, and semantic serialization (URF v5.1). Canonical outputs remain immutable.
- π Coaching Intelligence Pipeline β Uses validated URF outputs for Tier-3 structural performance modelling, progression analysis, phase governance, and deterministic Adaptive Decision Engine prescription logic. It never mutates Tier-1 or Tier-2 metrics.
- π΅ Tool & LLM Architecture β ChatGPT, MCP, Gemini App, browser app, and CLI resolve through Cloudflare Services. Client wrappers resolve to the shared Montis Intervals connection record where required. LLMs render and converse through tools without computing or mutating metrics.
This separation enforces:
- Measurement Integrity
- Transparent Decision Intelligence
- Interface Abstraction Without Authority
Conversational AI is a rendering layer β never a computational authority.
π§ System Strategy & Architectural Philosophy
The Montis.icu Coach App is engineered around strict authority separation. No layer may override or recompute another layerβs outputs.
π Core Architectural Contract
Coaching logic never mutates canonical metrics.
Tier-1 and Tier-2 outputs are immutable and remain the single source of performance truth.
- Measurement is deterministic and audited.
- Interpretation is rule-based and traceable.
- Prescription executes via a deterministic state engine.
- LLMs render outcomes but never compute, infer, or adjust metrics.
This prevents metric drift, silent recomputation, probabilistic coaching artifacts, and black-box behavior.
π§± Responsibility Separation Model
Measurement β Technical Pipeline (Tier-0 / Tier-1 / Tier-2) Interpretation β Coaching Pipeline (Tier-3 Intelligence) Prescription β Adaptive Decision Engine (Deterministic Rules) Interface β LLM Rendering Layer (Read-Only)
No single layer owns more than one responsibility. This structure enables auditability, stateless execution, and predictable system evolution.
π― Strategic Positioning
Unlike heuristic AI dashboards or machine-learning coaching engines, this system does not invent, infer, or probabilistically manipulate performance metrics.
- No hidden state
- No probabilistic coaching inference
- No language-model metric computation
- No silent threshold adjustment
The result is a deterministic performance intelligence platform β not a black-box AI coach.
π Identity & Token Resolution
Montis resolves athlete identity at runtime through client access wrappers: browser session, ChatGPT JWT, MCP JWT, or a limited legacy fallback. The primary data connection is the shared server-side KV token record.
montis_session cookie"] B2["ChatGPT OAuth facade
Montis GPT JWT"] B3["MCP OAuth facade
MCP JWT"] B4["Legacy bearer / ICU_OAUTH"] end subgraph Routes["Worker Routes"] direction TB C1["/connect
Intervals OAuth"] C2["/disconnect / /logout"] C3["/oauth/authorize
/api/oauth/token"] C4["/mcp/oauth/authorize
/mcp/oauth/token"] C5["/connection/status"] C6["Unified Auth Resolver"] C7["Dispatcher / Internal Tools"] end subgraph KV["Cloudflare KV"] direction TB D1["SESSIONS
session:{uuid}"] D2["MCP_GRANTS
GPT/MCP temporary grants"] D3["INTERVALS_TOKENS
intervals:{athleteId}
access_token + refresh_token"] end end subgraph External["External"] direction TB E1["Intervals.icu OAuth + API"] E2["OpenAI / ChatGPT"] E3["Claude / MCP"] end A1 --> B1 A2 --> B1 A3 --> B2 A4 --> B3 A5 --> B4 B1 --> D1 B2 --> C3 B3 --> C4 B4 --> C6 A1 --> C1 A2 --> C1 A1 --> C2 A2 --> C2 C1 --> E1 E1 --> C1 C1 --> D1 C1 --> D3 C2 --> D1 C2 --> D3 C3 --> D1 C3 --> D2 C3 --> B2 C3 --> E2 C4 --> D1 C4 --> D2 C4 --> B3 C4 --> E3 C5 --> C6 D1 -->|browser_session β athlete_id| C6 B2 -->|gpt_jwt β kv_key| C6 B3 -->|mcp_jwt β kv_key| C6 C6 -->|load shared token| D3 D3 --> C7 C7 --> E1
Browser session, ChatGPT JWT, and MCP JWT resolve to the shared KV token record.
Intervals access tokens remain server-side in Cloudflare KV.
π Separation of Concerns
- Execution access β MCP /run_*
- Data access β OAuth token (KV or direct)
MCP grants control tool execution only.
OAuth tokens control access to athlete data.
βοΈ Unified Execution Model
Montis.icu operates a multi-entry, shared-token execution architecture. Tool execution and athlete identity are resolved independently at runtime.
Client
β Cloudflare Services
β Unified Auth Resolver
β Dispatcher / Internal Tools
β Intervals API + Railway Engine
β Semantic JSON (URF v5.1)
β LLM Rendering Layer
βοΈ Runtime Token Resolution
if (valid_gpt_jwt_with_kv_key) {
load shared Intervals token from KV
} else if (valid_mcp_jwt_with_kv_key) {
load shared Intervals token from KV
} else if (valid_browser_session) {
resolve athlete_id and load shared Intervals token from KV
} else if (legacy_bearer_or_ICU_OAUTH) {
use fallback token path
} else {
return 401
}
This logic applies uniformly across:
- /run_* report endpoints
- /calendar/* calendar endpoints
- /athlete/* athlete data endpoints
- /connection/status diagnostics
- /mcp tool calls
π§© Separation of Concerns
| Concern | Mechanism |
|---|---|
| Tool Execution | ChatGPT Actions, MCP, REST endpoints, browser app, Gemini App, CLI |
| Athlete Data Access | Shared KV token: intervals:{athleteId} |
Tool access does not equal athlete data access.
Protected data execution requires resolution to the shared Intervals KV token record.
π§ Execution Patterns
Browser / Gemini App: Client β montis_session β KV β Intervals ChatGPT: ChatGPT β Montis GPT JWT β kv_key β KV β Intervals MCP: Claude / Codex β MCP JWT β kv_key β KV β Intervals CLI / Legacy: Client β Worker endpoint β Bearer or KV fallback β Intervals
All paths converge into the same dispatcher and produce identical outputs.
π Public API & MCP Documentation
Montis exposes two public integration surfaces: a REST/OpenAPI interface for direct HTTP integrations and a Model Context Protocol (MCP) interface for AI assistants and tool clients.
Railway remains a private compute backend. Public access is provided exclusively through Cloudflare Worker routes.
| Interface | Purpose | Documentation |
|---|---|---|
| REST API | Direct HTTP access to Montis APIs via Cloudflare. |
API Docs
OpenAPI Schema |
| MCP | Model Context Protocol endpoint for Claude, Codex, Gemini-style MCP clients and other MCP-capable clients. | MCP Documentation |
π MCP Endpoint
Server URL https://montis.icu/mcp Client ID intervals-mcp Local MCP Inspector npx @modelcontextprotocol/inspector Inspector URL http://localhost:6274/#tools
π Security Model
- MCP endpoint URLs and OAuth discovery metadata are public by design.
- The OAuth client identifier (
intervals-mcp) is public and not a secret. - Access to athlete data requires successful OAuth authentication.
- Bearer tokens are validated before tool execution.
- Intervals.icu access tokens remain server-side and are never exposed through MCP.
- MCP controls tool access; OAuth controls athlete data access.
βοΈ Current Operational Pipeline (Production)
Status: Live β’ Used in production β’ Backward compatible
intervals:{athleteId}"] end end subgraph Processing["Processing"] direction TB D1["Intervals.icu API"] D2["Railway Report Engine
URF v5.1
Tier 0-3"] end subgraph LLM["LLM / Rendering"] direction TB E1["OpenAI / ChatGPT"] E2["Claude / MCP"] E3["Gemini / BYOK"] end A1 -->|connect| B1 A2 -->|connect| B1 A1 -->|logout / disconnect| B2 A2 -->|logout / disconnect| B2 A1 -->|session cookie| B6 A1 -->|session cookie| B7 A1 -->|session cookie| B8 A1 --> B5 A2 -->|same browser session as /app| B6 A2 -->|same browser session as /app| B7 A2 -->|same browser session as /app| B8 A2 --> B5 A2 -->|BYOK direct| E3 A3 -->|direct API| B6 A4 -->|OAuth setup| B3 A4 -->|Bearer GPT JWT| B6 A4 -->|Bearer GPT JWT| B7 A4 -->|Bearer GPT JWT| B8 A4 --> B5 A5 -->|MCP discovery/tools| B4 B4 --> B9 B1 --> C1 B1 --> C3 B2 --> C1 B2 --> C3 B3 --> C1 B3 --> C2 B4 --> C1 B4 --> C2 B5 --> B9 B6 --> B9 B7 --> B9 B8 --> B9 B9 -->|browser_session| C1 B9 -->|gpt_jwt kv_key| C3 B9 -->|mcp_jwt kv_key| C3 C3 --> B10 B10 --> D1 B10 --> D2 D2 --> E1 D2 --> E2 D2 --> E3
π Cloudflare handles authentication, routing, and optional synthetic testing.
π Railway performs full computation, validation, and serialization.
π§© Current Architecture Guarantees
| Area | Implementation | Guarantee |
|---|---|---|
| Prefetch Flow | Cloudflare Services normalize date params, resolve identity, and inject optional test payloads | Safe staging tests without real data |
| Execution Model | Python execution on Railway (FastAPI + Pandas) | Deterministic, audited output |
| Tier-0 Validation | Baseline column checks (`moving_time`, `distance`, etc.) | No schema drift or missing fields |
| Tier-1 Audit | Filters invalid / null activities, computes daily summaries | Enforced numeric consistency |
| Tier-2 Metrics & Enforcement | Derived Metrics, Lock totals, enforce logical consistency | No variance bleed between scopes |
| Tier-3 Coaching | Forecast, Performance Intelligence and ESPE | Integrated performance modelling |
| Serialization | Single-pass semantic JSON (no float loss) | Stable numeric precision |
| Observability | Structured logs at all Tier boundaries | Traceable audit chain (lightβfullβwellness) |
| Schema Version | URF v5.1 unified contracts | Cross-version compatibility with GPT tool API |
π§ Unified Tool & LLM Architecture
| Capability | Implementation | Guarantee |
|---|---|---|
| Multi-LLM Support | MCP + Direct Tool Calls | Works across ChatGPT, Claude, Gemini |
| Shared Token Resolution | Browser session + GPT JWT + MCP JWT β KV | All clients resolve to the same Intervals connection |
| Execution Engine | Cloudflare Dispatcher β Railway | Single deterministic pipeline |
| Data Authority | Intervals API | Single source of truth |
| Semantic Contract | URF v5.1 | No recomputation or drift |
| Stateless Execution | No UI dependency | Fully reproducible |
βοΈ Execution Flow
Client / LLM
β
Cloudflare Services
β’ Token Resolver (GPT JWT / MCP JWT / browser session β KV)
β’ Routing
β
Dispatcher (Internal Tools)
β
Railway Engine (Tier 0β3)
β
Intervals API (Data)
β
Semantic JSON (URF v5.1)
β
LLM Rendering Layer (Read-only, tool-driven)
π Key Properties
- Single execution path β all clients use the same dispatcher
- Shared identity resolution β browser session, GPT JWT, and MCP JWT all resolve to KV
- No recomputation in LLMs
- Deterministic outputs across all interfaces
β οΈ Important Clarification
- MCP controls tool access
- OAuth controls data access
- ChatGPT uses a Montis OAuth facade and receives a Montis GPT JWT
π Key Insights
-
There is no UI state
Every interaction is stateless, reproducible, and tool-driven. -
LLMs never compute metrics
They only interpret pre-computed, audited semantic JSON. -
Intervals tokens remain server-side in Cloudflare KV
Client wrappers resolve to the shared token record without exposing Intervals tokens to LLM reasoning. -
Intervals.icu remains the single source of truth
All metrics originate from published APIs or FIT-derived data. -
Context is explicit, never inferred
Each metric declares whether it is activity, 7d, 90d, or rolling. -
The system is headless by design
It works equally well for chat, voice, automation, or background agents.
βοΈ How It Works (End-to-End)
-
User or AI issues a natural-language request
Example: βExplain my weekly intensity balance and recovery status.β -
Request is converted into a tool call (direct or MCP)
- Strongly typed inputs
- Explicit report scope (weekly / season / activity)
-
Cloudflare Services handle trust and policy
- OAuth token exchange with Intervals.icu
- Scope validation
- Rate limiting
- Parameter normalization
-
Railway executes the computation
- Tier-0: schema + column validation
- Tier-1: numeric consistency and filtering
- Tier-2: locked totals and scope enforcement
- No cross-window leakage (e.g. weekly β seasonal)
-
Canonical semantic JSON is produced
- URF v5.1 contract
- Explicit context windows
- Deterministic numeric precision
- No derived ambiguity
-
LLM renders the report
- Descriptive, coach-like language
- Anchored strictly to provided semantics
- No recomputation, guessing, or extrapolation
π§ Why This Matters
This architecture enables natural language coaching at scale without:
- Dashboards
- Sliders
- Charts
- Hidden state
- Silent recomputation
The result is a system that is:
- Auditable
- Secure
- Model-agnostic
- Future-proof
- Genuinely conversational
Natural language becomes the interface β not the source of truth.
Every decision is rule-based, auditable, and reproducible β never guessed or generated.
π Architectural Continuity
The system evolves toward a unified tool-based architecture (direct + MCP), without changing execution guarantees. It formalizes the same guarantees behind a standard tool interface.
- Same Railway execution engine
- Same Tier-0/1/2 enforcement
- Same URF v5.1 semantic contract
- Same Intervals.icu data authority
π― Decision Governance
- The Adaptive Decision Engine is the sole prescriptive authority.
- Tier-2 metrics provide diagnostic context.
- Tier-3 synthesizes capability state.
- LLMs never modify, override, or invent recommendations.
π§ Montis Intelligence Stack
From raw training load to adaptive coaching decisions β a closed-loop performance system.
π§ Coaching Intelligence Pipeline (Performance Layer)
Status: Active (v5 / ADE v2) β’ Rule-based β’ Closed-loop β’ Production
The Coaching Pipeline operates strictly on validated canonical data produced by the Technical Pipeline. It does not compute raw metrics. It transforms trusted semantic inputs into structured performance intelligence and executes deterministic training decisions.
Tier-3 now operates as a closed-loop system with hierarchical control: performance intelligence drives prescription, but phase governance can override execution.
CANONICAL SEMANTIC DATA (URF v5.1)
β
βΌ
Tier-3A: Stress Intelligence (PI)
(WDRM / ISDM / NDLI)
β
βΌ
Tier-3B: Progression Intelligence
ESPE v1 β Power Curve Adaptation (ACTIVE)
β
βΌ
Tier-3C: System Modeling
(PI + ESPE synthesis)
β
βΌ
ADE v2 β Adaptive Decision Engine
(Operational Layer β metrics driven)
β
βΌ
PHASE GOVERNANCE LAYER (Strategic Override)
(required_phase enforcement)
β
βΌ
COACHING SEMANTIC LAYER (v5)
β
βΌ
Final Structured Report
π Stage 1 β Stress Intelligence (PI)
Evaluates how the athlete expresses training load under fatigue.
- WDRM β Anaerobic repeatability and Wβ² depletion behavior
- ISDM β Durability and fatigue resistance
- NDLI β Neural load density and intensity clustering
Answers: βCan the athlete tolerate additional stress?β
π Stage 2 β Progression Intelligence (ESPE v1 β Active)
Tracks energy system adaptation using deterministic power curve comparison.
- Endurance (60min trend)
- Threshold (20min trend)
- VOβ Capacity (5min trend)
- Anaerobic Repeatability (1min + Wβ² behavior)
Answers: βIs current training producing adaptation?β
𧬠Stage 3 β System Modeling
Combines stress signals (PI) and progression signals (ESPE) into a unified physiological state model.
- Energy system balance
- Durability gradient
- Adaptation bias
- Plateau detection
This stage defines system capability and constraints.
π§ Stage 4 β ADE v2 (Operational Decision Layer)
Executes rule-based training adjustments based on current physiological state.
IF: Neural density high AND Repeatability decreasing AND FatigueTrend elevated THEN: Reduce VO2 duration 15% Convert tempo β endurance Insert OFF day
This layer answers: βWhat can the athlete handle right now?β
π§ Stage 5 β Phase Governance (Strategic Override Layer)
Enforces mesocycle intent over short-term optimisation.
Critical rule:
IF: required_phase != operational_state THEN: override ADE decision
This layer answers: βWhat should the athlete be doing now?β
- Prevents fatigue accumulation drift
- Forces recovery / taper when required
- Ends blocks when adaptation saturates
Hierarchy:
Phase (strategy) > ADE (execution)
π§ Training State Model (ADE v2)
Operational States: load_progression stable_load absorption_required recovery_priority
These states define execution capacity, but do not override phase intent.
π¦ Coaching Semantic Output (v5)
adaptive_layer: operational_state required_phase phase_alignment resolution adaptation_focus prescription_adjustment
The system supports:
- Athlete Mode β Clear directive
- Coach Mode β Full traceability
Complexity is abstracted in Athlete Mode, but fully accessible in Coach Mode. The system hides complexity β it never hides transparency.
π¬ Contact
For integration, customization, or support inquiries, connect via GitHub link below or DM via Intervals.icu DM and contribute in Intervals.icu Forum.
github.com/revo2wheels
Built with β€οΈ for endurance athletes β by Clive King.
Made in the Suisse Alps π¨π.
Powered by Intervals.icu, Cloudflare and the Railway Engine.