Skip to content

Commit 18682aa

Browse files
authored
Merge branch 'staging' into copilot/align-ci-and-makefile-tools
2 parents 0d61499 + 887b82f commit 18682aa

45 files changed

Lines changed: 1942 additions & 1409 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.template

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22
FALKORDB_HOST=localhost
33
FALKORDB_PORT=6379
44

5-
# OpenAI API key for LLM features
6-
OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
5+
# Optional FalkorDB authentication
6+
FALKORDB_USERNAME=
7+
FALKORDB_PASSWORD=
78

8-
# Secret token for API authentication
9+
# Token checked by authenticated endpoints. If left empty, the current
10+
# implementation accepts requests without an Authorization header.
911
SECRET_TOKEN=<YOUR_SECRET_TOKEN>
1012

11-
# Flask server settings
12-
FLASK_RUN_HOST=0.0.0.0
13-
FLASK_RUN_PORT=5000
14-
15-
# Set to 1 to enable public access for analyze_repo/switch_commit endpoints
13+
# Set to 1 to make read-only endpoints public.
1614
CODE_GRAPH_PUBLIC=0
15+
16+
# Limit /api/analyze_folder to this directory tree. Leave commented to use
17+
# the repository root as the default allowed directory.
18+
# ALLOWED_ANALYSIS_DIR=/absolute/path/to/projects
19+
20+
# LiteLLM model used by /api/chat
21+
MODEL_NAME=gemini/gemini-flash-lite-latest
22+
23+
# Provider credential for the default Gemini model. Change this to the
24+
# appropriate provider key if you change MODEL_NAME.
25+
GEMINI_API_KEY=<YOUR_GEMINI_API_KEY>
26+
27+
# Optional Uvicorn bind settings used by start.sh / make run-*
28+
HOST=0.0.0.0
29+
PORT=5000

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@v6
2222

2323
- name: Setup Node
2424
uses: actions/setup-node@v6
@@ -47,7 +47,7 @@ jobs:
4747
python-version: "3.12"
4848

4949
- name: Install uv
50-
uses: astral-sh/setup-uv@v5
50+
uses: astral-sh/setup-uv@v7
5151
with:
5252
version: "latest"
5353

@@ -58,7 +58,7 @@ jobs:
5858
runs-on: ubuntu-latest
5959
steps:
6060
- name: Checkout
61-
uses: actions/checkout@v4
61+
uses: actions/checkout@v6
6262

6363
- name: Build Docker image
6464
uses: docker/build-push-action@v7

.github/workflows/playwright.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
ports:
2626
- 6379:6379
2727
steps:
28-
- uses: actions/checkout@v4
28+
- uses: actions/checkout@v6
2929

3030
- uses: actions/setup-node@v6
3131
with:
@@ -40,7 +40,7 @@ jobs:
4040
python-version: '3.12'
4141

4242
- name: Install uv
43-
uses: astral-sh/setup-uv@v5
43+
uses: astral-sh/setup-uv@v7
4444
with:
4545
version: "latest"
4646

@@ -66,7 +66,7 @@ jobs:
6666
6767
- name: Cache Playwright browsers
6868
id: playwright-cache
69-
uses: actions/cache@v4
69+
uses: actions/cache@v5
7070
with:
7171
path: ~/.cache/ms-playwright
7272
key: playwright-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package-lock.json') }}
@@ -81,17 +81,17 @@ jobs:
8181
npx playwright install chromium firefox
8282
npx playwright install-deps chromium firefox
8383
84-
- name: Start Flask server
84+
- name: Start server
8585
id: start-server
8686
env:
8787
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
8888
SECRET_TOKEN: ${{ secrets.SECRET_TOKEN }}
8989
CODE_GRAPH_PUBLIC: "1"
9090
MODEL_NAME: "openai/gpt-4.1-mini"
9191
run: |
92-
uv run flask --app api/index.py run --host 0.0.0.0 --port 5000 &
92+
uv run uvicorn api.index:app --host 0.0.0.0 --port 5000 &
9393
echo "pid=$!" >> "$GITHUB_OUTPUT"
94-
# Wait for Flask to be ready
94+
# Wait for server to be ready
9595
timeout 30 bash -c 'until curl -s http://localhost:5000/ > /dev/null 2>&1; do sleep 0.5; done'
9696
9797
- name: Run Playwright tests
@@ -102,7 +102,7 @@ jobs:
102102
MODEL_NAME: "openai/gpt-4.1-mini"
103103
run: npx playwright test --shard=${{ matrix.shard }}/2 --reporter=dot,list
104104

105-
- name: Stop Flask server
105+
- name: Stop server
106106
if: always()
107107
run: kill ${{ steps.start-server.outputs.pid }} 2>/dev/null || true
108108

.github/workflows/release-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@v6
1616

1717
- name: Set tags
1818
run: |

AGENTS.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# CodeGraph - Agent Instructions
2+
3+
Knowledge graph visualization tool for codebases. Python FastAPI backend + React/TypeScript frontend + FalkorDB graph database.
4+
5+
## Architecture
6+
7+
- **Backend** (`api/`): FastAPI, async-first. All routes in `api/index.py`. Graph ops in `api/graph.py`. LLM chat via GraphRAG in `api/llm.py`.
8+
- **Frontend** (`app/`): React 18 + TypeScript + Vite. Tailwind CSS + Radix UI. 3D force-graph visualization (D3/Force-Graph).
9+
- **Database**: FalkorDB (graph DB on Redis). Metadata in Redis key-value store.
10+
- **Analyzers** (`api/analyzers/`): tree-sitter (Python), multilspy (Java, C#). Base class in `analyzer.py`, orchestrator in `source_analyzer.py`.
11+
12+
### Data flow
13+
14+
1. User submits repo URL or folder path -> backend clones/reads and analyzes via language-specific analyzers
15+
2. Entities stored in FalkorDB (nodes: File, Class, Function; edges: DEFINES, CALLS, etc.)
16+
3. Metadata (URL, commit) stored in Redis
17+
4. Frontend fetches graph, renders interactive visualization
18+
5. User can chat (GraphRAG), explore neighbors, find paths
19+
20+
## Directory structure
21+
22+
```text
23+
api/ # Python backend
24+
index.py # FastAPI app, routes, auth, SPA serving
25+
graph.py # FalkorDB graph operations (sync + async)
26+
llm.py # GraphRAG + LiteLLM chat
27+
project.py # Repo cloning and analysis pipeline
28+
info.py # Redis metadata operations
29+
prompts.py # LLM prompt templates
30+
auto_complete.py # Prefix search
31+
analyzers/ # Language-specific code analyzers
32+
entities/ # Graph entity models
33+
git_utils/ # Git history graph construction
34+
app/ # React frontend (Vite)
35+
src/components/ # React components (ForceGraph, chat, code-graph, etc.)
36+
src/lib/ # Utilities
37+
tests/ # Pytest backend tests
38+
endpoints/ # API endpoint integration tests
39+
e2e/ # Playwright E2E tests
40+
seed_test_data.py # Test data seeder
41+
```
42+
43+
## Commands
44+
45+
```bash
46+
make install # Install all deps (uv sync + npm install)
47+
make build-dev # Build frontend (dev mode)
48+
make build-prod # Build frontend (production)
49+
make run-dev # Build dev frontend + run API with reload
50+
make run-prod # Build prod frontend + run API
51+
make test # Run pytest suite
52+
make lint # Ruff + TypeScript type-check
53+
make lint-py # Ruff only
54+
make lint-fe # TypeScript type-check only
55+
make e2e # Run Playwright tests
56+
make clean # Remove build artifacts
57+
make docker-falkordb # Start FalkorDB container for testing
58+
make docker-stop # Stop test containers
59+
```
60+
61+
### Manual commands
62+
63+
```bash
64+
# Backend
65+
uv run uvicorn api.index:app --host 127.0.0.1 --port 5000 --reload
66+
uv run python -m pytest tests/ --verbose
67+
uv run ruff check .
68+
69+
# Frontend
70+
npm --prefix ./app run dev # Vite dev server (port 3000, proxies /api to 5000)
71+
npm --prefix ./app run build # Production build
72+
npm --prefix ./app run lint # Type-check
73+
74+
# E2E
75+
npx playwright test
76+
```
77+
78+
## Conventions
79+
80+
### Python (backend)
81+
- snake_case for functions/variables, PascalCase for classes
82+
- Async-first: route handlers and most graph operations are async, though api/graph.py includes some synchronous helpers
83+
- Auth: `public_or_auth` for read endpoints, `token_required` for mutating endpoints
84+
- Graph labels: PascalCase (File, Class, Function). Relations: SCREAMING_SNAKE_CASE (DEFINES, CALLS)
85+
- Linter: Ruff
86+
87+
### TypeScript (frontend)
88+
- camelCase for functions/variables, PascalCase for components
89+
- Tailwind CSS for styling
90+
- Radix UI for headless components
91+
- Linter: tsc (type-check only)
92+
93+
### General
94+
- Python >=3.12,<3.14. Node 20+.
95+
- Package managers: `uv` (Python), `npm` (frontend)
96+
- Environment variables: SCREAMING_SNAKE_CASE. See `.env.template` for reference.
97+
98+
## Environment variables
99+
100+
Key variables (see `.env.template` for full list):
101+
102+
| Variable | Default | Purpose |
103+
|----------|---------|---------|
104+
| `FALKORDB_HOST` | `localhost` | Graph DB host |
105+
| `FALKORDB_PORT` | `6379` | Graph DB port |
106+
| `SECRET_TOKEN` | empty | API auth token |
107+
| `CODE_GRAPH_PUBLIC` | `0` | Skip auth on read endpoints when `1` |
108+
| `MODEL_NAME` | `gemini/gemini-flash-lite-latest` | LiteLLM model for chat |
109+
| `ALLOWED_ANALYSIS_DIR` | repo root | Root path for analyze_folder |
110+
111+
## Testing
112+
113+
- **Backend**: `make test` runs pytest against `tests/`. Endpoint tests in `tests/endpoints/`.
114+
- **E2E**: `make e2e` runs Playwright (Chromium + Firefox). Test data seeded via `e2e/seed_test_data.py`.
115+
- **CI**: GitHub Actions — `build.yml` (lint + build), `playwright.yml` (E2E, 2 shards), `release-image.yml` (Docker image).
116+
117+
## API endpoints
118+
119+
### Read (public_or_auth)
120+
- `GET /api/list_repos` — List indexed repos
121+
- `GET /api/graph_entities?repo=<name>` — Fetch graph entities
122+
- `POST /api/get_neighbors` — Neighboring nodes
123+
- `POST /api/auto_complete` — Prefix search
124+
- `POST /api/repo_info` — Repo stats/metadata
125+
- `POST /api/find_paths` — Paths between nodes
126+
- `POST /api/chat` — GraphRAG chat
127+
- `POST /api/list_commits` — Git commit history
128+
129+
### Mutating (token_required)
130+
- `POST /api/analyze_folder` — Analyze local folder
131+
- `POST /api/analyze_repo` — Clone and analyze repo
132+
- `POST /api/switch_commit` — Switch to specific commit

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AGENTS.md

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ clean: ## Clean up build and test artifacts
4040
find . -name "*.pyo" -delete
4141

4242
run-dev: build-dev ## Run development server (Python backend serving built frontend)
43-
uv run flask --app api/index.py run --host $${HOST:-127.0.0.1} --port $${PORT:-5000} --debug
43+
uv run uvicorn api.index:app --host $${HOST:-127.0.0.1} --port $${PORT:-5000} --reload
4444

4545
run-prod: build-prod ## Run production server
46-
uv run flask --app api/index.py run --host $${HOST:-0.0.0.0} --port $${PORT:-5000}
46+
uv run uvicorn api.index:app --host $${HOST:-0.0.0.0} --port $${PORT:-5000}
4747

4848
docker-falkordb: ## Start FalkorDB in Docker for testing
4949
docker run -d --name falkordb-test -p 6379:6379 falkordb/falkordb:latest

0 commit comments

Comments
 (0)