Architecture
How codeweb is built — parsing pipeline, graph store, feature flags, module map, and extension points.
Pipeline
- Scan —
parser/scanner.rsdiscovers files through the configured include paths and excludes. - Parse —
parser/extractor.rsfans 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. - Build —
graph/builder.rsturns relationships into nodes and edges, resolving names to schema/package-qualified keys and marking unreferenced DML targets as inferred (*) nodes. - Store —
graph/store.rskeeps 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. - Serve — the same store backs the CLI/TUI, the axum HTTP server, and the rmcp MCP server.
Feature flags
| Feature | Enables | Default |
|---|---|---|
cli | clap-based command line | yes |
tui | ratatui + crossterm terminal UI | yes |
java | tree-sitter-java extraction plus ogsql-parser’s Java SQL extraction | yes |
jsp | JSP scriptlet/declaration/expression SQL extraction (implies java and the ogsql-parser ibatis feature) | yes |
serve | axum HTTP server, browser UI (rust-embed), access log | no |
mcp | rmcp MCP server with schemars-generated tool schemas | no |
analyze | Library-only build shape (no CLI/TUI/serve/MCP) used to embed analysis into other Rust applications | no |
search-sql-v2 | Activates the search-sql-v2 test suite for enhanced token-normalized SQL matching; today it changes tests, while runtime search is identical in every build | no |
full | Everything above | no |
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
| Module | Responsibility |
|---|---|
src/main.rs | clap 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 importit; custom node and edge types become first-classcustomnodes andCustomEdgeedges. - Automation: drive the same store from scripts via the REST API, the MCP tools, or
codeweb querywith JSON specs.
Known limitations
- Dynamic SQL (
EXECUTE IMMEDIATEwith a non-literal string) becomes aDynamicCalledge to anunresnode; 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.