# snoeyink/myai architecture

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

- Interactive diagram: https://gitdiagram.com/snoeyink/myai
- Repository: https://github.com/snoeyink/myai

## Overview

myAI is a configurable chatbot with a Next.js chat UI, intent-based response routing, and document-grounded answers using Pinecone. The main workflow runs from a user message through the chat API and intention detection; questions additionally retrieve document context before generation, while hostile and casual messages use separate response prompts. Responses stream back to the UI with loading indicators and citation links. Sampled files establish the chat, routing, and streaming paths; the retrieval helper and intention detector are represented by their exact tree paths, but their internal implementations were not sampled.

Main entry points: [`hooks/use-app.ts`](https://github.com/snoeyink/myai/blob/main/hooks/use-app.ts) (Chat state), [`actions/streaming.ts`](https://github.com/snoeyink/myai/blob/main/actions/streaming.ts) (Stream dispatch), [`app/page.tsx`](https://github.com/snoeyink/myai/blob/main/app/page.tsx) (Chat page), [`modules/response.ts`](https://github.com/snoeyink/myai/blob/main/modules/response.ts) (Response routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_chat_ui["Chat interface"]
  node_page["Chat page<br/>[page.tsx]"]
  node_chat_hook["Chat state<br/>[use-app.ts]"]
  node_chat_view["Messages and input<br/>[messages.tsx]"]
  node_chat_input["Chat input<br/>[input.tsx]"]
  node_browser_storage[("Browser storage")]
end

subgraph group_api_flow["API routing"]
  node_chat_api["Chat endpoint<br/>[route.ts]"]
  node_intention["Intent detection<br/>[intention.ts]"]
  node_intention_prompt["Intent prompt<br/>[prompts.ts]"]
  node_response_module["Response routing<br/>[response.ts]"]
end

subgraph group_retrieval["Question retrieval"]
  node_chat_utilities["Chat and retrieval helpers<br/>[chat.ts]"]
  node_pinecone[("Pinecone index")]
end

subgraph group_generation["Response generation"]
  node_response_prompts["Response prompts<br/>[prompts.ts]"]
  node_streaming["Stream dispatch<br/>[streaming.ts]"]
  node_stream_response["Streamed response<br/>[streaming.ts]"]
end

node_user(("User"))
node_openai{{"OpenAI"}}
node_anthropic{{"Anthropic"}}
node_fireworks{{"Fireworks"}}

node_user -->|"uses"| node_page
node_page -->|"uses state"| node_chat_hook
node_page -->|"renders"| node_chat_view
node_page -->|"renders"| node_chat_input
node_chat_input -->|"submits input"| node_chat_hook
node_chat_hook -->|"reads and writes"| node_browser_storage
node_chat_hook -->|"posts chat"| node_chat_api
node_chat_api -->|"detects intent"| node_intention
node_intention -->|"uses prompt"| node_intention_prompt
node_intention -->|"classifies with"| node_openai
node_chat_api -->|"dispatches by intent"| node_response_module
node_response_module -->|"prepares question context"| node_chat_utilities
node_chat_utilities -->|"searches index"| node_pinecone
node_response_module -->|"uses response prompt"| node_response_prompts
node_response_module -->|"queues generation"| node_streaming
node_streaming -->|"streams from"| node_openai
node_streaming -.->|"streams from"| node_anthropic
node_streaming -.->|"streams from"| node_fireworks
node_streaming -->|"enqueues chunks"| node_stream_response
node_stream_response -->|"returns stream"| node_chat_hook
node_chat_hook -->|"updates messages"| node_chat_view

click node_page "https://github.com/snoeyink/myai/blob/main/app/page.tsx"
click node_chat_hook "https://github.com/snoeyink/myai/blob/main/hooks/use-app.ts"
click node_chat_view "https://github.com/snoeyink/myai/blob/main/components/chat/messages.tsx"
click node_chat_input "https://github.com/snoeyink/myai/blob/main/components/chat/input.tsx"
click node_chat_api "https://github.com/snoeyink/myai/blob/main/app/api/chat/route.ts"
click node_intention "https://github.com/snoeyink/myai/blob/main/modules/intention.ts"
click node_intention_prompt "https://github.com/snoeyink/myai/blob/main/prompts.ts"
click node_response_module "https://github.com/snoeyink/myai/blob/main/modules/response.ts"
click node_chat_utilities "https://github.com/snoeyink/myai/blob/main/utilities/chat.ts"
click node_response_prompts "https://github.com/snoeyink/myai/blob/main/prompts.ts"
click node_streaming "https://github.com/snoeyink/myai/blob/main/actions/streaming.ts"
click node_stream_response "https://github.com/snoeyink/myai/blob/main/actions/streaming.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_page,node_chat_hook,node_chat_view,node_chat_input,node_browser_storage,node_user toneBlue
class node_chat_api,node_intention,node_intention_prompt,node_response_module toneAmber
class node_chat_utilities,node_pinecone toneMint
class node_response_prompts,node_streaming,node_stream_response toneRose
class node_openai,node_anthropic,node_fireworks toneIndigo
```

## Components

### Chat interface

- [Chat page](https://github.com/snoeyink/myai/blob/main/app/page.tsx): `app/page.tsx`
- [Chat state](https://github.com/snoeyink/myai/blob/main/hooks/use-app.ts): `hooks/use-app.ts`
- [Messages and input](https://github.com/snoeyink/myai/blob/main/components/chat/messages.tsx): `components/chat/messages.tsx`
- [Chat input](https://github.com/snoeyink/myai/blob/main/components/chat/input.tsx): `components/chat/input.tsx`
- **Browser storage**

### API routing

- [Chat endpoint](https://github.com/snoeyink/myai/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Intent detection](https://github.com/snoeyink/myai/blob/main/modules/intention.ts): `modules/intention.ts`
- [Intent prompt](https://github.com/snoeyink/myai/blob/main/prompts.ts): `prompts.ts`
- [Response routing](https://github.com/snoeyink/myai/blob/main/modules/response.ts): `modules/response.ts`

### Question retrieval

- [Chat and retrieval helpers](https://github.com/snoeyink/myai/blob/main/utilities/chat.ts): `utilities/chat.ts`
- **Pinecone index**

### Response generation

- [Response prompts](https://github.com/snoeyink/myai/blob/main/prompts.ts): `prompts.ts`
- [Stream dispatch](https://github.com/snoeyink/myai/blob/main/actions/streaming.ts): `actions/streaming.ts`
- [Streamed response](https://github.com/snoeyink/myai/blob/main/actions/streaming.ts): `actions/streaming.ts`

### Other components

- **User**
- **OpenAI**
- **Anthropic**
- **Fireworks**

## Connections

- User → Chat page: uses
- Chat page → Chat state: uses state
- Chat page → Messages and input: renders
- Chat page → Chat input: renders
- Chat input → Chat state: submits input
- Chat state → Browser storage: reads and writes
- Chat state → Chat endpoint: posts chat
- Chat endpoint → Intent detection: detects intent
- Intent detection → Intent prompt: uses prompt
- Intent detection → OpenAI: classifies with
- Chat endpoint → Response routing: dispatches by intent
- Response routing → Chat and retrieval helpers: prepares question context
- Chat and retrieval helpers → Pinecone index: searches index
- Response routing → Response prompts: uses response prompt
- Response routing → Stream dispatch: queues generation
- Stream dispatch → OpenAI: streams from
- Stream dispatch → Anthropic: streams from
- Stream dispatch → Fireworks: streams from
- Stream dispatch → Streamed response: enqueues chunks
- Streamed response → Chat state: returns stream
- Chat state → Messages and input: updates messages
