# shajeeve567/contexthub architecture

> Architecture diagram of the GitHub repository shajeeve567/contexthub, 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/shajeeve567/contexthub
- Repository: https://github.com/shajeeve567/contexthub

## Overview

ContextHub stores project knowledge and session memories so people and connected LLMs can resume work with relevant context. The main workflow enters through the FastAPI application: users manage documents, projects, sessions, and memories; document ingestion chunks and embeds content, while retrieval searches saved knowledge and can generate a grounded answer or context handoff. The MCP server exposes REST-backed tools to compatible LLMs. The graph follows documented capabilities and SOURCE INDEX relationships; unsampled implementations and relationships are not expanded beyond that evidence.

Main entry points: [`api/app/main.py`](https://github.com/shajeeve567/contexthub/blob/main/api/app/main.py) (REST API), [`api/app/services/core/memory_service.py`](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/core/memory_service.py) (Memory operations), [`api/app/services/documents/ingestion_service.py`](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/documents/ingestion_service.py) (Document ingestion), [`api/app/services/core/context_service.py`](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/core/context_service.py) (Context assembly)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Access"]
  node_mcp["MCP tools<br/>[server.py]"]
  node_app["REST API<br/>[main.py]"]
end

subgraph group_knowledge["Knowledge workflows"]
  node_document_routes["Document routes<br/>[documents.py]"]
  node_ingestion["Document ingestion"]
  node_chunking["Semantic chunking"]
  node_document_retrieval_route["Search route"]
  node_retrieval["Chunk retrieval"]
  node_context_route["Context route"]
  node_context_service["Context assembly<br/>[context_service.py]"]
  node_llm_service["LLM generation<br/>[llm_service.py]"]
  node_prompt_service["Prompt building<br/>[prompt_service.py]"]
end

subgraph group_memory["Memory workflows"]
  node_projects_route["Project routes<br/>[projects.py]"]
  node_sessions_route["Session routes<br/>[sessions.py]"]
  node_memories_route["Memory routes<br/>[memories.py]"]
  node_memory_service["Memory operations<br/>[memory_service.py]"]
end

subgraph group_persistence["Persistence and infrastructure"]
  node_memory_repo["Memory repository"]
  node_document_repo["Document repository"]
  node_chunk_repo["Chunk repository"]
  node_project_repo["Project repository"]
  node_session_repo["Session repository"]
  node_embedding["Embedding service"]
  node_database["Database setup<br/>[database.py]"]
end

node_user(("User"))
node_llm_client(("Connected LLM"))
node_postgres[("PostgreSQL + pgvector")]

node_user -->|"uses REST"| node_app
node_llm_client -->|"invokes tools"| node_mcp
node_mcp -->|"wraps REST"| node_app
node_app -->|"registers"| node_document_routes
node_app -->|"registers"| node_document_retrieval_route
node_app -->|"registers"| node_context_route
node_app -->|"registers"| node_projects_route
node_app -->|"registers"| node_sessions_route
node_app -->|"registers"| node_memories_route
node_document_routes -->|"starts processing"| node_ingestion
node_document_routes -->|"manages documents"| node_document_repo
node_ingestion -->|"chunks content"| node_chunking
node_ingestion -->|"embeds chunks"| node_embedding
node_ingestion -->|"stores chunks"| node_chunk_repo
node_ingestion -->|"updates status"| node_document_repo
node_document_retrieval_route -->|"searches chunks"| node_retrieval
node_document_retrieval_route -->|"generates answer"| node_llm_service
node_retrieval -->|"embeds query"| node_embedding
node_retrieval -->|"loads chunks"| node_chunk_repo
node_context_route -->|"assembles context"| node_context_service
node_context_route -->|"generates handoff"| node_llm_service
node_llm_service -->|"builds prompts"| node_prompt_service
node_context_service -->|"reads sessions"| node_session_repo
node_context_service -->|"reads projects"| node_project_repo
node_context_service -->|"gets memories"| node_memory_service
node_projects_route -->|"manages projects"| node_project_repo
node_sessions_route -->|"manages sessions"| node_session_repo
node_sessions_route -->|"extracts memories"| node_memory_service
node_memories_route -->|"manages memories"| node_memory_service
node_memory_service -->|"stores and searches"| node_memory_repo
node_memory_service -->|"embeds memories"| node_embedding
node_memory_service -->|"extracts candidates"| node_llm_service
node_memory_service -->|"uses extraction prompt"| node_prompt_service
node_database -->|"connects to"| node_postgres

click node_mcp "https://github.com/shajeeve567/contexthub/blob/main/mcp/server.py"
click node_app "https://github.com/shajeeve567/contexthub/blob/main/api/app/main.py"
click node_document_routes "https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/documents.py"
click node_ingestion "https://github.com/shajeeve567/contexthub/blob/main/api/app/services/documents/ingestion_service.py"
click node_chunking "https://github.com/shajeeve567/contexthub/blob/main/api/app/services/documents/chunking_service.py"
click node_document_retrieval_route "https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/document_retrieval.py"
click node_retrieval "https://github.com/shajeeve567/contexthub/blob/main/api/app/services/documents/retrieval_service.py"
click node_context_route "https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/context_retrieval.py"
click node_context_service "https://github.com/shajeeve567/contexthub/blob/main/api/app/services/core/context_service.py"
click node_llm_service "https://github.com/shajeeve567/contexthub/blob/main/api/app/services/infrastructure/llm_service.py"
click node_prompt_service "https://github.com/shajeeve567/contexthub/blob/main/api/app/services/infrastructure/prompt_service.py"
click node_projects_route "https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/projects.py"
click node_sessions_route "https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/sessions.py"
click node_memories_route "https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/memories.py"
click node_memory_service "https://github.com/shajeeve567/contexthub/blob/main/api/app/services/core/memory_service.py"
click node_memory_repo "https://github.com/shajeeve567/contexthub/blob/main/api/app/repositories/memory_repository.py"
click node_document_repo "https://github.com/shajeeve567/contexthub/blob/main/api/app/repositories/document_repository.py"
click node_chunk_repo "https://github.com/shajeeve567/contexthub/blob/main/api/app/repositories/chunk_repository.py"
click node_project_repo "https://github.com/shajeeve567/contexthub/blob/main/api/app/repositories/project_repository.py"
click node_session_repo "https://github.com/shajeeve567/contexthub/blob/main/api/app/repositories/session_repository.py"
click node_embedding "https://github.com/shajeeve567/contexthub/blob/main/api/app/services/infrastructure/embedding_service.py"
click node_database "https://github.com/shajeeve567/contexthub/blob/main/api/app/core/database.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_mcp,node_app,node_user toneBlue
class node_document_routes,node_ingestion,node_chunking,node_document_retrieval_route,node_retrieval,node_context_route,node_context_service,node_llm_service,node_prompt_service,node_postgres toneAmber
class node_projects_route,node_sessions_route,node_memories_route,node_memory_service toneMint
class node_memory_repo,node_document_repo,node_chunk_repo,node_project_repo,node_session_repo,node_embedding,node_database toneRose
class node_llm_client toneIndigo
```

## Components

### Access

- [MCP tools](https://github.com/shajeeve567/contexthub/blob/main/mcp/server.py): `mcp/server.py`
- [REST API](https://github.com/shajeeve567/contexthub/blob/main/api/app/main.py): `api/app/main.py`

### Knowledge workflows

- [Document routes](https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/documents.py): `api/app/api/routes/documents.py`
- [Document ingestion](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/documents/ingestion_service.py): `api/app/services/documents/ingestion_service.py`
- [Semantic chunking](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/documents/chunking_service.py): `api/app/services/documents/chunking_service.py`
- [Search route](https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/document_retrieval.py): `api/app/api/routes/document_retrieval.py`
- [Chunk retrieval](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/documents/retrieval_service.py): `api/app/services/documents/retrieval_service.py`
- [Context route](https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/context_retrieval.py): `api/app/api/routes/context_retrieval.py`
- [Context assembly](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/core/context_service.py): `api/app/services/core/context_service.py`
- [LLM generation](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/infrastructure/llm_service.py): `api/app/services/infrastructure/llm_service.py`
- [Prompt building](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/infrastructure/prompt_service.py): `api/app/services/infrastructure/prompt_service.py`

### Memory workflows

- [Project routes](https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/projects.py): `api/app/api/routes/projects.py`
- [Session routes](https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/sessions.py): `api/app/api/routes/sessions.py`
- [Memory routes](https://github.com/shajeeve567/contexthub/blob/main/api/app/api/routes/memories.py): `api/app/api/routes/memories.py`
- [Memory operations](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/core/memory_service.py): `api/app/services/core/memory_service.py`

### Persistence and infrastructure

- [Memory repository](https://github.com/shajeeve567/contexthub/blob/main/api/app/repositories/memory_repository.py): `api/app/repositories/memory_repository.py`
- [Document repository](https://github.com/shajeeve567/contexthub/blob/main/api/app/repositories/document_repository.py): `api/app/repositories/document_repository.py`
- [Chunk repository](https://github.com/shajeeve567/contexthub/blob/main/api/app/repositories/chunk_repository.py): `api/app/repositories/chunk_repository.py`
- [Project repository](https://github.com/shajeeve567/contexthub/blob/main/api/app/repositories/project_repository.py): `api/app/repositories/project_repository.py`
- [Session repository](https://github.com/shajeeve567/contexthub/blob/main/api/app/repositories/session_repository.py): `api/app/repositories/session_repository.py`
- [Embedding service](https://github.com/shajeeve567/contexthub/blob/main/api/app/services/infrastructure/embedding_service.py): `api/app/services/infrastructure/embedding_service.py`
- [Database setup](https://github.com/shajeeve567/contexthub/blob/main/api/app/core/database.py): `api/app/core/database.py`

### Other components

- **User**
- **Connected LLM**
- **PostgreSQL + pgvector**

## Connections

- User → REST API: uses REST (evidence: `README.md`)
- Connected LLM → MCP tools: invokes tools (evidence: `README.md`)
- MCP tools → REST API: wraps REST (evidence: `README.md`)
- REST API → Document routes: registers (evidence: `api/app/main.py`)
- REST API → Search route: registers (evidence: `api/app/main.py`)
- REST API → Context route: registers (evidence: `api/app/main.py`)
- REST API → Project routes: registers (evidence: `api/app/main.py`)
- REST API → Session routes: registers (evidence: `api/app/main.py`)
- REST API → Memory routes: registers (evidence: `api/app/main.py`)
- Document routes → Document ingestion: starts processing (evidence: `api/app/api/routes/documents.py`)
- Document routes → Document repository: manages documents (evidence: `api/app/api/routes/documents.py`)
- Document ingestion → Semantic chunking: chunks content (evidence: `api/app/services/documents/ingestion_service.py`)
- Document ingestion → Embedding service: embeds chunks (evidence: `api/app/services/documents/ingestion_service.py`)
- Document ingestion → Chunk repository: stores chunks (evidence: `api/app/services/documents/ingestion_service.py`)
- Document ingestion → Document repository: updates status (evidence: `api/app/services/documents/ingestion_service.py`)
- Search route → Chunk retrieval: searches chunks (evidence: `api/app/api/routes/document_retrieval.py`)
- Search route → LLM generation: generates answer (evidence: `api/app/api/routes/document_retrieval.py`)
- Chunk retrieval → Embedding service: embeds query (evidence: `api/app/services/documents/retrieval_service.py`)
- Chunk retrieval → Chunk repository: loads chunks (evidence: `api/app/services/documents/retrieval_service.py`)
- Context route → Context assembly: assembles context (evidence: `api/app/api/routes/context_retrieval.py`)
- Context route → LLM generation: generates handoff (evidence: `api/app/api/routes/context_retrieval.py`)
- LLM generation → Prompt building: builds prompts (evidence: `api/app/services/infrastructure/llm_service.py`)
- Context assembly → Session repository: reads sessions (evidence: `api/app/services/core/context_service.py`)
- Context assembly → Project repository: reads projects (evidence: `api/app/services/core/context_service.py`)
- Context assembly → Memory operations: gets memories (evidence: `api/app/services/core/context_service.py`)
- Project routes → Project repository: manages projects (evidence: `api/app/api/routes/projects.py`)
- Session routes → Session repository: manages sessions (evidence: `api/app/api/routes/sessions.py`)
- Session routes → Memory operations: extracts memories (evidence: `api/app/api/routes/sessions.py`)
- Memory routes → Memory operations: manages memories (evidence: `api/app/api/routes/memories.py`)
- Memory operations → Memory repository: stores and searches (evidence: `api/app/services/core/memory_service.py`)
- Memory operations → Embedding service: embeds memories (evidence: `api/app/services/core/memory_service.py`)
- Memory operations → LLM generation: extracts candidates (evidence: `api/app/services/core/memory_service.py`)
- Memory operations → Prompt building: uses extraction prompt (evidence: `api/app/services/core/memory_service.py`)
- Database setup → PostgreSQL + pgvector: connects to (evidence: `README.md`)
