Skip to content

Turn complex codebases into clear, navigable architecture diagrams with Claude Code.

refactor: rename omm serve → omm view + add /omm-view skill (#2)

김승진77e321541fc6
diff --git a/README.md b/README.md
index fb8d83d..e61faa5 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@ claude # or codex, cursor, etc.
/omm-scan
# 4. View in browser
-omm serve
+omm view
# → http://localhost:3000
```
@@ -126,8 +126,8 @@ omm refs --reverse <class> # Show classes this one references
### Local viewer
```bash
-omm serve # Start live viewer at http://localhost:3000
-omm serve --port 8080 # Custom port
+omm view # Start live viewer at http://localhost:3000
+omm view --port 8080 # Custom port
```
Auto-refreshes in the browser when files change (via SSE).
diff --git a/skills/omm-scan/SKILL.md b/skills/omm-scan/SKILL.md
index 53bd14b..3d4eeb8 100644
--- a/skills/omm-scan/SKILL.md
+++ b/skills/omm-scan/SKILL.md
@@ -112,20 +112,20 @@ EOF
### Step 4: Cross-References
-Use `@class-name` convention for nodes that represent another class. For `@ref` nodes, do NOT add a path as the second line — instead, use a plain concept label:
+Use `@class-name` in the label to mark a node as a drill-down into another class. Use a short node ID and put `@class-name` as the label:
```mermaid
graph LR
client["Browser Client\nsrc/client/"]
- client -->|"HTTP request"| @api-layer["API Layer"]
- client -->|"authenticate"| @auth-flow["Auth Service"]
+ client -->|"HTTP request"| api["@api-layer"]
+ client -->|"authenticate"| auth["@auth-flow"]
```
-The `@` prefix tells the viewer this node is a drill-down into another class. Adding a file path would be misleading since it represents a whole sub-diagram, not a single file.
+The viewer detects `@` in the label and renders the node as an expandable sub-group. Do NOT add a file path to `@ref` nodes — they represent a whole sub-diagram, not a single file.
### Step 5: Summarize
-Report what was created/updated and suggest `omm serve` to view.
+Report what was created/updated and suggest `omm view` to view.
---
@@ -155,8 +155,8 @@ This is the key differentiator from full scan:
1. Run `omm list` to get existing classes
2. For each existing class, run `omm <class> diagram` to read its diagram
-3. Check if the new class is already referenced as `@new-class`
-4. If NOT referenced, find the logical parent (usually `overall-architecture`) and update its diagram to include `@new-class[Label]` node
+3. Check if the new class is already referenced as `@new-class` in a label
+4. If NOT referenced, find the logical parent (usually `overall-architecture`) and update its diagram to include a node with `@new-class` as the label
Example: After creating `auth-flow`, update `overall-architecture`:
```bash
@@ -165,7 +165,7 @@ omm overall-architecture diagram
# Add @auth-flow reference and rewrite
omm overall-architecture diagram - <<'MERMAID'
graph LR
- Client --> @auth-flow[Auth Service]
+ Client --> auth["@auth-flow"]
...existing nodes...
MERMAID
```
@@ -191,14 +191,14 @@ When analyzing the codebase, identify sub-systems that are complex enough to war
**How to nest:**
1. Create a new class: `omm <child-class> diagram - <<'MERMAID'...MERMAID`
-2. In the parent diagram, use `@child-class[Label]` as the node ID
+2. In the parent diagram, add a node with `@child-class` as the label (e.g. `auth["@auth-flow"]`)
3. Fill all 7 fields for the child class (description, constraint, concern, context, todo, note)
**Example:**
If `overall-architecture` has an auth subsystem with 8+ nodes:
- Create `auth-flow` class with its own detailed diagram
-- In `overall-architecture` diagram: `Client --> @auth-flow[Auth Service]`
-- The viewer will render `@auth-flow` as a clickable, expandable sub-group
+- In `overall-architecture` diagram: `Client --> auth["@auth-flow"]`
+- The viewer detects `@` in the label and renders it as an expandable sub-group
### Edge Labels
@@ -268,3 +268,4 @@ The test: if you remove the label, does the reader lose important understanding?
```
Do not overuse — if everything has a color, nothing stands out.
+- Do NOT create circular `@`references. A child class must never `@`-reference its parent. If `overall-architecture` has `auth["@auth-flow"]`, then `auth-flow`'s diagram must NOT reference `@overall-architecture`. Use `context.md` to describe the parent relationship instead.
diff --git a/skills/omm-view/SKILL.md b/skills/omm-view/SKILL.md
new file mode 100644
index 0000000..0842c34
--- /dev/null
+++ b/skills/omm-view/SKILL.md
@@ -0,0 +1,58 @@
+---
+name: omm-view
+description: Start the omm web viewer to explore architecture diagrams in the browser. Use when the user says "omm view", "open viewer", "show diagrams", "view architecture", or "open architecture".
+argument-hint: "[--port <port>]"
+---
+
+# omm-view — Architecture Viewer
+
+## Purpose
+
+Launch the interactive web viewer so the user can explore `.omm/` architecture diagrams in their browser.
+
+## Prerequisites
+
+Ensure the `omm` CLI is available:
+
+```bash
+command -v omm || npm install -g oh-my-mermaid
+```
+
+If the install command fails (permission denied), tell the user:
+"Please run `npm install -g oh-my-mermaid` in your terminal, then try again."
+
+## Steps
+
+### Step 1: Verify .omm/ exists
+
+```bash
+omm list
+```
+
+If no classes found, tell the user:
+"No architecture docs found. Run `/omm-scan` first to generate them."
+Then stop.
+
+### Step 2: Start the viewer
+
+```bash
+omm view
+```
+
+If the user specified a port:
+
+```bash
+omm view --port <port>
+```
+
+### Step 3: Report
+
+Tell the user the viewer is running and provide the URL (default: `http://localhost:3000`).
+
+The viewer auto-refreshes when `.omm/` files change.
+
+## Rules
+
+- Always check for existing classes before starting the viewer
+- If no classes exist, suggest `/omm-scan` instead of starting an empty viewer
+- The viewer is read-only — it does not modify `.omm/` files
diff --git a/src/cli.ts b/src/cli.ts
index ec67387..79dbbb1 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -8,7 +8,7 @@ import { commandDelete } from './commands/delete.js';
import { commandStatus } from './commands/status.js';
import { commandDiff } from './commands/diff.js';
import { commandRefs } from './commands/refs.js';
-import { commandServe } from './commands/serve.js';
+import { commandView } from './commands/view.js';
import { commandLogin } from './commands/login.js';
import { commandLogout } from './commands/logout.js';
import { commandPush } from './commands/push.js';
@@ -17,7 +17,7 @@ import { commandLink } from './commands/link.js';
import { commandShare } from './commands/share.js';
import { commandSetup } from './commands/setup.js';
-const GLOBAL_COMMANDS = ['init', 'setup', 'list', 'show', 'delete', 'status', 'diff', 'refs', 'serve', 'login', 'logout', 'push', 'pull', 'link', 'share', 'help'];
+const GLOBAL_COMMANDS = ['init', 'setup', 'list', 'show', 'delete', 'status', 'diff', 'refs', 'view', 'login', 'logout', 'push', 'pull', 'link', 'share', 'help'];
function printHelp(): void {
const help = `
@@ -35,7 +35,7 @@ Usage:
omm diff <class> Compare current vs previous diagram
omm refs <class> Show classes that reference this class
omm refs --reverse <class> Show classes this class references
- omm serve [--port <port>] Start web viewer (default: 3000)
+ omm view [--port <port>] Start web viewer (default: 3000)
omm <class> <field> Read a field (stdout)
omm <class> <field> <content> Write a field
@@ -120,7 +120,7 @@ async function main(): Promise<void> {
return;
}
- case 'serve': {
+ case 'view': {
let port = 3000;
if (args[1] === '--port' && args[2]) {
port = parseInt(args[2], 10);
@@ -129,7 +129,7 @@ async function main(): Promise<void> {
process.exit(1);
}
}
- commandServe(port);
+ commandView(port);
return;
}
diff --git a/src/commands/serve.ts b/src/commands/view.ts
similarity index 73%
rename from src/commands/serve.ts
rename to src/commands/view.ts
index bd1f5e3..043bf28 100644
--- a/src/commands/serve.ts
+++ b/src/commands/view.ts
@@ -1,7 +1,7 @@
import { ensureOmmForRead } from '../lib/store.js';
import { startServer } from '../server/index.js';
-export function commandServe(port: number = 3000): void {
+export function commandView(port: number = 3000): void {
if (!ensureOmmForRead()) return;
startServer(port);
}
diff --git a/src/server/viewer.html b/src/server/viewer.html
index 5057a62..efb0c25 100644
--- a/src/server/viewer.html
+++ b/src/server/viewer.html
@@ -290,14 +290,19 @@ function parseFlowchart(raw) {
const nodesMap = new Map(), edges = [], classOf = {};
function cleanLabel(s) { return s.replace(/<br\s*\/?>/gi, '\n').replace(/\\n/g, '\n'); }
+ function refFromLabel(label) {
+ // Detect @class-name at start of label (e.g. "@channel-system" or "@auth-flow\nsome path")
+ const m = label.match(/^@([\w-]+)/);
+ return m ? m[1] : null;
+ }
function tok(t) {
t = t.trim();
let m;
- m = t.match(/^(@?[\w-]+)\["([^"]+)"\]$/); if (m) return {id:m[1].replace(/^@/,''),label:cleanLabel(m[2]),shape:'rect',isRef:m[1].startsWith('@')};
- m = t.match(/^(@?[\w-]+)\[([^\]]+)\]$/); if (m) return {id:m[1].replace(/^@/,''),label:cleanLabel(m[2]),shape:'rect',isRef:m[1].startsWith('@')};
- m = t.match(/^(@?[\w-]+)\(\(([^)]+)\)\)$/); if (m) return {id:m[1].replace(/^@/,''),label:cleanLabel(m[2]),shape:'stadium',isRef:m[1].startsWith('@')};
- m = t.match(/^(@?[\w-]+)\(([^)]+)\)$/); if (m) return {id:m[1].replace(/^@/,''),label:cleanLabel(m[2]),shape:'round',isRef:m[1].startsWith('@')};
- m = t.match(/^(@?[\w-]+)\{([^}]+)\}$/); if (m) return {id:m[1].replace(/^@/,''),label:cleanLabel(m[2]),shape:'diamond',isRef:m[1].startsWith('@')};
+ m = t.match(/^(@?[\w-]+)\["([^"]+)"\]$/); if (m) { const lbl=cleanLabel(m[2]),r=refFromLabel(lbl),idR=m[1].startsWith('@'); return {id:m[1].replace(/^@/,''),label:lbl,shape:'rect',isRef:idR||!!r,refTarget:r||(idR?m[1].replace(/^@/,''):null)}; }
+ m = t.match(/^(@?[\w-]+)\[([^\]]+)\]$/); if (m) { const lbl=cleanLabel(m[2]),r=refFromLabel(lbl),idR=m[1].startsWith('@'); return {id:m[1].replace(/^@/,''),label:lbl,shape:'rect',isRef:idR||!!r,refTarget:r||(idR?m[1].replace(/^@/,''):null)}; }
+ m = t.match(/^(@?[\w-]+)\(\(([^)]+)\)\)$/); if (m) { const lbl=cleanLabel(m[2]),r=refFromLabel(lbl),idR=m[1].startsWith('@'); return {id:m[1].replace(/^@/,''),label:lbl,shape:'stadium',isRef:idR||!!r,refTarget:r||(idR?m[1].replace(/^@/,''):null)}; }
+ m = t.match(/^(@?[\w-]+)\(([^)]+)\)$/); if (m) { const lbl=cleanLabel(m[2]),r=refFromLabel(lbl),idR=m[1].startsWith('@'); return {id:m[1].replace(/^@/,''),label:lbl,shape:'round',isRef:idR||!!r,refTarget:r||(idR?m[1].replace(/^@/,''):null)}; }
+ m = t.match(/^(@?[\w-]+)\{([^}]+)\}$/); if (m) { const lbl=cleanLabel(m[2]),r=refFromLabel(lbl),idR=m[1].startsWith('@'); return {id:m[1].replace(/^@/,''),label:lbl,shape:'diamond',isRef:idR||!!r,refTarget:r||(idR?m[1].replace(/^@/,''):null)}; }
if (/^@?[\w-]+$/.test(t)) { const id=t.replace(/^@/,''); return {id,label:id,shape:'rect',isRef:t.startsWith('@')}; }
return null;
}
@@ -398,14 +403,16 @@ function renderGroup(cls, classesData, allClasses, level, seen = new Set()) {
const nodeDims = {}; // nodeId -> { width, height }
for (const n of nodes) {
- const refCls = n.isRef ? n.id : null;
+ const refCls = n.isRef ? (n.refTarget || n.id) : null;
if (level < maxDepth && refCls && allClasses.includes(refCls) && !seen.has(refCls) && !_expandedGlobal.has(refCls)) {
_expandedGlobal.add(refCls);
const sub = renderGroup(refCls, classesData, allClasses, level+1, seen);
if (sub) {
- subGroups[n.id] = { cls: refCls, ...sub };
- // sub-group dims = content + inner padding
- nodeDims[n.id] = { width: sub.W + 24, height: sub.H + 30 }; // 30 = 16 top label + 14 bottom
+ // Scale down to fit max box. At small scales, edge overflow becomes negligible.
+ const MAX_W = 240, MAX_H = 160, PAD = 12;
+ const fs = Math.min((MAX_W - PAD*2) / sub.W, (MAX_H - PAD*2) / sub.H, 1);
+ subGroups[n.id] = { cls: refCls, ...sub, fitScale: fs };
+ nodeDims[n.id] = { width: sub.W * fs + PAD * 2, height: sub.H * fs + PAD * 2 };
}
}
if (!nodeDims[n.id]) {
@@ -552,16 +559,19 @@ function renderGroup(cls, classesData, allClasses, level, seen = new Set()) {
const isRef = n.label.startsWith('@');
const refSubStroke = th.subStroke;
const refDash = '';
+ const fs = sg.fitScale;
+ const PAD = 12;
+ const boxW = sg.W * fs + PAD * 2, boxH = sg.H * fs + PAD * 2;
svg += `<g class="grp-node" onclick="event.stopPropagation();window.__openSb('${safeId}')" data-cls="${safeId}" data-depth="${level+1}" transform="translate(${nx},${ny})">`;
- svg += `<rect class="grp-border" width="${dim.width}" height="${dim.height}" rx="5"
+ svg += `<rect class="grp-border" width="${r1(boxW)}" height="${r1(boxH)}" rx="5"
fill="${th.subFill}" stroke="${refSubStroke}" stroke-width="2"/>`;
const _slW = tw(fmtLabel(sg.cls), '600 9px "Plus Jakarta Sans",Inter,system-ui') + 12;
svg += `<rect class="grp-label-top grp-label-bg" x="5" y="-7" width="${_slW}" height="14" rx="2" fill="${th.subFill}" opacity="1"/>`;
svg += `<text class="grp-label-top" x="10" y="2" font-family="&quot;Plus Jakarta Sans&quot;,Inter,system-ui" font-size="9" font-weight="600"
fill="${th.subLabelFill}" letter-spacing="0.05em">${esc(fmtLabel(sg.cls))}</text>`;
- svg += `<g class="grp-inner" transform="translate(12,18)">${sg.svgContent}</g>`;
+ svg += `<g class="grp-inner" transform="translate(${r1(PAD)},${r1(PAD)}) scale(${r1(fs)})">${sg.svgContent}</g>`;
svg += `</g>`;
- labelOverlay += `<text class="grp-label-center" x="${r1(nx + dim.width/2)}" y="${r1(ny + dim.height/2)}" text-anchor="middle" dominant-baseline="central"
+ labelOverlay += `<text class="grp-label-center" x="${r1(nx + boxW/2)}" y="${r1(ny + boxH/2)}" text-anchor="middle" dominant-baseline="central"
font-family="&quot;Plus Jakarta Sans&quot;,Inter,system-ui" font-size="9" font-weight="600" fill="${th.grpLabelCenterFill}" letter-spacing="0.05em">${esc(fmtLabel(sg.cls))}</text>`;
} else {
// ── regular node ──
@@ -985,15 +995,24 @@ window.closeSidebar=closeSidebar;
function buildCanvas(classes, classesData, refsData) {
_expandedGlobal = new Set(); // reset per render
// Find top-level classes: those with no incoming @refs from other classes
- const referenced = new Set();
+ // Build outgoing ref counts to handle circular references
+ const outCount = {}; // cls -> number of outgoing @refs to other classes
+ const inCount = {}; // cls -> number of incoming @refs from other classes
+ for (const cls of classes) { outCount[cls] = 0; inCount[cls] = 0; }
for (const cls of classes) {
const diagram = classesData[cls]?.diagram || '';
- const refs = [...diagram.matchAll(/@([\w-]+)/g)].map(m=>m[1]);
- refs.forEach(r => { if (classes.includes(r)) referenced.add(r); });
+ const refs = [...new Set([...diagram.matchAll(/@([\w-]+)/g)].map(m=>m[1]).filter(r => classes.includes(r)))];
+ outCount[cls] = refs.length;
+ refs.forEach(r => { inCount[r]++; });
+ }
+ // Top-level = not referenced, OR referenced but has more outgoing refs than any referrer (cycle breaker)
+ let topLevel = classes.filter(c => inCount[c] === 0);
+ if (!topLevel.length) {
+ // All classes have incoming refs (circular). Pick the one with most outgoing refs as root.
+ const maxOut = Math.max(...classes.map(c => outCount[c]));
+ topLevel = classes.filter(c => outCount[c] === maxOut);
}
- const topLevel = classes.filter(c => !referenced.has(c));
- // Fallback: if everything is referenced, just show all
- const roots = topLevel.length ? topLevel : classes;
+ const roots = topLevel;
// Render each top-level group
const groups = [];
@@ -1119,17 +1138,22 @@ function buildNavTree() {
navList.innerHTML = '';
if (!classes.length) return;
- const referenced = new Set();
+ const navOutCount = {}, navInCount = {};
+ for (const c of classes) { navOutCount[c] = 0; navInCount[c] = 0; }
for (const name of classes) {
const out = refsData[name]?.outgoing || [];
- for (const o of out) {
- const ref = typeof o === 'string' ? o : (o.target_class || o);
- if (classes.includes(ref)) referenced.add(ref);
- }
+ const targets = [...new Set(out.map(o => typeof o === 'string' ? o : (o.target_class || o)).filter(r => classes.includes(r)))];
+ navOutCount[name] = targets.length;
+ targets.forEach(r => { navInCount[r]++; });
}
- let roots = classes.filter(c => !referenced.has(c));
- if (roots.length === 0 || roots.length === classes.length) {
+ let roots = classes.filter(c => navInCount[c] === 0);
+ if (roots.length === 0) {
+ // Circular refs — pick class with most outgoing refs as root
+ const maxOut = Math.max(...classes.map(c => navOutCount[c]));
+ roots = classes.filter(c => navOutCount[c] === maxOut);
+ }
+ if (roots.length === classes.length) {
classes.forEach(c => addNavItem(c, '', true));
return;
}