# thanetphon026/backend-smart_condo architecture

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

- Interactive diagram: https://gitdiagram.com/thanetphon026/backend-smart_condo
- Repository: https://github.com/thanetphon026/backend-smart_condo

## Overview

Smart Condo is a Flask service for condominium parcel handling, resident support, and administration. Residents interact through LINE or a web chat: the service identifies the user, interprets requests, checks parcel state, and returns status or pickup/registration prompts. Administrators manage parcels, residents, settings, logs, and a knowledge base. AI support includes chat and parcel-label analysis; images and documents have dedicated processing utilities. The route excerpts show parcel lookups and AI intent handling, while several admin and processing modules are represented from the tree and app registration; their internal wiring is not inferred.

Main entry points: [`app/utils/db.py`](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/db.py) (Database access), [`app/__init__.py`](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/__init__.py) (Flask application), [`app/routes/webhook.py`](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/webhook.py) (LINE webhook), [`app/routes/web_chat.py`](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/web_chat.py) (Web chat API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Service entrypoints"]
  node_flask["Flask application<br/>[__init__.py]"]
end

subgraph group_resident["Resident workflows"]
  node_line_webhook["LINE webhook<br/>[webhook.py]"]
  node_web_chat["Web chat API<br/>[web_chat.py]"]
  node_line_messaging["LINE messaging<br/>[line.py]"]
  node_flex_templates["Message templates<br/>[flex_templates.py]"]
  node_parcel_templates["Parcel templates"]
end

subgraph group_admin["Administration"]
  node_admin_auth["Admin authentication<br/>[admin_auth.py]"]
  node_admin_dashboard["Dashboard<br/>[admin_dashboard.py]"]
  node_admin_parcels["Parcel management<br/>[admin_parcels.py]"]
  node_admin_users["Resident management<br/>[admin_users.py]"]
  node_admin_logs["Audit logs<br/>[admin_logs.py]"]
  node_admin_settings["Settings<br/>[admin_settings.py]"]
  node_admin_kb["Knowledge base<br/>[admin_kb.py]"]
  node_maintenance["Maintenance<br/>[maintenance.py]"]
end

subgraph group_core["AI and processing"]
  node_ai["AI services<br/>[ai.py]"]
  node_lookup["Resident lookup<br/>[lookup.py]"]
  node_pdf["PDF processing<br/>[pdf_processor.py]"]
  node_keywords["Keyword extraction"]
  node_cloudinary["Image storage utility"]
end

subgraph group_state["State and integrations"]
  node_db_utils["Database access<br/>[db.py]"]
  node_mongo[("MongoDB")]
end

node_line_resident(("LINE resident"))
node_web_resident(("Web resident"))
node_admin_user(("Admin user"))
node_line_platform["LINE platform"]
node_ai_provider["AI providers"]
node_cloudinary_service["Cloudinary"]

node_flask -->|"registers"| node_line_webhook
node_flask -->|"registers"| node_web_chat
node_flask -->|"registers"| node_admin_auth
node_flask -->|"registers"| node_admin_dashboard
node_flask -->|"registers"| node_admin_parcels
node_flask -->|"registers"| node_admin_users
node_flask -->|"registers"| node_admin_logs
node_flask -->|"registers"| node_admin_settings
node_flask -->|"registers"| node_admin_kb
node_flask -->|"registers"| node_maintenance
node_line_resident -->|"sends events"| node_line_platform
node_line_platform -->|"webhook events"| node_line_webhook
node_line_webhook -->|"interprets intent"| node_ai
node_line_webhook -->|"reads and writes"| node_db_utils
node_line_webhook -->|"sends replies"| node_line_messaging
node_line_webhook -->|"builds cards"| node_flex_templates
node_line_webhook -->|"builds parcel cards"| node_parcel_templates
node_line_messaging -->|"sends messages"| node_line_platform
node_web_resident -->|"sends requests"| node_web_chat
node_web_chat -->|"interprets intent"| node_ai
node_web_chat -->|"reads and writes"| node_db_utils
node_web_chat -->|"builds cards"| node_flex_templates
node_web_chat -->|"builds parcel cards"| node_parcel_templates
node_ai -->|"calls models"| node_ai_provider
node_ai -->|"retrieves knowledge"| node_db_utils
node_ai -->|"normalizes identity"| node_lookup
node_admin_user -->|"logs in"| node_admin_auth
node_admin_user -->|"uses dashboard"| node_admin_dashboard
node_admin_user -->|"manages parcels"| node_admin_parcels
node_admin_user -->|"manages residents"| node_admin_users
node_admin_user -->|"reviews logs"| node_admin_logs
node_admin_user -->|"changes settings"| node_admin_settings
node_admin_user -->|"manages knowledge"| node_admin_kb
node_admin_auth -->|"checks admins"| node_db_utils
node_admin_auth -->|"records audit"| node_db_utils
node_admin_parcels -->|"manages records"| node_db_utils
node_admin_users -->|"manages records"| node_db_utils
node_admin_logs -->|"reads audit"| node_db_utils
node_admin_dashboard -->|"reads data"| node_db_utils
node_admin_settings -->|"reads and writes"| node_db_utils
node_admin_kb -->|"manages knowledge"| node_db_utils
node_db_utils -->|"queries"| node_mongo
node_line_webhook -.->|"uploads images"| node_cloudinary
node_web_chat -.->|"uploads images"| node_cloudinary
node_cloudinary -.->|"stores images"| node_cloudinary_service
node_admin_kb -.->|"processes documents"| node_pdf
node_admin_kb -.->|"extracts terms"| node_keywords

click node_flask "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/__init__.py"
click node_line_webhook "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/webhook.py"
click node_web_chat "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/web_chat.py"
click node_line_messaging "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/line.py"
click node_flex_templates "https://github.com/thanetphon026/backend-smart_condo/blob/main/flex_templates.py"
click node_parcel_templates "https://github.com/thanetphon026/backend-smart_condo/blob/main/parcel_flex_templates.py"
click node_admin_auth "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_auth.py"
click node_admin_dashboard "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_dashboard.py"
click node_admin_parcels "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_parcels.py"
click node_admin_users "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_users.py"
click node_admin_logs "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_logs.py"
click node_admin_settings "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_settings.py"
click node_admin_kb "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_kb.py"
click node_maintenance "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/maintenance.py"
click node_ai "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/ai.py"
click node_lookup "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/lookup.py"
click node_pdf "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/pdf_processor.py"
click node_keywords "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/keyword_extractor.py"
click node_cloudinary "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/cloudinary_utils.py"
click node_db_utils "https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/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_flask,node_admin_user toneBlue
class node_line_webhook,node_web_chat,node_line_messaging,node_flex_templates,node_parcel_templates toneAmber
class node_admin_auth,node_admin_dashboard,node_admin_parcels,node_admin_users,node_admin_logs,node_admin_settings,node_admin_kb,node_maintenance toneMint
class node_ai,node_lookup,node_pdf,node_keywords,node_cloudinary toneRose
class node_db_utils,node_mongo,node_line_resident,node_web_resident,node_line_platform,node_ai_provider,node_cloudinary_service toneIndigo
```

## Components

### Service entrypoints

- [Flask application](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/__init__.py): `app/__init__.py`

### Resident workflows

- [LINE webhook](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/webhook.py): `app/routes/webhook.py`
- [Web chat API](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/web_chat.py): `app/routes/web_chat.py`
- [LINE messaging](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/line.py): `app/utils/line.py`
- [Message templates](https://github.com/thanetphon026/backend-smart_condo/blob/main/flex_templates.py): `flex_templates.py`
- [Parcel templates](https://github.com/thanetphon026/backend-smart_condo/blob/main/parcel_flex_templates.py): `parcel_flex_templates.py`

### Administration

- [Admin authentication](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_auth.py): `app/routes/admin_auth.py`
- [Dashboard](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_dashboard.py): `app/routes/admin_dashboard.py`
- [Parcel management](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_parcels.py): `app/routes/admin_parcels.py`
- [Resident management](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_users.py): `app/routes/admin_users.py`
- [Audit logs](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_logs.py): `app/routes/admin_logs.py`
- [Settings](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_settings.py): `app/routes/admin_settings.py`
- [Knowledge base](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/admin_kb.py): `app/routes/admin_kb.py`
- [Maintenance](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/routes/maintenance.py): `app/routes/maintenance.py`

### AI and processing

- [AI services](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/ai.py): `app/utils/ai.py`
- [Resident lookup](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/lookup.py): `app/utils/lookup.py`
- [PDF processing](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/pdf_processor.py): `app/utils/pdf_processor.py`
- [Keyword extraction](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/keyword_extractor.py): `app/utils/keyword_extractor.py`
- [Image storage utility](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/cloudinary_utils.py): `app/utils/cloudinary_utils.py`

### State and integrations

- [Database access](https://github.com/thanetphon026/backend-smart_condo/blob/main/app/utils/db.py): `app/utils/db.py`
- **MongoDB**

### Other components

- **LINE resident**
- **Web resident**
- **Admin user**
- **LINE platform**
- **AI providers**
- **Cloudinary**

## Connections

- Flask application → LINE webhook: registers
- Flask application → Web chat API: registers
- Flask application → Admin authentication: registers
- Flask application → Dashboard: registers
- Flask application → Parcel management: registers
- Flask application → Resident management: registers
- Flask application → Audit logs: registers
- Flask application → Settings: registers
- Flask application → Knowledge base: registers
- Flask application → Maintenance: registers
- LINE resident → LINE platform: sends events
- LINE platform → LINE webhook: webhook events
- LINE webhook → AI services: interprets intent
- LINE webhook → Database access: reads and writes
- LINE webhook → LINE messaging: sends replies
- LINE webhook → Message templates: builds cards
- LINE webhook → Parcel templates: builds parcel cards
- LINE messaging → LINE platform: sends messages
- Web resident → Web chat API: sends requests
- Web chat API → AI services: interprets intent
- Web chat API → Database access: reads and writes
- Web chat API → Message templates: builds cards
- Web chat API → Parcel templates: builds parcel cards
- AI services → AI providers: calls models
- AI services → Database access: retrieves knowledge
- AI services → Resident lookup: normalizes identity
- Admin user → Admin authentication: logs in
- Admin user → Dashboard: uses dashboard
- Admin user → Parcel management: manages parcels
- Admin user → Resident management: manages residents
- Admin user → Audit logs: reviews logs
- Admin user → Settings: changes settings
- Admin user → Knowledge base: manages knowledge
- Admin authentication → Database access: checks admins
- Admin authentication → Database access: records audit
- Parcel management → Database access: manages records
- Resident management → Database access: manages records
- Audit logs → Database access: reads audit
- Dashboard → Database access: reads data
- Settings → Database access: reads and writes
- Knowledge base → Database access: manages knowledge
- Database access → MongoDB: queries
- LINE webhook → Image storage utility: uploads images
- Web chat API → Image storage utility: uploads images
- Image storage utility → Cloudinary: stores images
- Knowledge base → PDF processing: processes documents
- Knowledge base → Keyword extraction: extracts terms
