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 (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.

Answers: β€œCan the athlete tolerate additional stress?”


πŸ“ˆ Stage 2 β€” Progression Intelligence (ESPE v1 β€” Active)

Tracks energy system adaptation using deterministic power curve comparison.

Answers: β€œIs current training producing adaptation?”


🧬 Stage 3 β€” System Modeling

Combines stress signals (PI) and progression signals (ESPE) into a unified physiological state model.

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?”

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:

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.

⬆