# atharvagupta0/musafir-cafe architecture

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

- Interactive diagram: https://gitdiagram.com/atharvagupta0/musafir-cafe
- Repository: https://github.com/atharvagupta0/musafir-cafe

## Overview

Café Fernweh combines an embedded café-chatbot product with an academic AI-behaviour evaluation harness. The customer workflow is message entry, API transport, server-side conversation orchestration, menu grounding and inference, then a response with optional product details. Separate branches support menu/sales administration and a framework-independent widget. The source index identifies the evaluation modules as substantial, so they are included as a distinct research subsystem. Some route and provider wiring is only partially excerpted; unverified links are omitted or marked dashed.

Main entry points: [`ChatBot/src/server/index.ts`](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/index.ts) (HTTP worker), [`ChatBot/src/server/lib/orchestration.ts`](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/orchestration.ts) (Conversation orchestration), [`ChatBot/src/client/components/Chat.tsx`](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/components/Chat.tsx) (Chat interface), [`ChatBot/src/server/lib/menu.ts`](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/menu.ts) (Menu grounding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_customer["Customer Chat"]
  node_chat_ui["Chat interface<br/>[Chat.tsx]"]
  node_chat_input["Message input<br/>[ChatInput.tsx]"]
  node_chat_api["Client API<br/>[api.ts]"]
  node_chat_display["Message display<br/>[MessageBubble.tsx]"]
  node_welcome["Suggestions<br/>[suggestions.ts]"]
  node_widget["Embeddable widget<br/>[widget.ts]"]
end

subgraph group_server["Chat Services"]
  node_worker["HTTP worker<br/>[index.ts]"]
  node_orchestration["Conversation orchestration<br/>[orchestration.ts]"]
  node_inference["Inference adapter<br/>[adapter.ts]"]
  node_state["Conversation state<br/>[state.ts]"]
  node_validation["Reply validation<br/>[validation.ts]"]
  node_menu["Menu grounding<br/>[menu.ts]"]
  node_db_access["Database access<br/>[db.ts]"]
  node_database[("Café database<br/>[schema.sql]")]
  node_schema["Shared schemas<br/>[schema.ts]"]
end

subgraph group_admin["Café Administration"]
  node_admin_ui["Admin dashboard<br/>[App.tsx]"]
  node_admin_auth["Admin sessions<br/>[admin-auth.ts]"]
  node_admin_data["Menu and sales admin<br/>[admin.ts]"]
end

subgraph group_research["AI Evaluation"]
  node_eval_runner["Evaluation runner<br/>[runner.ts]"]
  node_eval_live["Live evaluation<br/>[eval-runner.ts]"]
  node_eval_metrics["Evaluation metrics<br/>[metrics.ts]"]
end

node_customer(("Café customer"))
node_host(("Website host"))
node_gemini{{"Gemini service"}}

node_customer -->|"enters message"| node_chat_input
node_chat_input -->|"submits text"| node_chat_ui
node_chat_ui -->|"posts chat"| node_chat_api
node_chat_api -->|"HTTP request"| node_worker
node_worker -->|"runs conversation"| node_orchestration
node_orchestration -.->|"requests inference"| node_inference
node_inference -.->|"model inference"| node_gemini
node_orchestration -->|"runs menu tools"| node_menu
node_orchestration -->|"updates context"| node_state
node_orchestration -->|"validates reply"| node_validation
node_menu -->|"queries menu"| node_db_access
node_db_access -.->|"reads and writes"| node_database
node_worker -->|"initializes database"| node_db_access
node_worker -.->|"returns reply"| node_chat_ui
node_chat_ui -->|"renders messages"| node_chat_display
node_chat_ui -->|"shows suggestions"| node_welcome
node_host -.->|"embeds widget"| node_widget
node_admin_ui -.->|"calls admin API"| node_worker
node_worker -->|"checks sessions"| node_admin_auth
node_worker -->|"routes admin actions"| node_admin_data
node_admin_data -->|"queries admin data"| node_db_access
node_eval_runner -->|"sends chat cases"| node_worker
node_eval_runner -->|"checks product data"| node_menu
node_eval_live -->|"uses menu data"| node_menu
node_eval_live -->|"uses provider"| node_inference

click node_chat_ui "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/components/Chat.tsx"
click node_chat_input "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/components/ChatInput.tsx"
click node_chat_api "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/lib/api.ts"
click node_chat_display "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/components/MessageBubble.tsx"
click node_welcome "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/lib/suggestions.ts"
click node_widget "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/widget/widget.ts"
click node_worker "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/index.ts"
click node_orchestration "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/orchestration.ts"
click node_inference "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/inference/adapter.ts"
click node_state "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/state.ts"
click node_validation "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/validation.ts"
click node_menu "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/menu.ts"
click node_db_access "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/db.ts"
click node_database "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/db/schema.sql"
click node_schema "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/shared/schema.ts"
click node_admin_ui "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/admin/App.tsx"
click node_admin_auth "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/admin-auth.ts"
click node_admin_data "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/admin.ts"
click node_eval_runner "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/experiments/runner.ts"
click node_eval_live "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/experiments/eval-runner.ts"
click node_eval_metrics "https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/experiments/metrics.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_chat_ui,node_chat_input,node_chat_api,node_chat_display,node_welcome,node_widget toneBlue
class node_worker,node_orchestration,node_inference,node_state,node_validation,node_menu,node_db_access,node_database,node_schema toneAmber
class node_admin_ui,node_admin_auth,node_admin_data toneMint
class node_eval_runner,node_eval_live,node_eval_metrics toneRose
class node_customer,node_host,node_gemini toneIndigo
```

## Components

### Customer Chat

- [Chat interface](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/components/Chat.tsx): `ChatBot/src/client/components/Chat.tsx`
- [Message input](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/components/ChatInput.tsx): `ChatBot/src/client/components/ChatInput.tsx`
- [Client API](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/lib/api.ts): `ChatBot/src/client/lib/api.ts`
- [Message display](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/components/MessageBubble.tsx): `ChatBot/src/client/components/MessageBubble.tsx`
- [Suggestions](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/lib/suggestions.ts): `ChatBot/src/client/lib/suggestions.ts`
- [Embeddable widget](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/widget/widget.ts): `ChatBot/src/client/widget/widget.ts`

### Chat Services

- [HTTP worker](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/index.ts): `ChatBot/src/server/index.ts`
- [Conversation orchestration](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/orchestration.ts): `ChatBot/src/server/lib/orchestration.ts`
- [Inference adapter](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/inference/adapter.ts): `ChatBot/src/server/inference/adapter.ts`
- [Conversation state](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/state.ts): `ChatBot/src/server/lib/state.ts`
- [Reply validation](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/validation.ts): `ChatBot/src/server/lib/validation.ts`
- [Menu grounding](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/menu.ts): `ChatBot/src/server/lib/menu.ts`
- [Database access](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/db.ts): `ChatBot/src/server/lib/db.ts`
- [Café database](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/db/schema.sql): `ChatBot/db/schema.sql`
- [Shared schemas](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/shared/schema.ts): `ChatBot/src/shared/schema.ts`

### Café Administration

- [Admin dashboard](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/client/admin/App.tsx): `ChatBot/src/client/admin/App.tsx`
- [Admin sessions](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/admin-auth.ts): `ChatBot/src/server/lib/admin-auth.ts`
- [Menu and sales admin](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/src/server/lib/admin.ts): `ChatBot/src/server/lib/admin.ts`

### AI Evaluation

- [Evaluation runner](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/experiments/runner.ts): `ChatBot/experiments/runner.ts`
- [Live evaluation](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/experiments/eval-runner.ts): `ChatBot/experiments/eval-runner.ts`
- [Evaluation metrics](https://github.com/atharvagupta0/musafir-cafe/blob/main/ChatBot/experiments/metrics.ts): `ChatBot/experiments/metrics.ts`

### Other components

- **Café customer**
- **Website host**
- **Gemini service**

## Connections

- Café customer → Message input: enters message
- Message input → Chat interface: submits text (evidence: `ChatBot/src/client/components/Chat.tsx`)
- Chat interface → Client API: posts chat (evidence: `ChatBot/src/client/components/Chat.tsx`)
- Client API → HTTP worker: HTTP request (evidence: `ChatBot/src/client/lib/api.ts`)
- HTTP worker → Conversation orchestration: runs conversation (evidence: `ChatBot/src/server/index.ts`)
- Conversation orchestration → Inference adapter: requests inference
- Inference adapter → Gemini service: model inference
- Conversation orchestration → Menu grounding: runs menu tools (evidence: `ChatBot/src/server/lib/orchestration.ts`)
- Conversation orchestration → Conversation state: updates context (evidence: `ChatBot/src/server/lib/orchestration.ts`)
- Conversation orchestration → Reply validation: validates reply (evidence: `ChatBot/src/server/lib/orchestration.ts`)
- Menu grounding → Database access: queries menu (evidence: `ChatBot/src/server/lib/menu.ts`)
- Database access → Café database: reads and writes
- HTTP worker → Database access: initializes database (evidence: `ChatBot/src/server/index.ts`)
- HTTP worker → Chat interface: returns reply
- Chat interface → Message display: renders messages (evidence: `ChatBot/src/client/components/Chat.tsx`)
- Chat interface → Suggestions: shows suggestions (evidence: `ChatBot/src/client/components/Chat.tsx`)
- Website host → Embeddable widget: embeds widget
- Admin dashboard → HTTP worker: calls admin API
- HTTP worker → Admin sessions: checks sessions (evidence: `ChatBot/src/server/index.ts`)
- HTTP worker → Menu and sales admin: routes admin actions (evidence: `ChatBot/src/server/index.ts`)
- Menu and sales admin → Database access: queries admin data (evidence: `ChatBot/src/server/lib/admin.ts`)
- Evaluation runner → HTTP worker: sends chat cases (evidence: `ChatBot/experiments/runner.ts`)
- Evaluation runner → Menu grounding: checks product data (evidence: `ChatBot/experiments/runner.ts`)
- Live evaluation → Menu grounding: uses menu data (evidence: `ChatBot/experiments/eval-runner.ts`)
- Live evaluation → Inference adapter: uses provider (evidence: `ChatBot/experiments/eval-runner.ts`)
