# phani-manda/the-cortex architecture

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

## Overview

Cortex is an AI-assisted second-brain application. Users capture notes, links, or files; the notes API authenticates and rate-limits the request, invokes AI analysis, and persists enriched notes. Users can browse and search their notes, ask questions answered from retrieved notes, and expose selected public knowledge through APIs and an embeddable chat. The graph includes the documented capabilities whose implementation was not sampled; those links are dashed where source evidence is unavailable.

Main entry points: [`src/app/api/notes/route.ts`](https://github.com/phani-manda/the-cortex/blob/master/src/app/api/notes/route.ts) (Notes API), [`src/lib/db.ts`](https://github.com/phani-manda/the-cortex/blob/master/src/lib/db.ts) (Note data service), [`src/components/note-grid.tsx`](https://github.com/phani-manda/the-cortex/blob/master/src/components/note-grid.tsx) (Note grid), [`src/app/api/public/brain/query/route.ts`](https://github.com/phani-manda/the-cortex/blob/master/src/app/api/public/brain/query/route.ts) (Public query route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["User experience"]
  node_dashboard["Dashboard<br/>[dashboard.tsx]"]
  node_capture["Capture form<br/>[capture-form.tsx]"]
  node_notegrid["Note grid<br/>[note-grid.tsx]"]
  node_notecard["Note card<br/>[note-card.tsx]"]
  node_notemodal["Note modal<br/>[note-modal.tsx]"]
  node_skeleton["Note skeleton<br/>[note-skeleton.tsx]"]
  node_askbrain["Ask brain<br/>[ask-brain.tsx]"]
  node_ui["UI primitives"]
end

subgraph group_identity["Identity and access"]
  node_login["Login page<br/>[page.tsx]"]
  node_authapi["Auth routes<br/>[route.ts]"]
  node_register["Registration route<br/>[route.ts]"]
  node_auth["Auth service<br/>[auth.ts]"]
end

subgraph group_knowledge["Knowledge services"]
  node_notesapi["Notes API<br/>[route.ts]"]
  node_ai["AI analysis<br/>[ai.ts]"]
  node_ratelimit["Rate limiting<br/>[rate-limit.ts]"]
  node_db["Note data service<br/>[db.ts]"]
  node_store[("PostgreSQL")]
end

subgraph group_sharing["Public access"]
  node_queryapi["Public query route<br/>[route.ts]"]
  node_query["Knowledge query<br/>[query.ts]"]
  node_publicapi["Public notes route<br/>[route.ts]"]
  node_embed["Embed chat<br/>[page.tsx]"]
end

node_person(("User"))
node_groq{{"Groq AI"}}

node_person -->|"uses"| node_dashboard
node_dashboard -.->|"renders"| node_capture
node_dashboard -->|"renders"| node_notegrid
node_notegrid -->|"renders"| node_notecard
node_notegrid -->|"opens"| node_notemodal
node_notegrid -->|"renders"| node_skeleton
node_capture -->|"submits"| node_notesapi
node_notesapi -->|"authenticates"| node_auth
node_notesapi -->|"checks limit"| node_ratelimit
node_notesapi -->|"analyzes input"| node_ai
node_notesapi -->|"creates or reads"| node_db
node_db -->|"queries"| node_store
node_notesapi -.->|"returns notes"| node_person
node_person -.->|"signs in"| node_login
node_login -.->|"authenticates"| node_authapi
node_authapi -->|"uses handlers"| node_auth
node_register -->|"registers user"| node_auth
node_auth -->|"checks users"| node_db
node_person -.->|"asks"| node_askbrain
node_askbrain -.->|"submits query"| node_queryapi
node_queryapi -.->|"checks limit"| node_ratelimit
node_queryapi -->|"dispatches query"| node_query
node_query -->|"retrieves notes"| node_db
node_query -.->|"generates answer"| node_groq
node_person -.->|"requests public notes"| node_publicapi
node_publicapi -->|"reads public notes"| node_db
node_person -.->|"opens widget"| node_embed
node_embed -.->|"queries brain"| node_queryapi
node_ui -.->|"renders controls"| node_person

click node_dashboard "https://github.com/phani-manda/the-cortex/blob/master/src/components/dashboard.tsx"
click node_capture "https://github.com/phani-manda/the-cortex/blob/master/src/components/capture-form.tsx"
click node_notegrid "https://github.com/phani-manda/the-cortex/blob/master/src/components/note-grid.tsx"
click node_notecard "https://github.com/phani-manda/the-cortex/blob/master/src/components/note-card.tsx"
click node_notemodal "https://github.com/phani-manda/the-cortex/blob/master/src/components/note-modal.tsx"
click node_skeleton "https://github.com/phani-manda/the-cortex/blob/master/src/components/note-skeleton.tsx"
click node_askbrain "https://github.com/phani-manda/the-cortex/blob/master/src/components/ask-brain.tsx"
click node_ui "https://github.com/phani-manda/the-cortex/tree/master/src/components/ui"
click node_login "https://github.com/phani-manda/the-cortex/blob/master/src/app/login/page.tsx"
click node_authapi "https://github.com/phani-manda/the-cortex/blob/master/src/app/api/auth/%5B...nextauth%5D/route.ts"
click node_register "https://github.com/phani-manda/the-cortex/blob/master/src/app/api/auth/register/route.ts"
click node_auth "https://github.com/phani-manda/the-cortex/blob/master/src/lib/auth.ts"
click node_notesapi "https://github.com/phani-manda/the-cortex/blob/master/src/app/api/notes/route.ts"
click node_ai "https://github.com/phani-manda/the-cortex/blob/master/src/lib/ai.ts"
click node_ratelimit "https://github.com/phani-manda/the-cortex/blob/master/src/lib/rate-limit.ts"
click node_db "https://github.com/phani-manda/the-cortex/blob/master/src/lib/db.ts"
click node_queryapi "https://github.com/phani-manda/the-cortex/blob/master/src/app/api/public/brain/query/route.ts"
click node_query "https://github.com/phani-manda/the-cortex/blob/master/src/lib/query.ts"
click node_publicapi "https://github.com/phani-manda/the-cortex/blob/master/src/app/api/public/brain/route.ts"
click node_embed "https://github.com/phani-manda/the-cortex/blob/master/src/app/embed/page.tsx"

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_dashboard,node_capture,node_notegrid,node_notecard,node_notemodal,node_skeleton,node_askbrain,node_ui,node_person toneBlue
class node_login,node_authapi,node_register,node_auth toneAmber
class node_notesapi,node_ai,node_ratelimit,node_db,node_store toneMint
class node_queryapi,node_query,node_publicapi,node_embed toneRose
class node_groq toneIndigo
```

## Components

### User experience

- [Dashboard](https://github.com/phani-manda/the-cortex/blob/master/src/components/dashboard.tsx): `src/components/dashboard.tsx`
- [Capture form](https://github.com/phani-manda/the-cortex/blob/master/src/components/capture-form.tsx): `src/components/capture-form.tsx`
- [Note grid](https://github.com/phani-manda/the-cortex/blob/master/src/components/note-grid.tsx): `src/components/note-grid.tsx`
- [Note card](https://github.com/phani-manda/the-cortex/blob/master/src/components/note-card.tsx): `src/components/note-card.tsx`
- [Note modal](https://github.com/phani-manda/the-cortex/blob/master/src/components/note-modal.tsx): `src/components/note-modal.tsx`
- [Note skeleton](https://github.com/phani-manda/the-cortex/blob/master/src/components/note-skeleton.tsx): `src/components/note-skeleton.tsx`
- [Ask brain](https://github.com/phani-manda/the-cortex/blob/master/src/components/ask-brain.tsx): `src/components/ask-brain.tsx`
- [UI primitives](https://github.com/phani-manda/the-cortex/tree/master/src/components/ui): `src/components/ui`

### Identity and access

- [Login page](https://github.com/phani-manda/the-cortex/blob/master/src/app/login/page.tsx): `src/app/login/page.tsx`
- [Auth routes](https://github.com/phani-manda/the-cortex/blob/master/src/app/api/auth/%5B...nextauth%5D/route.ts): `src/app/api/auth/[...nextauth]/route.ts`
- [Registration route](https://github.com/phani-manda/the-cortex/blob/master/src/app/api/auth/register/route.ts): `src/app/api/auth/register/route.ts`
- [Auth service](https://github.com/phani-manda/the-cortex/blob/master/src/lib/auth.ts): `src/lib/auth.ts`

### Knowledge services

- [Notes API](https://github.com/phani-manda/the-cortex/blob/master/src/app/api/notes/route.ts): `src/app/api/notes/route.ts`
- [AI analysis](https://github.com/phani-manda/the-cortex/blob/master/src/lib/ai.ts): `src/lib/ai.ts`
- [Rate limiting](https://github.com/phani-manda/the-cortex/blob/master/src/lib/rate-limit.ts): `src/lib/rate-limit.ts`
- [Note data service](https://github.com/phani-manda/the-cortex/blob/master/src/lib/db.ts): `src/lib/db.ts`
- **PostgreSQL**

### Public access

- [Public query route](https://github.com/phani-manda/the-cortex/blob/master/src/app/api/public/brain/query/route.ts): `src/app/api/public/brain/query/route.ts`
- [Knowledge query](https://github.com/phani-manda/the-cortex/blob/master/src/lib/query.ts): `src/lib/query.ts`
- [Public notes route](https://github.com/phani-manda/the-cortex/blob/master/src/app/api/public/brain/route.ts): `src/app/api/public/brain/route.ts`
- [Embed chat](https://github.com/phani-manda/the-cortex/blob/master/src/app/embed/page.tsx): `src/app/embed/page.tsx`

### Other components

- **User**
- **Groq AI**

## Connections

- User → Dashboard: uses
- Dashboard → Capture form: renders (evidence: `src/components/dashboard.tsx`)
- Dashboard → Note grid: renders (evidence: `src/components/dashboard.tsx`)
- Note grid → Note card: renders (evidence: `src/components/note-grid.tsx`)
- Note grid → Note modal: opens (evidence: `src/components/note-grid.tsx`)
- Note grid → Note skeleton: renders (evidence: `src/components/note-grid.tsx`)
- Capture form → Notes API: submits (evidence: `src/components/capture-form.tsx`)
- Notes API → Auth service: authenticates (evidence: `src/app/api/notes/route.ts`)
- Notes API → Rate limiting: checks limit (evidence: `src/app/api/notes/route.ts`)
- Notes API → AI analysis: analyzes input (evidence: `src/app/api/notes/route.ts`)
- Notes API → Note data service: creates or reads (evidence: `src/app/api/notes/route.ts`)
- Note data service → PostgreSQL: queries (evidence: `src/lib/db.ts`)
- Notes API → User: returns notes
- User → Login page: signs in
- Login page → Auth routes: authenticates
- Auth routes → Auth service: uses handlers (evidence: `src/app/api/auth/[...nextauth]/route.ts`)
- Registration route → Auth service: registers user (evidence: `src/app/api/auth/register/route.ts`)
- Auth service → Note data service: checks users (evidence: `src/lib/auth.ts`)
- User → Ask brain: asks
- Ask brain → Public query route: submits query
- Public query route → Rate limiting: checks limit (evidence: `src/app/api/public/brain/query/route.ts`)
- Public query route → Knowledge query: dispatches query (evidence: `src/app/api/public/brain/query/route.ts`)
- Knowledge query → Note data service: retrieves notes (evidence: `src/lib/query.ts`)
- Knowledge query → Groq AI: generates answer
- User → Public notes route: requests public notes
- Public notes route → Note data service: reads public notes (evidence: `src/app/api/public/brain/route.ts`)
- User → Embed chat: opens widget
- Embed chat → Public query route: queries brain
- UI primitives → User: renders controls
