စနစ် ဗိသုကာ
Cherry Land Taunggyi သည် Microservices Architecture ကို အသုံးပြုပြီး ခေတ်မီနည်းပညာများဖြင့် တည်ဆောက်ထားသော Delivery Platform ဖြစ်ပါတယ်
Database Ownership
MariaDB vs MongoDB - Purpose and Usage
MariaDB (Relational Database)
Ownership
Python FastAPI parser processes and cleans data before storage
Purpose
Primary database for business workflow operations
Data Type
Structured, processed data with consistent schemas
Use Cases
- • Operational users, sessions, realtime data
- • FCM tokens
- • Parsed orders (one row per assigned rider)
- • Settlements, deposits, expenses
- • Marketplace data
Access Pattern
FastAPI writes processed data; PHP, Go, and NestJS read for business operations
Note: One MongoDB order message can create multiple MariaDB rows (one per mentioned rider)
MongoDB (Document Database)
Ownership
NestJS OrdersService stores raw data directly
Purpose
Raw data storage for unstructured information across multiple chat types
Data Type
Complex, inconsistent formats without fixed schemas
Use Cases
- • Multiple chat types stored as single documents
- • All chat types include: attachments, reactions, mentions, raw text, riderStatus
- • Chat types identified by chatType field value
Access Pattern
NestJS writes raw chat data for all types; reads for chat history and message context
Note: Each chat type uses the same Order schema but different chatType values
Data Flow Pattern
Single Document] B --> C[FastAPI Parser] C --> D[MariaDB
Structured Rows
One per Rider] D --> E[Business Operations] style A fill:#3b82f6 style B fill:#10b981 style C fill:#8b5cf6 style D fill:#f59e0b style E fill:#ef4444
Admin Panel
Vue.js 3 + Tailwind CSS + Socket.IO
Vue.js 3
Composition API with reactive state management
Tailwind CSS
Utility-first CSS framework for styling
Socket.IO
Real-time bidirectional communication
IndexedDB
Client-side storage with Dexie.js
MapLibre GL
Interactive map visualization
Day.js
Lightweight date/time manipulation
Component Architecture
Data Flow with Composables
Socket.IO Integration
IndexedDB Data Flow
Key Composables
useAuth
Token management, user data storage, role hierarchy (office < admin < ceo < developer), permission checking, route-based access control
useAlert
Alert modal for confirmations, toast notifications (success, error, warning, info), auto-dismiss with configurable duration
usePermissions
Message permission checks: edit message, delete message, reaction, reply permissions
useSocket
Socket client management, automatic reconnection, message queuing when offline, cross-tab sync via BroadcastChannel
IndexedDB Schema
chatDB
- • messages: Chat messages with indexes for chatType, tempId, serverId, senderId, timestamp, status
- • images: Binary image data with messageId reference
- • syncMetadata: Sync timestamps for incremental sync
- • pinnedMessages: Pinned messages (max 5 per user)
usersDB
- • users: User data with indexes for userId, username, name, avatar, role, status
Socket.IO Events
Connection
- • connect, disconnect, connect_error
Chat
- • new-message, message-edited, message-deleted, reaction-updated, message-read
Acknowledgments
- • message-acknowledged, delete-acknowledged
Orders
- • order-cancelled
Key Features
Page Components
Dashboard
Advanced filtering, statistics cards, billing calculation, CSV export
Realtime
Rider status filtering, location updates, battery monitoring, thermal box tracking
Map
Interactive rider map, search functionality, focused rider details
Chat
Multi-type chat (order, payment, settlement), IndexedDB storage, real-time sync
Settlement
Financial settlement tracking, Telegram message links, status toggling
Marketplace
Business, category, product management, overall posts, image uploads
Composables
useAuth
Token management, user data storage, role hierarchy (office < admin < ceo < developer), permission checking, route-based access control
useAlert
Alert modal for confirmations, toast notifications (success, error, warning, info), auto-dismiss with configurable duration
usePermissions
Message permission checks: edit message, delete message, reaction, reply permissions
useSocket
Socket client management, automatic reconnection, message queuing when offline, cross-tab sync via BroadcastChannel
IndexedDB Schema
chatDB
- • messages: Chat messages with indexes for chatType, tempId, serverId, senderId, timestamp, status
- • images: Binary image data with messageId reference
- • syncMetadata: Sync timestamps for incremental sync
- • pinnedMessages: Pinned messages (max 5 per user)
usersDB
- • users: User data with indexes for userId, username, name, avatar, role, status
Cronjob Architecture
Automated Task Scheduling System
PHP
Duty checking & penalty enforcement
Python
Data analysis & reporting
Bash
Database backup operations
Telegram API
Notifications & alerts
Core Components
Morning Duty Checker
Monitors morning duty compliance, enforces penalties, rotates duty schedule, sends Telegram notifications
Non-Morning Duty Checker
Checks general rider compliance, handles leave exemptions, applies penalties for non-ready status
Morning Duty Reporter
Announces tomorrow's morning duty assignment via Telegram with @username mentions
Daily Summary Reporter
Generates analytical reports with matplotlib charts: 3-day revenue, delivery ways, top riders
Database Backup Script
Automated MySQL backups with mysqldump, gzip compression, and secure file permissions
Environment Loader
Centralized configuration management for database credentials, API tokens, and settings
Cronjob Execution Flow
Database Tables Accessed
Duty Schedule
Daily duty assignments with date and username list (JSON)
Users Table
Rider information: username, Telegram username, chat ID
Realtime Table
Rider status updates: username, status, timestamp
Orders Table
Order records: username, delivery fee, way count, timestamp
Penalties Table
Penalty records: username, date, reason, amount
Leave Days
Approved leave records: username, date
Cron Schedule
Security & Performance
Script Details
Morning Duty Checker (PHP)
Monitors morning duty compliance, enforces penalties, rotates duty schedule, sends Telegram notifications. Checks realtime status and order completion.
Non-Morning Duty Checker (PHP)
Checks general rider compliance, handles leave exemptions, applies penalties for non-ready status. Filters by active riders and leave days.
Morning Duty Reporter (Python)
Announces tomorrow's morning duty assignment via Telegram with @username mentions. Queries duty schedule and formats message.
Daily Summary Reporter (Python)
Generates analytical reports with matplotlib charts: 3-day revenue, delivery ways, top riders. Sends charts via Telegram API.
Database Backup (Bash)
Automated MySQL backups with mysqldump, gzip compression, and secure file permissions. Single transaction for consistency.
Environment Loader (PHP)
Centralized configuration management for database credentials, API tokens, and settings. Loads .env file and sets environment variables.
Database Tables Accessed
Duty Schedule
Daily duty assignments with date and username list (JSON)
Users Table
Rider information: username, Telegram username, chat ID
Realtime Table
Rider status updates: username, status, timestamp
Orders Table
Order records: username, delivery fee, way count, timestamp
Penalties Table
Penalty records: username, date, reason, amount
Leave Days
Approved leave records: username, date
Deployment Architecture
Docker Compose + Cloudflare Tunnel
Docker Compose
Container orchestration for all microservices with persistent volumes
Cloudflare Tunnel
Secure public exposure without public IP, DDoS protection, auto HTTPS
MySQL 8.0
Relational database with persistent volume storage
MongoDB 6.0
Document database for chat and order storage
Security Features
Service Details
MySQL 8.0
Relational database with persistent volume storage. Localhost-only binding, optimized for high connection limits, timezone Asia/Yangon.
MongoDB 6.0
Document database for chat and order storage. Localhost-only binding, built-in health check, persistent volume for data persistence.
Cloudflare Tunnel
Secure public exposure without public IP. DDoS protection, auto HTTPS, SSL/TLS termination at Cloudflare edge.
Docker Network
External bridge network for inter-service communication. Services communicate using container names as hostnames.
Volume Management
Persistent Data Volumes
- • Relational database volume for MySQL data
- • Document database volume for MongoDB data
- • Node modules volume for dependency caching
- • Image storage directory for persistent images
Application Data Mounts
- • Frontend code mounted for live updates
- • Laravel code mounted for live updates
- • FastAPI code mounted for live updates
- • NestJS code mounted for live updates
FastAPI Backend
Order Parsing Service with NLP
Python 3.x
Modern async web framework with automatic OpenAPI docs
Regex Parser
Natural language processing for Myanmar/English orders
PyMySQL
Relational database driver with DictCursor support
Pydantic
Data validation and serialization with type hints
Capabilities
Parser Modules
DeliveryParser (order.py)
Parses delivery orders with pickup/delivery extraction, fee calculation, way counting, complexity scoring, and warning generation.
SettleParser (settle.py)
Parses settlement messages with payer information, fee breakdowns, and order validation. Handles delivery and service fees.
DepositParser (deposit.py)
Parses deposit and stake transactions with multi-user support, expense tracking, and promotion card parsing.
Data Flow
Image Service
Go + Gin + WebP Conversion
Go (Golang)
High-performance HTTP server with Gin framework
WebP Conversion
Automatic conversion with 25-35% size reduction
MySQL
Session validation for admin and rider auth
Local Storage
Filesystem-based storage with volume mounting
Service Types
NestJS Backend
Real-time Communication with WebSocket
NestJS
Progressive Node.js framework with TypeScript
WebSocket
Real-time bidirectional event-based communication
MongoDB
Document database for chat and order storage
Firebase
Push notifications for rider updates
Real-time Features
Gateway Details
ChatGateway
Handles real-time chat communication, message persistence, broadcasting, user presence, and multi-chat type support (order, payment, settlement).
RidersGateway
Manages rider location tracking, status updates, online/offline detection, and rider room management for real-time rider monitoring.
Chat Types
Order Chat
Delivery order discussions with rider assignment and tracking. Parsed by FastAPI DeliveryParser.
Payment Chat
Deposit and stake transaction discussions. Parsed by FastAPI DepositParser.
Settlement Chat
Financial settlement discussions with payer information. Parsed by FastAPI SettleParser.
Core Services
OrdersService
Message transformation, mention parsing, MongoDB operations, FastAPI integration based on chatType, and rider notification management.
RiderNotificationService
Socket.IO events to rider rooms, FCM push notifications, rider assignment/removal notifications, and action-based alerts.
FirebaseService
Push notification delivery for admin and rider notifications, token management, and message formatting.
RealtimeService
Rider realtime tracking table management, order ID assignment/removal, and status updates for rider availability.
Laravel Backend
PHP 8.2 + Marketplace API
Laravel
PHP framework for marketplace and admin operations
PHP 8.2
Modern PHP with Apache web server
MySQL
Relational database for business data
Apache
Web server with optimized configuration
Marketplace Features
Order Processing Workflow
End-to-End Order Flow
Order Submission
Customer submits order via phone/chat → Order text received by system
Order Parsing
FastAPI parses order text → Extracts pickup, delivery, fee, ways, complexity → Multi-rider mention detection
Database Storage
Parsed order saved to MySQL → Order rows created per mentioned rider → Transaction committed
Rider Assignment
Socket.IO broadcasts order to mentioned riders → Riders receive notification → Rider accepts/rejects
Real-time Tracking
Rider location updates via WebSocket → Admin panel shows live map → Customer receives status updates
Delivery & Settlement
Order completed → Settlement calculated → Payment processed → Financial records updated
Image Upload Workflow
WebP Optimization Pipeline
Image Upload
User uploads image (JPEG/PNG/GIF/WebP) → Multipart form data sent to Go service
Authentication
Middleware validates X-Internal-Auth or X-Session-Token → Session checked in MySQL → Access granted/denied
Validation & Conversion
File type validated → Image integrity checked → Converted to WebP (75% quality) → 25-35% size reduction
Storage
UUID generated → WebP file saved to service-specific directory → Persistent volume mounted
Response & Caching
Public URL returned → 1-year cache headers set → CDN-ready for global distribution
Real-time Communication Workflow
WebSocket & Socket.IO Flow
Connection Establishment
Client connects to NestJS WebSocket → Authentication validated → Room joined (rider/admin)
Location Updates
Rider app sends GPS coordinates → NestJS receives → Broadcasts to admin room → Admin panel updates map
Chat Messaging
User sends message → Saved to MongoDB → Broadcasted to chat room → IndexedDB sync for offline
Order Status Changes
Status updated in MySQL → Event emitted → All connected clients notified → UI updates instantly
Push Notifications
Firebase integration → Rider app receives push → Order assignment alerts → Status notifications
Marketplace Data Flow
Business → Category → Product Pipeline
Business Creation
Admin creates business → Logo/cover uploaded to Go service → Business saved to MySQL → API endpoint exposed
Category Management
Categories created → Image uploaded → Sort order set → Linked to businesses → Active status managed
Product Catalog
Products added → Images uploaded → Price/sale price set → Business/category linked → Availability toggled
API Exposure
Laravel REST API → JSON responses → Pagination support → Filtering by active status → Frontend consumption
Frontend Display
Vue.js fetches data → Components render → Images loaded from Go service → User browses marketplace
Code Execution Architecture
Detailed Function-to-Function Execution Flows
Admin Chat Message Flow
(ChatGateway + OrdersService) participant M as MongoDB participant P as FastAPI participant D as Relational DB participant R as Rider participant F as Firebase UI->>N: send-message event N->>N: Validate sender ID N->>N: Transform DTO & Parse mentions N->>M: Save chat document N->>P: Parse based on chatType P->>D: Save structured rows D-->>P: Success P-->>N: Success N->>N: Broadcast raw message to rider N-->>UI: message-acknowledged N->>N: Broadcast to room N->>F: Push notifications
Rider Order Assignment Flow
(OrdersService) participant M as MongoDB participant P as FastAPI participant D as Relational DB participant R as Rider participant S as RealtimeService participant Notif as RiderNotification UI->>N: Create order with mentions N->>N: Parse @mentions N->>M: Save with mentions array N->>P: Parse structured data P->>D: Save per-rider rows D-->>P: Success P-->>N: Success N->>N: Broadcast raw message to rider N->>S: Add to realtime tracking N->>Notif: Notify riders Notif->>Notif: Socket + FCM
Rider Delivery Action Flow
Key Execution Details
System Builder
Soe Nyi Nyi Aung