From c46fc18839197e3d3dad5a5a30689e3ad01abc98 Mon Sep 17 00:00:00 2001 From: Pranav Mathad Date: Fri, 4 Dec 2026 19:40:20 +0100 Subject: [PATCH] Lead the README with a project overview and bring it up to date with the app --- README.md | 205 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 170 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 8f203715..8deaa13b 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,142 @@ # CodeXray -CodeXray reads a large codebase and answers one question: +CodeXray checks whether a codebase still keeps its own architecture decisions. Code finds +and ranks the exceptions; AI only explains them. Every claim links to a commit, file and +line. + +Built at hackaTUM 2026 for the CHECK24 track "Visualise and judge a codebase". +[Devpost submission](https://devpost.com/software/code-xray) · +[Specification](spec.md) + +## What it does + +CodeXray reads a Git repository at 14 dates, from January 2024 to the pinned commit of +November 2026, and answers one question: > Are the architecture decisions of this project being kept, and where are they not? -It is our entry for the CHECK24 track of hackaTUM 2026, "Visualise and judge a codebase". -The full specification is [spec.md](spec.md). +- **Decisions come from the project itself.** Its architecture tests and import bans, its + decision documents and agent rule files, and habits the code measurably follows (at + least 50 links between two folder roles, at least 95% of them in one direction). A model + proposes a rule from each source and a person reviews it before it can produce a + finding; habits and the built-in rule are computed. Artemis has 49 decisions, Shopware + 66, Graylog 3. +- **A short list to fix first.** Seven finding types, ranked by arithmetic alone: + + `priority = authority × (0.4 breach + 0.4 reach + 0.2 change pressure) × ease` + + The report opens on the top 10. Artemis has 257 findings, Shopware 213, Graylog 221. +- **One click to the evidence.** Each of the 691 findings cites the pinned commit and at + least one file and line; the three runs hold 8,623 evidence records in all. +- **Try the fix.** A proposed fix is replayed on a copy of the module dependency graph: + 119 fixes were simulated across the three repositories. On Artemis, applying 8 + cheap-loop fixes together takes the simulation's count of module loops from 304 to 285 + with no new exceptions. +- **Stable results.** A second run with the same commit and settings writes the same bytes. + The ranking was tested five ways (spec.md §11.3), and at least 4 of the top 5 stayed in + the top 5 in every test on all three repositories. With 5% of commits removed at random, + the top 5 stayed the same on Artemis and Shopware and kept 4 of 5 on Graylog. +- **Before and after March 2025.** The code is compared before and after the date the + sponsor set (2025-03-01), and each structural change is labelled planned or "no stated + intent", with its evidence. On Artemis, links between modules rose 16.2% from April to + July 2026; measured on the old module map, the same code rose 4.4%, so most of the jump + came from a planned split. The view describes change; it does not show cause. +- **A check for CI.** `codexray check .. --repo ` lists the decisions a + change breaks, with file and line, and exits 1 when there is one. +- **Any public repository.** `codexray import ` runs every stage on a public + repository and adds its report to the web app. + +The model is used for three narrow reading and writing jobs and nothing else. For the three +committed runs, jobs B and C made 607 calls costing $6.36; job A, run once to propose the +rules, made 458 calls costing $6.14 (see +[Token usage per analysis](#token-usage-per-analysis)). Without a model the report is +complete, with fixed sentences built from the facts in place of AI text. + +## How it works + +Seven stages, as in the track brief. Only stage 6 calls a model. + +| # | Stage | Command | What it does | Model | +|---|---|---|---|---| +| 1 | Repository | `ingest` | Mines the history, pins the commit, takes 14 snapshots, credits each line to the change that last touched it | No | +| 2 | Parse | `parse` | One language-neutral reader on tree-sitter; each unique file is read once and its imports and calls become links between files | No | +| 3 | Model | `model` | Modules and folder roles per snapshot, stored in DuckDB | No | +| 4 | Visualize | `make web` | A static React app: decisions, findings, module grid, close-up, code pane, before and after | No, it shows stored text | +| 5 | Analyze | `analyze` | Decision checks, seven finding types, drift, and the "same code, old layout" comparison | No | +| 6 | LLM judge | `decisions propose`, `judge` | Job A turns a written decision into a checkable rule for a person to review; job B judges a shown finding (three votes); job C describes a module in two sentences | Yes | +| 7 | Explain | `report` | Ranking, `findings.json` and the web bundle | No | + +Adding a language is lines in `src/codexray/settings/grammars.yaml` and one dependency, +and `tests/test_engine_neutral.py` fails if a language or project name appears in engine +code. Every stored fact has an evidence record, every row is keyed by repository and +snapshot commit, and output is sorted before it is written. + +## Results at a glance + +| Repository | Main languages | Lines traced at END | Decisions (checkable) | Findings | Evidence records | AI calls, cost | +|---|---|---|---|---|---|---| +| ls1intum/Artemis | Java, TypeScript | 1,025,560 | 49 (25) | 257 | 2,944 | 163, $2.28 | +| shopware/shopware | PHP, JavaScript, TypeScript | 1,250,015 | 66 (9) | 213 | 3,276 | 247, $2.25 | +| Graylog2/graylog2-server | Java, TypeScript | 869,402 | 3 (3) | 221 | 2,403 | 197, $1.82 | + +"Lines traced" counts the lines of production files at the pinned commit that were credited +to a landed change. The AI columns are jobs B and C for that run; job A is counted +separately below. The files behind every number are in [`results/`](results/). -Detection, counting and ranking are done by ordinary code from the Git history and the -source files. Every finding cites the commit, file and lines behind it. An AI model only -writes prose on top of those facts, and the app marks every AI sentence as AI. +## Built with -## Status +- **Pipeline:** Python 3.12 with uv, Typer, DuckDB, NetworkX, Pydantic, PyYAML, and + tree-sitter with the Java, PHP, Python, JavaScript and TypeScript grammars. Ruff and + pytest for checks. +- **Web app:** React 19, React Router, TypeScript, Vite, Tailwind CSS, elkjs, + d3-hierarchy, d3-scale-chromatic, Shiki and lucide-react. Vitest, Testing Library and + jsdom for tests. +- **Models:** `claude-opus-5-5` for jobs A and B and `claude-haiku-5-5` for job C, + through the LLM gateway provided for the hackathon (`src/codexray/settings/judge.yaml`). + +## Quick start + +The committed bundles of the three repositories are enough to browse the results; no run +and no key are needed. + +```sh +make setup # uv sync, then npm ci in web/ +make web # the web app at http://localhost:5173 +``` + +Open http://localhost:5173. The first page lists the three repositories; click one to +open it. + +## Team + +Aryan Nagbanshi, Pranav Mathad, Viraj Dalsania. + +## Contents + +- [What works](#what-works) +- [Prerequisites](#prerequisites) +- [Reproduce one repository from scratch](#reproduce-one-repository-from-scratch) +- [Import any public repository](#import-any-public-repository) +- [Where the results are](#where-the-results-are) +- [Token usage per analysis](#token-usage-per-analysis) +- [Stability of the ranking](#stability-of-the-ranking) +- [Web app](#web-app) +- [Limits](#limits) +- [Layout](#layout) +- [Working in parallel](#working-in-parallel) + +## What works | Part | State | |---|---| -| Stage 1, `ingest`: history, snapshots, line origin, pull requests | Works on all three repositories | -| Stage 2, `parse`: reading and linking files | Works on all three repositories | -| Stage 3, `model`: the map of modules per snapshot | Works on all three repositories | -| Stage 5, `analyze`: decisions, finding types, before and after | Works on all three repositories | -| Stage 7, `report`: ranking, `findings.json`, the web bundle | Works on all three repositories | -| Web app: the tabs Report, Findings (with finding detail), Map, Before and after, Approach, and the Decisions and Size screens | Works on the three bundles and the two synthetic fixtures in `web/public/bundles/`; see [Web app](#web-app) | +| Stages 1, 2, 3, 5 and 7 (`ingest`, `parse`, `model`, `analyze`, `report`) | Work on all three repositories | +| Stage 4, the web app: the tabs Report, Journeys, Findings (with finding detail), Map, Before and after, Approach, and the Decisions and Size screens | Works on the three bundles and the two synthetic fixtures in `web/public/bundles/`; Journeys only where a bundle has them (see [Web app](#web-app)) | | Stage 6, `judge`: AI text for the shown findings | Works with `LLM_API_KEY` set; answers are cached in the run folder, so a re-run makes no call | | `decisions propose`: rules proposed from written decision documents | Works with `LLM_API_KEY` set; writes `proposals.yaml` for review, and the reviewed rules are in `rules/` | | `check ..`: decisions a change breaks | Works; lists each broken decision with file and line, and exits 1 when there is one | +| `import` and `serve`: any public repository by link | Works; see [Import any public repository](#import-any-public-repository) | | Stability table (spec.md §11.3) | Measured on all three repositories: `make robustness REPO=` after `report` measures it and rebuilds the report | -| Emerging-hotspots list (spec.md §12.2) | Filled on all three repositories; the Change screen lists up to 25 files, highest z first (25 on Artemis, 18 on Shopware, 1 on Graylog) | +| Emerging-hotspots list (spec.md §12.2) | Filled on all three repositories; the Before and after screen lists up to 25 files, highest z first (25 on Artemis, 18 on Shopware, 1 on Graylog) | The results in this repository include AI text. On each repository `judge` judged the 25 highest-ranked findings of four types (broken rule, cheap loop, foundation depending on @@ -40,7 +151,7 @@ descriptions that passed their checks. The calls are in - [uv](https://docs.astral.sh/uv/). It installs Python 3.12 (`.python-version`) and the Python packages. -- Node 22.12 or newer, the minimum the web build tool (Vite) states. +- Node 22.22 or newer, the minimum that React Router states (CI uses Node 24). - git. - Disk: per repository, a clone of 0.2 to 0.6 GB in `repos/` and a run folder of 0.6 to 1.1 GB in `runs/`. The stability step keeps a second run (END one month earlier) inside @@ -103,6 +214,9 @@ The other two take the same commands with their own URL and id: - The rules in `rules/.yaml` are already reviewed and committed, so `decisions propose` (AI job A) is not part of a reproduction. It writes new proposals into the run folder for a person to review. +- `make bundle` replaces the whole folder `web/public/bundles//`. On Artemis that + removes the hand-traced `journeys.json`, which no stage writes; restore it with + `git checkout web/public/bundles/artemis/journeys.json`. - `uv run codexray --help` lists every command. Every step is safe to re-run. ## Import any public repository @@ -131,25 +245,27 @@ uv run codexray serve # the app at http://1 - [`results//`](results/): `findings.json`, `manifest.json`, `decisions.yaml`, `usage.json`, `robustness.json` and `ARCHITECTURE_RULES.md` of each run, copied byte for - byte. [results/README.md](results/README.md) says what each file is. + byte, and the job A files `usage_job_a.json`, `proposals.yaml` and `proposals.json`. + [results/README.md](results/README.md) says what each file is. - `web/public/bundles//`: the files the web app loads for each repository. Run `make web` to browse them. | Repository | Pinned commit | Findings at END | Decisions | From `rules/.yaml` | Checkable by machine | Bundle on disk | |---|---|---|---|---|---|---| -| ls1intum/Artemis | `d8fc451` | 257 | 49 | 33 | 25 | 43 MB, 2,370 files | +| ls1intum/Artemis | `d8fc451` | 257 | 49 | 33 | 25 | 43 MB, 2,371 files | | shopware/shopware | `ec8b714` | 213 | 66 | 65 | 9 | 33 MB, 2,348 files | | Graylog2/graylog2-server | `4912933` | 221 | 3 | 2 | 3 | 32 MB, 2,564 files | Each repository has 10 findings in the list to fix first. Besides the reviewed rules, Artemis has 15 measured habits, and all three have the built-in decision "production code does not depend on test code". A decision that is written but not checkable by machine -(24 on Artemis, 57 on Shopware) is listed with its source and gives no finding. +(24 on Artemis, 57 on Shopware) is listed with its source and gives no finding. The +Artemis bundle's file count includes its hand-traced `journeys.json`. ## Token usage per analysis The ledger of every AI call the gateway answered for these three runs, summed from -`results//usage.json`. The Trust screen shows the same rows. Job B writes the claim +`results//usage.json`. The Approach screen shows the same rows. Job B writes the claim and fix for the 25 judged findings (three votes per finding, and one more call for a vote whose answer fails a check that allows a retry); job C writes a two-sentence description of each module. @@ -184,7 +300,7 @@ of each module. ## Stability of the ranking `make robustness REPO=` runs the five tests of spec.md §11.3 and writes -`robustness.json`; the Trust screen shows the same rows. Each cell says how many of the +`robustness.json`; the Approach screen shows the same rows. Each cell says how many of the top 5 and of the top 10 are still in the top 5 and top 10 under the test. | Test | Artemis top 5 | Artemis top 10 | Shopware top 5 | Shopware top 10 | Graylog top 5 | Graylog top 10 | @@ -224,18 +340,25 @@ lives after the `#` of the address. `make bundle REPO=` copies a run's bundl `web/public/bundles//` and lists it in `web/public/bundles/index.json`; build again to include it in `web/dist`. +The tabs of a repository are Report, Journeys, Findings, Map, Before and after, and +Approach, in that order. Decisions is reached from Report and Size from Map. + | Address (after `#`) | Screen | |---|---| -| `/` | every repository, with the finding to fix first and its decisions by status; how the pipeline works | -| `/r/` | Report: verdict, yardsticks, decisions, the simulated fix batch, the top findings | +| `/` | each analysed repository with its languages, the finding to fix first, its decisions by status and the share of links against the main dependency direction over time; the import box when served by `codexray serve`; how the pipeline works. The two synthetic fixtures are not listed here and open at their own address | +| `/r/` | Report: a verdict naming the modules whose code goes against a decision and those at risk, from the top 10 findings; at a glance: findings, decisions still holding, measures worse since the comparison date, re-run stability, AI calls and cost | +| `/r//journeys` | Journeys: one user action followed stop by stop through the modules, each stop naming the code that runs there and linking to a ranked finding where the step is one. `?j=&s=`. A hand-traced sample, not produced by the pipeline, and the screen says so. Only the Artemis bundle has journeys (3); for any other repository the tab is hidden and the address opens the report | | `/r//decisions` | Decisions, reached from Report: each checked decision with its conformance over time, and the written ones that cannot be checked | | `/r//findings` | Findings: the ranked list and how the ranking is worked out | -| `/r//findings/` | one finding: the reading of the code, the cited lines, the simulation, the priority | +| `/r//findings/` | one finding: the reading of the code, the cited lines, the simulation, the priority, and the journey stop where it appears, if any | | `/r//map` | Map: the module grid. `?view=before\|now\|after`, `?cell=,`, `?finding=`, `?fix=` | -| `/r//change` | Before and after: before and after the compared date, structural events, hotspots | +| `/r//change` | Before and after: architectural drift, what changed in the structure (planned, or no stated intent, shown as "unexplained"), emerging hotspots, new links between modules, AI-generated risk per finding | | `/r//trust` | Approach: coverage, limits, stability of the ranking, AI calls and their cost | | `/r//size` | Size, reached from Map: lines by module and file, and where the new lines landed | +The repository cards on `/` open on Journeys, which falls back to the report when the +repository has none. + Some values show "not measured in this run" because the bundle does not carry them yet: - the rules hash; @@ -260,13 +383,15 @@ Some values show "not measured in this run" because the bundle does not carry th answers. It does not make a new call, so it does not show how the AI text would change on a run with the cache off. - A simulated fix that leaves its target link on the map is shown as "Simulated: the link - remains" (on the finding page, "Fix simulated: the link remains."), not as checked: 29 of the 50 - simulated fixes on Artemis, 1 of 19 on Shopware and 22 of 50 on Graylog. + remains" (on the finding page, "Fix simulated: the link remains."), not as checked: 29 + of the 50 simulated fixes on Artemis, 1 of 19 on Shopware and 22 of 50 on Graylog. - The simulation works on link counts between modules, and a move moves the whole declaring file. Of the 119 simulated fixes, 14 are fixes that remove a link (Artemis 8, Shopware 5, Graylog 1): the link is taken away by assumption, so they are shown as "Effect if the link is removed", not as checked. Another 26 (Artemis 4, Shopware 9, Graylog 13) changed nothing on the map and are shown as "Not simulated". +- The module-loop counts of the simulated fix batch are the simulation's own, on its set + of module links, so they differ from the two-way dependencies yardstick. - When the AI answer names no fix action (for example when it judges the link to be intended wiring), the finding shows "No improvement proposed." and the AI's fix text is not shown. In the list to fix first that is 2 of 10 findings on Artemis, 5 of 10 on @@ -280,44 +405,54 @@ Some values show "not measured in this run" because the bundle does not carry th - Linking accuracy is agreement with separate comparison linkers, not with a compiler. Links made while the program runs (computed paths, settings files, reflection) are not seen. +- The journeys on the Journeys screen are traced by hand for Artemis only. No stage + produces them, and they are not checked against the run. +- The AI steps call the gateway at `gateway.base_url` in `src/codexray/settings/judge.yaml`, + the one provided for the hackathon. - Thresholds and ranking weights are judgements, kept in `src/codexray/settings/`. -- Every run writes its own limits into `manifest.json`; the Trust screen lists them. +- Every run writes its own limits into `manifest.json`; the Approach screen lists them. ## Layout ``` spec.md the specification: single source of truth PRODUCT.md who the web app is for and how it should speak +DESIGN.md the web app's visual design: colours, type, components src/codexray/ core/ shared by every stage; changes are contract changes contracts.py the records that cross lane boundaries schema/*.sql database tables, one file per stage - runs.py db.py settings.py + runs.py db.py settings.py errors.py settings/*.yaml every threshold and weight, starting from the spec's "(initial)" values - repository/ parse/ model/ decisions/ analyze/ judge/ report/ check/ + repository/ parse/ model/ decisions/ analyze/ judge/ report/ check/ importer/ one package per lane; each __init__.py is that lane's brief cli.py the command line tests/ Python tests; conftest.py builds a small repository to test on schemas/ JSON Schema generated from contracts.py +scripts/ builds the synthetic fixture bundle (`make contracts`) rules/ reviewed decisions per analysed repository repos.yaml the three repositories and their pinned commits results/ findings, manifest, decisions, AI usage and stability of each repository's run web/ the static web app (React, Vite, TypeScript, Tailwind) src/App.tsx the routes - src/routes/ one file per screen: Landing, Overview, Decisions, Findings, - FindingDetail, MapPage, Change, Trust, Size - src/components/cx/ shared parts: header, map grid, close-up, code pane, badges + src/routes/ one file per screen: Landing, Overview (Report), Journeys, + Decisions, Findings, FindingDetail, MapPage, Change, Trust, + Size, NotFound; their parts in subfolders + src/components/cx/ shared parts: header, map grid, close-up, code pane, badges, + journey player src/cx/ the shapes the screens read, addresses, labels - src/data/ the bundle loader and the adapter from bundle to screens + src/data/ the bundle loader, the adapter from bundle to screens, the + journeys loader and the import client scripts/ contract types and the stored map layouts, run at bundle-build time - public/bundles/ the bundles it loads: the three repositories and two synthetic fixtures + public/bundles/ the bundles it loads: the three repositories and two synthetic fixtures probes/ measurement scripts behind the spec's numbers; kept as measured docs/research/ the team's research documents and starter kits docs/sponsor/ the sponsor deck and judging hints ``` The AI steps (`judge` and `decisions propose`) read the gateway key from the -`LLM_API_KEY` environment variable. Copy `.env.example` to `.env`; never put the key in a file that is committed. +`LLM_API_KEY` environment variable. Copy `.env.example` to `.env`; never put the key in a +file that is committed. ## Working in parallel