# pratiksinha-rzp/context-graph architecture

> Architecture diagram of the GitHub repository pratiksinha-rzp/context-graph, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pratiksinha-rzp/context-graph
- Repository: https://github.com/pratiksinha-rzp/context-graph

## Overview

Context Graph is a backend for importing GitHub repositories, extracting Go code structure and call relationships, and serving repository, entity, and dependency-graph queries. The documented-by-code workflow runs from GitHub synchronization through parsing and persistence, then exposes results through an HTTP API. The excerpts show the API routes, repository creation/query handlers, GitHub client, and parser entry points; ingestion internals and several query implementations were not sampled, so their connections are left unverified where necessary.

Main entry points: [`backend/internal/handlers`](https://github.com/pratiksinha-rzp/context-graph/tree/main/backend/internal/handlers) (API handlers), [`backend/cmd/resolve-calls/main.go`](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/cmd/resolve-calls/main.go) (Call analysis command), [`backend/internal/database/postgres.go`](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/database/postgres.go) (PostgreSQL), [`backend/internal/services/go_parser.go`](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/services/go_parser.go) (Parse and persist)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["GitHub ingestion"]
  node_sync_command["Repository sync<br/>[main.go]"]
  node_github_client["GitHub client<br/>[client.go]"]
  node_ingestion["File ingestion"]
end

subgraph group_analysis["Code analysis"]
  node_parser_service["Parse and persist<br/>[go_parser.go]"]
  node_go_parser["Go parser<br/>[go_parser.go]"]
  node_call_resolver["Call resolver<br/>[call_resolver.go]"]
  node_resolve_command["Call analysis command<br/>[main.go]"]
end

subgraph group_storage["Graph storage"]
  node_database[("PostgreSQL<br/>[postgres.go]")]
  node_repositories["Repository records<br/>[repository.go]"]
  node_documents["Source documents<br/>[document.go]"]
  node_graph_repository["Graph queries<br/>[graph.go]"]
  node_models["Domain models"]
end

subgraph group_api["Query API"]
  node_api_server["HTTP API<br/>[main.go]"]
  node_handlers["API handlers"]
  node_entity_search["Entity search<br/>[entity_search.go]"]
  node_entity_details["Entity details<br/>[entity_details.go]"]
end

node_operator(("Operator"))
node_github["GitHub API"]

node_operator -->|"starts sync"| node_sync_command
node_sync_command -->|"initializes"| node_github_client
node_sync_command -->|"invokes sync"| node_ingestion
node_github_client -->|"requests files"| node_github
node_ingestion -.->|"fetches content"| node_github_client
node_operator -.->|"queries"| node_api_server
node_api_server -->|"routes requests"| node_handlers
node_handlers -->|"accesses records"| node_repositories
node_handlers -->|"searches entities"| node_entity_search
node_handlers -->|"loads details"| node_entity_details
node_handlers -.->|"queries dependencies"| node_graph_repository
node_repositories -.->|"reads and writes"| node_database
node_documents -.->|"reads and writes"| node_database
node_graph_repository -.->|"queries graph"| node_database
node_parser_service -.->|"parses Go"| node_go_parser
node_parser_service -.->|"resolves calls"| node_call_resolver
node_parser_service -.->|"persists source"| node_documents
node_operator -->|"runs analysis"| node_resolve_command
node_resolve_command -->|"loads documents"| node_database
node_resolve_command -->|"parses files"| node_go_parser
node_resolve_command -->|"resolves calls"| node_call_resolver
node_models -.->|"represents records"| node_repositories

click node_sync_command "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/cmd/sync-github/main.go"
click node_github_client "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/connectors/github/client.go"
click node_ingestion "https://github.com/pratiksinha-rzp/context-graph/tree/main/backend/internal/services"
click node_parser_service "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/services/go_parser.go"
click node_go_parser "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/parser/go_parser.go"
click node_call_resolver "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/parser/call_resolver.go"
click node_resolve_command "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/cmd/resolve-calls/main.go"
click node_database "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/database/postgres.go"
click node_repositories "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/repositories/repository.go"
click node_documents "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/repositories/document.go"
click node_graph_repository "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/repositories/graph.go"
click node_models "https://github.com/pratiksinha-rzp/context-graph/tree/main/backend/internal/models"
click node_api_server "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/cmd/api/main.go"
click node_handlers "https://github.com/pratiksinha-rzp/context-graph/tree/main/backend/internal/handlers"
click node_entity_search "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/repositories/entity_search.go"
click node_entity_details "https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/repositories/entity_details.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sync_command,node_github_client,node_ingestion toneBlue
class node_parser_service,node_go_parser,node_call_resolver,node_resolve_command toneAmber
class node_database,node_repositories,node_documents,node_graph_repository,node_models,node_github toneMint
class node_api_server,node_handlers,node_entity_search,node_entity_details toneRose
class node_operator toneIndigo
```

## Components

### GitHub ingestion

- [Repository sync](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/cmd/sync-github/main.go): `backend/cmd/sync-github/main.go`
- [GitHub client](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/connectors/github/client.go): `backend/internal/connectors/github/client.go`
- [File ingestion](https://github.com/pratiksinha-rzp/context-graph/tree/main/backend/internal/services): `backend/internal/services`

### Code analysis

- [Parse and persist](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/services/go_parser.go): `backend/internal/services/go_parser.go`
- [Go parser](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/parser/go_parser.go): `backend/internal/parser/go_parser.go`
- [Call resolver](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/parser/call_resolver.go): `backend/internal/parser/call_resolver.go`
- [Call analysis command](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/cmd/resolve-calls/main.go): `backend/cmd/resolve-calls/main.go`

### Graph storage

- [PostgreSQL](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/database/postgres.go): `backend/internal/database/postgres.go`
- [Repository records](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/repositories/repository.go): `backend/internal/repositories/repository.go`
- [Source documents](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/repositories/document.go): `backend/internal/repositories/document.go`
- [Graph queries](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/repositories/graph.go): `backend/internal/repositories/graph.go`
- [Domain models](https://github.com/pratiksinha-rzp/context-graph/tree/main/backend/internal/models): `backend/internal/models`

### Query API

- [HTTP API](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/cmd/api/main.go): `backend/cmd/api/main.go`
- [API handlers](https://github.com/pratiksinha-rzp/context-graph/tree/main/backend/internal/handlers): `backend/internal/handlers`
- [Entity search](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/repositories/entity_search.go): `backend/internal/repositories/entity_search.go`
- [Entity details](https://github.com/pratiksinha-rzp/context-graph/blob/main/backend/internal/repositories/entity_details.go): `backend/internal/repositories/entity_details.go`

### Other components

- **Operator**
- **GitHub API**

## Connections

- Operator → Repository sync: starts sync (evidence: `backend/cmd/sync-github/main.go`)
- Repository sync → GitHub client: initializes (evidence: `backend/cmd/sync-github/main.go`)
- Repository sync → File ingestion: invokes sync (evidence: `backend/cmd/sync-github/main.go`)
- GitHub client → GitHub API: requests files (evidence: `backend/internal/connectors/github/client.go`)
- File ingestion → GitHub client: fetches content
- Operator → HTTP API: queries
- HTTP API → API handlers: routes requests (evidence: `backend/cmd/api/main.go`)
- API handlers → Repository records: accesses records (evidence: `backend/internal/handlers/repository.go`)
- API handlers → Entity search: searches entities
- API handlers → Entity details: loads details
- API handlers → Graph queries: queries dependencies
- Repository records → PostgreSQL: reads and writes
- Source documents → PostgreSQL: reads and writes
- Graph queries → PostgreSQL: queries graph
- Parse and persist → Go parser: parses Go
- Parse and persist → Call resolver: resolves calls
- Parse and persist → Source documents: persists source
- Operator → Call analysis command: runs analysis (evidence: `backend/cmd/resolve-calls/main.go`)
- Call analysis command → PostgreSQL: loads documents (evidence: `backend/cmd/resolve-calls/main.go`)
- Call analysis command → Go parser: parses files (evidence: `backend/cmd/resolve-calls/main.go`)
- Call analysis command → Call resolver: resolves calls (evidence: `backend/cmd/resolve-calls/main.go`)
- Domain models → Repository records: represents records
