# rkomp9802-prog/matizdetail architecture

> Architecture diagram of the GitHub repository rkomp9802-prog/matizdetail, 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/rkomp9802-prog/matizdetail
- Repository: https://github.com/rkomp9802-prog/matizdetail

## Overview

MATIZ Detail combines a detailing-service landing page with customer support through a website chat widget and Telegram bot. Website text questions are first handled by local intents in the browser; other questions go to the server’s shared answer flow, which checks the FAQ before using Gemini. Chats, unanswered questions, and attachments are retained for the admin panel, while Telegram can notify the owner. The README documents these capabilities; some subsystem links use documented paths whose source was not sampled, so uncertain call wiring is omitted.

Main entry points: [`app/admin/page.tsx`](https://github.com/rkomp9802-prog/matizdetail/blob/main/app/admin/page.tsx) (Admin panel), [`lib/chatLog.ts`](https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/chatLog.ts) (Conversation storage), [`lib/answer.ts`](https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/answer.ts) (Answer flow), [`hooks/useChat.ts`](https://github.com/rkomp9802-prog/matizdetail/blob/main/hooks/useChat.ts) (Chat state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_site["Public site"]
  node_landing["Landing page<br/>[page.tsx]"]
  node_landing_sections["Landing sections<br/>[Services.tsx]"]
  node_business_data["Service defaults<br/>[business.ts]"]
  node_feedback["Feedback form<br/>[FeedbackForm.tsx]"]
  node_feedback_api["Feedback endpoint<br/>[route.ts]"]
end

subgraph group_conversation["Chat and answers"]
  node_chat_widget["Chat widget<br/>[ChatWidget.tsx]"]
  node_chat_hook["Chat state<br/>[useChat.ts]"]
  node_local_intents["Local intents<br/>[chatBot.ts]"]
  node_chat_api["Website chat API<br/>[route.ts]"]
  node_answer_flow["Answer flow<br/>[answer.ts]"]
  node_faq_match["FAQ matching<br/>[qaMatch.ts]"]
  node_telegram_webhook["Telegram webhook<br/>[route.ts]"]
  node_chat_log_api["Local chat logging<br/>[route.ts]"]
end

subgraph group_admin["Administration"]
  node_admin_panel["Admin panel<br/>[page.tsx]"]
  node_admin_questions["FAQ management<br/>[route.ts]"]
  node_admin_info["Business settings API<br/>[route.ts]"]
  node_business_info["Business settings<br/>[businessInfo.ts]"]
  node_media_api["Protected media<br/>[route.ts]"]
  node_auth["Admin access<br/>[proxy.ts]"]
end

subgraph group_storage["Data storage"]
  node_turso["Turso client<br/>[turso.ts]"]
  node_chat_log["Conversation storage<br/>[chatLog.ts]"]
end

subgraph group_integrations["External services"]
  node_gemini["Gemini<br/>[gemini.ts]"]
  node_telegram_service["Telegram service<br/>[telegram.ts]"]
end

node_visitor(("Visitor"))
node_owner(("Owner"))
node_telegram(("Telegram user"))

node_visitor -->|"visits"| node_landing
node_landing -->|"renders"| node_landing_sections
node_landing_sections -->|"reads defaults"| node_business_data
node_visitor -->|"opens chat"| node_chat_widget
node_chat_widget -->|"uses"| node_chat_hook
node_chat_hook -->|"checks intents"| node_local_intents
node_chat_hook -->|"sends unresolved"| node_chat_api
node_chat_hook -->|"logs local replies"| node_chat_log_api
node_chat_api -->|"requests answer"| node_answer_flow
node_answer_flow -->|"checks FAQ"| node_faq_match
node_answer_flow -->|"generates answer"| node_gemini
node_chat_api -->|"saves messages"| node_chat_log
node_chat_api -->|"sends alerts/media"| node_telegram_service
node_chat_log_api -->|"saves messages"| node_chat_log
node_telegram -->|"sends updates"| node_telegram_webhook
node_telegram_webhook -->|"requests answer"| node_answer_flow
node_telegram_webhook -->|"saves messages"| node_chat_log
node_telegram_webhook -->|"sends replies"| node_telegram_service
node_visitor -->|"submits feedback"| node_feedback
node_feedback -->|"posts message"| node_feedback_api
node_feedback_api -->|"forwards feedback"| node_telegram_service
node_owner -->|"manages service"| node_admin_panel
node_admin_panel -->|"requires access"| node_auth
node_admin_panel -->|"manages FAQ"| node_admin_questions
node_admin_panel -->|"edits settings"| node_admin_info
node_admin_panel -->|"views conversations"| node_chat_log
node_admin_panel -->|"loads attachments"| node_media_api
node_admin_questions -->|"reads/writes FAQ"| node_turso
node_admin_info -->|"loads/saves values"| node_business_info
node_business_info -->|"reads/writes settings"| node_turso
node_chat_log -->|"stores messages/media"| node_turso
node_answer_flow -->|"uses service details"| node_business_info
node_local_intents -->|"reads service data"| node_business_data
node_media_api -->|"loads attachment"| node_chat_log

click node_landing "https://github.com/rkomp9802-prog/matizdetail/blob/main/app/page.tsx"
click node_landing_sections "https://github.com/rkomp9802-prog/matizdetail/blob/main/components/landing/Services.tsx"
click node_business_data "https://github.com/rkomp9802-prog/matizdetail/blob/main/data/business.ts"
click node_feedback "https://github.com/rkomp9802-prog/matizdetail/blob/main/components/FeedbackForm.tsx"
click node_feedback_api "https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/feedback/route.ts"
click node_chat_widget "https://github.com/rkomp9802-prog/matizdetail/blob/main/components/chat/ChatWidget.tsx"
click node_chat_hook "https://github.com/rkomp9802-prog/matizdetail/blob/main/hooks/useChat.ts"
click node_local_intents "https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/chatBot.ts"
click node_chat_api "https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/chat/route.ts"
click node_answer_flow "https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/answer.ts"
click node_faq_match "https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/qaMatch.ts"
click node_telegram_webhook "https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/telegram/webhook/route.ts"
click node_chat_log_api "https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/chat/log/route.ts"
click node_admin_panel "https://github.com/rkomp9802-prog/matizdetail/blob/main/app/admin/page.tsx"
click node_admin_questions "https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/admin/questions/route.ts"
click node_admin_info "https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/admin/info/route.ts"
click node_business_info "https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/businessInfo.ts"
click node_media_api "https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/admin/media/%5Bid%5D/route.ts"
click node_auth "https://github.com/rkomp9802-prog/matizdetail/blob/main/proxy.ts"
click node_turso "https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/turso.ts"
click node_chat_log "https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/chatLog.ts"
click node_gemini "https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/gemini.ts"
click node_telegram_service "https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/telegram.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_landing,node_landing_sections,node_business_data,node_feedback,node_feedback_api,node_telegram toneBlue
class node_chat_widget,node_chat_hook,node_local_intents,node_chat_api,node_answer_flow,node_faq_match,node_telegram_webhook,node_chat_log_api toneAmber
class node_admin_panel,node_admin_questions,node_admin_info,node_business_info,node_media_api,node_auth toneMint
class node_turso,node_chat_log toneRose
class node_gemini,node_telegram_service,node_visitor,node_owner toneIndigo
```

## Components

### Public site

- [Landing page](https://github.com/rkomp9802-prog/matizdetail/blob/main/app/page.tsx): `app/page.tsx`
- [Landing sections](https://github.com/rkomp9802-prog/matizdetail/blob/main/components/landing/Services.tsx): `components/landing/Services.tsx`
- [Service defaults](https://github.com/rkomp9802-prog/matizdetail/blob/main/data/business.ts): `data/business.ts`
- [Feedback form](https://github.com/rkomp9802-prog/matizdetail/blob/main/components/FeedbackForm.tsx): `components/FeedbackForm.tsx`
- [Feedback endpoint](https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/feedback/route.ts): `app/api/feedback/route.ts`

### Chat and answers

- [Chat widget](https://github.com/rkomp9802-prog/matizdetail/blob/main/components/chat/ChatWidget.tsx): `components/chat/ChatWidget.tsx`
- [Chat state](https://github.com/rkomp9802-prog/matizdetail/blob/main/hooks/useChat.ts): `hooks/useChat.ts`
- [Local intents](https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/chatBot.ts): `lib/chatBot.ts`
- [Website chat API](https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [Answer flow](https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/answer.ts): `lib/answer.ts`
- [FAQ matching](https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/qaMatch.ts): `lib/qaMatch.ts`
- [Telegram webhook](https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/telegram/webhook/route.ts): `app/api/telegram/webhook/route.ts`
- [Local chat logging](https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/chat/log/route.ts): `app/api/chat/log/route.ts`

### Administration

- [Admin panel](https://github.com/rkomp9802-prog/matizdetail/blob/main/app/admin/page.tsx): `app/admin/page.tsx`
- [FAQ management](https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/admin/questions/route.ts): `app/api/admin/questions/route.ts`
- [Business settings API](https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/admin/info/route.ts): `app/api/admin/info/route.ts`
- [Business settings](https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/businessInfo.ts): `lib/businessInfo.ts`
- [Protected media](https://github.com/rkomp9802-prog/matizdetail/blob/main/app/api/admin/media/%5Bid%5D/route.ts): `app/api/admin/media/[id]/route.ts`
- [Admin access](https://github.com/rkomp9802-prog/matizdetail/blob/main/proxy.ts): `proxy.ts`

### Data storage

- [Turso client](https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/turso.ts): `lib/turso.ts`
- [Conversation storage](https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/chatLog.ts): `lib/chatLog.ts`

### External services

- [Gemini](https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/gemini.ts): `lib/gemini.ts`
- [Telegram service](https://github.com/rkomp9802-prog/matizdetail/blob/main/lib/telegram.ts): `lib/telegram.ts`

### Other components

- **Visitor**
- **Owner**
- **Telegram user**

## Connections

- Visitor → Landing page: visits
- Landing page → Landing sections: renders
- Landing sections → Service defaults: reads defaults
- Visitor → Chat widget: opens chat
- Chat widget → Chat state: uses
- Chat state → Local intents: checks intents
- Chat state → Website chat API: sends unresolved
- Chat state → Local chat logging: logs local replies
- Website chat API → Answer flow: requests answer
- Answer flow → FAQ matching: checks FAQ
- Answer flow → Gemini: generates answer
- Website chat API → Conversation storage: saves messages
- Website chat API → Telegram service: sends alerts/media
- Local chat logging → Conversation storage: saves messages
- Telegram user → Telegram webhook: sends updates
- Telegram webhook → Answer flow: requests answer
- Telegram webhook → Conversation storage: saves messages
- Telegram webhook → Telegram service: sends replies
- Visitor → Feedback form: submits feedback
- Feedback form → Feedback endpoint: posts message
- Feedback endpoint → Telegram service: forwards feedback
- Owner → Admin panel: manages service
- Admin panel → Admin access: requires access
- Admin panel → FAQ management: manages FAQ
- Admin panel → Business settings API: edits settings
- Admin panel → Conversation storage: views conversations
- Admin panel → Protected media: loads attachments
- FAQ management → Turso client: reads/writes FAQ
- Business settings API → Business settings: loads/saves values
- Business settings → Turso client: reads/writes settings
- Conversation storage → Turso client: stores messages/media
- Answer flow → Business settings: uses service details
- Local intents → Service defaults: reads service data
- Protected media → Conversation storage: loads attachment
