# dawaaaaaa8/yamat-mlsp architecture

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

- Interactive diagram: https://gitdiagram.com/dawaaaaaa8/yamat-mlsp
- Repository: https://github.com/dawaaaaaa8/yamat-mlsp

## Overview

ҮАМАТ is a Mongolian occupational classification browser with an administration interface and AI-assisted search/chat. Users browse categories, occupational details, content and catalog tables, or ask questions; administrators manage categories and users. The repository separates a Next.js frontend, an Express/MySQL domain API and a FastAPI AI service. AI chat can use cached or direct answers, category search and an Ollama-generated response. Frontend-to-service wiring is not shown in the excerpts, so those links are left unverified.

Main entry points: [`yamat-ai/app/routers/chat.py`](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/routers/chat.py) (Chat orchestration), [`yamat-api/src/index.ts`](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/index.ts) (API router), [`yamat-api/src/config/db.ts`](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/config/db.ts) (MySQL access), [`yamat-api/src/routes/managementRoutes.ts`](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/routes/managementRoutes.ts) (Admin management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_web_browse["Browse pages<br/>[page.tsx]"]
  node_web_search["Search page<br/>[page.tsx]"]
  node_web_details["Detail and content<br/>[page.tsx]"]
  node_web_catalog["Catalog tables<br/>[CatalogTable.tsx]"]
  node_web_chat["AI chat UI<br/>[AiChat.tsx]"]
  node_web_admin["Admin workspace<br/>[AdminWorkspace.tsx]"]
  node_web_auth["Session context<br/>[AuthContext.tsx]"]
  node_web_proxy["AI and catalog routes<br/>[route.ts]"]
end

subgraph group_api["Domain API"]
  node_api_entry["API router<br/>[index.ts]"]
  node_api_categories["Category browsing"]
  node_api_content["Content and catalog"]
  node_api_admin["Admin management"]
  node_api_users["User management<br/>[userController.ts]"]
  node_api_auth["Authentication<br/>[authMiddleware.ts]"]
  node_api_ai["AI endpoints<br/>[ai.ts]"]
end

subgraph group_ai["AI assistant"]
  node_ai_entry["AI service<br/>[main.py]"]
  node_ai_chat["Chat orchestration<br/>[chat.py]"]
  node_ai_search["Category search<br/>[search.py]"]
  node_ai_intents["Intent handling<br/>[intents.py]"]
  node_ai_cache["Answer cache<br/>[cache.py]"]
  node_ai_llm["Answer generation<br/>[llm.py]"]
  node_ai_embeddings["Semantic embeddings<br/>[embeddings.py]"]
  node_ai_feedback["Chat feedback<br/>[feedback.py]"]
  node_ai_admin["AI administration<br/>[admin.py]"]
end

subgraph group_state["Data and integrations"]
  node_mysql_api[("MySQL access<br/>[db.ts]")]
  node_mysql_ai[("MySQL access<br/>[db.py]")]
  node_ollama["Ollama service"]
end

node_visitor(("Visitor"))
node_admin(("Administrator"))

node_visitor -.->|"opens"| node_web_browse
node_visitor -.->|"searches"| node_web_search
node_visitor -.->|"asks"| node_web_chat
node_admin -.->|"manages"| node_web_admin
node_web_auth -.->|"guards"| node_web_admin
node_web_proxy -.->|"forwards requests"| node_api_entry
node_web_browse -.->|"requests categories"| node_api_categories
node_web_details -.->|"requests content"| node_api_content
node_web_catalog -.->|"requests catalog"| node_api_content
node_web_chat -.->|"sends chat"| node_web_proxy
node_web_admin -.->|"submits changes"| node_api_admin
node_api_entry -->|"mounts routes"| node_api_categories
node_api_entry -->|"mounts routes"| node_api_content
node_api_entry -->|"mounts routes"| node_api_admin
node_api_entry -->|"mounts routes"| node_api_ai
node_api_admin -->|"checks roles"| node_api_auth
node_api_admin -->|"reads and writes"| node_mysql_api
node_api_categories -->|"queries categories"| node_mysql_api
node_api_content -->|"queries content"| node_mysql_api
node_api_users -->|"queries users"| node_mysql_api
node_api_auth -->|"checks user"| node_mysql_api
node_ai_entry -->|"mounts router"| node_ai_chat
node_ai_entry -->|"mounts router"| node_ai_admin
node_ai_entry -->|"mounts router"| node_ai_feedback
node_ai_chat -->|"checks cache"| node_ai_cache
node_ai_chat -->|"classifies query"| node_ai_intents
node_ai_chat -->|"searches categories"| node_ai_search
node_ai_chat -->|"generates answer"| node_ai_llm
node_ai_search -->|"uses semantic index"| node_ai_embeddings
node_ai_search -->|"loads categories"| node_mysql_ai
node_ai_chat -->|"logs and saves"| node_mysql_ai
node_ai_feedback -->|"stores feedback"| node_mysql_ai
node_ai_admin -->|"manages data"| node_mysql_ai
node_ai_llm -->|"requests completion"| node_ollama

click node_web_browse "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/app/%5Blocale%5D/angilal/page.tsx"
click node_web_search "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/app/%5Blocale%5D/hailt/page.tsx"
click node_web_details "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/app/%5Blocale%5D/content/%5Bid%5D/page.tsx"
click node_web_catalog "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/components/CatalogTable.tsx"
click node_web_chat "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/components/AiChat.tsx"
click node_web_admin "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/components/AdminWorkspace.tsx"
click node_web_auth "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/lib/auth/AuthContext.tsx"
click node_web_proxy "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/app/api/ai/chat/route.ts"
click node_api_entry "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/index.ts"
click node_api_categories "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/controllers/categoryController.ts"
click node_api_content "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/controllers/contentController.ts"
click node_api_admin "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/routes/managementRoutes.ts"
click node_api_users "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/controllers/userController.ts"
click node_api_auth "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/middleware/authMiddleware.ts"
click node_api_ai "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/routes/ai.ts"
click node_ai_entry "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/main.py"
click node_ai_chat "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/routers/chat.py"
click node_ai_search "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/search.py"
click node_ai_intents "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/intents.py"
click node_ai_cache "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/cache.py"
click node_ai_llm "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/llm.py"
click node_ai_embeddings "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/embeddings.py"
click node_ai_feedback "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/routers/feedback.py"
click node_ai_admin "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/routers/admin.py"
click node_mysql_api "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/config/db.ts"
click node_mysql_ai "https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/db.py"

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_web_browse,node_web_search,node_web_details,node_web_catalog,node_web_chat,node_web_admin,node_web_auth,node_web_proxy toneBlue
class node_api_entry,node_api_categories,node_api_content,node_api_admin,node_api_users,node_api_auth,node_api_ai toneAmber
class node_ai_entry,node_ai_chat,node_ai_search,node_ai_intents,node_ai_cache,node_ai_llm,node_ai_embeddings,node_ai_feedback,node_ai_admin toneMint
class node_mysql_api,node_mysql_ai,node_ollama toneRose
class node_visitor,node_admin toneIndigo
```

## Components

### Web application

- [Browse pages](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/app/%5Blocale%5D/angilal/page.tsx): `yamat-08/src/app/[locale]/angilal/page.tsx`
- [Search page](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/app/%5Blocale%5D/hailt/page.tsx): `yamat-08/src/app/[locale]/hailt/page.tsx`
- [Detail and content](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/app/%5Blocale%5D/content/%5Bid%5D/page.tsx): `yamat-08/src/app/[locale]/content/[id]/page.tsx`
- [Catalog tables](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/components/CatalogTable.tsx): `yamat-08/src/components/CatalogTable.tsx`
- [AI chat UI](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/components/AiChat.tsx): `yamat-08/src/components/AiChat.tsx`
- [Admin workspace](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/components/AdminWorkspace.tsx): `yamat-08/src/components/AdminWorkspace.tsx`
- [Session context](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/lib/auth/AuthContext.tsx): `yamat-08/src/lib/auth/AuthContext.tsx`
- [AI and catalog routes](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-08/src/app/api/ai/chat/route.ts): `yamat-08/src/app/api/ai/chat/route.ts`

### Domain API

- [API router](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/index.ts): `yamat-api/src/index.ts`
- [Category browsing](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/controllers/categoryController.ts): `yamat-api/src/controllers/categoryController.ts`
- [Content and catalog](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/controllers/contentController.ts): `yamat-api/src/controllers/contentController.ts`
- [Admin management](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/routes/managementRoutes.ts): `yamat-api/src/routes/managementRoutes.ts`
- [User management](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/controllers/userController.ts): `yamat-api/src/controllers/userController.ts`
- [Authentication](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/middleware/authMiddleware.ts): `yamat-api/src/middleware/authMiddleware.ts`
- [AI endpoints](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/routes/ai.ts): `yamat-api/src/routes/ai.ts`

### AI assistant

- [AI service](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/main.py): `yamat-ai/main.py`
- [Chat orchestration](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/routers/chat.py): `yamat-ai/app/routers/chat.py`
- [Category search](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/search.py): `yamat-ai/app/search.py`
- [Intent handling](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/intents.py): `yamat-ai/app/intents.py`
- [Answer cache](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/cache.py): `yamat-ai/app/cache.py`
- [Answer generation](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/llm.py): `yamat-ai/app/llm.py`
- [Semantic embeddings](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/embeddings.py): `yamat-ai/app/embeddings.py`
- [Chat feedback](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/routers/feedback.py): `yamat-ai/app/routers/feedback.py`
- [AI administration](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/routers/admin.py): `yamat-ai/app/routers/admin.py`

### Data and integrations

- [MySQL access](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-api/src/config/db.ts): `yamat-api/src/config/db.ts`
- [MySQL access](https://github.com/dawaaaaaa8/yamat-mlsp/blob/main/yamat-ai/app/db.py): `yamat-ai/app/db.py`
- **Ollama service**

### Other components

- **Visitor**
- **Administrator**

## Connections

- Visitor → Browse pages: opens
- Visitor → Search page: searches
- Visitor → AI chat UI: asks
- Administrator → Admin workspace: manages
- Session context → Admin workspace: guards
- AI and catalog routes → API router: forwards requests
- Browse pages → Category browsing: requests categories
- Detail and content → Content and catalog: requests content
- Catalog tables → Content and catalog: requests catalog
- AI chat UI → AI and catalog routes: sends chat
- Admin workspace → Admin management: submits changes
- API router → Category browsing: mounts routes (evidence: `yamat-api/src/index.ts`)
- API router → Content and catalog: mounts routes (evidence: `yamat-api/src/index.ts`)
- API router → Admin management: mounts routes (evidence: `yamat-api/src/index.ts`)
- API router → AI endpoints: mounts routes (evidence: `yamat-api/src/index.ts`)
- Admin management → Authentication: checks roles (evidence: `yamat-api/src/routes/managementRoutes.ts`)
- Admin management → MySQL access: reads and writes (evidence: `yamat-api/src/routes/managementRoutes.ts`)
- Category browsing → MySQL access: queries categories (evidence: `yamat-api/src/controllers/categoryController.ts`)
- Content and catalog → MySQL access: queries content (evidence: `yamat-api/src/controllers/contentController.ts`)
- User management → MySQL access: queries users (evidence: `yamat-api/src/controllers/userController.ts`)
- Authentication → MySQL access: checks user (evidence: `yamat-api/src/middleware/authMiddleware.ts`)
- AI service → Chat orchestration: mounts router (evidence: `yamat-ai/main.py`)
- AI service → AI administration: mounts router (evidence: `yamat-ai/main.py`)
- AI service → Chat feedback: mounts router (evidence: `yamat-ai/main.py`)
- Chat orchestration → Answer cache: checks cache (evidence: `yamat-ai/app/routers/chat.py`)
- Chat orchestration → Intent handling: classifies query (evidence: `yamat-ai/app/routers/chat.py`)
- Chat orchestration → Category search: searches categories (evidence: `yamat-ai/app/routers/chat.py`)
- Chat orchestration → Answer generation: generates answer (evidence: `yamat-ai/app/routers/chat.py`)
- Category search → Semantic embeddings: uses semantic index (evidence: `yamat-ai/app/search.py`)
- Category search → MySQL access: loads categories (evidence: `yamat-ai/app/search.py`)
- Chat orchestration → MySQL access: logs and saves (evidence: `yamat-ai/app/routers/chat.py`)
- Chat feedback → MySQL access: stores feedback (evidence: `yamat-ai/app/routers/feedback.py`)
- AI administration → MySQL access: manages data (evidence: `yamat-ai/app/routers/admin.py`)
- Answer generation → Ollama service: requests completion (evidence: `yamat-ai/app/llm.py`)
