How drcount-root/knowledge_base works
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: web Web app · services Services · api API · workers Ingest pipeline
Components 17
Apps
Deployable Next.js frontends and API
- Web app · Main product shell with auth flows and dashboard surfaces
apps/web - API · Central orchestration layer for auth, search, research, chat, graph, and documents
apps/api - Docs site · Standalone documentation site
apps/docs - Auth UI · Login, register, reset password, and email verification flows
apps/web/app - Dashboard · Authenticated hub for chat, discover, documents, graph, research, and settings
apps/web/app/(dashboard)/dashboard - API 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 · Route modules for auth, chat, documents, graph, health, insights, research, and search
apps/api/src/routes - Middleware · Authentication, error handling, and rate limiting around requests
apps/api/src/middleware - Services · Business logic for auth, AI, chat indexing, graph, ingest, research, and search
apps/api/src/services - AI layer · LLM calls, structured parsing, embeddings, and provider coordination
apps/api/src/lib - Data stores · Prisma relational DB plus Neo4j, Qdrant, and Redis integrations
apps/api/src/db - Ingest pipeline · Queue and worker for document chunking, parsing, embedding, and indexing
apps/api/src/workers - External tools · Storage, mail, SMS, web search, and other outbound integrations
apps/api/src/lib
Shared packages
Reusable UI and workspace tooling
- UI kit · Reusable buttons, cards, and code components for the apps
packages/ui - ESLint config · Shared linting rules across the monorepo
packages/eslint-config - TS config · Shared TypeScript base and framework presets
packages/typescript-config
Other components
- Workspace · Monorepo orchestration with shared tooling and app boundaries
Connections 20
- 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