Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
FALKORDB_HOST=localhost
FALKORDB_PORT=6379

# Database backend. Use "lite" to run against an embedded FalkorDBLite
# instance instead of an external FalkorDB host/port.
CODE_GRAPH_DB_BACKEND=falkordb
FALKORDB_LITE_PATH=~/.cache/code-graph/falkordblite.rdb
# Optional: expose FalkorDBLite on localhost for host/port-only integrations
# such as GraphRAG chat. Structural CodeGraph/MCP tools do not need this.
# FALKORDB_LITE_HOST=127.0.0.1
# FALKORDB_LITE_PORT=6379

# Optional FalkorDB authentication
FALKORDB_USERNAME=
FALKORDB_PASSWORD=
Expand Down
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ code-graph/
- Python `>=3.12,<3.14`
- Node.js 20+
- [`uv`](https://docs.astral.sh/uv/)
- A FalkorDB instance (local/cloud) or the optional FalkorDBLite backend
- A FalkorDB instance (local or cloud)

### 1. Start FalkorDB

Expand All @@ -68,16 +68,6 @@ code-graph/
docker run -p 6379:6379 -it --rm falkordb/falkordb
```

**Option C:** Use embedded FalkorDBLite:

```bash
uv sync --extra light
export CODE_GRAPH_DB_BACKEND=lite
export FALKORDB_LITE_PATH=~/.cache/code-graph/falkordblite.rdb
```

FalkorDBLite runs a local embedded server over a private Unix socket by default. Set `FALKORDB_LITE_PORT` only when a host/port-only integration, such as GraphRAG chat, must connect to the embedded database.

### 2. Configure environment variables

Copy the template and adjust it for your setup:
Expand All @@ -88,14 +78,10 @@ cp .env.template .env

| Variable | Description | Required | Default |
|----------|-------------|----------|---------|
| `CODE_GRAPH_DB_BACKEND` | Database backend: `falkordb` or `lite` | No | `falkordb` |
| `FALKORDB_HOST` | FalkorDB hostname | No | `localhost` |
| `FALKORDB_PORT` | FalkorDB port | No | `6379` |
| `FALKORDB_USERNAME` | Optional FalkorDB username | No | empty |
| `FALKORDB_PASSWORD` | Optional FalkorDB password | No | empty |
| `FALKORDB_LITE_PATH` | FalkorDBLite database file path | No | `~/.cache/code-graph/falkordblite.rdb` |
| `FALKORDB_LITE_HOST` | Host used when exposing FalkorDBLite over TCP | No | `127.0.0.1` |
| `FALKORDB_LITE_PORT` | Optional TCP port for FalkorDBLite host/port clients | No | empty |
| `SECRET_TOKEN` | Token checked by protected endpoints | No | empty |
| `CODE_GRAPH_PUBLIC` | Set `1` to skip auth on read-only endpoints | No | `0` |
| `ALLOWED_ANALYSIS_DIR` | Root path allowed for `/api/analyze_folder` | No | repository root |
Expand Down
12 changes: 0 additions & 12 deletions api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ def _check_connection(host: str, port: int) -> bool:
def ensure_db() -> None:
"""Ensure FalkorDB is running, auto-starting a Docker container if needed."""

from .db import create_falkordb, is_lite_backend

if is_lite_backend():
try:
db = create_falkordb()
db.connection.ping()
except Exception as e:
_json_error(f"Failed to initialize FalkorDBLite: {e}")
_stderr("FalkorDBLite embedded backend is ready")
_json_out({"status": "ok", "backend": "lite"})
return

host = os.getenv("FALKORDB_HOST", "localhost")
try:
port = int(os.getenv("FALKORDB_PORT", "6379"))
Expand Down
157 changes: 0 additions & 157 deletions api/db.py

This file was deleted.

18 changes: 14 additions & 4 deletions api/git_utils/git_graph.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import logging
from falkordb import Node
from falkordb import FalkorDB, Node
from falkordb.asyncio import FalkorDB as AsyncFalkorDB
from typing import List, Optional

from api.db import create_async_falkordb, create_falkordb
from pygit2 import Commit

# Configure logging
Expand All @@ -18,7 +19,10 @@ class GitGraph():

def __init__(self, name: str):

self.db = create_falkordb()
self.db = FalkorDB(host=os.getenv('FALKORDB_HOST', 'localhost'),
port=os.getenv('FALKORDB_PORT', 6379),
username=os.getenv('FALKORDB_USERNAME', None),
password=os.getenv('FALKORDB_PASSWORD', None))

self.g = self.db.select_graph(name)

Expand Down Expand Up @@ -178,7 +182,12 @@ class AsyncGitGraph:
"""Async read-only git graph for endpoint use."""

def __init__(self, name: str):
self.db = create_async_falkordb()
self.db = AsyncFalkorDB(
host=os.getenv('FALKORDB_HOST', 'localhost'),
port=int(os.getenv('FALKORDB_PORT', 6379)),
username=os.getenv('FALKORDB_USERNAME', None),
password=os.getenv('FALKORDB_PASSWORD', None),
)
self.g = self.db.select_graph(name)

def _commit_from_node(self, node: Node) -> dict:
Expand All @@ -196,3 +205,4 @@ async def list_commits(self) -> List[dict]:

async def close(self) -> None:
await self.db.aclose()

43 changes: 31 additions & 12 deletions api/graph.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import re
import time
from .entities import *
from typing import Optional
from falkordb import Path, Node, QueryResult
from .db import create_async_falkordb, create_falkordb
from .entities import File, encode_edge, encode_node
from falkordb import FalkorDB, Path, Node, QueryResult
from falkordb.asyncio import FalkorDB as AsyncFalkorDB

# Configure the logger
import logging
Expand Down Expand Up @@ -61,7 +62,10 @@ def parse_graph_name(graph_name: str) -> Optional[tuple[str, str]]:


def graph_exists(name: str):
db = create_falkordb()
db = FalkorDB(host=os.getenv('FALKORDB_HOST', 'localhost'),
port=os.getenv('FALKORDB_PORT', 6379),
username=os.getenv('FALKORDB_USERNAME', None),
password=os.getenv('FALKORDB_PASSWORD', None))

return name in db.list_graphs()

Expand All @@ -82,7 +86,10 @@ def get_repos() -> list[dict]:
single graph until the migration is run.
"""

db = create_falkordb()
db = FalkorDB(host=os.getenv('FALKORDB_HOST', 'localhost'),
port=os.getenv('FALKORDB_PORT', 6379),
username=os.getenv('FALKORDB_USERNAME', None),
password=os.getenv('FALKORDB_PASSWORD', None))

repos = []
for g in db.list_graphs():
Expand Down Expand Up @@ -133,7 +140,10 @@ def __init__(self, name: str, branch: Optional[str] = None) -> None:
self.branch = branch or DEFAULT_BRANCH
self.name = compose_graph_name(self.project, self.branch)

self.db = create_falkordb()
self.db = FalkorDB(host=os.getenv('FALKORDB_HOST', 'localhost'),
port=os.getenv('FALKORDB_PORT', 6379),
username=os.getenv('FALKORDB_USERNAME', None),
password=os.getenv('FALKORDB_PASSWORD', None))
self.g = self.db.select_graph(self.name)

# Initialize the backlog as disabled by default
Expand Down Expand Up @@ -170,7 +180,10 @@ def from_raw_name(cls, raw_name: str) -> "Graph":
obj.branch = DEFAULT_BRANCH
else:
obj.project, obj.branch = parsed
obj.db = create_falkordb()
obj.db = FalkorDB(host=os.getenv('FALKORDB_HOST', 'localhost'),
port=os.getenv('FALKORDB_PORT', 6379),
username=os.getenv('FALKORDB_USERNAME', None),
password=os.getenv('FALKORDB_PASSWORD', None))
obj.g = obj.db.select_graph(raw_name)
obj.backlog = None
return obj
Expand Down Expand Up @@ -284,7 +297,7 @@ def _query(self, q: str, params: Optional[dict] = None) -> QueryResult:

return result_set

def get_sub_graph(self, limit: int) -> dict:
def get_sub_graph(self, l: int) -> dict:

q = """MATCH (src)
OPTIONAL MATCH (src)-[e]->(dest)
Expand All @@ -293,7 +306,7 @@ def get_sub_graph(self, limit: int) -> dict:

sub_graph = {'nodes': [], 'edges': [] }

result_set = self._query(q, {'limit': limit}).result_set
result_set = self._query(q, {'limit': l}).result_set
for row in result_set:
src = row[0]
e = row[1]
Expand Down Expand Up @@ -579,7 +592,7 @@ def set_file_coverage(self, path: str, name: str, ext: str, coverage: float) ->

params = {'path': path, 'name': name, 'ext': ext, 'coverage': coverage}

self._query(q, params)
res = self._query(q, params)

def connect_entities(self, relation: str, src_id: int, dest_id: int, properties: dict = {}) -> None:
"""
Expand Down Expand Up @@ -776,9 +789,14 @@ def unreachable_entities(self, lbl: Optional[str], rel: Optional[str]) -> list[d
# Async helpers and read-only async graph wrapper
# ---------------------------------------------------------------------------

def _async_db():
def _async_db() -> AsyncFalkorDB:
"""Create an async FalkorDB connection using environment config."""
return create_async_falkordb()
return AsyncFalkorDB(
host=os.getenv('FALKORDB_HOST', 'localhost'),
port=int(os.getenv('FALKORDB_PORT', 6379)),
username=os.getenv('FALKORDB_USERNAME', None),
password=os.getenv('FALKORDB_PASSWORD', None),
)


async def async_graph_exists(name: str) -> bool:
Expand Down Expand Up @@ -934,3 +952,4 @@ async def stats(self) -> dict:

async def close(self) -> None:
await self.db.aclose()

Loading
Loading