AI-powered codebase visualizer that maps dependencies, explains architecture, and answers natural language questions about your repository.
- π Graph-based code analysis
- π Dependency visualization
- π€ AI-powered explanations (via embeddings)
- π¬ Natural language querying of your codebase
- β‘ Queue processing with Redis
- π§© Vector search using pgvector
- Backend: Node.js + Express
- Frontend: SPA (client)
- Database: PostgreSQL + pgvector
- Queue: Redis (BullMQ)
- AI: OpenAI embeddings
codegraph-ai/
βββ client/ # Frontend SPA
βββ server/ # Backend API
βββ docker-compose.yml
βββ README.md
cd server
npm installcd client
npm installThis project uses Docker to run:
- PostgreSQL (with pgvector)
- Redis
- Backend
docker compose up -ddocker compose downdocker compose down -vpsql -h localhost -p 5433 -U postgres -d codegraph -f ./server/src/infrastructure/migrations/001_initial.sqlPassword:
postgres
Inside pgAdmin:
-
Right-click βServersβ β Register β Server
-
General tab Name: local-postgres (or anything)
-
Connection tab Use your connection string details:
- Host name/address: host.docker.internal
β οΈ important - Port: 5433
- Username: postgres
- Password: postgres
- Database: codegraph
- Host name/address: host.docker.internal
-
Why host.docker.internal? Because pgAdmin runs inside a container, and:
- localhost inside that container β your machine
- host.docker.internal points to your host machine
- PostgreSQL runs on:
localhost:5433 - Redis runs on:
localhost:6379 - Backend runs on:
localhost:3000
Create server/.env:
DATABASE_URL=postgres://postgres:postgres@postgres:5432/codegraph
REDIS_URL=redis://redis:6379
OPENAI_API_KEY=your_key_here
Optional cache tuning:
ANALYSIS_HISTORY_CACHE_TTL_SECONDS=60
GRAPH_CACHE_TTL_SECONDS=300
REPOSITORIES_LIST_CACHE_TTL_SECONDS=60
REPOSITORY_JOBS_CACHE_TTL_SECONDS=60
QUERY_AGENT_CACHE_TTL_SECONDS=3600
ENRICHMENT_CACHE_TTL_SECONDS=3600
Implemented Redis-backed cache-aside and invalidation now cover:
GET /api/analyze/historyGET /api/graph/:jobIdGET /api/repositoriesGET /api/repositories/:id/jobs
Each endpoint returns X-Cache: HIT or X-Cache: MISS for easy verification.
Cache invalidation is triggered:
- When a new analysis job is enqueued
- When a job reaches terminal status (
completed,failed,partial)
This keeps dashboard/repository/graph reads fast while preserving correctness.
Detailed implementation guide:
Quick verification:
- Call an endpoint above once and confirm
X-Cache: MISS. - Call it again with the same params and confirm
X-Cache: HIT. - Enqueue a new analysis and confirm repository/list endpoints return
MISSagain (cache invalidated).
Then:
cd server
npm run migrate
npm run devcd client
npm run devcd client
npm run buildTo avoid:
Cannot GET /analyze
In production (NODE_ENV=production), backend serves client/dist.
cd client
npm run buildcd server
npm startserver {
listen 80;
server_name your-domain.com;
root /var/www/codegraph-ai/client/dist;
index index.html;
location /api/ {
proxy_pass http://127.0.0.1:5000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /health {
proxy_pass http://127.0.0.1:5000;
}
location /analyze {
try_files $uri /index.html;
}
location / {
try_files $uri $uri/ /index.html;
}
}docker compose logs -fdocker compose restart backenddocker compose up -d --buildβ Fixed by using pgvector Docker image
β Use SPA fallback (Express or Nginx)
β Ensure backend uses:
postgres://postgres:postgres@postgres:5432/codegraph
- Migration versioning (Prisma / Knex)
- Auth system expansion
- Multi-repo analysis
- Graph UI enhancements
- Background job monitoring
PRs welcome. Open an issue first for major changes.
MIT