Skip to content

Latest commit

Β 

History

55 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” RepoTrace

License: MIT PRs Welcome Node Version TypeScript JavaScript Python Dart Flutter React CI Status

An interactive, AST-powered codebase dependency graph and architecture explorer for TypeScript, JavaScript, Python, and Dart / Flutter repositories, built with ts-morph, React Flow, and Dagre.

Statically parses local repositories into an Abstract Syntax Tree (AST), resolves internal module imports/exports, maps architectural layers via Kahn's Topological Sort, and animates code execution flow step-by-step.


πŸš€ Getting Started

⚑ Instant Run via npx (No Clone or Install Needed!)

Inside any local TypeScript, JavaScript, Python, or Flutter/Dart project on your machine, simply run:

npx repotrace

RepoTrace will automatically:

  1. Detect your current codebase directory.
  2. Boot the dashboard on an isolated production port (default 4242).
  3. Launch your default browser to http://localhost:4242 and render your codebase graph!

CLI Options:

# Analyze a specific project path
npx repotrace ./my-project

# Run on a custom port
npx repotrace --port 5050

# Run in headless/server mode (skip auto-opening browser)
npx repotrace --no-open

# View all CLI options
npx repotrace --help

πŸ’» Local Development & Contributing

If you want to contribute to or hack on RepoTrace:

# 1. Clone repository
git clone https://github.com/your-username/repotrace.git
cd repotrace

# 2. Install dependencies
npm install

# 3. Start development servers (Vite :5173 + Express :3001)
npm run dev

πŸŽ₯ Demo Video

Watch RepoTrace explore codebases, trace architectural execution flow, and cluster directories in real time:

RepoTrace Interactive Demo Video

▢️ Click here to watch the full demo on YouTube


πŸ“Έ Interface Preview

🌐 High-Level Architecture Overview

Dagre-powered hierarchical tier layout color-coded by module category with circuit blueprint corridor routing:

RepoTrace Architecture Overview

πŸ” Node Inspection & Flow Stepper

Inspect discovered symbols (components, hooks, functions, interfaces) with caller/dependency counts, or step through execution flow step-by-step using the bottom canvas player:

RepoTrace Node Inspection and Flow Stepper


✨ Features

  • ⚑ Circuit Blueprint Flow Engine: Clean orthogonal corridor routing (smoothstep) eliminates spaghetti crisscrossing wires. Hovering any card dynamically illuminates incoming callers in cyan (#06b6d4) and outgoing dependencies in purple (#a855f7).

  • 🎯 Focus Neighborhood Mode: 1-click micro-blueprint isolation ([ Callers ] ──▢ [ Active File ] ──▢ [ Dependencies ]) that automatically fits to the screen with zero manual panning or scrolling needed.

  • πŸ“ Folder View Layout & Directory Clustering: Seamlessly switch between dependency flow and glassmorphic directory boundary containers that group files inside their physical folders.

  • πŸ” Real-Time Folder & File Search: Search files and physical folders simultaneously, spotlighting matching folder containers with glowing borders and camera centering.

  • ⚑ Multi-Language AST Engine (TypeScript, JavaScript, Python, Dart/Flutter): Statically inspects and maps .ts, .tsx, .js, .jsx, .mjs, .cjs, .py, and .dart files. Resolves ES Modules, CommonJS (require()), Python imports, and Flutter package imports (package:<app>/... via pubspec.yaml). Honors path aliases (@/*, ~/*) and automatically ignores build caches, virtual environments (.venv, venv), Flutter platform runners (android/, ios/), and vendor packages (node_modules, .dart_tool).

  • πŸ” Discovered Symbols & Functions: Extracts internal declarations from every fileβ€”React Components, Custom Hooks, Helper Functions, TypeScript Interfaces, Type Aliases, and Classesβ€”badging public exports versus private declarations.

  • πŸ“‚ Zero-Upload Directory Navigator & Direct Path Input: Select any repository on your computer without uploading or moving source files. Includes an in-app filesystem navigator with quick shortcuts, direct path input/paste, and automatic codebase detection (package.json/tsconfig.json).

  • πŸ“ Automatic Dagre Layout: Computes optimal hierarchical coordinates supporting Top-to-Bottom (TB) and Left-to-Right (LR) orientations with smooth bezier connections.

  • πŸ”„ Bidirectional Topological Sort:

    • Execution Flow (Entrypoint β†’ Leaves, default): Traces the runtime boot path starting at index.tsx down through containers, UI components, and leaf utilities.
    • Build Order (Leaves β†’ Entrypoint): Traces the compilation sequence starting at foundational primitives with zero dependencies up toward the entrypoint.
  • πŸ›‘οΈ Fault-Tolerant Cycle Breaking: Mathematically detects circular import loops ($A \rightarrow B \rightarrow C \rightarrow A$) using Kahn's algorithm and DFS back-edge detection. Bypasses the deadlock to ensure 100% of your codebase remains sorted and visible, while highlighting cyclic nodes in pulsing crimson red.

  • 🎬 Interactive Canvas Flow Player: Floating player docked at the bottom of the canvas. Traverses the codebase step-by-step or with auto-play, smoothly illuminating each module in glowing amber as it resolves.

  • 🎯 1-Hop Neighborhood Isolation: Clicking any file isolates its direct incoming callers (cyan) and outgoing dependencies (purple), dimming unrelated files to reduce visual noise.


πŸ—οΈ Architecture

The system decouples the Backend AST Engine (Data Producer) from the Frontend Canvas (Data Consumer):

flowchart TD
    subgraph Frontend ["Client (React 18 + Vite + React Flow + Dagre)"]
        UI[User inputs path or picks folder]
        TopBar[TopBar Toolbar]
        Canvas[React Flow Graph Canvas]
        Drawer[Topo Order Drawer]
        Player[Canvas Flow Player]
        DagreEngine[Dagre Layout Engine]
        TopoEngine[Kahn Topo Sort & Cycle Breaker]
    end

    subgraph Backend ["Server (Node.js + Express + ts-morph)"]
        API["Express API (:3001)"]
        Explorer["Directory Explorer (/api/explore)"]
        WinDialog["Windows Dialog (/api/browse-folder)"]
        Analyzer["CodebaseAnalyzer (server/analyzer.ts)"]
        TSMorph["ts-morph AST Engine"]
    end

    UI --> TopBar
    TopBar -->|POST /api/analyze| API
    TopBar -->|POST /api/browse-folder| WinDialog
    TopBar -->|GET /api/explore| Explorer
    API --> Analyzer
    Analyzer --> TSMorph
    TSMorph -->|AST Nodes & Symbols| Analyzer
    Analyzer -->|JSON: nodes, edges, symbols| API
    API -->|GraphPayload| Frontend
    Frontend --> DagreEngine
    Frontend --> TopoEngine
    DagreEngine --> Canvas
    TopoEngine --> Drawer
    TopoEngine --> Player
    Player -->|Sync active step| Canvas
Loading

πŸ“ Repository Structure

repotrace/
β”œβ”€β”€ server/                         # Backend AST & Discovery Engine
β”‚   β”œβ”€β”€ analyzer.ts                 # CodebaseAnalyzer: ts-morph AST parser & symbol extractor
β”‚   β”œβ”€β”€ index.ts                    # Express API server & routes (/api/analyze, /api/explore)
β”‚   β”œβ”€β”€ mockData.ts                 # Fallback graph data for resilience
β”‚   β”œβ”€β”€ test-analyzer.ts            # CLI test runner for AST extraction
β”‚   └── test-topo.ts                # CLI test runner for Topo Sort & Cycle Breaking
β”‚
β”œβ”€β”€ src/                            # Frontend UI & Visualization Layer
β”‚   β”œβ”€β”€ components/                 # UI Components
β”‚   β”‚   β”œβ”€β”€ CanvasFlowPlayer.tsx    # Bottom floating stepper & playback controls
β”‚   β”‚   β”œβ”€β”€ CycleAlertModal.tsx     # Circular dependency loop diagnosis dialog
β”‚   β”‚   β”œβ”€β”€ FileNode.tsx            # Custom React Flow card (badges, states, counters)
β”‚   β”‚   β”œβ”€β”€ FolderBrowserModal.tsx  # In-app visual directory picker & OS dialog trigger
β”‚   β”‚   β”œβ”€β”€ GraphCanvas.tsx         # React Flow canvas wrapper with minimap & controls
β”‚   β”‚   β”œβ”€β”€ Sidebar.tsx             # Selected node inspector (symbols, callers, deps)
β”‚   β”‚   β”œβ”€β”€ TopBar.tsx              # Top toolbar with search, presets, layout & topo triggers
β”‚   β”‚   └── TopoOrderDrawer.tsx     # Slide-out topological architectural tier guide
β”‚   β”‚
β”‚   β”œβ”€β”€ utils/                      # Client Graph Utilities & Algorithms
β”‚   β”‚   β”œβ”€β”€ graphAnalysis.ts        # Category heuristics & 1-hop neighborhood math
β”‚   β”‚   β”œβ”€β”€ layout.ts               # Dagre layout coordinate math & edge styling
β”‚   β”‚   └── topoSort.ts             # Fault-tolerant Kahn's algorithm & cycle breaking
β”‚   β”‚
β”‚   β”œβ”€β”€ types/                      # Domain Type Definitions
β”‚   β”‚   └── graph.ts                # RawNode, RawEdge, GraphPayload, FileSymbol, FileNodeData
β”‚   β”‚
β”‚   β”œβ”€β”€ App.tsx                     # Root application coordinator
β”‚   β”œβ”€β”€ main.tsx                    # React DOM entrypoint
β”‚   └── index.css                   # Tailwind CSS utilities
β”‚
β”œβ”€β”€ example-repo/                   # Realistic 10-file React+TS sample chat app
β”œβ”€β”€ progress.md                     # Roadmap tracking and completed milestones
β”œβ”€β”€ walkthrough.md                  # In-depth technical architecture guide
└── package.json                    # Scripts and dependencies

πŸ§ͺ Testing & Validation

Run AST Analyzer Test

Statically parses example-repo and logs discovered symbols, outgoing dependencies, and incoming callers to the terminal:

npm run test:analyzer

Run Topological Sort & Cycle Breaking Test

Runs Kahn's algorithm over example-repo (verifying 7 architectural tiers) and an intentionally cyclic test graph ($A \rightarrow B \rightarrow C \rightarrow A$), verifying fault-tolerant cycle breaking:

npm run test:topo

🌐 Language Extensibility

While the current AST analyzer uses ts-morph for TypeScript & JavaScript (.ts, .tsx, .js, .jsx), the frontend graph consumer is language-agnostic.

To support other languages (Python, Go, Rust, Java), implement an adapter in server/ that emits the standardized { nodes, edges } JSON structure:

  • Python: Use Python's built-in ast module or Tree-sitter.
  • Go: Use go/parser and go/ast.
  • Rust: Use syn or ra_ap_syntax.

The entire frontend canvas, Dagre layout, Topological Sort drawer, and Stepper player will work immediately without any client-side changes.


🀝 Contributing

Contributions make the open-source community an incredible place to learn, inspire, and create!

  • Read our Contributing Guide to get started with local setup, branch conventions, and testing workflows.
  • Check out open issues or submit ideas for new language adapters, symbol call-graphs, or canvas themes.
  • Please review and adhere to our Code of Conduct.

πŸ“„ License

This project is licensed under the MIT License.

About

Interactive codebase intelligence tool that analyzes your repository, maps dependencies, and visualizes how your code is connected.

Topics

Resources

Code of conduct

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages