# mh-electronic/capstone_fpga-driven-medicine-dispenser architecture

> Architecture diagram of the GitHub repository mh-electronic/capstone_fpga-driven-medicine-dispenser, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mh-electronic/capstone_fpga-driven-medicine-dispenser
- Repository: https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser

## Overview

This repository implements a cloud-connected medicine dispenser: a doctor records prescriptions, a patient scans an RFID card and selects a visit, and the server sends medication quantities to FPGA-controlled dispensing hardware. Staff can monitor stock, dispensing logs, and an ESP32-CAM video feed. The README documents several hardware and monitoring capabilities; the available source excerpts support the web, Firebase, and UART interactions, while internal HDL wiring is only represented at the top-level/module level.

Main entry points: [`web/User_Interface/app.py`](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/app.py) (Dispenser Web Server), [`HDL/system_top.v`](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/system_top.v) (FPGA System), [`web/Doctor_Interface/auth.js`](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Doctor_Interface/auth.js) (Doctor Authentication), [`web/Doctor_Interface/app.js`](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Doctor_Interface/app.js) (Prescription Entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clinical["Clinical Workflow"]
  node_doctor_portal["Doctor Portal<br/>[login_page.html]"]
  node_doctor_auth["Doctor Authentication<br/>[auth.js]"]
  node_doctor_app["Prescription Entry<br/>[app.js]"]
  node_firebase_config["Firebase Client Setup<br/>[firebase-config.js]"]
end

subgraph group_patient["Patient Dispensing"]
  node_patient_ui["Patient Interface<br/>[auth.html]"]
  node_patient_auth["RFID Scan UI<br/>[auth.js]"]
  node_flask["Dispenser Web Server<br/>[app.py]"]
  node_firebase_helpers["Patient and Stock Data<br/>[firebase.py]"]
  node_schedule_ui["Visit Selection<br/>[schedule.js]"]
  node_prescription_ui["Prescription and Dispense UI<br/>[prescription.js]"]
end

subgraph group_hardware["Dispenser Hardware"]
  node_fpga_top["FPGA System<br/>[system_top.v]"]
  node_protocol["Protocol Handler<br/>[protocol_handler.v]"]
  node_rc522["RFID Reader<br/>[rc522.v]"]
  node_uart["UART Controller<br/>[uart_controller.v]"]
  node_servo["Servo Control<br/>[servo_driver.v]"]
  node_servo_fsm["Dispense Motion FSM"]
end

subgraph group_monitoring["Staff Monitoring"]
  node_dashboard["Monitoring Dashboard<br/>[index.html]"]
  node_dashboard_logic["Monitoring and Logs<br/>[script.js]"]
  node_camera["ESP32-CAM<br/>[ESP32_CAM.ino]"]
end

node_doctor(("Doctor"))
node_firestore[("Firebase Firestore")]
node_patient(("Patient"))
node_staff(("Staff"))
node_camera_stream["Camera Stream"]

node_doctor -->|"uses"| node_doctor_portal
node_doctor_portal -->|"submits login"| node_doctor_auth
node_doctor_auth -->|"uses auth"| node_firebase_config
node_doctor_auth -->|"opens portal"| node_doctor_app
node_doctor_app -->|"uses client"| node_firebase_config
node_firebase_config -->|"connects"| node_firestore
node_doctor_app -->|"reads and writes"| node_firestore
node_patient -->|"uses"| node_patient_ui
node_patient_ui -->|"starts scan"| node_patient_auth
node_patient_auth -->|"posts scan"| node_flask
node_flask -->|"requests card ID"| node_uart
node_uart -->|"exchanges serial data"| node_fpga_top
node_fpga_top -->|"handles RFID"| node_rc522
node_fpga_top -->|"handles commands"| node_protocol
node_fpga_top -->|"controls actuation"| node_servo
node_servo -->|"drives motion"| node_servo_fsm
node_flask -->|"calls data functions"| node_firebase_helpers
node_firebase_helpers -->|"reads and updates"| node_firestore
node_patient_auth -->|"opens visit selection"| node_schedule_ui
node_schedule_ui -->|"requests schedule page"| node_flask
node_schedule_ui -->|"selects visit"| node_prescription_ui
node_prescription_ui -->|"loads and requests dispense"| node_flask
node_flask -->|"sends dispense command"| node_uart
node_flask -->|"records outcome"| node_firebase_helpers
node_staff -->|"uses"| node_dashboard
node_dashboard -->|"loads monitoring"| node_dashboard_logic
node_dashboard_logic -->|"subscribes to status and logs"| node_firestore
node_dashboard_logic -.->|"displays feed"| node_camera_stream
node_camera -.->|"provides video"| node_camera_stream

click node_doctor_portal "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Doctor_Interface/login_page.html"
click node_doctor_auth "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Doctor_Interface/auth.js"
click node_doctor_app "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Doctor_Interface/app.js"
click node_firebase_config "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Doctor_Interface/firebase-config.js"
click node_patient_ui "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/templates/auth.html"
click node_patient_auth "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/static/auth.js"
click node_flask "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/app.py"
click node_firebase_helpers "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/firebase.py"
click node_schedule_ui "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/static/schedule.js"
click node_prescription_ui "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/static/prescription.js"
click node_fpga_top "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/system_top.v"
click node_protocol "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/protocol_handler.v"
click node_rc522 "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/rc522.v"
click node_uart "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/uart_controller.v"
click node_servo "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/servo_driver.v"
click node_servo_fsm "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/servo_fsm_unit_anticlockwise.v"
click node_dashboard "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Monitoring_Dashboard/index.html"
click node_dashboard_logic "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Monitoring_Dashboard/script.js"
click node_camera "https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/ESP32_CAM/ESP32_CAM.ino"

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_doctor_portal,node_doctor_auth,node_doctor_app,node_firebase_config toneBlue
class node_patient_ui,node_patient_auth,node_flask,node_firebase_helpers,node_schedule_ui,node_prescription_ui,node_firestore toneAmber
class node_fpga_top,node_protocol,node_rc522,node_uart,node_servo,node_servo_fsm toneMint
class node_dashboard,node_dashboard_logic,node_camera toneRose
class node_doctor,node_patient,node_staff,node_camera_stream toneIndigo
```

## Components

### Clinical Workflow

- [Doctor Portal](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Doctor_Interface/login_page.html): `web/Doctor_Interface/login_page.html`
- [Doctor Authentication](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Doctor_Interface/auth.js): `web/Doctor_Interface/auth.js`
- [Prescription Entry](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Doctor_Interface/app.js): `web/Doctor_Interface/app.js`
- [Firebase Client Setup](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Doctor_Interface/firebase-config.js): `web/Doctor_Interface/firebase-config.js`

### Patient Dispensing

- [Patient Interface](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/templates/auth.html): `web/User_Interface/templates/auth.html`
- [RFID Scan UI](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/static/auth.js): `web/User_Interface/static/auth.js`
- [Dispenser Web Server](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/app.py): `web/User_Interface/app.py`
- [Patient and Stock Data](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/firebase.py): `web/User_Interface/firebase.py`
- [Visit Selection](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/static/schedule.js): `web/User_Interface/static/schedule.js`
- [Prescription and Dispense UI](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/User_Interface/static/prescription.js): `web/User_Interface/static/prescription.js`

### Dispenser Hardware

- [FPGA System](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/system_top.v): `HDL/system_top.v`
- [Protocol Handler](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/protocol_handler.v): `HDL/protocol_handler.v`
- [RFID Reader](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/rc522.v): `HDL/rc522.v`
- [UART Controller](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/uart_controller.v): `HDL/uart_controller.v`
- [Servo Control](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/servo_driver.v): `HDL/servo_driver.v`
- [Dispense Motion FSM](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/HDL/servo_fsm_unit_anticlockwise.v): `HDL/servo_fsm_unit_anticlockwise.v`

### Staff Monitoring

- [Monitoring Dashboard](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Monitoring_Dashboard/index.html): `web/Monitoring_Dashboard/index.html`
- [Monitoring and Logs](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/web/Monitoring_Dashboard/script.js): `web/Monitoring_Dashboard/script.js`
- [ESP32-CAM](https://github.com/mh-electronic/capstone_fpga-driven-medicine-dispenser/blob/main/ESP32_CAM/ESP32_CAM.ino): `ESP32_CAM/ESP32_CAM.ino`

### Other components

- **Doctor**
- **Firebase Firestore**
- **Patient**
- **Staff**
- **Camera Stream**

## Connections

- Doctor → Doctor Portal: uses
- Doctor Portal → Doctor Authentication: submits login
- Doctor Authentication → Firebase Client Setup: uses auth
- Doctor Authentication → Prescription Entry: opens portal
- Prescription Entry → Firebase Client Setup: uses client
- Firebase Client Setup → Firebase Firestore: connects
- Prescription Entry → Firebase Firestore: reads and writes
- Patient → Patient Interface: uses
- Patient Interface → RFID Scan UI: starts scan
- RFID Scan UI → Dispenser Web Server: posts scan
- Dispenser Web Server → UART Controller: requests card ID
- UART Controller → FPGA System: exchanges serial data
- FPGA System → RFID Reader: handles RFID
- FPGA System → Protocol Handler: handles commands
- FPGA System → Servo Control: controls actuation
- Servo Control → Dispense Motion FSM: drives motion
- Dispenser Web Server → Patient and Stock Data: calls data functions
- Patient and Stock Data → Firebase Firestore: reads and updates
- RFID Scan UI → Visit Selection: opens visit selection
- Visit Selection → Dispenser Web Server: requests schedule page
- Visit Selection → Prescription and Dispense UI: selects visit
- Prescription and Dispense UI → Dispenser Web Server: loads and requests dispense
- Dispenser Web Server → UART Controller: sends dispense command
- Dispenser Web Server → Patient and Stock Data: records outcome
- Staff → Monitoring Dashboard: uses
- Monitoring Dashboard → Monitoring and Logs: loads monitoring
- Monitoring and Logs → Firebase Firestore: subscribes to status and logs
- Monitoring and Logs → Camera Stream: displays feed
- ESP32-CAM → Camera Stream: provides video
