# thdwlndjs/knowledge-graph architecture

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

- Interactive diagram: https://gitdiagram.com/thdwlndjs/knowledge-graph
- Repository: https://github.com/thdwlndjs/knowledge-graph

## Overview

This is a small FastAPI knowledge-graph API. A client submits a paper to the graph endpoint; the router passes it to GraphService, which delegates creation or listing to Neo4jRepository, where queries run through the Neo4j driver. The API also exposes a health response. The graph reflects the sampled routes and persistence code; external HTTP and database interactions are shown only where the code supports them.

Main entry points: [`backend/app/routers/graph.py`](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/routers/graph.py) (Graph Routes), [`backend/app/repository/neo4j_repository.py`](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/repository/neo4j_repository.py) (Paper Repository), [`backend/app/db/neo4j.py`](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/db/neo4j.py) (Neo4j Driver), [`backend/app/main.py`](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/main.py) (FastAPI App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_app["FastAPI App<br/>[main.py]"]
  node_graph_router["Graph Routes<br/>[graph.py]"]
  node_health_router["Health Route<br/>[health.py]"]
  node_paper_schema["Paper Schema<br/>[schemas.py]"]
end

subgraph group_logic["Graph Logic"]
  node_graph_service["Graph Service<br/>[graph_service.py]"]
end

subgraph group_storage["Neo4j Storage"]
  node_repository["Paper Repository"]
  node_neo4j_driver["Neo4j Driver<br/>[neo4j.py]"]
  node_config["Neo4j Config<br/>[config.py]"]
end

node_client(("API Client"))
node_neo4j_db[("Neo4j Database")]

node_app -->|"registers"| node_health_router
node_app -->|"registers"| node_graph_router
node_client -.->|"sends requests"| node_graph_router
node_client -.->|"checks status"| node_health_router
node_graph_router -->|"accepts"| node_paper_schema
node_graph_router -->|"calls"| node_graph_service
node_graph_service -->|"delegates"| node_repository
node_repository -->|"opens sessions"| node_neo4j_driver
node_neo4j_driver -->|"uses settings"| node_config
node_neo4j_driver -.->|"connects"| node_neo4j_db
node_repository -->|"reads and writes"| node_neo4j_db

click node_app "https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/main.py"
click node_graph_router "https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/routers/graph.py"
click node_health_router "https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/routers/health.py"
click node_paper_schema "https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/schemas.py"
click node_graph_service "https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/services/graph_service.py"
click node_repository "https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/repository/neo4j_repository.py"
click node_neo4j_driver "https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/db/neo4j.py"
click node_config "https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/core/config.py"

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_app,node_graph_router,node_health_router,node_paper_schema,node_client toneBlue
class node_graph_service,node_neo4j_db toneAmber
class node_repository,node_neo4j_driver,node_config toneMint
```

## Components

### HTTP API

- [FastAPI App](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/main.py): `backend/app/main.py`
- [Graph Routes](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/routers/graph.py): `backend/app/routers/graph.py`
- [Health Route](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/routers/health.py): `backend/app/routers/health.py`
- [Paper Schema](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/schemas.py): `backend/app/schemas.py`

### Graph Logic

- [Graph Service](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/services/graph_service.py): `backend/app/services/graph_service.py`

### Neo4j Storage

- [Paper Repository](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/repository/neo4j_repository.py): `backend/app/repository/neo4j_repository.py`
- [Neo4j Driver](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/app/db/neo4j.py): `backend/app/db/neo4j.py`
- [Neo4j Config](https://github.com/thdwlndjs/knowledge-graph/blob/main/backend/core/config.py): `backend/core/config.py`

### Other components

- **API Client**
- **Neo4j Database**

## Connections

- FastAPI App → Health Route: registers (evidence: `backend/app/main.py`)
- FastAPI App → Graph Routes: registers (evidence: `backend/app/main.py`)
- API Client → Graph Routes: sends requests
- API Client → Health Route: checks status
- Graph Routes → Paper Schema: accepts (evidence: `backend/app/routers/graph.py`)
- Graph Routes → Graph Service: calls (evidence: `backend/app/routers/graph.py`)
- Graph Service → Paper Repository: delegates (evidence: `backend/app/services/graph_service.py`)
- Paper Repository → Neo4j Driver: opens sessions (evidence: `backend/app/repository/neo4j_repository.py`)
- Neo4j Driver → Neo4j Config: uses settings (evidence: `backend/app/db/neo4j.py`)
- Neo4j Driver → Neo4j Database: connects
- Paper Repository → Neo4j Database: reads and writes (evidence: `backend/app/repository/neo4j_repository.py`)
