# jubayeronrob/vinci-monsoon architecture

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

- Interactive diagram: https://gitdiagram.com/jubayeronrob/vinci-monsoon
- Repository: https://github.com/jubayeronrob/vinci-monsoon

## Overview

1. **Purpose and deployment shape**
   - This repo is a containerized “hybrid router” for a benchmark harness.
   - Its only contract is to read `/input/tasks.json`, process each task, and write `/output/results.json`, then exit 0.

2. **Top-level execution path**
   - `entrypoint.py` is the runtime entry.
   - It likely orchestrates the full pipeline: load tasks, classify each task, decide whether to answer locally or escalate, then serialize final results.

3. **Stage 1: local task classification**
   - `src/router/classifier.py` performs the first pass entirely on-device.
   - The README says this stage uses a local llama.cpp-backed model with grammar-constrained JSON output.
   - The classifier predicts three fields: `intent`, `difficulty` (`shallow` or `deep`), and `confidence` (`high` or `low`).

4. **Stage 2: routing and escalation policy**
   - `src/router/dispatch.py` applies the policy after classification.
   - The central routing rules live in `config/routing_map.yaml`.
   - The key architectural split is:
     - **trusted + shallow** tasks go to the local model for a zero-token answer.
     - everything else is escalated to Fireworks through the remote judging proxy.

5. **Intent-to-role mapping boundary**
   - The routing map groups work into categories such as reasoning, code, and general.
   - Those categories map to roles like math, logic, debugging, generation, factual, sentiment, summarize, and NER.
   - This mapping is a policy layer, not hardcoded model selection; it is intended to be editable at launch time.

6. **Remote LLM access**
   - `src/api_clients/fireworks.py` is the only external API client.
   - It uses `FIREWORKS_API_KEY` and `FIREWORKS_BASE_URL`, so all remote model calls are forced through the provided proxy.
   - The README notes per-request retry logic and a 25-second timeout, which is a key operational boundary for the architecture.

7. **Local model subsystem**
   - `src/local_models/loader.py` owns CPU-only GGUF loading and local inference setup.
   - The local model path comes from `LOCAL_MODEL_PATH`, defaulting to `/models/model.gguf`.
   - If no real model is present, the loader falls back to a heuristic backend so the pipeline can still run offline for development and tests.

8. **Model selection is environment-driven**
   - The repo does not hardcode remote model IDs.
   - Instead, roles are resolved at runtime by case-insensitive substring matching against `ALLOWED_MODELS`, with fallback to the first allowed entry.
   - This makes model choice an external deployment concern rather than a code dependency.

9. **Failure handling and answer completeness**
   - The architecture is intentionally fail-soft.
   - If a remote call fails, the system falls back to the local path rather than returning an empty result.
   - That “never empty answer” behavior is a core reliability boundary in the design.

10. **Configuration and prompts**
   - The `config/` directory holds non-code control planes: routing policy, prompt templates, and any classifier instructions.
   - `config/prompts.py` and `config/routing_map.yaml` separate prompt/routing behavior from execution logic, which makes tuning easier without changing the core router.

11. **Testing and offline evaluation**
   - `tests/mock_tasks.json` provides representative inputs.
   - `tests/run_eval.py` appears to support offline evaluation, likely with Fireworks mocked.
   - `tests/test_schema.py` enforces output shape/validity, which is important because the harness only accepts correctly structured results.

12. **Packaging and runtime constraints**
   - The repo is designed for a Linux amd64 Docker image with CPU-only execution.
   - The README emphasizes a small memory footprint and no GPU dependency, which explains the choice of compact GGUF local models and aggressive escalation to remote models only when needed.

13. **End-to-end data flow**
   - Input tasks arrive from the harness.
   - Stage 1 classifies each task locally.
   - Stage 2 decides local answer vs. remote escalation based on `config/routing_map.yaml` and `ALLOWED_MODELS`.
   - The final answers are collected and written to `/output/results.json`.

14. **Main architectural boundary**
   - The biggest design boundary is between **local inference** and **remote inference**.
   - Everything before routing is optimized for zero-token, low-latency local handling; everything after routing is a controlled, env-driven Fireworks escalation path.

Main entry points: [`src/router/dispatch.py`](https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/router/dispatch.py) (Dispatcher), [`entrypoint.py`](https://github.com/jubayeronrob/vinci-monsoon/blob/main/entrypoint.py) (Entrypoint), [`src/api_clients/fireworks.py`](https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/api_clients/fireworks.py) (Fireworks client), [`src/router/classifier.py`](https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/router/classifier.py) (Classifier)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime flow"]
  node_entrypoint["Entrypoint<br/>runtime<br/>[entrypoint.py]"]
  node_tasks_input["Task input<br/>io"]
  node_results_output["Results output<br/>io"]
end

subgraph group_policy["Routing policy"]
  node_classifier["Classifier<br/>router stage<br/>[classifier.py]"]
  node_dispatch["Dispatcher<br/>router stage<br/>[dispatch.py]"]
  node_routing_map["Routing map<br/>policy config<br/>[routing_map.yaml]"]
  node_prompts["Prompts<br/>policy config<br/>[prompts.py]"]
end

subgraph group_models["Model backends"]
  node_local_loader[("Local loader<br/>local runtime<br/>[loader.py]")]
  node_heuristic_backend(("Heuristic fallback<br/>local fallback<br/>[loader.py]"))
  node_fireworks_client[("Fireworks client<br/>remote api<br/>[fireworks.py]")]
  node_model_selector["Model selector<br/>env policy"]
  node_allowed_models["Allowed models<br/>env config"]
end

subgraph group_qa["Validation"]
  node_schema_tests["Schema tests<br/>validation<br/>[test_schema.py]"]
  node_offline_eval["Offline eval<br/>validation<br/>[run_eval.py]"]
  node_mock_tasks["Mock tasks<br/>test data<br/>[mock_tasks.json]"]
end

node_tasks_input -->|"read"| node_entrypoint
node_entrypoint -->|"classify"| node_classifier
node_classifier -->|"uses"| node_prompts
node_classifier -->|"task metadata"| node_dispatch
node_dispatch -->|"consults"| node_routing_map
node_dispatch -->|"local path"| node_local_loader
node_local_loader -.->|"fallback"| node_heuristic_backend
node_dispatch -->|"selects"| node_model_selector
node_model_selector -->|"matches against"| node_allowed_models
node_dispatch -->|"escalate"| node_fireworks_client
node_fireworks_client -->|"remote result"| node_entrypoint
node_fireworks_client -.->|"fail-soft fallback"| node_local_loader
node_entrypoint -->|"write"| node_results_output
node_schema_tests -.->|"validate"| node_results_output
node_offline_eval -->|"loads"| node_mock_tasks
node_offline_eval -.->|"mocks"| node_fireworks_client

click node_entrypoint "https://github.com/jubayeronrob/vinci-monsoon/blob/main/entrypoint.py"
click node_classifier "https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/router/classifier.py"
click node_dispatch "https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/router/dispatch.py"
click node_routing_map "https://github.com/jubayeronrob/vinci-monsoon/blob/main/config/routing_map.yaml"
click node_prompts "https://github.com/jubayeronrob/vinci-monsoon/blob/main/config/prompts.py"
click node_local_loader "https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/local_models/loader.py"
click node_heuristic_backend "https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/local_models/loader.py"
click node_fireworks_client "https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/api_clients/fireworks.py"
click node_schema_tests "https://github.com/jubayeronrob/vinci-monsoon/blob/main/tests/test_schema.py"
click node_offline_eval "https://github.com/jubayeronrob/vinci-monsoon/blob/main/tests/run_eval.py"
click node_mock_tasks "https://github.com/jubayeronrob/vinci-monsoon/blob/main/tests/mock_tasks.json"

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_entrypoint,node_tasks_input,node_results_output toneBlue
class node_classifier,node_dispatch,node_routing_map,node_prompts toneAmber
class node_local_loader,node_heuristic_backend,node_fireworks_client,node_model_selector,node_allowed_models toneMint
class node_schema_tests,node_offline_eval,node_mock_tasks toneRose
```

## Components

### Runtime flow

Container entrypoint and end-to-end task processing path.

- [Entrypoint](https://github.com/jubayeronrob/vinci-monsoon/blob/main/entrypoint.py): runtime · Container entry that reads tasks, runs the router, and writes results. · `entrypoint.py`
- **Task input**: io · Benchmark harness input file at /input/tasks.json.
- **Results output**: io · Final answer file written at /output/results.json.

### Routing policy

Classification, dispatch, and editable control-plane configuration.

- [Classifier](https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/router/classifier.py): router stage · Local first-pass task classifier producing intent, difficulty, and confidence. · `src/router/classifier.py`
- [Dispatcher](https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/router/dispatch.py): router stage · Applies routing policy and chooses local answer or escalation. · `src/router/dispatch.py`
- [Routing map](https://github.com/jubayeronrob/vinci-monsoon/blob/main/config/routing_map.yaml): policy config · Editable intent-to-role mapping and escalation policy. · `config/routing_map.yaml`
- [Prompts](https://github.com/jubayeronrob/vinci-monsoon/blob/main/config/prompts.py): policy config · Prompt templates and classifier instructions. · `config/prompts.py`

### Model backends

Local inference and remote escalation paths.

- [Local loader](https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/local_models/loader.py): local runtime · Loads CPU-only GGUF models and sets up local inference. · `src/local_models/loader.py`
- [Heuristic fallback](https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/local_models/loader.py): local fallback · Offline fallback when no real local model is available. · `src/local_models/loader.py`
- [Fireworks client](https://github.com/jubayeronrob/vinci-monsoon/blob/main/src/api_clients/fireworks.py): remote api · Single remote client for proxy-mediated model calls with retries and timeout. · `src/api_clients/fireworks.py`
- **Model selector**: env policy · Resolves allowed remote model choice from environment via substring matching.
- **Allowed models**: env config · Deployment-provided set of permitted remote model names.

### Validation

Offline evaluation and schema checks.

- [Schema tests](https://github.com/jubayeronrob/vinci-monsoon/blob/main/tests/test_schema.py): validation · Checks output shape and validity for harness compatibility. · `tests/test_schema.py`
- [Offline eval](https://github.com/jubayeronrob/vinci-monsoon/blob/main/tests/run_eval.py): validation · Local evaluation harness for representative mock tasks. · `tests/run_eval.py`
- [Mock tasks](https://github.com/jubayeronrob/vinci-monsoon/blob/main/tests/mock_tasks.json): test data · Representative input tasks used for offline evaluation. · `tests/mock_tasks.json`

## Connections

- Task input → Entrypoint: read · Harness input is consumed by the runtime entry.
- Entrypoint → Classifier: classify · Each task is first classified locally.
- Classifier → Prompts: uses · Classifier behavior is driven by prompt instructions.
- Classifier → Dispatcher: task metadata · Classification output feeds routing decisions.
- Dispatcher → Routing map: consults · Dispatcher applies the editable policy map.
- Dispatcher → Local loader: local path · Trusted shallow tasks are answered locally.
- Local loader → Heuristic fallback: fallback · If no real model exists, inference degrades to heuristics.
- Dispatcher → Model selector: selects · Escalated work chooses a remote model at runtime.
- Model selector → Allowed models: matches against · Model selection is constrained by deployment allowlist.
- Dispatcher → Fireworks client: escalate · Non-local tasks are sent to the remote judging proxy.
- Fireworks client → Entrypoint: remote result · Remote responses return to the orchestrator for assembly.
- Fireworks client → Local loader: fail-soft fallback · Remote failure falls back to local handling instead of empty output.
- Entrypoint → Results output: write · Final results are serialized for the harness.
- Schema tests → Results output: validate · Tests enforce the required output structure.
- Offline eval → Mock tasks: loads · Offline evaluation runs against representative tasks.
- Offline eval → Fireworks client: mocks · Evaluation can simulate the remote path.
