Skip to content

Commit bcbcb71

Browse files
committed
feat(typescript): add Neo4j-backed analysis backend (Cypher over codeanalyzer-ts graph)
Add TSNeo4jBackend, a drop-in alternative to the in-memory TSCodeanalyzer that answers the exact same get_* query surface (call graph, callers/callees, class hierarchy, call sites, decorators, symbol/method/field lookups, imports/exports/ variables, ...) by running Cypher over a live Neo4j graph instead of walking the pydantic / NetworkX structures. The graph is the one codeanalyzer-typescript emits with `--emit neo4j` (schema schema.neo4j.json). The backend can populate the database for you over Bolt (running the analyzer with --emit neo4j --neo4j-uri), or query a DB that is already loaded (build_db=False). Results are re-hydrated into the same cldk.models.typescript pydantic objects the in-memory backend returns; lossy fields inherent to the projection (collapsed comments/type-params, aggregated import edges, the three round-tripped CALLS tag keys) are reconstructed best-effort and documented inline. - cldk/analysis/typescript/neo4j/: backend, model reconstruction, Neo4jConnectionConfig. - TypeScriptAnalysis / CLDK.analysis: optional neo4j_config selects the backend; default behavior unchanged. - pyproject: optional `neo4j` extra for the driver. - tests: live-DB integration tests (skipped when no Neo4j reachable) mirroring the in-memory backend's sample-app expectations, plus no-DB backend-selection unit tests.
1 parent 9a43542 commit bcbcb71

10 files changed

Lines changed: 1645 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Added
11+
- Neo4j-backed TypeScript analysis backend (`cldk.analysis.typescript.neo4j.TSNeo4jBackend`). It
12+
is a drop-in alternative to the in-memory `TSCodeanalyzer`: it answers the **same** `get_*`
13+
query surface (call graph, callers/callees, class hierarchy, call sites, decorators, symbol
14+
lookups, ...) by running **Cypher over a live Neo4j graph** instead of walking the pydantic /
15+
NetworkX structures. The graph is the one `codeanalyzer-typescript` emits with `--emit neo4j`
16+
(schema `schema.neo4j.json`); the backend can populate the database for you over Bolt, or query
17+
one that is already loaded.
18+
- `TypeScriptAnalysis` / `CLDK.analysis(language="typescript")` now accept an optional
19+
`neo4j_config` (`Neo4jConnectionConfig`) to select the Neo4j backend; without it the in-memory
20+
backend is used, unchanged.
21+
- Optional `neo4j` extra (`pip install cldk[neo4j]`) for the Neo4j Python driver.
22+
823
## [v1.0.7] - 2026-02-14
924

1025
### Added
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
################################################################################
2+
# Copyright IBM Corporation 2026
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
################################################################################
16+
17+
"""Neo4j-backed TypeScript analysis backend (Cypher queries over the codeanalyzer-ts graph)."""
18+
19+
from cldk.analysis.typescript.neo4j.config import Neo4jConnectionConfig
20+
from cldk.analysis.typescript.neo4j.neo4j_backend import TSNeo4jBackend
21+
22+
__all__ = ["TSNeo4jBackend", "Neo4jConnectionConfig"]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
################################################################################
2+
# Copyright IBM Corporation 2026
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
################################################################################
16+
17+
"""Connection settings for the Neo4j-backed TypeScript analysis backend."""
18+
19+
from __future__ import annotations
20+
21+
from dataclasses import dataclass
22+
23+
24+
@dataclass
25+
class Neo4jConnectionConfig:
26+
"""How :class:`TSNeo4jBackend` reaches (and, optionally, populates) the graph database.
27+
28+
Attributes:
29+
uri: Bolt URI of the Neo4j server (e.g. ``bolt://localhost:7687``).
30+
username: Neo4j username.
31+
password: Neo4j password.
32+
database: Database name (None ⇒ server default).
33+
application_name: The ``:Application`` anchor name to scope queries to. Defaults to the
34+
analyzed project directory's name (matching ``codeanalyzer-typescript``'s
35+
``--app-name`` default).
36+
build_db: If True (default), populate the database from the project on construction by
37+
running ``codeanalyzer-typescript --emit neo4j``. Set False to query a DB that is
38+
already loaded.
39+
"""
40+
41+
uri: str
42+
username: str = "neo4j"
43+
password: str = "neo4j"
44+
database: str | None = None
45+
application_name: str | None = None
46+
build_db: bool = True

0 commit comments

Comments
 (0)