Skip to content

System Architecture Design (DESIGN) - Open MES

1. Architectural Approach

Hệ thống sử dụng kiến trúc Monolithic (Nguyên khối) để đảm bảo dễ dàng triển khai ở các nhà máy có hạ tầng hạn chế, với các module sau:

  • Frontend riêng bằng React 19 + Vite (JavaScript với thư viện React và sử dụng Vite làm công cụ build.)
  • Backend Django 5.1 + Django REST Framework
  • Database PostgreSQL
  • Cache/Broker Redis
  • Worker Celery
  • Web serving qua Gunicorn
  • Reverse proxy riêng
  • Chạy bằng **Docker Compose

2. System / Sequence Diagram

graph TD
    User((User/Browser)) -->|HTTP/HTTPS| Nginx[Nginx Reverse Proxy]
    IoT((IoT Sensor/Scanner)) -->|REST API/JSON| Nginx

    Nginx -->|WSGI| Django[Django Backend App]

    subgraph Django Application
        Auth[User Module]
        Master[Master Module]
        Prod[Production Module]
        Inv[Inventory Module]
        QC[Quality Module]
        Mach[Machine Module]
    end

    Django --> Auth & Master & Prod & Inv & QC & Mach

    Auth --> DB[(PostgreSQL Database)]
    Master --> DB
    Prod --> DB
    Inv --> DB
    QC --> DB
    Mach --> DB

3. Database Schema Core Entities (ERD)

Các Bảng dữ liệu chính được map qua Django ORM:

  • Users: (id, username, password, role, is_active).
  • Product_Master: (id, code, name, category, standard_cost).
  • BOM (Bill of Materials): (id, product_id, raw_material_id, quantity).
  • Work_Order: (id, order_code, product_id, planned_qty, actual_qty, status, start_time, end_time).
  • Inventory: (id, material_id, warehouse_id, current_stock, last_updated).
  • Quality_Inspection: (id, work_order_id, inspect_date, passed_qty, failed_qty, defect_reason).
  • Machine_Log: (id, machine_id, work_order_id, status, timestamp, maintenance_note).

4. API Contract (Giao tiếp với bên thứ 3 hoặc IoT)

Mặc dù hệ thống dùng Django template rendering cho UI, vẫn cần thiết kế API để phục vụ IoT/ Barcode Scanner gửi dữ liệu tự động.

4.1 Update Production Progress API

  • Endpoint: POST /api/v1/production/work-order/{order_code}/progress/
  • Auth: Bearer Token
  • Request Payload:
    {
      "machine_id": "M-101",
      "worker_id": "W-05",
      "good_qty": 50,
      "scrap_qty": 2,
      "timestamp": "2026-03-10T14:30:00Z"
    }
    
  • Response:
    {
      "status": "success",
      "message": "Progress recorded and inventory deducted.",
      "recorded_qty": 50
    }