# rumethsandinu/drowsycloudapi architecture

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

- Interactive diagram: https://gitdiagram.com/rumethsandinu/drowsycloudapi
- Repository: https://github.com/rumethsandinu/drowsycloudapi

## Overview

This is a cloud API linking a drowsiness-detection system with a mobile app. The main workflow is user registration and login, emergency-contact management, then a device-triggered alert that looks up contacts and sends SMS messages. MongoDB stores users and device keys; bcrypt handles password hashing and verification, and Twilio delivers alerts. The README establishes the product’s external clients, while source excerpts show route mounting and implementation details. The excerpts do not show client request wiring or the detection system’s integration mechanism.

Main entry points: [`server.js`](https://github.com/rumethsandinu/drowsycloudapi/blob/main/server.js) (Express API), [`routes/registerUser.js`](https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/registerUser.js) (Register user), [`routes/loginUser.js`](https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/loginUser.js) (User login), [`routes/sendAlerts.js`](https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/sendAlerts.js) (Send alerts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["User identity"]
  node_register["Register user<br/>[registerUser.js]"]
  node_login["User login<br/>[loginUser.js]"]
  node_passwords["Password hashing<br/>[registerUser.js]"]
  node_password_check["Password verification<br/>[loginUser.js]"]
end

subgraph group_contacts["Contact management"]
  node_contacts_update["Update contacts"]
  node_contacts_get["Get contacts"]
end

subgraph group_alerts["Alert delivery"]
  node_alert_route["Send alerts<br/>[sendAlerts.js]"]
end

node_mobile(("Mobile app"))
node_detector(("Drowsiness detector"))
node_api["Express API<br/>[server.js]"]
node_mongo[("MongoDB")]
node_twilio["Twilio SMS"]
node_recipients(("Emergency contacts"))

node_mobile -.->|"uses API"| node_api
node_detector -.->|"triggers alerts"| node_api
node_api -->|"mounts route"| node_register
node_api -->|"mounts route"| node_login
node_api -->|"mounts route"| node_contacts_update
node_api -->|"mounts route"| node_contacts_get
node_api -->|"mounts route"| node_alert_route
node_register -->|"reads and writes"| node_mongo
node_register -->|"hashes password"| node_passwords
node_login -->|"reads user"| node_mongo
node_login -->|"checks password"| node_password_check
node_contacts_update -->|"updates contacts"| node_mongo
node_contacts_get -->|"reads contacts"| node_mongo
node_alert_route -->|"looks up contacts"| node_mongo
node_alert_route -->|"sends SMS"| node_twilio
node_twilio -->|"delivers messages"| node_recipients

click node_api "https://github.com/rumethsandinu/drowsycloudapi/blob/main/server.js"
click node_register "https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/registerUser.js"
click node_login "https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/loginUser.js"
click node_passwords "https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/registerUser.js"
click node_password_check "https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/loginUser.js"
click node_contacts_update "https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/updateEmergencyContacts.js"
click node_contacts_get "https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/getEmergencyContacts.js"
click node_alert_route "https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/sendAlerts.js"

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_register,node_login,node_passwords,node_password_check toneBlue
class node_contacts_update,node_contacts_get,node_mongo toneAmber
class node_alert_route,node_api toneMint
class node_mobile,node_detector,node_twilio,node_recipients toneIndigo
```

## Components

### User identity

- [Register user](https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/registerUser.js): `routes/registerUser.js`
- [User login](https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/loginUser.js): `routes/loginUser.js`
- [Password hashing](https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/registerUser.js): `routes/registerUser.js`
- [Password verification](https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/loginUser.js): `routes/loginUser.js`

### Contact management

- [Update contacts](https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/updateEmergencyContacts.js): `routes/updateEmergencyContacts.js`
- [Get contacts](https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/getEmergencyContacts.js): `routes/getEmergencyContacts.js`

### Alert delivery

- [Send alerts](https://github.com/rumethsandinu/drowsycloudapi/blob/main/routes/sendAlerts.js): `routes/sendAlerts.js`

### Other components

- **Mobile app**
- **Drowsiness detector**
- [Express API](https://github.com/rumethsandinu/drowsycloudapi/blob/main/server.js): `server.js`
- **MongoDB**
- **Twilio SMS**
- **Emergency contacts**

## Connections

- Mobile app → Express API: uses API (evidence: `README.md`)
- Drowsiness detector → Express API: triggers alerts (evidence: `README.md`)
- Express API → Register user: mounts route (evidence: `server.js`)
- Express API → User login: mounts route (evidence: `server.js`)
- Express API → Update contacts: mounts route (evidence: `server.js`)
- Express API → Get contacts: mounts route (evidence: `server.js`)
- Express API → Send alerts: mounts route (evidence: `server.js`)
- Register user → MongoDB: reads and writes (evidence: `routes/registerUser.js`)
- Register user → Password hashing: hashes password (evidence: `routes/registerUser.js`)
- User login → MongoDB: reads user (evidence: `routes/loginUser.js`)
- User login → Password verification: checks password (evidence: `routes/loginUser.js`)
- Update contacts → MongoDB: updates contacts (evidence: `routes/updateEmergencyContacts.js`)
- Get contacts → MongoDB: reads contacts (evidence: `routes/getEmergencyContacts.js`)
- Send alerts → MongoDB: looks up contacts (evidence: `routes/sendAlerts.js`)
- Send alerts → Twilio SMS: sends SMS (evidence: `routes/sendAlerts.js`)
- Twilio SMS → Emergency contacts: delivers messages
