# daveebbelaar/company-knowledge-base architecture

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

- Interactive diagram: https://gitdiagram.com/daveebbelaar/company-knowledge-base
- Repository: https://github.com/daveebbelaar/company-knowledge-base

## Overview

This is a password-gated company handbook: employees browse department policies and profiles, search for relevant pages, or ask a chat assistant for cited answers. Content is read from local Markdown/JSON or published Sanity documents; search combines keyword, semantic, or hybrid retrieval in Sanity and keyword matching locally. The graph includes the documented Sanity editing and embedding capability. Some page-rendering and content-source internals are unsampled, so their wiring is shown only where the README or sampled code supports it.

Main entry points: [`app/api/chat/route.ts`](https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/api/chat/route.ts) (Chat endpoint), [`lib/content.ts`](https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/content.ts) (Content access), [`lib/people.ts`](https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/people.ts) (Employee access), [`lib/retrieval.ts`](https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/retrieval.ts) (Knowledge retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Handbook experience"]
  node_home["Company homepage<br/>[page.tsx]"]
  node_docs["Handbook pages<br/>[page.tsx]"]
  node_team["Team directory<br/>[page.tsx]"]
end

subgraph group_content["Knowledge content"]
  node_contentlib["Content access<br/>[content.ts]"]
  node_peoplelib["Employee access<br/>[people.ts]"]
  node_localdocs["Local handbook files"]
  node_localpeople["Local employee profiles"]
  node_sanity["Sanity content service<br/>[sanity.mjs]"]
  node_studio["Sanity schemas<br/>[schema.ts]"]
end

subgraph group_discovery["Search and chat"]
  node_searchui["Search interface<br/>[search.tsx]"]
  node_searchapi["Search endpoint<br/>[route.ts]"]
  node_retrieval["Knowledge retrieval<br/>[retrieval.ts]"]
  node_chatui["Chat panel<br/>[chat.tsx]"]
  node_chatapi["Chat endpoint<br/>[route.ts]"]
  node_chatlogic["Chat protocol<br/>[chat.mjs]"]
end

subgraph group_access["Site access"]
  node_login["Password login<br/>[page.tsx]"]
  node_unlock["Unlock endpoint<br/>[route.ts]"]
  node_proxy["Session gate<br/>[proxy.ts]"]
  node_logout["Logout endpoint<br/>[route.ts]"]
  node_accesslib["Session utilities<br/>[access.mjs]"]
end

node_employee(("Employee"))
node_sanityservice[("Sanity Content Lake")]
node_openai["OpenAI Responses API"]

node_employee -->|"browses"| node_home
node_employee -->|"reads"| node_docs
node_employee -->|"finds colleagues"| node_team
node_employee -->|"searches"| node_searchui
node_employee -->|"asks"| node_chatui
node_home -->|"loads pages"| node_contentlib
node_home -->|"loads profiles"| node_peoplelib
node_docs -->|"loads content"| node_contentlib
node_team -->|"loads profiles"| node_peoplelib
node_searchui -->|"requests results"| node_searchapi
node_searchapi -->|"searches"| node_retrieval
node_retrieval -->|"reads pages"| node_contentlib
node_retrieval -->|"reads profiles"| node_peoplelib
node_retrieval -->|"queries"| node_sanity
node_contentlib -->|"reads"| node_localdocs
node_peoplelib -->|"reads"| node_localpeople
node_contentlib -->|"loads published content"| node_sanity
node_peoplelib -->|"loads published profiles"| node_sanity
node_sanity -->|"queries"| node_sanityservice
node_studio -.->|"edits and publishes"| node_sanityservice
node_chatui -->|"reads saved chats"| node_chatlogic
node_chatui -->|"sends turns"| node_chatapi
node_chatapi -->|"validates and parses"| node_chatlogic
node_chatapi -->|"loads profiles"| node_peoplelib
node_chatapi -->|"loads current page"| node_contentlib
node_chatapi -.->|"plans and streams answer"| node_openai
node_chatapi -->|"retrieves cited pages"| node_retrieval
node_employee -->|"opens site"| node_login
node_login -->|"submits password"| node_unlock
node_unlock -->|"creates session"| node_accesslib
node_proxy -->|"validates session"| node_accesslib
node_employee -->|"locks site"| node_logout
node_logout -->|"uses cookie name"| node_accesslib

click node_home "https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/page.tsx"
click node_docs "https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/docs/%5B%5B...slug%5D%5D/page.tsx"
click node_team "https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/docs/team/page.tsx"
click node_searchui "https://github.com/daveebbelaar/company-knowledge-base/blob/main/components/search.tsx"
click node_searchapi "https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/api/search/route.ts"
click node_retrieval "https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/retrieval.ts"
click node_chatui "https://github.com/daveebbelaar/company-knowledge-base/blob/main/components/chat.tsx"
click node_chatapi "https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/api/chat/route.ts"
click node_chatlogic "https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/chat.mjs"
click node_contentlib "https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/content.ts"
click node_peoplelib "https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/people.ts"
click node_localdocs "https://github.com/daveebbelaar/company-knowledge-base/tree/main/content/docs"
click node_localpeople "https://github.com/daveebbelaar/company-knowledge-base/tree/main/content/employees"
click node_sanity "https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/sanity.mjs"
click node_studio "https://github.com/daveebbelaar/company-knowledge-base/blob/main/sanity/schema.ts"
click node_login "https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/login/page.tsx"
click node_unlock "https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/api/unlock/route.ts"
click node_proxy "https://github.com/daveebbelaar/company-knowledge-base/blob/main/proxy.ts"
click node_logout "https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/api/logout/route.ts"
click node_accesslib "https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/access.mjs"

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_home,node_docs,node_team toneBlue
class node_contentlib,node_peoplelib,node_localdocs,node_localpeople,node_sanity,node_studio,node_sanityservice toneAmber
class node_searchui,node_searchapi,node_retrieval,node_chatui,node_chatapi,node_chatlogic,node_openai toneMint
class node_login,node_unlock,node_proxy,node_logout,node_accesslib toneRose
class node_employee toneIndigo
```

## Components

### Handbook experience

- [Company homepage](https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/page.tsx): `app/page.tsx`
- [Handbook pages](https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/docs/%5B%5B...slug%5D%5D/page.tsx): `app/docs/[[...slug]]/page.tsx`
- [Team directory](https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/docs/team/page.tsx): `app/docs/team/page.tsx`

### Knowledge content

- [Content access](https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/content.ts): `lib/content.ts`
- [Employee access](https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/people.ts): `lib/people.ts`
- [Local handbook files](https://github.com/daveebbelaar/company-knowledge-base/tree/main/content/docs): `content/docs`
- [Local employee profiles](https://github.com/daveebbelaar/company-knowledge-base/tree/main/content/employees): `content/employees`
- [Sanity content service](https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/sanity.mjs): `lib/sanity.mjs`
- [Sanity schemas](https://github.com/daveebbelaar/company-knowledge-base/blob/main/sanity/schema.ts): `sanity/schema.ts`

### Search and chat

- [Search interface](https://github.com/daveebbelaar/company-knowledge-base/blob/main/components/search.tsx): `components/search.tsx`
- [Search endpoint](https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/api/search/route.ts): `app/api/search/route.ts`
- [Knowledge retrieval](https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/retrieval.ts): `lib/retrieval.ts`
- [Chat panel](https://github.com/daveebbelaar/company-knowledge-base/blob/main/components/chat.tsx): `components/chat.tsx`
- [Chat endpoint](https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Chat protocol](https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/chat.mjs): `lib/chat.mjs`

### Site access

- [Password login](https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/login/page.tsx): `app/login/page.tsx`
- [Unlock endpoint](https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/api/unlock/route.ts): `app/api/unlock/route.ts`
- [Session gate](https://github.com/daveebbelaar/company-knowledge-base/blob/main/proxy.ts): `proxy.ts`
- [Logout endpoint](https://github.com/daveebbelaar/company-knowledge-base/blob/main/app/api/logout/route.ts): `app/api/logout/route.ts`
- [Session utilities](https://github.com/daveebbelaar/company-knowledge-base/blob/main/lib/access.mjs): `lib/access.mjs`

### Other components

- **Employee**
- **Sanity Content Lake**
- **OpenAI Responses API**

## Connections

- Employee → Company homepage: browses
- Employee → Handbook pages: reads
- Employee → Team directory: finds colleagues
- Employee → Search interface: searches
- Employee → Chat panel: asks
- Company homepage → Content access: loads pages
- Company homepage → Employee access: loads profiles
- Handbook pages → Content access: loads content
- Team directory → Employee access: loads profiles
- Search interface → Search endpoint: requests results
- Search endpoint → Knowledge retrieval: searches
- Knowledge retrieval → Content access: reads pages
- Knowledge retrieval → Employee access: reads profiles
- Knowledge retrieval → Sanity content service: queries
- Content access → Local handbook files: reads
- Employee access → Local employee profiles: reads
- Content access → Sanity content service: loads published content
- Employee access → Sanity content service: loads published profiles
- Sanity content service → Sanity Content Lake: queries
- Sanity schemas → Sanity Content Lake: edits and publishes
- Chat panel → Chat protocol: reads saved chats
- Chat panel → Chat endpoint: sends turns
- Chat endpoint → Chat protocol: validates and parses
- Chat endpoint → Employee access: loads profiles
- Chat endpoint → Content access: loads current page
- Chat endpoint → OpenAI Responses API: plans and streams answer
- Chat endpoint → Knowledge retrieval: retrieves cited pages
- Employee → Password login: opens site
- Password login → Unlock endpoint: submits password
- Unlock endpoint → Session utilities: creates session
- Session gate → Session utilities: validates session
- Employee → Logout endpoint: locks site
- Logout endpoint → Session utilities: uses cookie name
