How ymoola/llm4cp-mod-ref works
1. This repository has two major subsystems:
- src/cpmod_web: a product-oriented web app for managing projects, change requests, runs, and model packages.
- src/mod-ref-benchmark: an offline benchmark / agent pipeline for model-refinement experiments on structured problem folders.
2. The web app is split into a Python backend and a Next.js frontend. The backend is the system of record for projects, model packages, change requests, and run records; the frontend is the interactive UI that calls the backend APIs and also talks directly to Supabase for authentication.
3. Backend entrypoint and API boundary:
- backend/main.py wires the FastAPI application.
- backend/routers/* exposes domain routes for projects, runs, dashboard, settings, model packages, and change requests.
- backend/middleware/auth.py sits at the request boundary to enforce auth behavior.
This creates a clear separation between HTTP transport and the underlying domain/services.
4. Backend domain logic is organized by service layer:
- model_package_service.py, resource_service.py, storage_service.py, credential_service.py, dependency_policy.py, diff_service.py, and llm_service.py encapsulate business logic.
- workflow/* contains the orchestration logic for automated change-request processing, with graph/state/schema/prompt definitions.
- services/execution/* abstracts execution environments through a common base, with local and E2B implementations selected via a factory.
This means “what to do” is separated from “how/where it runs.”
5. Persistence is Supabase-backed. The backend db/supabase_client.py and db/queries.py indicate a query layer over Supabase rather than a local database. The supabase/migrations/*.sql files define the schema evolution for core entities such as projects, change requests, run metadata, credentials, model selections, and validation artifacts.
6. The frontend is a Next.js app (frontend/app/*) using the app router structure. It has auth pages, dashboard, project views, model-package pages, run pages, and settings. UI components like run-launcher, run-viewer, diff-view, cr-form, and model-upload map closely to backend concepts, so the frontend is mostly a presentation and interaction layer rather than a separate domain engine.
7. Frontend infrastructure details matter architecturally:
- frontend/lib/api.ts centralizes backend API calls.
- frontend/lib/supabase.ts handles Supabase client/auth integration.
- frontend/middleware.ts and components/auth-gate.tsx enforce authenticated routing on the client side.
This means the browser is not just rendering data; it is also participating in auth/session management.
8. The backend’s workflow subsystem is the automation core for the web product. It likely coordinates:
- parsing model/reference artifacts,
- generating or revising changes,
- executing candidate models,
- validating outputs,
- serializing run state and logs.
The workflow/service.py, graph.py, state.py, schemas.py, and prompts.py files indicate a graph-based or state-machine-like orchestration boundary around LLM-driven steps.
9. Execution is explicitly abstracted as an environment boundary:
- services/execution/local.py for local runs,
- services/execution/e2b.py for remote/sandboxed runs,
- services/execution/harness.py for the common contract.
This is important for the architecture diagram because model execution is not assumed to happen inside the web server process.
10. src/mod-ref-benchmark is a separate experimental pipeline, not part of the web product runtime. It contains:
- benchmark problem corpora under problems/,
- standalone agent scripts for parser/planner/modifier/executor/validator,
- a LangGraph-based orchestrator under langgraph_workflow/,
- baseline and ablation experiment runners.
Its primary boundary is filesystem-based problem folders rather than an HTTP API.
11. The benchmark data model is folder-centric. Each problemN directory contains a base problem description and reference model plus multiple CR subfolders with CR-specific descriptions, input data, unit tests, and generated outputs/logs. That structure is the main input/output contract for the benchmark agents.
12. The benchmark workflow is a staged LLM pipeline:
- Parser aligns natural language to code structure.
- Planner produces a structured edit plan using CR context and parser output.
- Modifier rewrites the target model.
- Executor runs the candidate model to capture behavior/errors.
- Validator reviews generated vs. reference behavior and can feed iterative repair loops.
The README makes clear that this pipeline is designed to end in a unit test run when validation passes.
13. llm_client.py, llm_prompts.py, llm_schemas.py, and model_presets.py in the benchmark package are the shared LLM integration layer. They standardize provider access, prompt content, and structured outputs across the various agent stages and experiments.
14. In diagram terms, the key boundaries are:
- browser/UI vs. backend API,
- backend services vs. Supabase persistence,
- orchestration logic vs. execution sandboxes,
- product web app vs. benchmark/experiment pipeline.
The repository is therefore best drawn as two related but distinct systems sharing the same research theme: one operational web app and one offline evaluation harness for model refinement.
Main entry points: main.py Backend app · workflow.py LangGraph flow · page.tsx Next app · model_package_service.py Domain services
Components 19
cpmod_web
Product web app for projects, change requests, runs, and model packages.
- Backend app · Wires the HTTP application and mounts routers.
src/cpmod_web/backend/main.py - Auth guard · Request-boundary auth enforcement for backend traffic.
src/cpmod_web/backend/middleware/auth.py - API routes · Domain HTTP endpoints for projects, runs, dashboard, settings, model packages, and change requests.
src/cpmod_web/backend/routers/projects.py - Domain services · Business logic for packages, resources, storage, credentials, diffs, policies, and LLM support.
src/cpmod_web/backend/services/model_package_service.py - CR workflow · Graph/state-based automation for change-request processing and LLM-driven steps.
src/cpmod_web/backend/workflow/service.py - Execution env · Common execution contract with local and remote E2B implementations plus factory selection.
src/cpmod_web/backend/services/execution/factory.py - Supabase DB · Supabase client and query layer backing the system of record.
src/cpmod_web/backend/db/supabase_client.py - Schema migrations · Migration history for projects, change requests, runs, credentials, model selections, and validation artifacts.
src/cpmod_web/supabase/migrations/001_initial_schema.sql - Next app · App-router UI for auth, dashboard, projects, runs, settings, and package pages.
src/cpmod_web/frontend/app/page.tsx - API client · Centralized backend API calls from the browser app.
src/cpmod_web/frontend/lib/api.ts - Supabase auth · Browser-side Supabase client and session integration.
src/cpmod_web/frontend/lib/supabase.ts - Auth gate · Authenticated routing and access control on the client side.
src/cpmod_web/frontend/components/auth-gate.tsx - UI views · Project, run, diff, CR form, and upload views mapped to backend concepts.
src/cpmod_web/frontend/components/run-viewer.tsx
mod-ref-benchmark
Offline model-refinement benchmark and experiment pipeline.
- Problem folders · Folder-centric benchmark inputs with base problem data and CR-specific subfolders.
src/mod-ref-benchmark/problems/problem1/base/problem_desc.txt - LLM core · Provider access, prompts, schemas, and model presets shared across benchmark agents.
src/mod-ref-benchmark/llm_client.py - LangGraph flow · Staged parser/planner/modifier/executor/validator workflow for refinement experiments.
src/mod-ref-benchmark/langgraph_workflow/workflow.py - Agents · Parser, planner, modifier, executor, and validator agent implementations.
src/mod-ref-benchmark/langgraph_workflow/agents/parser_agent.py - Experiments · Baseline runner, ablations, and cross-model evaluation scripts.
src/mod-ref-benchmark/baseline/run_baseline.py - Legacy flow · Simpler earlier mod-ref workflow used alongside the LangGraph pipeline.
src/mod-ref-benchmark/og_workflow_simple/run_modref.py
Connections 20
- Backend app → Auth guard: enforces · Request handling passes through auth middleware.
- Backend app → API routes: mounts · FastAPI app wires the domain routers.
- API routes → Domain services: delegates · Routers call into service-layer business logic.
- Domain services → CR workflow: orchestrates · Change-request processing uses workflow orchestration.
- CR workflow → Execution env: runs in · Workflow invokes execution environments through the adapter contract.
- Domain services → Supabase DB: queries · Services persist and retrieve records through Supabase queries.
- Supabase DB → Schema migrations: shaped by · Schema evolution defines the persistence model.
- Next app → Auth gate: guards · Client routes are protected by the auth gate.
- Auth gate → Supabase auth: uses · Auth state is sourced from Supabase on the client.
- Next app → API client: calls · UI pages fetch and mutate via the centralized API client.
- Next app → UI views: composes · Pages are built from shared product-specific components.
- API client → Backend app: consumes · Browser UI talks to the FastAPI backend.
- Supabase auth → Supabase DB: authenticates · Frontend session management aligns with Supabase-backed backend data.
- LangGraph flow → LLM core: uses · Workflow stages share prompts, schemas, and model/provider access.
- LangGraph flow → Agents: coordinates · The orchestrator runs the staged agents.
- Agents → Problem folders: reads/writes · Agents operate over problem folders and generated artifacts.
- Experiments → LangGraph flow: executes · Baseline and evaluation scripts drive the workflow pipeline.
- Legacy flow → LLM core: uses · Legacy workflow also relies on the shared LLM layer.
- Problem folders → Experiments: evaluates · Experiment runs consume the benchmark corpus.
- Backend app → LangGraph flow: separate runtime · Architecturally distinct systems; no direct in-process dependency implied.