# flaviochaia/iot-estacionamento architecture

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

- Interactive diagram: https://gitdiagram.com/flaviochaia/iot-estacionamento
- Repository: https://github.com/flaviochaia/iot-estacionamento

## Overview

Smart Parking G3 monitors four parking spaces with an ESP32, stores live status and events, and presents occupancy, history, statistics, and gate controls in a web dashboard. The main workflow is sensor readings and device events → MQTT → FastAPI processing and Prisma persistence → REST dashboard; gate commands travel back through MQTT to the device. The repository also contains a separate, older backend in main.py and an MQTT simulator. Relationships for the main workflow are supported by source excerpts or README documentation; unsampled dashboard and schema internals are not inferred.

Main entry points: [`app/main.py`](https://github.com/flaviochaia/iot-estacionamento/blob/main/app/main.py) (FastAPI service), [`esp32/src/main.cpp`](https://github.com/flaviochaia/iot-estacionamento/blob/main/esp32/src/main.cpp) (ESP32 MQTT device), [`static/index.html`](https://github.com/flaviochaia/iot-estacionamento/blob/main/static/index.html) (Parking dashboard), [`main.py`](https://github.com/flaviochaia/iot-estacionamento/blob/main/main.py) (Legacy backend)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_device["Parking device"]
  node_sensors["Sensors and rules<br/>[main.cpp]"]
  node_actuators["Gate and indicators<br/>[main.cpp]"]
  node_firmware["ESP32 MQTT device<br/>[main.cpp]"]
end

subgraph group_backend["Backend services"]
  node_api["FastAPI service<br/>[main.py]"]
  node_legacy["Legacy backend<br/>[main.py]"]
  node_simulator["Device simulator<br/>[simulate.py]"]
  node_rest["REST endpoints<br/>[main.py]"]
end

subgraph group_data["Persistence"]
  node_schema["Parking data model<br/>[schema.prisma]"]
  node_database[("SQLite database")]
end

subgraph group_dashboard["Dashboard"]
  node_dashboard["Parking dashboard<br/>[index.html]"]
end

node_driver(("Dashboard user"))
node_broker["MQTT broker"]

node_sensors -->|"updates state"| node_firmware
node_firmware -->|"drives"| node_actuators
node_firmware -->|"publishes status/events"| node_broker
node_broker -->|"delivers MQTT"| node_api
node_api -->|"persists and queries"| node_database
node_api -.->|"uses data model"| node_schema
node_api -->|"serves"| node_rest
node_rest -->|"supplies dashboard data"| node_dashboard
node_driver -->|"views and controls"| node_dashboard
node_dashboard -.->|"requests API"| node_rest
node_rest -->|"publishes gate command"| node_broker
node_broker -->|"delivers command"| node_firmware
node_simulator -->|"publishes status/events"| node_broker
node_legacy -->|"subscribes and publishes"| node_broker
node_legacy -->|"persists and queries"| node_database

click node_sensors "https://github.com/flaviochaia/iot-estacionamento/blob/main/esp32/src/main.cpp"
click node_actuators "https://github.com/flaviochaia/iot-estacionamento/blob/main/esp32/src/main.cpp"
click node_firmware "https://github.com/flaviochaia/iot-estacionamento/blob/main/esp32/src/main.cpp"
click node_api "https://github.com/flaviochaia/iot-estacionamento/blob/main/app/main.py"
click node_legacy "https://github.com/flaviochaia/iot-estacionamento/blob/main/main.py"
click node_simulator "https://github.com/flaviochaia/iot-estacionamento/blob/main/scripts/simulate.py"
click node_schema "https://github.com/flaviochaia/iot-estacionamento/blob/main/prisma/schema.prisma"
click node_rest "https://github.com/flaviochaia/iot-estacionamento/blob/main/app/main.py"
click node_dashboard "https://github.com/flaviochaia/iot-estacionamento/blob/main/static/index.html"

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_sensors,node_actuators,node_firmware,node_driver toneBlue
class node_api,node_legacy,node_simulator,node_rest toneAmber
class node_schema,node_database toneMint
class node_dashboard toneRose
class node_broker toneIndigo
```

## Components

### Parking device

- [Sensors and rules](https://github.com/flaviochaia/iot-estacionamento/blob/main/esp32/src/main.cpp): `esp32/src/main.cpp`
- [Gate and indicators](https://github.com/flaviochaia/iot-estacionamento/blob/main/esp32/src/main.cpp): `esp32/src/main.cpp`
- [ESP32 MQTT device](https://github.com/flaviochaia/iot-estacionamento/blob/main/esp32/src/main.cpp): `esp32/src/main.cpp`

### Backend services

- [FastAPI service](https://github.com/flaviochaia/iot-estacionamento/blob/main/app/main.py): `app/main.py`
- [Legacy backend](https://github.com/flaviochaia/iot-estacionamento/blob/main/main.py): `main.py`
- [Device simulator](https://github.com/flaviochaia/iot-estacionamento/blob/main/scripts/simulate.py): `scripts/simulate.py`
- [REST endpoints](https://github.com/flaviochaia/iot-estacionamento/blob/main/app/main.py): `app/main.py`

### Persistence

- [Parking data model](https://github.com/flaviochaia/iot-estacionamento/blob/main/prisma/schema.prisma): `prisma/schema.prisma`
- **SQLite database**

### Dashboard

- [Parking dashboard](https://github.com/flaviochaia/iot-estacionamento/blob/main/static/index.html): `static/index.html`

### Other components

- **Dashboard user**
- **MQTT broker**

## Connections

- Sensors and rules → ESP32 MQTT device: updates state (evidence: `esp32/src/main.cpp`)
- ESP32 MQTT device → Gate and indicators: drives (evidence: `esp32/src/main.cpp`)
- ESP32 MQTT device → MQTT broker: publishes status/events (evidence: `README`)
- MQTT broker → FastAPI service: delivers MQTT (evidence: `README`)
- FastAPI service → SQLite database: persists and queries (evidence: `app/main.py`)
- FastAPI service → Parking data model: uses data model
- FastAPI service → REST endpoints: serves (evidence: `app/main.py`)
- REST endpoints → Parking dashboard: supplies dashboard data (evidence: `README`)
- Dashboard user → Parking dashboard: views and controls (evidence: `README`)
- Parking dashboard → REST endpoints: requests API
- REST endpoints → MQTT broker: publishes gate command (evidence: `app/main.py`)
- MQTT broker → ESP32 MQTT device: delivers command (evidence: `README`)
- Device simulator → MQTT broker: publishes status/events (evidence: `scripts/simulate.py`)
- Legacy backend → MQTT broker: subscribes and publishes (evidence: `main.py`)
- Legacy backend → SQLite database: persists and queries (evidence: `main.py`)
