App Icon Montis.icu

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.

This separation enforces:

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.

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.

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.

flowchart TB subgraph Clients["Clients"] direction TB A1["Browser /app"] A2["Gemini App"] A3["ChatGPT GPT Actions"] A4["Claude / Codex MCP Clients"] A5["CLI report.py"] end subgraph Cloudflare["Cloudflare Services"] direction TB subgraph Entry["Entry / Auth Wrapper"] direction TB B1["Browser/App session
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

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:


🧩 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

βš™οΈ Current Operational Pipeline (Production)

Status: Live β€’ Used in production β€’ Backward compatible

flowchart TB subgraph Clients["Clients"] direction TB A1["Browser /app"] A2["Gemini App"] A3["CLI report.py"] A4["ChatGPT GPT Actions"] A5["Claude / Codex MCP Clients"] end subgraph Cloudflare["Cloudflare Services"] direction TB subgraph Routes["Worker Routes"] direction TB B1["/connect"] B2["/logout / /disconnect"] B3["/oauth/* GPT facade"] B4["/mcp"] B5["/connection/status"] B6["/run_*"] B7["/calendar/*"] B8["/athlete/*"] B9["Unified Auth Resolver"] B10["Dispatcher / Internal Tools"] end subgraph KV["Cloudflare KV"] direction TB C1["SESSIONS"] C2["MCP_GRANTS"] C3["INTERVALS_TOKENS
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


⚠️ Important Clarification

πŸ”‘ Key Insights


βš™οΈ How It Works (End-to-End)

  1. User or AI issues a natural-language request
    Example: β€œExplain my weekly intensity balance and recovery status.”
  2. Request is converted into a tool call (direct or MCP)
    • Strongly typed inputs
    • Explicit report scope (weekly / season / activity)
  3. Cloudflare Services handle trust and policy
    • OAuth token exchange with Intervals.icu
    • Scope validation
    • Rate limiting
    • Parameter normalization
  4. 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)
  5. Canonical semantic JSON is produced
    • URF v5.1 contract
    • Explicit context windows
    • Deterministic numeric precision
    • No derived ambiguity
  6. 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:

The result is a system that is:

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.

🎯 Decision Governance

🧠 Montis Intelligence Stack

From raw training load to adaptive coaching decisions β€” a closed-loop performance system.

Montis Intelligence Stack

🧠 Coaching Intelligence Pipeline

Status: Active β€’ PI v1.61 β€’ ESPE v1.2 β€’ ADE v2.21 β€’ Deterministic β€’ Production

The Coaching Intelligence Pipeline operates on validated Tier-1 and Tier-2 outputs. It does not recompute canonical metrics. Tier-3 models capability under stress, ESPE evaluates adaptation direction, and ADE produces the operational decision before phase and event governance determine the final coaching instruction.

VALIDATED TIER-1 / TIER-2 OUTPUTS
                β”‚
                β–Ό
Performance Intelligence β€” PI v1.61
WDRM / ISDM / NDLI
                β”‚
                β–Ό
Training State
load_accepting / recovery_priority
                β”‚
                β–Ό
Energy System Progression β€” ESPE v1.2
Power-curve adaptation state
                β”‚
                β–Ό
ADE v2.21 BASE DECISION β€” CAN
Operational capacity and risk
                β”‚
                β–Ό
PHASE + EVENT GOVERNANCE β€” SHOULD
Recovery, build, taper and event-form control
                β”‚
                β–Ό
SEMANTIC OUTPUT
Actions / Guidance / Alignment / Event Context
                β”‚
                β–Ό
LLM RENDERING
Read-only interpretation

βš™οΈ Stage 1 β€” Performance Intelligence

Performance Intelligence evaluates how fitness is expressed under current stress.

Weekly reports use the 7-day FULL dataset. Season and Summary reports use the 90-day LIGHT dataset with a 7-day FULL acute overlay.

PI does not directly measure CNS fatigue, Wβ€² recovery between efforts, or stream-level late-session power decay.


🧠 Stage 2 β€” Training State

Montis combines load, wellness, forecast, and Performance Intelligence into a consolidated Training State.

ADE consumes two operational states:

load_accepting
recovery_priority

πŸ“ˆ Stage 3 β€” ESPE v1.2

ESPE evaluates power-curve progression using two normalized comparison windows, normally equal rolling windows of approximately 84 days.

Anchor Primary system
1 minuteAnaerobic
5 minutesVOβ‚‚
20 minutesThreshold
60 minutesAerobic durability

ESPE also exposes CP, Wβ€², pMax, FTP, regression slope, regression RΒ², curve quality, curve profile, plateau state, adaptation bias, and adaptation state.

When no previous comparison window exists, ESPE returns a baseline state rather than inventing progression.


🎯 Stage 4 β€” ADE v2.21 Base Decision

ADE determines what the athlete can tolerate now.

It consumes the governed operational state, forecast fatigue, load trend, HRV ratio, ESPE adaptation state, nutrition context, and target-event context.

ADE produces a pre-governance score and directive. It does not directly rewrite workouts or automatically insert calendar events.


🧭 Stage 5 β€” Phase and Event Governance

Phase and event governance determine what the athlete should do.

Recovery and Deload share a recovery bucket. Taper remains separate because event form can justify selective intensity preservation or sharpening.

Can: ADE operational directive
Should: governed phase and event action

πŸ“¦ Final Semantic Output

performance_intelligence
energy_system_progression
actions
training_guidance
decision_context
phase_alignment
event_targets
future_forecast

Final ADE resolution is classified as:

The LLM renders this governed output. It does not compute metrics, replace classifications, or invent a competing coaching directive.

πŸ“¬ 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.

⬆