# zalo-miniapp/zaui-doctor architecture

> Architecture diagram of the GitHub repository zalo-miniapp/zaui-doctor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zalo-miniapp/zaui-doctor
- Repository: https://github.com/zalo-miniapp/zaui-doctor

## Overview

##### Project type and purpose
- This is a single–page, front-end application (a Zalo Mini App) built with Vite, React, ZMP-UI, ZMP-SDK, Jotai, and Tailwind CSS.
- It serves as a healthcare-oriented mini program (“ZaUI Doctor”) that runs inside the Zalo client, providing booking, inquiry, feedback, search, profile, scheduling, and chat features.

##### File structure
- Top-level config & build files: package.json, vite.config.mts, tsconfig.json, tailwind.config.js, postcss.config.js, zmp-cli.json, app-config.json
- src/app.ts: app bootstrap and ZMP SDK initialization
- src/router.tsx: page routing definitions
- src/state.ts: Jotai atoms (state management)
- src/pages: feature pages organized by route (home, ask, booking, categories, detail, explore, feedback, profile, invoices, schedule, search, services, 404)
- src/utils: helper functions (errors, formatting, mocks)
- src/static: static assets (images for doctors, services, explore)
- CSS: multiple SCSS entrypoints (app.scss, tailwind.scss)

##### README for additional insights
- Architecture is purely client-side; data come from Jotai atoms which can wrap fetch calls to external APIs
- ZMP SDK is used for interacting with the Zalo host (e.g., chat with OA)
- Deployment happens via zmp-cli or VSCode extension to Zalo’s Mini App platform
- No bundled backend code in this repo

##### Main components & how they interact
a. Zalo Mini App Host (Zalo client)
– Provides webview container, lifecycle events, native APIs via ZMP-SDK.
b. SPA Application (delivered by Vite build)
1. Bootstrapping (src/app.ts)
- Initializes ZMP SDK and global config (app-config.json).
2. Router Layer (src/router.tsx)
- Maps URL paths → React pages, handles back button, titles.
3. Page Components (src/pages/*)
- Compose domain screens (booking, ask, feedback, etc.)
4. UI Components (src/components/*)
5. State Layer (src/state.ts with Jotai)
- Atoms represent asynchronous data (doctors, services, news, schedules, invoices).
- Components subscribe to atoms; trigger fetch/update logic.
6. Data / Network Layer (fetch calls via utils, wrapped in atoms)
- src/utils/mock.ts for local dev; replace with real fetch in atoms.
7. Styling Layer
- Tailwind + SCSS → global and component-level styling.
c. External Services
– REST APIs (hospital backend, news service, scheduling service, payments, etc.)
– Zalo OA Chat via ZMP-SDK and configured oaID in app-config.json

##### Architectural patterns & design principles
- Component-based UI (atomic design)
- State decoupling with Jotai atoms: separates data fetching from rendering
- Route-driven pages with metadata for back/title
- Theming via CSS variables + Tailwind utilities
- Mock data abstraction: easily replaceable with real API
- Host integration via ZMP-SDK

##### Final checklist
– Layers clearly separated and labeled
– Modules/components named exactly as in the code (e.g., src/state.ts, src/router.tsx, src/app.ts)
– Optional: note that Vite build produces a static bundle hosted within the Zalo Mini App

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Zalo Host Layer
    subgraph "Zalo Host" 
        direction TB
        Host["Zalo Mini App Client"]:::host
    end

    %% Bootstrap & Config Layer
    subgraph "Bootstrap & Config" 
        direction TB
        Bootstrap["SPA Bootstrap (src/app.ts)"]:::bootstrap
        AppConfig["Zalo Mini App Configuration (app-config.json)"]:::config
        TailwindCfg["Tailwind Config (tailwind.config.js)"]:::config
        ViteCfg["Vite Config (vite.config.mts)"]:::config
    end

    %% Routing Layer
    subgraph "Routing Layer" 
        direction TB
        Router["Router Layer (src/router.tsx)"]:::router
    end

    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        Pages["Page Components (src/pages)"]:::pages
        UIComp["UI Components (src/components)"]:::ui
        Static["Static Assets (src/static)"]:::static
    end

    %% State & Data Layer
    subgraph "State & Data Layer" 
        direction TB
        State["State Layer (src/state.ts)"]:::state
        Utils["Data/Network Utilities (src/utils)"]:::utils
    end

    %% External Services Layer
    subgraph "External Services" 
        direction TB
        ExtAPI["REST APIs"]:::external
        ZMP["ZMP-SDK (Host Integration)"]:::external
    end

    %% Connections
    Host -->|"launches"| Bootstrap
    Bootstrap -->|"loads config"| AppConfig
    Bootstrap --> Router
    Bootstrap --> TailwindCfg
    Bootstrap --> ViteCfg

    Router -->|"routes to"| Pages
    Pages -->|"uses"| UIComp
    UIComp -->|"subscribes to"| State
    State -->|"fetch via"| Utils
    Utils --> ExtAPI

    UIComp -->|"native calls"| ZMP
    ZMP --> Host

    Pages --> Static

    %% Click Events
    click Bootstrap "https://github.com/zalo-miniapp/zaui-doctor/blob/main/src/app.ts"
    click AppConfig "https://github.com/zalo-miniapp/zaui-doctor/blob/main/app-config.json"
    click TailwindCfg "https://github.com/zalo-miniapp/zaui-doctor/blob/main/tailwind.config.js"
    click ViteCfg "https://github.com/zalo-miniapp/zaui-doctor/blob/main/vite.config.mts"
    click Router "https://github.com/zalo-miniapp/zaui-doctor/blob/main/src/router.tsx"
    click State "https://github.com/zalo-miniapp/zaui-doctor/blob/main/src/state.ts"
    click UIComp "https://github.com/zalo-miniapp/zaui-doctor/tree/main/src/components"
    click Static "https://github.com/zalo-miniapp/zaui-doctor/tree/main/src/static"
    click Utils "https://github.com/zalo-miniapp/zaui-doctor/tree/main/src/utils"

    %% Styles
    classDef host fill:#f2f2f2,stroke:#333,stroke-width:1px;
    classDef bootstrap fill:#d0e7ff,stroke:#3399ff,stroke-width:2px;
    classDef config fill:#f0f0f0,stroke:#999,stroke-width:1px;
    classDef router fill:#e6ffe6,stroke:#33cc33,stroke-width:2px;
    classDef pages fill:#cce0ff,stroke:#3366ff,stroke-width:2px;
    classDef ui fill:#cce0ff,stroke:#3366ff,stroke-width:2px;
    classDef static fill:#ffe6cc,stroke:#ff9933,stroke-width:2px;
    classDef state fill:#e6ffe6,stroke:#33cc33,stroke-width:2px;
    classDef utils fill:#fff0b3,stroke:#ffcc00,stroke-width:2px;
    classDef external fill:#ffe6e6,stroke:#ff3333,stroke-width:2px;
```
