# loveday-791812/jaffas-trap-monitoring-system architecture

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

- Interactive diagram: https://gitdiagram.com/loveday-791812/jaffas-trap-monitoring-system
- Repository: https://github.com/loveday-791812/jaffas-trap-monitoring-system

## Overview

TrapWatch monitors predator-trap signals, records events, and provides a web interface for account access and trap oversight; Firebase-backed scheduled functions also produce email reports. The principal device flow is signal generation and UART processing followed by a Firebase event write. Authentication and reporting are distinct backend capabilities. Some website modules and scheduled-function internals are unsampled, so their nodes reflect the tree and documented capabilities, while uncertain connections are omitted.

Main entry points: [`cloud-functions/index.js`](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/cloud-functions/index.js) (Account functions), [`Website/dashboard-auth.js`](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/dashboard-auth.js) (Dashboard access), [`ESP-program/main.py`](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/ESP-program/main.py) (Trap firmware), [`Website/Login/script.js`](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/Login/script.js) (Login and signup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_device["Trap device"]
  node_signal["Signal generator<br/>[signal.py]"]
  node_firmware["Trap firmware<br/>[main.py]"]
end

subgraph group_web["Web interface"]
  node_login["Login and signup<br/>[script.js]"]
  node_dashboard_auth["Dashboard access<br/>[dashboard-auth.js]"]
  node_dashboard["Trap dashboard<br/>[dashboard.js]"]
  node_recipients["Recipients<br/>[recipients.js]"]
  node_traps["Trap management<br/>[traps.js]"]
  node_settings["Settings<br/>[settings.js]"]
  node_stats["Statistics<br/>[stats.js]"]
  node_firebase_config["Firebase client setup<br/>[firebase-config.js]"]
end

subgraph group_identity["Identity services"]
  node_auth_functions["Account functions<br/>[index.js]"]
end

subgraph group_reporting["Reporting services"]
  node_scheduled_reports["Scheduled reports<br/>[main.py]"]
  node_email_alerts["Legacy email alerts"]
end

node_trap_user(("Trap sensor"))
node_firebase_auth[("Firebase Auth")]
node_rtdb[("Realtime Database")]
node_resend["Resend"]

node_trap_user -.->|"sends signal"| node_firmware
node_firmware -->|"calls transmitter"| node_signal
node_firmware -->|"writes events"| node_rtdb
node_login -->|"posts auth requests"| node_auth_functions
node_firebase_config -->|"configures endpoints"| node_auth_functions
node_login -->|"signs in"| node_firebase_auth
node_dashboard_auth -->|"requests magic login"| node_auth_functions
node_dashboard_auth -->|"signs in with token"| node_firebase_auth
node_dashboard_auth -->|"checks roles"| node_rtdb
node_auth_functions -->|"manages accounts"| node_firebase_auth
node_auth_functions -->|"stores account data"| node_rtdb
node_scheduled_reports -->|"reads events and recipients"| node_rtdb
node_scheduled_reports -->|"sends reports"| node_resend
node_email_alerts -->|"sends email"| node_resend

click node_signal "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/ESP-program/signal.py"
click node_firmware "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/ESP-program/main.py"
click node_login "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/Login/script.js"
click node_dashboard_auth "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/dashboard-auth.js"
click node_dashboard "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/dashboard.js"
click node_recipients "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/recipients.js"
click node_traps "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/traps.js"
click node_settings "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/settings.js"
click node_stats "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/stats.js"
click node_firebase_config "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/Website-backEnd/firebase-config.js"
click node_auth_functions "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/cloud-functions/index.js"
click node_scheduled_reports "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/functions/main.py"
click node_email_alerts "https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/email-alerts%20OLD/send_daily_alert.py"

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_signal,node_firmware toneBlue
class node_login,node_dashboard_auth,node_dashboard,node_recipients,node_traps,node_settings,node_stats,node_firebase_config,node_firebase_auth,node_rtdb toneAmber
class node_auth_functions toneMint
class node_scheduled_reports,node_email_alerts toneRose
class node_trap_user,node_resend toneIndigo
```

## Components

### Trap device

- [Signal generator](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/ESP-program/signal.py): `ESP-program/signal.py`
- [Trap firmware](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/ESP-program/main.py): `ESP-program/main.py`

### Web interface

- [Login and signup](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/Login/script.js): `Website/Login/script.js`
- [Dashboard access](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/dashboard-auth.js): `Website/dashboard-auth.js`
- [Trap dashboard](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/dashboard.js): `Website/dashboard.js`
- [Recipients](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/recipients.js): `Website/recipients.js`
- [Trap management](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/traps.js): `Website/traps.js`
- [Settings](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/settings.js): `Website/settings.js`
- [Statistics](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/stats.js): `Website/stats.js`
- [Firebase client setup](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/Website/Website-backEnd/firebase-config.js): `Website/Website-backEnd/firebase-config.js`

### Identity services

- [Account functions](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/cloud-functions/index.js): `cloud-functions/index.js`

### Reporting services

- [Scheduled reports](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/functions/main.py): `functions/main.py`
- [Legacy email alerts](https://github.com/loveday-791812/jaffas-trap-monitoring-system/blob/main/email-alerts%20OLD/send_daily_alert.py): `email-alerts OLD/send_daily_alert.py`

### Other components

- **Trap sensor**
- **Firebase Auth**
- **Realtime Database**
- **Resend**

## Connections

- Trap sensor → Trap firmware: sends signal
- Trap firmware → Signal generator: calls transmitter (evidence: `ESP-program/main.py`)
- Trap firmware → Realtime Database: writes events (evidence: `ESP-program/main.py`)
- Login and signup → Account functions: posts auth requests (evidence: `Website/Login/script.js`)
- Firebase client setup → Account functions: configures endpoints (evidence: `Website/Website-backEnd/firebase-config.js`)
- Login and signup → Firebase Auth: signs in (evidence: `Website/Login/script.js`)
- Dashboard access → Account functions: requests magic login (evidence: `Website/dashboard-auth.js`)
- Dashboard access → Firebase Auth: signs in with token (evidence: `Website/dashboard-auth.js`)
- Dashboard access → Realtime Database: checks roles (evidence: `Website/dashboard-auth.js`)
- Account functions → Firebase Auth: manages accounts (evidence: `cloud-functions/index.js`)
- Account functions → Realtime Database: stores account data (evidence: `cloud-functions/index.js`)
- Scheduled reports → Realtime Database: reads events and recipients (evidence: `functions/main.py`)
- Scheduled reports → Resend: sends reports (evidence: `functions/main.py`)
- Legacy email alerts → Resend: sends email (evidence: `email-alerts OLD/send_daily_alert.py`)
