# Architecture

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

---

LLMS index: [llms.txt](/codeweb/llms.txt)

---

## Pipeline {#pipeline}

```text
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](https://github.com/c2j/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 {#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-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 {#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 {#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.

---

Backlinks:

- [Getting started](/codeweb/docs/getting-started/)
