REFRAX — Visual Code Comprehension
"Stop reading code. Start seeing it."
Author: jord0 | Version: 1.0
Prerequisites
- Python 3 (for
http.server)
- Modern browser (Chrome, Firefox, Safari, Edge)
Usage
/refrax
Point REFRAX at any code — a file, function, endpoint, or diff — and it generates an interactive visual logic spine in your browser. Use NOV (novice) mode for plain-English explanations or DEV mode for technical detail.
When to Invoke
- User asks to understand or review code they didn't write
- User wants a visual explanation of a function, endpoint, or flow
- User says "explain this code", "review this", "what does this do"
- User wants to identify risks or security issues visually
- User asks to review a diff or pull request
- User needs to explain code to non-technical stakeholders
Capability Lookup
| Task |
REFRAX Does |
| Explain code visually |
Generate logic spine with plain-English steps |
| Review AI-generated code |
Identify risks, show fix prompts |
| Understand unfamiliar code |
Break into numbered steps with context |
| Review a diff |
Show changes linked to logic spine |
| Explain to non-technical users |
Novice mode with jargon-free language |
| Identify security risks |
Risk cards with severity, fix steps, fix prompts |
How It Works
The Flow
1. User points at code (file, function, diff, or paste)
2. You analyse the code and generate structured JSON
3. Copy template → /tmp/refrax/index.html
4. Write analysis → /tmp/refrax/data.json
5. Start local server on port 8789
6. User opens browser, clicks through the logic spine
7. User asks for changes → you update data.json → UI morphs live
Step-by-Step
1. Set Up the Server (First Time)
mkdir -p /tmp/refrax
cp ~/.claude/skills/refrax/references/template.html /tmp/refrax/index.html
2. Analyse the Code
Read the target code. Think through it step by step:
- Identify the flow — What triggers this code? What are the steps?
- Map decisions — Where does it branch? What are the conditions?
- Find side effects — Database writes, network calls, file operations
- Assess risks — Security holes, performance issues, logic errors
- Extract tech stack — What libraries/frameworks are in play?
- Build glossary — What terms would a novice not understand?
3. Write the Data File
Write /tmp/refrax/data.json following the contract below.
4. Start the Server
cd /tmp/refrax && python3 -m http.server 8789 &
Run in background. Tell user to open http://localhost:8789.
IMPORTANT — Tell the user this is interactive. REFRAX is a live visual page, not a
static report. After starting the server, always remind the user:
"Open http://localhost:8789 in your browser. This is an interactive page — click
nodes in the spine to inspect them, switch between Plain/Dev/Code views, browse risks
with copy-paste fix prompts, and use the Files tab to filter by file. Toggle NOV/PRO
mode for technical vs plain-English language. The page updates live whenever I refine
the analysis — no need to refresh. If you want to explore a different part of the
codebase, just ask and I'll update the view."
Users who haven't seen REFRAX before won't know the output is visual and clickable.
Always point this out explicitly on first use.
5. Update the Analysis (Live)
When the user asks for changes (deeper analysis, fix applied, new risks), rewrite
/tmp/refrax/data.json. The browser polls every 500ms and morphs automatically.
Do NOT restart the server. The poller handles everything.
The data.json Contract
Top-Level Structure
{
"meta": { ... },
"techStack": [ ... ],
"files": [ ... ],
"spine": { ... },
"risks": [ ... ],
"diff": { ... },
"glossary": [ ... ]
}
meta (required)
| Field |
Type |
Required |
Description |
projectName |
string |
yes |
Name of the project or component |
generatedAt |
string |
no |
ISO timestamp |
summary |
string |
yes |
Summary of what this code does (2-3 sentences for overview) |
confidence |
number |
no |
0-1 confidence in analysis accuracy |
environment |
object |
no |
{ venv: bool, venvPath: string, pythonVersion: string } |
dependencies |
array |
no |
[{ name, version }] — key project dependencies |
techStack (optional)
Array of { name, role, version, evidence } objects. Each tech detected in the code.
The version field is shown inline on chips and in tooltips.
files (required)
Array of file objects:
| Field |
Type |
Description |
fileId |
string |
Unique ID (e.g., "f1") |
path |
string |
File path |
language |
string |
"python", "javascript", "typescript" |
content |
string |
Full file content (for code highlighting) |
spine (required)
The logic spine — the heart of the visualisation:
{
"title": "User Login Flow",
"trigger": "User submits email + password",
"nodes": [ ... ]
}
Node types
| Type |
Shape |
Colour |
Use For |
step |
Rounded rect |
Cyan |
Actions, operations, transformations |
decision |
Diamond |
Violet |
If/else, switch, validation checks |
side_effect |
Rounded rect |
Amber |
DB queries, API calls, file I/O |
outcome |
Pill |
Emerald/Rose |
Final results (success or failure) |
Node fields
| Field |
Type |
Required |
Description |
id |
string |
yes |
Unique ID (e.g., "n1") |
type |
string |
yes |
"step", "decision", "side_effect", "outcome" |
label |
string |
yes |
Short label (verb-first, max ~30 chars) |
plain |
string |
yes |
Plain English explanation (no jargon) |
dev |
string |
yes |
Technical explanation |
fileId |
string |
no |
Links to a file in files[] |
lines |
[int,int] |
no |
Start and end line numbers |
riskIds |
string[] |
no |
IDs of linked risks |
diffStatus |
string |
no |
"added", "modified", "deleted", or null |
branches |
array |
no |
Decision branches (decision nodes only) |
Branch fields (for decision nodes)
| Field |
Type |
Description |
condition |
string |
"Yes", "No", "Valid", "Invalid", etc. |
targetId |
string |
ID of the target node |
risks (optional)
Array of risk objects:
| Field |
Type |
Description |
id |
string |
Unique ID (e.g., "r1") |
title |
string |
Short title |
severity |
string |
"high", "medium", "low" |
category |
string |
"security", "performance", "logic", "reliability" |
plain |
string |
Plain explanation of the risk |
whyItMatters |
string |
Why this is dangerous |
where |
object |
{ fileId, lines: [start, end] } |
nodeIds |
string[] |
Affected spine nodes |
fix.title |
string |
Fix description |
fix.steps |
string[] |
Step-by-step fix instructions |
fix.effort |
string |
"low", "medium", "high" |
fixPrompt |
string |
Ready-made prompt to give Claude to fix this |
diff (optional)
{
"baseLabel": "main@abc123",
"headLabel": "feature/auth@def456",
"summary": "Added password hashing with bcrypt.",
"hunks": [ ... ]
}
Hunk fields
| Field |
Type |
Description |
id |
string |
Unique ID |
fileId |
string |
Links to a file |
lines |
array |
`{ type: "add" |
nodeIds |
string[] |
Linked spine nodes |
explanation |
string |
What this change does |
glossary (optional)
Array of { term, plain, dev } objects. Terms are auto-linked in the UI.
The optional dev field provides a technical definition shown in PRO mode.
Outcome Node Colours
Outcome nodes are coloured by their label text:
- Labels containing "fail", "error", or "reject" → render as rose (failure)
- All other outcomes → render as emerald (success)
Write outcome labels accordingly. Example: "Login failed" (rose), "Token created" (emerald).
Labelling Rules
Labels should be readable by someone who has never programmed:
DO use:
- Verbs first: "Checks the password", "Saves to database", "Sends email"
- Plain nouns: "the user's email", "the login form", "the saved record"
- Questions for decisions: "Is the email valid?", "Does the user exist?"
DON'T use:
void, return, class, instantiate, callback, middleware
- Function signatures in labels
- Variable names without explanation
Novice alternatives:
- "function" → "helper"
- "endpoint" → "URL"
- "exception" → "error"
- "parameter" → "input"
- "boolean" → "yes/no value"
Spine Size Guidance
Aim for 8–20 nodes per spine. If the code has more steps, group related operations
into single nodes. For large codebases, create separate analyses per function or module
rather than one massive spine. A focused spine is more useful than an exhaustive one.
AI Partnership Patterns
Analysing Code
When the user points at code:
- Read the full file — understand context, imports, dependencies
- Identify the entry point — what triggers this code?
- Trace the flow — step by step, decision by decision
- Mark side effects — anything that touches external systems
- Assess risks — security, performance, logic, reliability
- Generate data.json — following the contract exactly
- Serve and explain — start server, give user the overview
Reviewing Diffs
When the user has a diff to review:
- Read both versions — understand what changed and why
- Build the spine — for the NEW version's logic
- Mark diff status — which nodes are added/modified/deleted
- Generate hunks — with explanations of each change
- Assess new risks — what did this change introduce?
Iterative Refinement
The power move: user sees the spine, asks questions, you refine.
- User: "What does step 3 actually do?"
- You: Expand the
plain and dev text for that node
- You: Update data.json → UI morphs
- User: "That risk looks bad, can you fix it?"
- You: Fix the code, update the spine, risks update accordingly
Serving Instructions
Start Server
mkdir -p /tmp/refrax
cp ~/.claude/skills/refrax/references/template.html /tmp/refrax/index.html
cd /tmp/refrax && python3 -m http.server 8789 &
Check If Already Running
lsof -i :8789
If already running, skip the server start. Just update data.json.
Stop Server
kill $(lsof -t -i :8789) 2>/dev/null
Companion Skills
- REGTRAX — Regex railroad visualizer (same architecture)
- CANVAS — Immersive 3D web experiences
- LOCUS — Interactive image hotspots
- OPTIC — AI image generation
Security Checklist
Quality Checklist
1---2name: refrax3description: INVOKE THIS SKILL when: reviewing AI-generated code, understanding unfamiliar codebases, visualizing code logic as flow diagrams, explaining code to non-technical stakeholders, identifying security risks in code, reviewing diffs visually, or when users need to understand code they didn't write. Generates interactive visual code comprehension pages.4---56# REFRAX — Visual Code Comprehension78> "Stop reading code. Start seeing it."910**Author:** jord0 | **Version:** 1.01112---1314## Prerequisites1516- Python 3 (for `http.server`)17- Modern browser (Chrome, Firefox, Safari, Edge)1819---2021## Usage2223```24/refrax25```2627Point REFRAX at any code — a file, function, endpoint, or diff — and it generates an interactive visual logic spine in your browser. Use NOV (novice) mode for plain-English explanations or DEV mode for technical detail.2829---3031## When to Invoke3233- User asks to understand or review code they didn't write34- User wants a visual explanation of a function, endpoint, or flow35- User says "explain this code", "review this", "what does this do"36- User wants to identify risks or security issues visually37- User asks to review a diff or pull request38- User needs to explain code to non-technical stakeholders3940---4142## Capability Lookup4344| Task | REFRAX Does |45|------|-------------|46| Explain code visually | Generate logic spine with plain-English steps |47| Review AI-generated code | Identify risks, show fix prompts |48| Understand unfamiliar code | Break into numbered steps with context |49| Review a diff | Show changes linked to logic spine |50| Explain to non-technical users | Novice mode with jargon-free language |51| Identify security risks | Risk cards with severity, fix steps, fix prompts |5253---5455## How It Works5657### The Flow5859```601. User points at code (file, function, diff, or paste)612. You analyse the code and generate structured JSON623. Copy template → /tmp/refrax/index.html634. Write analysis → /tmp/refrax/data.json645. Start local server on port 8789656. User opens browser, clicks through the logic spine667. User asks for changes → you update data.json → UI morphs live67```6869### Step-by-Step7071#### 1. Set Up the Server (First Time)7273```bash74mkdir -p /tmp/refrax75cp ~/.claude/skills/refrax/references/template.html /tmp/refrax/index.html76```7778#### 2. Analyse the Code7980Read the target code. Think through it step by step:81821. **Identify the flow** — What triggers this code? What are the steps?832. **Map decisions** — Where does it branch? What are the conditions?843. **Find side effects** — Database writes, network calls, file operations854. **Assess risks** — Security holes, performance issues, logic errors865. **Extract tech stack** — What libraries/frameworks are in play?876. **Build glossary** — What terms would a novice not understand?8889#### 3. Write the Data File9091Write `/tmp/refrax/data.json` following the contract below.9293#### 4. Start the Server9495```bash96cd /tmp/refrax && python3 -m http.server 8789 &97```9899Run in background. Tell user to open `http://localhost:8789`.100101**IMPORTANT — Tell the user this is interactive.** REFRAX is a live visual page, not a102static report. After starting the server, always remind the user:103104> "Open **http://localhost:8789** in your browser. This is an interactive page — click105> nodes in the spine to inspect them, switch between Plain/Dev/Code views, browse risks106> with copy-paste fix prompts, and use the Files tab to filter by file. Toggle NOV/PRO107> mode for technical vs plain-English language. The page updates live whenever I refine108> the analysis — no need to refresh. If you want to explore a different part of the109> codebase, just ask and I'll update the view."110111Users who haven't seen REFRAX before won't know the output is visual and clickable.112Always point this out explicitly on first use.113114#### 5. Update the Analysis (Live)115116When the user asks for changes (deeper analysis, fix applied, new risks), rewrite117`/tmp/refrax/data.json`. The browser polls every 500ms and morphs automatically.118119**Do NOT restart the server.** The poller handles everything.120121---122123## The data.json Contract124125### Top-Level Structure126127```json128{129 "meta": { ... },130 "techStack": [ ... ],131 "files": [ ... ],132 "spine": { ... },133 "risks": [ ... ],134 "diff": { ... },135 "glossary": [ ... ]136}137```138139### meta (required)140141| Field | Type | Required | Description |142|-------|------|----------|-------------|143| `projectName` | string | yes | Name of the project or component |144| `generatedAt` | string | no | ISO timestamp |145| `summary` | string | yes | Summary of what this code does (2-3 sentences for overview) |146| `confidence` | number | no | 0-1 confidence in analysis accuracy |147| `environment` | object | no | `{ venv: bool, venvPath: string, pythonVersion: string }` |148| `dependencies` | array | no | `[{ name, version }]` — key project dependencies |149150### techStack (optional)151152Array of `{ name, role, version, evidence }` objects. Each tech detected in the code.153The `version` field is shown inline on chips and in tooltips.154155### files (required)156157Array of file objects:158159| Field | Type | Description |160|-------|------|-------------|161| `fileId` | string | Unique ID (e.g., "f1") |162| `path` | string | File path |163| `language` | string | "python", "javascript", "typescript" |164| `content` | string | Full file content (for code highlighting) |165166### spine (required)167168The logic spine — the heart of the visualisation:169170```json171{172 "title": "User Login Flow",173 "trigger": "User submits email + password",174 "nodes": [ ... ]175}176```177178#### Node types179180| Type | Shape | Colour | Use For |181|------|-------|--------|---------|182| `step` | Rounded rect | Cyan | Actions, operations, transformations |183| `decision` | Diamond | Violet | If/else, switch, validation checks |184| `side_effect` | Rounded rect | Amber | DB queries, API calls, file I/O |185| `outcome` | Pill | Emerald/Rose | Final results (success or failure) |186187#### Node fields188189| Field | Type | Required | Description |190|-------|------|----------|-------------|191| `id` | string | yes | Unique ID (e.g., "n1") |192| `type` | string | yes | "step", "decision", "side_effect", "outcome" |193| `label` | string | yes | Short label (verb-first, max ~30 chars) |194| `plain` | string | yes | Plain English explanation (no jargon) |195| `dev` | string | yes | Technical explanation |196| `fileId` | string | no | Links to a file in files[] |197| `lines` | [int,int] | no | Start and end line numbers |198| `riskIds` | string[] | no | IDs of linked risks |199| `diffStatus` | string | no | "added", "modified", "deleted", or null |200| `branches` | array | no | Decision branches (decision nodes only) |201202#### Branch fields (for decision nodes)203204| Field | Type | Description |205|-------|------|-------------|206| `condition` | string | "Yes", "No", "Valid", "Invalid", etc. |207| `targetId` | string | ID of the target node |208209### risks (optional)210211Array of risk objects:212213| Field | Type | Description |214|-------|------|-------------|215| `id` | string | Unique ID (e.g., "r1") |216| `title` | string | Short title |217| `severity` | string | "high", "medium", "low" |218| `category` | string | "security", "performance", "logic", "reliability" |219| `plain` | string | Plain explanation of the risk |220| `whyItMatters` | string | Why this is dangerous |221| `where` | object | `{ fileId, lines: [start, end] }` |222| `nodeIds` | string[] | Affected spine nodes |223| `fix.title` | string | Fix description |224| `fix.steps` | string[] | Step-by-step fix instructions |225| `fix.effort` | string | "low", "medium", "high" |226| `fixPrompt` | string | Ready-made prompt to give Claude to fix this |227228### diff (optional)229230```json231{232 "baseLabel": "main@abc123",233 "headLabel": "feature/auth@def456",234 "summary": "Added password hashing with bcrypt.",235 "hunks": [ ... ]236}237```238239#### Hunk fields240241| Field | Type | Description |242|-------|------|-------------|243| `id` | string | Unique ID |244| `fileId` | string | Links to a file |245| `lines` | array | `{ type: "add"|"del"|"context", num, text }` |246| `nodeIds` | string[] | Linked spine nodes |247| `explanation` | string | What this change does |248249### glossary (optional)250251Array of `{ term, plain, dev }` objects. Terms are auto-linked in the UI.252The optional `dev` field provides a technical definition shown in PRO mode.253254---255256## Outcome Node Colours257258Outcome nodes are coloured by their label text:259- Labels containing **"fail"**, **"error"**, or **"reject"** → render as **rose** (failure)260- All other outcomes → render as **emerald** (success)261262Write outcome labels accordingly. Example: "Login failed" (rose), "Token created" (emerald).263264---265266## Labelling Rules267268Labels should be readable by someone who has never programmed:269270**DO use:**271- Verbs first: "Checks the password", "Saves to database", "Sends email"272- Plain nouns: "the user's email", "the login form", "the saved record"273- Questions for decisions: "Is the email valid?", "Does the user exist?"274275**DON'T use:**276- `void`, `return`, `class`, `instantiate`, `callback`, `middleware`277- Function signatures in labels278- Variable names without explanation279280**Novice alternatives:**281- "function" → "helper"282- "endpoint" → "URL"283- "exception" → "error"284- "parameter" → "input"285- "boolean" → "yes/no value"286287---288289## Spine Size Guidance290291Aim for **8–20 nodes** per spine. If the code has more steps, group related operations292into single nodes. For large codebases, create separate analyses per function or module293rather than one massive spine. A focused spine is more useful than an exhaustive one.294295---296297## AI Partnership Patterns298299### Analysing Code300301When the user points at code:3023031. **Read the full file** — understand context, imports, dependencies3042. **Identify the entry point** — what triggers this code?3053. **Trace the flow** — step by step, decision by decision3064. **Mark side effects** — anything that touches external systems3075. **Assess risks** — security, performance, logic, reliability3086. **Generate data.json** — following the contract exactly3097. **Serve and explain** — start server, give user the overview310311### Reviewing Diffs312313When the user has a diff to review:3143151. **Read both versions** — understand what changed and why3162. **Build the spine** — for the NEW version's logic3173. **Mark diff status** — which nodes are added/modified/deleted3184. **Generate hunks** — with explanations of each change3195. **Assess new risks** — what did this change introduce?320321### Iterative Refinement322323The power move: user sees the spine, asks questions, you refine.3243251. User: "What does step 3 actually do?"3262. You: Expand the `plain` and `dev` text for that node3273. You: Update data.json → UI morphs3284. User: "That risk looks bad, can you fix it?"3295. You: Fix the code, update the spine, risks update accordingly330331---332333## Serving Instructions334335### Start Server336337```bash338mkdir -p /tmp/refrax339cp ~/.claude/skills/refrax/references/template.html /tmp/refrax/index.html340cd /tmp/refrax && python3 -m http.server 8789 &341```342343### Check If Already Running344345```bash346lsof -i :8789347```348349If already running, skip the server start. Just update data.json.350351### Stop Server352353```bash354kill $(lsof -t -i :8789) 2>/dev/null355```356357---358359## Companion Skills360361- **REGTRAX** — Regex railroad visualizer (same architecture)362- **CANVAS** — Immersive 3D web experiences363- **LOCUS** — Interactive image hotspots364- **OPTIC** — AI image generation365366---367368## Security Checklist369370- [ ] No external CDN or script tags — everything is inline371- [ ] No eval() or Function() constructor372- [ ] No localStorage of sensitive data (only sessionStorage for mode toggle)373- [ ] Server binds to localhost only374- [ ] data.json contains analysis data only, no executable code375- [ ] Template is read-only — never modified at runtime376- [ ] File content in data.json is display-only, never executed377378---379380## Quality Checklist381382- [ ] Every spine node has both `plain` and `dev` text383- [ ] Labels use verbs, not jargon384- [ ] At least one risk identified (or explicitly noted if code is clean)385- [ ] File content is included for code highlighting386- [ ] Line numbers in nodes match actual file content387- [ ] Glossary covers terms a novice wouldn't know388- [ ] data.json is valid JSON389- [ ] Server is running before telling user to open browser