How falkordb/code-graph-backend works
Project Type and Purpose
• This is a RESTful source-code analysis service (Flask API) that inspects local code folders (Python/C/Java), builds a graph representation using FalkorDB (a graph database), and exposes endpoints for querying and exploring that graph. It also provides simple static UI assets and integrates optional LLM-based code completion and git-history utils.
Top-Level Structure & Architectural Patterns
• “api/” holds the backend service:
• index.py – Flask app entrypoint (routes & wsgi)
• analyzers/ – language-specific code parsers (Python, C, Java) plus a generic analyzer wrapper
• code_coverage/ – LCOV parser to attach coverage metadata
• git_utils/ – git-history graph builder
• llm.py & prompts.py – optional LLM integration for auto-completion
• project.py, info.py – orchestration & metadata endpoints
• “static/index.html” – client-side landing page (minimal UI)
• Dockerfile, .github/workflows – containerization and CI/CD (build/test/release)
• Tests cover endpoints, analyzers, graph operations, and git utils.
a. Clients & Entry Points
• REST Clients (curl, Postman)
• Web UI (static/index.html served or external code-graph UI)
• Third-party tools (GraphRAG-SDK, FalkorDB Browser)
b. API Layer (Flask Service)
• HTTP server hosting routes (/analyze_folder, /list_repos, /get_neighbors, etc.)
• Authentication via SECRET_TOKEN from .env
c. Business Logic Modules
• Analyzers: parse source files → produce graph entities
• Git Utils: read git history → enrich graph
• Code Coverage: parse .lcov → annotate nodes/edges
• LLM Module: generate completions or semantic queries
d. Data Layer
• FalkorDB Graph Database (cloud or local Redis-based)
• Python client library (api/project.py) writes/reads graph data
e. Deployment & CI
• Docker container runs Flask + Python dependencies (requirements.txt / pyproject.toml)
• GitHub Actions: lint, test, build and publish Docker images
• Vercel config for static hosting if applicable
Relationships & Data Flows
1. Client → HTTP(S) → Flask API
2. Flask routes dispatch → Business Logic Modules
3. Analyzers & git_utils read the file system / git repo
4. Modules emit graph entities → Graph DB write operations
5. Client queries graph endpoints → Flask reads from Graph DB → JSON responses
6. Optional: LLM module queries Graph DB + prompts → returns completions
Highlighted Design Principles
• Single-responsibility per analyzer (one language each)
• Clear separation: API layer vs. business modules vs. data persistence
• Configurable: .env template driving secrets, FalkorDB endpoint, ports
• Extensible: plug new analyzers or LLM backends via api/analyzers and api/llm