How Egonex-AI's Domain Analysis Feature Extracts Project Business Logic

Egonex-AI's domain analysis extracts business logic by scanning source trees for entry points using 13 regex patterns, aggregating file metadata into a structured JSON context, and employing an LLM-driven Domain Analyzer Agent to hierarchically map domains, flows, and implementation steps.

The Egonex-AI/Understand-Anything repository automates architectural reverse-engineering through intelligent code analysis. Its domain analysis feature systematically transforms raw source code into actionable business logic representations without requiring manual documentation.

The Three-Stage Extraction Pipeline

The domain analysis implementation in understand-anything-plugin/skills/understand-domain/extract-domain-context.py operates through three tightly-coupled stages that progressively refine raw source code into structured business logic.

Stage 1: File System Scanning and Filtering

The process begins with scan_file_tree (line 51), a lightweight scanner that walks the project tree while respecting .gitignore rules and a hard-coded SKIP_DIRS ignore list. The scanner imposes strict limits on traversal depth, file count, and total byte size to ensure the output remains digestible for LLM context windows.

This stage produces a filtered file-tree containing only relevant source files, eliminating noise from dependency directories and build artifacts before deeper analysis begins.

Stage 2: Entry Point Detection via Regex Patterns

Once the file tree is established, the detect_entry_points function (line 97) applies the ENTRY_POINT_PATTERNS table (line 70) to identify where business flows begin. This table contains 13 language-agnostic regex patterns that detect:

  • HTTP routes (Express, FastAPI, NestJS, Next.js)
  • CLI commands and argument parsers
  • Event listeners and message queue consumers
  • Cron jobs and scheduled tasks
  • GraphQL resolvers

For each match, the system records the file path, line number, entry type, matched text, and a surrounding code snippet, creating a precise map of application boundaries.

Stage 3: Domain-Context JSON Assembly

The main() function (line 76) orchestrates the final aggregation, combining the file tree, detected entry points, file signatures (exports/imports), and project metadata (from package.json, README.md, etc.) into a single JSON document. The output is written to .understand-anything/intermediate/domain-context.json and automatically trimmed to stay under MAX_OUTPUT_BYTES limits.

This JSON structure serves as the sole input for the downstream Domain Analyzer Agent when no existing knowledge graph is present.

LLM-Driven Business Logic Inference

Once the domain-context.json is generated, the Domain Analyzer Agent defined in agents/domain-analyzer.md processes the raw data through a three-level hierarchical mapping:

  1. Flow Construction: Entry points sharing logical purposes (e.g., all routes under /orders/*) are grouped into discrete business flows such as "Create Order" or "Process Payment"
  2. Domain Clustering: Related flows are clustered under higher-level business domains (e.g., "Order Management" or "User Authentication")
  3. Step Node Creation: Each code fragment implementing a flow (controller methods, CLI handlers, event listeners) becomes a step node with attached file paths and line ranges

The agent emits a domain-analysis.json file following the strict schema validated by understand-anything-plugin/packages/core/src/__tests__/domain-types.test.ts.

If a knowledge graph already exists, the agent operates top-down by reading existing nodes, edges, and tags to derive the hierarchy without re-scanning source files.

Running the Domain Analysis Pipeline

Execute the extraction pipeline from the repository root to analyze any target project:

python understand-anything-plugin/skills/understand-domain/extract-domain-context.py /path/to/your/project

This generates the intermediate context file at:


/path/to/your/project/.understand-anything/intermediate/domain-context.json

The resulting JSON structure contains:

{
  "projectRoot": "/path/to/your/project",
  "fileCount": 387,
  "fileTree": ["src/server.ts", "src/controllers/order.ts", "..."],
  "entryPoints": [
    {
      "file": "src/controllers/order.ts",
      "line": 12,
      "type": "http",
      "description": "Express/Koa route",
      "match": "router.post('/api/orders'",
      "snippet": "router.post('/api/orders', async (req, res) => { ..."
    }
  ],
  "fileSignatures": [
    {
      "file": "src/controllers/order.ts",
      "exports": ["createOrder", "getOrder"],
      "imports": ["express", "orderService"],
      "lines": 210,
      "preview": "export async function createOrder(req, res) { ..."
    }
  ],
  "metadata": {
    "package.json": {
      "name": "my‑app",
      "description": "E‑commerce API",
      "scripts": ["start", "test"],
      "dependencies": ["express", "prisma"]
    }
  }
}

Trigger the Domain Analyzer Agent through the Claude Code CLI:

/understand --full

This produces the analyzed output at:


/path/to/your/project/.understand-anything/intermediate/domain-analysis.json

Consolidating Multi-Project Graphs

For monorepos or distributed systems, the merge-subdomain-graphs.py utility consolidates multiple sub-domain analyses into a unified knowledge graph:

python understand-anything-plugin/skills/understand-domain/merge-subdomain-graphs.py /path/to/your/project

The script deduplicates nodes, resolves edge weight conflicts, and reports consolidation statistics (e.g., "Fixed 12 duplicate nodes, 7 dangling edges") before writing the final knowledge-graph.json used by the visualization dashboard.

Summary

  • File System Scanning: The scan_file_tree function filters source files using .gitignore rules and size limits to create a manageable context window
  • Pattern Matching: ENTRY_POINT_PATTERNS uses 13 regexes to identify HTTP routes, CLI commands, cron jobs, and event listeners across multiple frameworks
  • Context Generation: The main() function outputs domain-context.json containing file trees, entry points, and metadata for LLM consumption
  • Hierarchical Mapping: The Domain Analyzer Agent transforms raw context into business domains, flows, and step nodes according to the schema in agents/domain-analyzer.md
  • Graph Consolidation: merge-subdomain-graphs.py combines multiple analyses while deduplicating nodes and resolving conflicts

Frequently Asked Questions

What programming languages and frameworks does the domain analysis support?

The domain analysis supports any language through the extensible ENTRY_POINT_PATTERNS regex table in extract-domain-context.py, which currently includes patterns for Express, FastAPI, NestJS, Next.js, standard CLI patterns, cron syntax, and GraphQL resolvers. The file signature extraction works on any text-based source code by parsing import/export statements.

How does the system handle enterprise-scale codebases?

The implementation imposes hard limits on file count, directory depth, and total output size (MAX_OUTPUT_BYTES) to prevent context window overflow. The scanner respects .gitignore patterns and skips binary files, while the merge utility allows partitioning large monorepos into sub-domain analyses that are later consolidated into a single knowledge graph.

Can developers customize which code patterns are detected as entry points?

Yes. The ENTRY_POINT_PATTERNS table at line 70 of extract-domain-context.py defines the 13 detection regexes, which can be extended to support additional frameworks or organizational coding patterns. Each pattern specifies the entry type, description, and capture groups for extracting route paths or command names.

What is the difference between domain-context.json and knowledge-graph.json?

The domain-context.json file is the raw output of the extraction phase containing file trees, regex matches, and code snippets. The knowledge-graph.json is the final processed output containing the hierarchical business logic structure (domains, flows, steps) suitable for visualization and querying, produced either directly by the Domain Analyzer Agent or via the merge utility for multi-project analyses.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →