# shaivpidadi/freeride architecture

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

- Interactive diagram: https://gitdiagram.com/shaivpidadi/freeride
- Repository: https://github.com/shaivpidadi/freeride

## Overview

1. **What this repo is**
   - **FreeRide** is a Python-based CLI skill for **OpenClaw** that automates model selection for **OpenRouter free models**.
   - It is not an application server or UI app; its core job is to **inspect available models, choose/rank them, and rewrite OpenClaw configuration** so the gateway can use free models and fallbacks.

2. **Primary execution paths**
   - The main user-facing entrypoint is the **`freeride` CLI**.
   - A second entrypoint, **`freeride-watcher`**, runs the monitoring/rotation loop that reacts to rate limits and switches models automatically.
   - These are the two operational subsystems the architecture diagram should show as separate but related command-line tools.

3. **Core orchestration flow**
   - The main flow is: **user command → model discovery → ranking → config update → OpenClaw restart**.
   - FreeRide does not itself serve traffic; it **prepares OpenClaw’s model configuration** so OpenClaw can route future agent requests through OpenRouter.

4. **Model selection subsystem**
   - FreeRide’s central logic is around **enumerating free OpenRouter models**, assigning a score, and selecting the best primary model plus fallbacks.
   - The README describes the ranking dimensions as **context length, capabilities, recency, and provider trust**.
   - A special router model, **`openrouter/free`**, is treated as the first fallback because it dynamically chooses among available free models.

5. **Configuration management boundary**
   - The main persistence boundary is **OpenClaw’s local config** under the user’s home workspace, specifically the OpenClaw JSON configuration mentioned in the README.
   - FreeRide is careful to modify only the model-related parts: **`agents.defaults.model`** and **`agents.defaults.models`**.
   - Everything else in the OpenClaw config is intended to remain untouched, so the diagram should show FreeRide as a **targeted config editor**, not a full config owner.

6. **External service boundary: OpenRouter**
   - FreeRide depends on **OpenRouter’s API** as the source of truth for available free models and availability changes.
   - The user provides an **`OPENROUTER_API_KEY`** via environment variable or OpenClaw config.
   - The API boundary matters because model availability and rate limits are external, dynamic inputs to both the auto-configuration and watcher behavior.

7. **Watcher / auto-rotation subsystem**
   - `watcher.py` backs a daemon-like process that monitors for **rate limits** and **rotates to the next model** when needed.
   - This subsystem is distinct from the one-time setup commands: it is the **runtime resilience layer** that keeps OpenClaw usable after the initial config is applied.
   - The watcher also supports operational actions like checking status, forcing rotation, and clearing cooldowns.

8. **Command surface / user interactions**
   - The CLI exposes distinct commands for different phases of the workflow:
     - **auto**: full discovery + rank + configure
     - **list**: inspect available models
     - **switch**: choose a specific model
     - **status**: inspect current setup
     - **fallbacks**: update only fallback list
     - **refresh**: rebuild the model cache
   - These commands are likely implemented in `main.py` and should be shown as the primary control surface.

9. **Packaging and distribution**
   - `setup.py` indicates this is packaged as an installable Python tool, likely with console entrypoints for the two commands.
   - `requirements.txt` defines the runtime dependency set, suggesting the repository is intended to be installed locally into the OpenClaw skill workspace rather than deployed as a service.

10. **Skill/marketplace metadata**
   - `skill.json` and `SKILL.md` indicate integration with the **ClawHub/OpenClaw skill ecosystem**.
   - These files are not part of the runtime logic, but they are important architectural metadata for **installation, discovery, and documentation** in the host platform.

11. **Operational dependency on OpenClaw**
   - FreeRide assumes OpenClaw is already installed and that the operator can run **`openclaw gateway restart`** after config changes.
   - This makes OpenClaw the downstream consumer of FreeRide’s output: FreeRide prepares the config; OpenClaw actually uses it to route agent traffic.

12. **End-to-end data flow to show in a diagram**
   - **Input sources:** user CLI command, environment variable/API key, OpenRouter model list, existing OpenClaw config.
   - **Processing:** model ranking, primary/fallback selection, optional watcher-based rotation.
   - **Output:** updated OpenClaw config and, indirectly, model routing behavior inside the OpenClaw gateway.

13. **Important architectural takeaway**
   - The repo is essentially a **local automation layer** around an external model marketplace and a local agent runtime.
   - Its responsibility is limited but critical: **keep OpenClaw pointed at the best currently-available free OpenRouter model, and recover automatically when rate limits occur**.

Main entry points: [`main.py`](https://github.com/shaivpidadi/freeride/blob/main/main.py) (freeride CLI), [`watcher.py`](https://github.com/shaivpidadi/freeride/blob/main/watcher.py) (Rotation loop), [`setup.py`](https://github.com/shaivpidadi/freeride/blob/main/setup.py) (setup.py), [`skill.json`](https://github.com/shaivpidadi/freeride/blob/main/skill.json) (skill.json)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_cli["CLI surface"]
  node_n_main["freeride CLI<br/>command entrypoint<br/>[main.py]"]
  node_n_auto(("Auto setup<br/>workflow<br/>[main.py]"))
  node_n_list(("List models<br/>command<br/>[main.py]"))
  node_n_switch(("Switch model<br/>command<br/>[main.py]"))
  node_n_status(("Status check<br/>command<br/>[main.py]"))
  node_n_fallbacks(("Fallbacks<br/>command<br/>[main.py]"))
  node_n_refresh(("Refresh cache<br/>command<br/>[main.py]"))
end

subgraph group_grp_core["Selection logic"]
  node_n_discovery[("Model discovery<br/>api client<br/>[main.py]")]
  node_n_ranking{{"Rank models<br/>scoring engine<br/>[main.py]"}}
  node_n_selector["Select set<br/>policy<br/>[main.py]"]
  node_n_config["Config editor<br/>mutator<br/>[main.py]"]
end

subgraph group_grp_runtime["Watcher runtime"]
  node_n_watcher["freeride-watcher<br/>monitor entrypoint<br/>[watcher.py]"]
  node_n_rotation{{"Rotation loop<br/>resilience loop<br/>[watcher.py]"}}
end

subgraph group_grp_external["External systems"]
  node_n_restart(("Gateway restart<br/>operation"))
  node_n_openrouter[("OpenRouter API<br/>external service")]
  node_n_openclaw["OpenClaw config<br/>local state"]
end

subgraph group_grp_meta["Packaging metadata"]
  node_n_setup["setup.py<br/>packaging<br/>[setup.py]"]
  node_n_requirements["requirements.txt<br/>dependencies<br/>[requirements.txt]"]
  node_n_skill["skill.json<br/>skill metadata<br/>[skill.json]"]
  node_n_skillmd["SKILL.md<br/>skill docs<br/>[SKILL.md]"]
end

node_n_main -->|"dispatches"| node_n_auto
node_n_main -->|"dispatches"| node_n_list
node_n_main -->|"dispatches"| node_n_switch
node_n_main -->|"dispatches"| node_n_status
node_n_main -->|"dispatches"| node_n_fallbacks
node_n_main -->|"dispatches"| node_n_refresh
node_n_auto -->|"fetches"| node_n_discovery
node_n_list -->|"reads"| node_n_discovery
node_n_refresh -->|"rebuilds"| node_n_discovery
node_n_discovery -->|"feeds"| node_n_ranking
node_n_ranking -->|"produces"| node_n_selector
node_n_selector -->|"writes"| node_n_config
node_n_config -->|"targets"| node_n_openclaw
node_n_config -->|"after change"| node_n_restart
node_n_watcher -->|"runs"| node_n_rotation
node_n_rotation -->|"monitors"| node_n_openrouter
node_n_rotation -->|"advances"| node_n_selector
node_n_rotation -->|"updates"| node_n_config
node_n_selector -->|"consults"| node_n_openrouter
node_n_main -->|"auth via key"| node_n_openrouter
node_n_setup -->|"installs"| node_n_main
node_n_setup -->|"installs"| node_n_watcher
node_n_setup -->|"depends on"| node_n_requirements
node_n_skill -->|"describes"| node_n_main
node_n_skillmd -->|"documents"| node_n_main
node_n_openclaw -->|"consumed by"| node_n_restart

click node_n_main "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_auto "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_list "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_switch "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_status "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_fallbacks "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_refresh "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_discovery "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_ranking "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_selector "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_config "https://github.com/shaivpidadi/freeride/blob/main/main.py"
click node_n_watcher "https://github.com/shaivpidadi/freeride/blob/main/watcher.py"
click node_n_rotation "https://github.com/shaivpidadi/freeride/blob/main/watcher.py"
click node_n_setup "https://github.com/shaivpidadi/freeride/blob/main/setup.py"
click node_n_requirements "https://github.com/shaivpidadi/freeride/blob/main/requirements.txt"
click node_n_skill "https://github.com/shaivpidadi/freeride/blob/main/skill.json"
click node_n_skillmd "https://github.com/shaivpidadi/freeride/blob/main/SKILL.md"

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_n_main,node_n_auto,node_n_list,node_n_switch,node_n_status,node_n_fallbacks,node_n_refresh toneBlue
class node_n_discovery,node_n_ranking,node_n_selector,node_n_config toneAmber
class node_n_watcher,node_n_rotation toneMint
class node_n_restart,node_n_openrouter,node_n_openclaw toneRose
class node_n_setup,node_n_requirements,node_n_skill,node_n_skillmd toneIndigo
```

## Components

### CLI surface

User-facing commands and operational entrypoints

- [freeride CLI](https://github.com/shaivpidadi/freeride/blob/main/main.py): command entrypoint · Primary command surface for discovery, switching, status, and auto-configuration · `main.py`
- [Auto setup](https://github.com/shaivpidadi/freeride/blob/main/main.py): workflow · End-to-end discover, rank, select, and configure flow · `main.py`
- [List models](https://github.com/shaivpidadi/freeride/blob/main/main.py): command · Inspect available free models · `main.py`
- [Switch model](https://github.com/shaivpidadi/freeride/blob/main/main.py): command · Select a specific model and update the target config · `main.py`
- [Status check](https://github.com/shaivpidadi/freeride/blob/main/main.py): command · Inspect current model selection and runtime state · `main.py`
- [Fallbacks](https://github.com/shaivpidadi/freeride/blob/main/main.py): command · Update the fallback model list without a full refresh · `main.py`
- [Refresh cache](https://github.com/shaivpidadi/freeride/blob/main/main.py): command · Rebuild the cached model list from the upstream API · `main.py`

### Selection logic

Discovery, ranking, and config mutation

- [Model discovery](https://github.com/shaivpidadi/freeride/blob/main/main.py): api client · Fetches available free OpenRouter models and availability changes · `main.py`
- [Rank models](https://github.com/shaivpidadi/freeride/blob/main/main.py): scoring engine · Scores models by context, capabilities, recency, and provider trust · `main.py`
- [Select set](https://github.com/shaivpidadi/freeride/blob/main/main.py): policy · Chooses a primary model plus fallback chain, including openrouter/free · `main.py`
- [Config editor](https://github.com/shaivpidadi/freeride/blob/main/main.py): mutator · Updates only agents.defaults.model and agents.defaults.models in OpenClaw config · `main.py`

### Watcher runtime

Rate-limit monitoring and rotation loop

- [freeride-watcher](https://github.com/shaivpidadi/freeride/blob/main/watcher.py): monitor entrypoint · Daemon-like watcher for rate limits and automatic rotation · `watcher.py`
- [Rotation loop](https://github.com/shaivpidadi/freeride/blob/main/watcher.py): resilience loop · Detects rate limits, advances to the next model, and manages cooldowns · `watcher.py`

### External systems

Dependencies outside the repository

- **Gateway restart**: operation · Triggers or expects OpenClaw gateway restart after config changes
- **OpenRouter API**: external service · Source of truth for free model availability and rate limits
- **OpenClaw config**: local state · Local gateway configuration that FreeRide targets and OpenClaw consumes

### Packaging metadata

Installation and skill ecosystem files

- [setup.py](https://github.com/shaivpidadi/freeride/blob/main/setup.py): packaging · Installable Python package and console entrypoint wiring · `setup.py`
- [requirements.txt](https://github.com/shaivpidadi/freeride/blob/main/requirements.txt): dependencies · Runtime dependency set · `requirements.txt`
- [skill.json](https://github.com/shaivpidadi/freeride/blob/main/skill.json): skill metadata · ClawHub/OpenClaw skill metadata for discovery and installation · `skill.json`
- [SKILL.md](https://github.com/shaivpidadi/freeride/blob/main/SKILL.md): skill docs · Human-facing skill documentation and usage notes · `SKILL.md`

## Connections

- freeride CLI → Auto setup: dispatches · Routes the main CLI into the full automation workflow
- freeride CLI → List models: dispatches · Routes the main CLI to model listing
- freeride CLI → Switch model: dispatches · Routes the main CLI to specific model switching
- freeride CLI → Status check: dispatches · Routes the main CLI to status inspection
- freeride CLI → Fallbacks: dispatches · Routes the main CLI to fallback-only updates
- freeride CLI → Refresh cache: dispatches · Routes the main CLI to cache refresh
- Auto setup → Model discovery: fetches · Starts by discovering available models
- List models → Model discovery: reads · Lists models from the upstream source
- Refresh cache → Model discovery: rebuilds · Refreshes cached model data from the API
- Model discovery → Rank models: feeds · Model inventory becomes ranking input
- Rank models → Select set: produces · Turns scored models into a chosen primary and fallbacks
- Select set → Config editor: writes · Persists selected model set into OpenClaw config
- Config editor → OpenClaw config: targets · Edits the local configuration used by OpenClaw
- Config editor → Gateway restart: after change · Config changes are followed by a gateway restart
- freeride-watcher → Rotation loop: runs · Watcher entrypoint drives the rotation loop
- Rotation loop → OpenRouter API: monitors · Checks for rate limits and changing availability
- Rotation loop → Select set: advances · Moves to the next selected model on failure or cooldown
- Rotation loop → Config editor: updates · Rewrites the model selection in OpenClaw config
- Select set → OpenRouter API: consults · Uses upstream availability as a selection constraint
- freeride CLI → OpenRouter API: auth via key · Relies on OPENROUTER_API_KEY for API access
- setup.py → freeride CLI: installs · Packages the main console entrypoint
- setup.py → freeride-watcher: installs · Packages the watcher console entrypoint
- setup.py → requirements.txt: depends on · Declares runtime dependencies
- skill.json → freeride CLI: describes · Metadata for skill installation and use
- SKILL.md → freeride CLI: documents · Usage guidance for the CLI skill
- OpenClaw config → Gateway restart: consumed by · Gateway restart applies the updated local config
