Skip to content

Architecture

How codeweb is built — parsing pipeline, graph store, feature flags, module map, and extension points.

Pipeline

scan (globset) → load (encoding detection) → parse (rayon, parallel)
      │                │                          │
      │           SQL: ogsql-parser          relationships
      │           XML: iBatis loader         as (caller, callee, Edge)
      │           Java: tree-sitter-java           │
      │           JSP: preprocess to Java          ▼
      ▼                                    GraphBuilder
  fingerprints (blake3)                            │
 (incremental re-parse)                            ▼
                                         GraphStore (petgraph)
                                                │        │
                                     bincode on disk    in-memory index
                                                     │         │          │
                                                 CLI/TUI   serve (axum)  mcp (rmcp)
                                                              │
                                                   export: dot / json / mermaid / ndjson
  1. Scan — parser/scanner.rs discovers files through the configured include paths and excludes.
  2. Parse — parser/extractor.rs fans out over a rayon thread pool. SQL goes through ogsql-parser (openGauss/GaussDB dialect), mapper XML through its iBatis loader, Java through tree-sitter-java, and JSP through a preprocessor that synthesizes Java and reuses the Java SQL extraction.
  3. Build — graph/builder.rs turns relationships into nodes and edges, resolving names to schema/package-qualified keys and marking unreferenced DML targets as inferred (*) nodes.
  4. Store — graph/store.rs keeps the graph in a petgraph graph with query indexes, serializes to bincode under .codeweb/, merges and dedups stores, and supports incremental re-parse via blake3 fingerprints.
  5. Serve — the same store backs the CLI/TUI, the axum HTTP server, and the rmcp MCP server.

Feature flags

FeatureEnablesDefault
cliclap-based command lineyes
tuiratatui + crossterm terminal UIyes
javatree-sitter-java extraction plus ogsql-parser’s Java SQL extractionyes
jspJSP scriptlet/declaration/expression SQL extraction (implies java and the ogsql-parser ibatis feature)yes
serveaxum HTTP server, browser UI (rust-embed), access logno
mcprmcp MCP server with schemars-generated tool schemasno
analyzeLibrary-only build shape (no CLI/TUI/serve/MCP) used to embed analysis into other Rust applicationsno
search-sql-v2Activates the search-sql-v2 test suite for enhanced token-normalized SQL matching; today it changes tests, while runtime search is identical in every buildno
fullEverything aboveno

Feature composition matters at runtime: binaries built without serve or mcp lack those subcommands entirely. The default build already extracts SQL from Java and JSP; only the server surfaces are opt-in.

Module map

ModuleResponsibility
src/main.rsclap entry point and command dispatch
src/parser/File scanning, loading, and relationship extraction (extractor.rs, ibatis_loader.rs, java_loader.rs, java_method.rs, jsp_loader.rs, jsp_preprocessor.rs, fingerprint.rs)
src/graph/Graph model: store.rs (GraphStore, indexes, dedup, merge), builder.rs, traverse.rs, lineage.rs, cluster.rs, columns.rs, conflict.rs, key.rs; query/ (QuerySpec engine), search/ (fuzzy + SQL search)
src/export/dot.rs, json.rs, mermaid.rs, ndjson.rs
src/import/CGEF document model, parser, validator, custom schema registry, path prefix mapper
src/server/axum router, handlers, state, embedded UI assets, access log (serve)
src/mcp/MCP server entry and tool definitions (mcp)
src/tui/Terminal UI app, theme (tui)
src/project/codeweb.toml loading and project lifecycle
locales/rust-i18n catalogs at the repository root (en, zh-CN)

Extension points

  • New source language: add a loader under src/parser/ that emits relationships as (caller, callee, Edge) triples, then feed them to the graph builder — the JSP loader is the worked example (it preprocesses to synthetic Java and reuses the Java extraction).
  • External graphs: produce CGEF JSON from any tool and codeweb import it; custom node and edge types become first-class custom nodes and CustomEdge edges.
  • Automation: drive the same store from scripts via the REST API, the MCP tools, or codeweb query with JSON specs.

Known limitations

  • Dynamic SQL (EXECUTE IMMEDIATE with a non-literal string) becomes a DynamicCall edge to an unres node; codeweb resolves what is statically visible and marks the rest as unresolved rather than guessing.
  • JSP extraction reuses the Java SQL keyword gate, so JDBC escape calls such as {call pkg.x(...)} in scriptlets are filtered out today; direct stored-procedure calls from JSP need a follow-up post-processor.
  • The openGauss/GaussDB parser accepts the target dialect; other vendor dialects may parse partially or fail.
  • codeweb analyzes static source only: runtime configuration, reflection-based dispatch, and dynamically assembled SQL appear only to the extent they are literal in the code.