# 1valcl3b/projeto_rc architecture

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

- Interactive diagram: https://gitdiagram.com/1valcl3b/projeto_rc
- Repository: https://github.com/1valcl3b/projeto_rc

## Overview

This repository simulates an intelligent residential-security system. Camera footage is analyzed for people, animals, movement, and perimeter or zone threats; detections are published over MQTT, triggering protective actions while a separate receiver records occurrences and evidence for authenticated dashboard and API access. The graph also preserves zone calibration, actuator-state reporting, and optional Home Assistant, notification, and Asterisk integrations. Source excerpts support the main calls and data flows; file-based evidence/live-frame handoffs are documented or implied but not fully shown.

Main entry points: [`mosquitto/mosquitto.conf`](https://github.com/1valcl3b/projeto_rc/blob/main/mosquitto/mosquitto.conf) (MQTT broker), [`reacao/reacao.py`](https://github.com/1valcl3b/projeto_rc/blob/main/reacao/reacao.py) (Threat response), [`api/api.py`](https://github.com/1valcl3b/projeto_rc/blob/main/api/api.py) (Authenticated API), [`deteccao/deteccao.py`](https://github.com/1valcl3b/projeto_rc/blob/main/deteccao/deteccao.py) (Video detection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_monitoring["Detection and monitoring"]
  node_detection["Video detection<br/>[deteccao.py]"]
  node_zone_config["Camera zones<br/>[cameras.json]"]
  node_zone_calibration["Zone calibration<br/>[calibrar_zonas.py]"]
  node_live_evidence[("Live and evidence files<br/>[deteccao.py]")]
end

subgraph group_messaging["Messaging and response"]
  node_mqtt_util["MQTT client utilities<br/>[mqtt_util.py]"]
  node_broker["MQTT broker<br/>[mosquitto.conf]"]
  node_reaction["Threat response<br/>[reacao.py]"]
  node_actuator["Virtual ESP32<br/>[esp32.py]"]
end

subgraph group_records["Records and access"]
  node_receiver["Event receiver<br/>[receptor.py]"]
  node_mysql[("Security database<br/>[01_schema.sql]")]
  node_sqlite_queue[("Retry queue<br/>[receptor.py]")]
  node_api["Authenticated API<br/>[api.py]"]
  node_dashboard["Web dashboard<br/>[dashboard.html]"]
end

subgraph group_operations["Simulation and configuration"]
  node_emulator["Event emulator<br/>[emulador.py]"]
end

node_camera_sources(("Camera sources"))
node_home_assistant["Home Assistant"]
node_notify_service["Notification endpoint"]
node_asterisk["Asterisk calling"]
node_user(("Homeowner"))

node_camera_sources -.->|"provides video"| node_detection
node_zone_config -->|"configures zones"| node_detection
node_zone_calibration -->|"outputs settings"| node_zone_config
node_detection -.->|"writes frames"| node_live_evidence
node_detection -->|"publishes detections"| node_broker
node_mqtt_util -->|"connects clients"| node_broker
node_broker -->|"dispatches events"| node_reaction
node_reaction -->|"publishes commands"| node_broker
node_broker -->|"dispatches commands"| node_actuator
node_actuator -->|"publishes state"| node_broker
node_broker -->|"dispatches actuator state"| node_reaction
node_reaction -.->|"publishes discovery"| node_home_assistant
node_reaction -.->|"sends notification"| node_notify_service
node_reaction -.->|"writes call file"| node_asterisk
node_broker -->|"dispatches records"| node_receiver
node_receiver -->|"stores events"| node_mysql
node_receiver -->|"queues failures"| node_sqlite_queue
node_sqlite_queue -->|"retries records"| node_mysql
node_api -->|"queries records"| node_mysql
node_api -->|"reads live frames"| node_live_evidence
node_broker -->|"dispatches state"| node_api
node_user -->|"opens dashboard"| node_dashboard
node_dashboard -.->|"requests views"| node_api
node_user -->|"queries securely"| node_api
node_emulator -->|"publishes scenarios"| node_broker

click node_detection "https://github.com/1valcl3b/projeto_rc/blob/main/deteccao/deteccao.py"
click node_zone_config "https://github.com/1valcl3b/projeto_rc/blob/main/config/cameras.json"
click node_zone_calibration "https://github.com/1valcl3b/projeto_rc/blob/main/scripts/calibrar_zonas.py"
click node_live_evidence "https://github.com/1valcl3b/projeto_rc/blob/main/deteccao/deteccao.py"
click node_mqtt_util "https://github.com/1valcl3b/projeto_rc/blob/main/comum/mqtt_util.py"
click node_broker "https://github.com/1valcl3b/projeto_rc/blob/main/mosquitto/mosquitto.conf"
click node_reaction "https://github.com/1valcl3b/projeto_rc/blob/main/reacao/reacao.py"
click node_actuator "https://github.com/1valcl3b/projeto_rc/blob/main/esp32/esp32.py"
click node_receiver "https://github.com/1valcl3b/projeto_rc/blob/main/receptor/receptor.py"
click node_mysql "https://github.com/1valcl3b/projeto_rc/blob/main/mysql/init/01_schema.sql"
click node_sqlite_queue "https://github.com/1valcl3b/projeto_rc/blob/main/receptor/receptor.py"
click node_api "https://github.com/1valcl3b/projeto_rc/blob/main/api/api.py"
click node_dashboard "https://github.com/1valcl3b/projeto_rc/blob/main/api/dashboard.html"
click node_emulator "https://github.com/1valcl3b/projeto_rc/blob/main/emulador/emulador.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_detection,node_zone_config,node_zone_calibration,node_live_evidence toneBlue
class node_mqtt_util,node_broker,node_reaction,node_actuator toneAmber
class node_receiver,node_mysql,node_sqlite_queue,node_api,node_dashboard toneMint
class node_emulator toneRose
class node_camera_sources,node_home_assistant,node_notify_service,node_asterisk,node_user toneIndigo
```

## Components

### Detection and monitoring

- [Video detection](https://github.com/1valcl3b/projeto_rc/blob/main/deteccao/deteccao.py): `deteccao/deteccao.py`
- [Camera zones](https://github.com/1valcl3b/projeto_rc/blob/main/config/cameras.json): `config/cameras.json`
- [Zone calibration](https://github.com/1valcl3b/projeto_rc/blob/main/scripts/calibrar_zonas.py): `scripts/calibrar_zonas.py`
- [Live and evidence files](https://github.com/1valcl3b/projeto_rc/blob/main/deteccao/deteccao.py): `deteccao/deteccao.py`

### Messaging and response

- [MQTT client utilities](https://github.com/1valcl3b/projeto_rc/blob/main/comum/mqtt_util.py): `comum/mqtt_util.py`
- [MQTT broker](https://github.com/1valcl3b/projeto_rc/blob/main/mosquitto/mosquitto.conf): `mosquitto/mosquitto.conf`
- [Threat response](https://github.com/1valcl3b/projeto_rc/blob/main/reacao/reacao.py): `reacao/reacao.py`
- [Virtual ESP32](https://github.com/1valcl3b/projeto_rc/blob/main/esp32/esp32.py): `esp32/esp32.py`

### Records and access

- [Event receiver](https://github.com/1valcl3b/projeto_rc/blob/main/receptor/receptor.py): `receptor/receptor.py`
- [Security database](https://github.com/1valcl3b/projeto_rc/blob/main/mysql/init/01_schema.sql): `mysql/init/01_schema.sql`
- [Retry queue](https://github.com/1valcl3b/projeto_rc/blob/main/receptor/receptor.py): `receptor/receptor.py`
- [Authenticated API](https://github.com/1valcl3b/projeto_rc/blob/main/api/api.py): `api/api.py`
- [Web dashboard](https://github.com/1valcl3b/projeto_rc/blob/main/api/dashboard.html): `api/dashboard.html`

### Simulation and configuration

- [Event emulator](https://github.com/1valcl3b/projeto_rc/blob/main/emulador/emulador.py): `emulador/emulador.py`

### Other components

- **Camera sources**
- **Home Assistant**
- **Notification endpoint**
- **Asterisk calling**
- **Homeowner**

## Connections

- Camera sources → Video detection: provides video
- Camera zones → Video detection: configures zones (evidence: `deteccao/deteccao.py`)
- Zone calibration → Camera zones: outputs settings (evidence: `scripts/calibrar_zonas.py`)
- Video detection → Live and evidence files: writes frames (evidence: `deteccao/deteccao.py`)
- Video detection → MQTT broker: publishes detections (evidence: `deteccao/deteccao.py`)
- MQTT client utilities → MQTT broker: connects clients (evidence: `comum/mqtt_util.py`)
- MQTT broker → Threat response: dispatches events (evidence: `reacao/reacao.py`)
- Threat response → MQTT broker: publishes commands (evidence: `reacao/reacao.py`)
- MQTT broker → Virtual ESP32: dispatches commands (evidence: `esp32/esp32.py`)
- Virtual ESP32 → MQTT broker: publishes state (evidence: `esp32/esp32.py`)
- MQTT broker → Threat response: dispatches actuator state (evidence: `reacao/reacao.py`)
- Threat response → Home Assistant: publishes discovery (evidence: `reacao/reacao.py`)
- Threat response → Notification endpoint: sends notification (evidence: `reacao/reacao.py`)
- Threat response → Asterisk calling: writes call file (evidence: `reacao/reacao.py`)
- MQTT broker → Event receiver: dispatches records (evidence: `receptor/receptor.py`)
- Event receiver → Security database: stores events (evidence: `receptor/receptor.py`)
- Event receiver → Retry queue: queues failures (evidence: `receptor/receptor.py`)
- Retry queue → Security database: retries records (evidence: `receptor/receptor.py`)
- Authenticated API → Security database: queries records (evidence: `api/api.py`)
- Authenticated API → Live and evidence files: reads live frames (evidence: `api/api.py`)
- MQTT broker → Authenticated API: dispatches state (evidence: `api/api.py`)
- Homeowner → Web dashboard: opens dashboard
- Web dashboard → Authenticated API: requests views
- Homeowner → Authenticated API: queries securely (evidence: `api/api.py`)
- Event emulator → MQTT broker: publishes scenarios (evidence: `emulador/emulador.py`)
