# drcount-root/knowledge_base architecture

> Architecture diagram of the GitHub repository drcount-root/knowledge_base, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/drcount-root/knowledge_base
- Repository: https://github.com/drcount-root/knowledge_base

## Overview

1. **Repository shape**
   - This is a Turborepo monorepo with three apps and shared packages.
   - The primary product surfaces are `apps/web` (user-facing app), `apps/api` (backend API), and `apps/docs` (separate Next.js docs site).
   - Shared infrastructure lives in `packages/ui`, `packages/eslint-config`, and `packages/typescript-config`.

2. **Frontend applications**
   - `apps/web` is the main application shell: login/register/reset/verify flows plus an authenticated dashboard.
   - The dashboard is split into feature pages for chat, discover, documents, graph, research, and settings, which implies a product centered on knowledge management and AI-assisted workflows.
   - `apps/docs` is an independent Next.js documentation site, not part of the product runtime.

3. **Backend API as the core orchestration layer**
   - `apps/api` is the system’s central integration layer. It exposes route modules for auth, chat, documents, graph, health, insights, research, and search.
   - Requests flow through middleware for authentication, error handling, and rate limiting before hitting the route handlers.
   - The route layer delegates most business logic to services rather than talking directly to databases or external providers.

4. **Domain/service boundaries**
   - `auth.service` handles account/session concerns, while `jwt.ts` and `middleware/auth.ts` suggest token-based auth on the API side.
   - `chat-index.service`, `search.service`, `research.service`, `graph.service`, and `ingest.service` separate the major product capabilities into distinct subsystems.
   - `ai.service` appears to centralize model calls and AI-related coordination so the rest of the codebase can stay provider-agnostic.

5. **Data persistence and specialized stores**
   - The backend uses Prisma with a relational database as the system of record for core application data, users, and workflow state.
   - `neo4j.ts` indicates a graph database for relationship-heavy features exposed through the graph route/service.
   - `qdrant.ts` indicates a vector database for semantic retrieval and embedding-based search.
   - `redis.ts` suggests caching and queue/backplane responsibilities, especially for ingest and worker coordination.

6. **Ingestion and background processing**
   - The presence of `workers/ingest.queue.ts` and `workers/ingest.worker.ts` shows that document ingestion is asynchronous, not purely request/response.
   - The ingest flow likely chunks content (`chunker.ts`), extracts/parses it (`parsers.ts`), creates embeddings (`embedder.ts`), and then stores indexable representations in the vector/graph/datastore layers.
   - This is the main pipeline that turns uploaded or imported content into searchable, queryable knowledge.

7. **AI, retrieval, and external integrations**
   - `llm.ts`, `parse-llm-json.ts`, and `web-search.ts` show the API combines LLM calls with structured-output parsing and live web research.
   - `mailer.ts` and `sms.ts` imply notification channels for auth or workflow events.
   - `storage.ts` suggests object/file storage for uploaded documents or generated artifacts.
   - Together, these modules support retrieval-augmented workflows rather than a simple CRUD backend.

8. **Feature data flow**
   - A typical path is: web app submits a user action → API route authenticates and rate-limits it → service layer resolves data from Prisma/Redis/Neo4j/Qdrant → AI or search services enrich the response → frontend renders the result.
   - For document-related operations, the flow branches into the ingest queue/worker so indexing happens out of band.
   - Search, research, and chat are therefore likely read-heavy and retrieval-driven, while ingestion is write-heavy and asynchronous.

9. **Authentication and user lifecycle**
   - The web app includes sign-in, registration, email verification, and password reset screens, so the product has a full account lifecycle.
   - `apps/api/src/routes/auth.ts` plus JWT middleware imply the API owns authentication enforcement, while the web app handles the UI flows.
   - Migration history in Prisma shows auth-related schema evolution, reinforcing that identity is a first-class backend concern.

10. **Shared UI and platform tooling**
   - `packages/ui` is a reusable component library shared across the Next.js apps.
   - `packages/eslint-config` and `packages/typescript-config` standardize code quality and TypeScript settings across the monorepo.
   - `turbo.json`, `bun.lock`, and `docker-compose.yml` indicate a workspace-oriented development model with local service orchestration for the backend dependencies.

11. **Operational boundaries**
   - `apps/api/src/index.ts` is the backend entrypoint, while each Next.js app has its own app router and deployment boundary.
   - `apps/api/tests/health.test.ts` plus `routes/health.ts` provide a minimal service liveness surface for deployment checks.
   - `.env.example` suggests the architecture is configured primarily through environment variables, which is expected given the number of external stores and providers.

12. **High-level diagram takeaway**
   - Draw this repo as three independently deployable apps around one central API.
   - The API fans out to a relational DB, Neo4j, Qdrant, Redis, storage, and AI/notification/search providers.
   - The most important asynchronous boundary is the ingest worker pipeline, which converts documents into graph/vector/searchable knowledge used by chat, research, and discovery features.

Main entry points: [`apps/web`](https://github.com/drcount-root/knowledge_base/tree/main/apps/web) (Web app), [`apps/api/src/services`](https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/services) (Services), [`apps/api`](https://github.com/drcount-root/knowledge_base/tree/main/apps/api) (API), [`apps/api/src/workers`](https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/workers) (Ingest pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Apps"]
  node_apps_web["Web app<br/>Next.js frontend"]
  node_apps_api["API"]
  node_apps_docs["Docs site<br/>Next.js docs"]
  node_web_auth["Auth UI<br/>auth screens"]
  node_web_dashboard["Dashboard<br/>product shell"]
  node_web_api["API client<br/>frontend client<br/>[api.ts]"]
end

subgraph group_backend["API internals"]
  node_api_routes["Routes"]
  node_api_middleware{{"Middleware<br/>cross-cutting"}}
  node_api_services["Services"]
  node_api_ai{{"AI layer<br/>model orchestration"}}
  node_api_db[("Data stores<br/>persistence adapters")]
  node_api_ingest["Ingest pipeline<br/>async pipeline"]
  node_api_integrations{{"External tools<br/>providers"}}
end

subgraph group_packages["Shared packages"]
  node_shared_ui["UI kit<br/>component library"]
  node_shared_eslint["ESLint config<br/>workspace config"]
  node_shared_ts["TS config<br/>workspace config"]
end

node_repo_root{{"Workspace<br/>turborepo monorepo"}}

node_repo_root -->|"contains"| node_apps_web
node_repo_root -->|"contains"| node_apps_api
node_repo_root -->|"contains"| node_apps_docs
node_repo_root -->|"shares"| node_shared_ui
node_repo_root -->|"standardizes"| node_shared_eslint
node_repo_root -->|"standardizes"| node_shared_ts
node_apps_web -->|"hosts"| node_web_auth
node_apps_web -->|"hosts"| node_web_dashboard
node_apps_web -->|"calls"| node_web_api
node_apps_web -->|"uses"| node_shared_ui
node_apps_api -->|"applies"| node_api_middleware
node_apps_api -->|"exposes"| node_api_routes
node_api_routes -->|"delegates"| node_api_services
node_api_services -->|"uses"| node_api_ai
node_api_services -->|"reads/writes"| node_api_db
node_api_services -->|"uses"| node_api_integrations
node_api_services -->|"enqueues"| node_api_ingest
node_api_ingest -->|"indexes"| node_api_db
node_api_ingest -->|"embeds/parses"| node_api_ai
node_apps_docs -->|"uses"| node_shared_ui

click node_apps_web "https://github.com/drcount-root/knowledge_base/tree/main/apps/web"
click node_apps_api "https://github.com/drcount-root/knowledge_base/tree/main/apps/api"
click node_apps_docs "https://github.com/drcount-root/knowledge_base/tree/main/apps/docs"
click node_web_auth "https://github.com/drcount-root/knowledge_base/tree/main/apps/web/app"
click node_web_dashboard "https://github.com/drcount-root/knowledge_base/tree/main/apps/web/app/(dashboard)/dashboard"
click node_api_routes "https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/routes"
click node_api_middleware "https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/middleware"
click node_api_services "https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/services"
click node_api_ai "https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/lib"
click node_api_db "https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/db"
click node_api_ingest "https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/workers"
click node_api_integrations "https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/lib"
click node_shared_ui "https://github.com/drcount-root/knowledge_base/tree/main/packages/ui"
click node_shared_eslint "https://github.com/drcount-root/knowledge_base/tree/main/packages/eslint-config"
click node_shared_ts "https://github.com/drcount-root/knowledge_base/tree/main/packages/typescript-config"
click node_web_api "https://github.com/drcount-root/knowledge_base/blob/main/apps/web/lib/api.ts"

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_apps_web,node_apps_api,node_apps_docs,node_web_auth,node_web_dashboard,node_web_api toneBlue
class node_api_routes,node_api_middleware,node_api_services,node_api_ai,node_api_db,node_api_ingest,node_api_integrations toneAmber
class node_shared_ui,node_shared_eslint,node_shared_ts toneMint
class node_repo_root toneNeutral
```

## Components

### Apps

Deployable Next.js frontends and API

- [Web app](https://github.com/drcount-root/knowledge_base/tree/main/apps/web): Next.js frontend · Main product shell with auth flows and dashboard surfaces · `apps/web`
- [API](https://github.com/drcount-root/knowledge_base/tree/main/apps/api): Fastify API · Central orchestration layer for auth, search, research, chat, graph, and documents · `apps/api`
- [Docs site](https://github.com/drcount-root/knowledge_base/tree/main/apps/docs): Next.js docs · Standalone documentation site · `apps/docs`
- [Auth UI](https://github.com/drcount-root/knowledge_base/tree/main/apps/web/app): auth screens · Login, register, reset password, and email verification flows · `apps/web/app`
- [Dashboard](https://github.com/drcount-root/knowledge_base/tree/main/apps/web/app/(dashboard)/dashboard): product shell · Authenticated hub for chat, discover, documents, graph, research, and settings · `apps/web/app/(dashboard)/dashboard`
- [API client](https://github.com/drcount-root/knowledge_base/blob/main/apps/web/lib/api.ts): frontend client · Browser-side API access layer used by the web app · `apps/web/lib/api.ts`

### API internals

Core request handling, services, persistence, and workers

- [Routes](https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/routes): HTTP routes · Route modules for auth, chat, documents, graph, health, insights, research, and search · `apps/api/src/routes`
- [Middleware](https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/middleware): cross-cutting · Authentication, error handling, and rate limiting around requests · `apps/api/src/middleware`
- [Services](https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/services): domain services · Business logic for auth, AI, chat indexing, graph, ingest, research, and search · `apps/api/src/services`
- [AI layer](https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/lib): model orchestration · LLM calls, structured parsing, embeddings, and provider coordination · `apps/api/src/lib`
- [Data stores](https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/db): persistence adapters · Prisma relational DB plus Neo4j, Qdrant, and Redis integrations · `apps/api/src/db`
- [Ingest pipeline](https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/workers): async pipeline · Queue and worker for document chunking, parsing, embedding, and indexing · `apps/api/src/workers`
- [External tools](https://github.com/drcount-root/knowledge_base/tree/main/apps/api/src/lib): providers · Storage, mail, SMS, web search, and other outbound integrations · `apps/api/src/lib`

### Shared packages

Reusable UI and workspace tooling

- [UI kit](https://github.com/drcount-root/knowledge_base/tree/main/packages/ui): component library · Reusable buttons, cards, and code components for the apps · `packages/ui`
- [ESLint config](https://github.com/drcount-root/knowledge_base/tree/main/packages/eslint-config): workspace config · Shared linting rules across the monorepo · `packages/eslint-config`
- [TS config](https://github.com/drcount-root/knowledge_base/tree/main/packages/typescript-config): workspace config · Shared TypeScript base and framework presets · `packages/typescript-config`

### Other components

- **Workspace**: turborepo monorepo · Monorepo orchestration with shared tooling and app boundaries

## Connections

- Workspace → Web app: contains · Monorepo includes the main web application
- Workspace → API: contains · Monorepo includes the backend API
- Workspace → Docs site: contains · Monorepo includes the docs site
- Workspace → UI kit: shares · Shared component library used across apps
- Workspace → ESLint config: standardizes · Common lint rules for the workspace
- Workspace → TS config: standardizes · Common TypeScript settings for the workspace
- Web app → Auth UI: hosts · Public account lifecycle screens
- Web app → Dashboard: hosts · Authenticated product experience
- Web app → API client: calls · Frontend talks to the backend API
- Web app → UI kit: uses · Web app composes shared UI primitives
- API → Middleware: applies · Requests pass through middleware first
- API → Routes: exposes · Route modules define public API surface
- Routes → Services: delegates · Handlers push business logic into services
- Services → AI layer: uses · Services coordinate model and retrieval tasks
- Services → Data stores: reads/writes · Services persist and query core state
- Services → External tools: uses · Services call storage, mail, SMS, and web search
- Services → Ingest pipeline: enqueues · Document work is handed to background ingestion
- Ingest pipeline → Data stores: indexes · Worker stores processed knowledge in persistence layers
- Ingest pipeline → AI layer: embeds/parses · Pipeline generates embeddings and structured output
- Docs site → UI kit: uses · Docs site can reuse shared UI primitives
