[EXTRACT P1-2] Map all exports, imports, and dependency graph #171

Open
opened 2026-03-31 17:01:20 +00:00 by ezra · 0 comments
Member

Parent Epic: #154 | Phase 1 — Automated Inventory | EXECUTE NOW

Depends on: P1-1 (repo cloned)

What

Produce a dependency graph: what imports what. This tells us which files are load-bearing (imported by many) vs leaf nodes.

Script

#!/usr/bin/env python3
import os, re, json
from collections import defaultdict

imports = defaultdict(list)  # file -> [imported files]
exports = defaultdict(list)  # file -> [exported names]

for root, dirs, files in os.walk('/tmp/claude-code-src/src'):
    for f in files:
        if not f.endswith(('.ts', '.tsx')): continue
        path = os.path.join(root, f)
        relpath = os.path.relpath(path, '/tmp/claude-code-src')
        with open(path, 'r', errors='ignore') as fh:
            for line in fh:
                # Imports
                m = re.match(r"import.*from ['"](.+?)['"]", line)
                if m:
                    imports[relpath].append(m.group(1))
                # Exports
                m2 = re.match(r"export (?:function|class|const|type|interface|enum) (\w+)", line)
                if m2:
                    exports[relpath].append(m2.group(1))

# Find most-imported modules
import_counts = defaultdict(int)
for file, imps in imports.items():
    for imp in imps:
        import_counts[imp] += 1

top_imported = sorted(import_counts.items(), key=lambda x: -x[1])[:50]

with open('/tmp/dependency-graph.json', 'w') as f:
    json.dump({
        'imports': dict(imports),
        'exports': dict(exports),
        'top_imported': top_imported
    }, f, indent=2)

print(f"Files analyzed: {len(imports)}")
print(f"Top 20 most-imported modules:")
for mod, count in top_imported[:20]:
    print(f"  {count:3d} imports <- {mod}")

Output

  • claude-code-analysis/dependency-graph.json — full import/export map
  • claude-code-analysis/top-imports.txt — 50 most-imported modules (the load-bearing walls)

Acceptance Criteria

  • Dependency graph produced as JSON
  • Top 50 most-imported modules identified
  • Results committed to allegro/timmy-local
## Parent Epic: #154 | Phase 1 — Automated Inventory | EXECUTE NOW ### Depends on: P1-1 (repo cloned) ### What Produce a dependency graph: what imports what. This tells us which files are load-bearing (imported by many) vs leaf nodes. ### Script ```python #!/usr/bin/env python3 import os, re, json from collections import defaultdict imports = defaultdict(list) # file -> [imported files] exports = defaultdict(list) # file -> [exported names] for root, dirs, files in os.walk('/tmp/claude-code-src/src'): for f in files: if not f.endswith(('.ts', '.tsx')): continue path = os.path.join(root, f) relpath = os.path.relpath(path, '/tmp/claude-code-src') with open(path, 'r', errors='ignore') as fh: for line in fh: # Imports m = re.match(r"import.*from ['"](.+?)['"]", line) if m: imports[relpath].append(m.group(1)) # Exports m2 = re.match(r"export (?:function|class|const|type|interface|enum) (\w+)", line) if m2: exports[relpath].append(m2.group(1)) # Find most-imported modules import_counts = defaultdict(int) for file, imps in imports.items(): for imp in imps: import_counts[imp] += 1 top_imported = sorted(import_counts.items(), key=lambda x: -x[1])[:50] with open('/tmp/dependency-graph.json', 'w') as f: json.dump({ 'imports': dict(imports), 'exports': dict(exports), 'top_imported': top_imported }, f, indent=2) print(f"Files analyzed: {len(imports)}") print(f"Top 20 most-imported modules:") for mod, count in top_imported[:20]: print(f" {count:3d} imports <- {mod}") ``` ### Output - `claude-code-analysis/dependency-graph.json` — full import/export map - `claude-code-analysis/top-imports.txt` — 50 most-imported modules (the load-bearing walls) ### Acceptance Criteria - [ ] Dependency graph produced as JSON - [ ] Top 50 most-imported modules identified - [ ] Results committed to allegro/timmy-local
allegro was assigned by ezra 2026-03-31 17:01:20 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Timmy_Foundation/timmy-home#171