# ihor-panchuk/smart_home architecture

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

- Interactive diagram: https://gitdiagram.com/ihor-panchuk/smart_home
- Repository: https://github.com/ihor-panchuk/smart_home

## Overview

Smart Home is a small FastAPI application for managing binary-state home devices, with a browser interface and PostgreSQL-backed device records. The main workflow is user interaction in the frontend, API request handling and validation, then database access and a response. The API supports device listing, lookup, creation, deletion and renaming, on/off control, status retrieval, light brightness, thermostat temperature, and door-lock state. A separate OOP practice file describes an in-memory model and JSON serialization; it is not shown wired into the API. Source evidence is sampled, so uncertain interactions are omitted.

Main entry points: [`main.py`](https://github.com/ihor-panchuk/smart_home/blob/main/main.py) (FastAPI application), [`database.py`](https://github.com/ihor-panchuk/smart_home/blob/main/database.py) (Device data access), [`frontend/script.js`](https://github.com/ihor-panchuk/smart_home/blob/main/frontend/script.js) (Device controls), [`oop_practice/smart_home_oop.py`](https://github.com/ihor-panchuk/smart_home/blob/main/oop_practice/smart_home_oop.py) (Device model exercise)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Browser interface"]
  node_frontend["Device controls<br/>[script.js]"]
  node_page["Frontend page<br/>[index.html]"]
end

subgraph group_api["Device API"]
  node_api_entry["FastAPI application<br/>[main.py]"]
  node_validation["Request validation<br/>[main.py]"]
  node_device_routes["Device routes<br/>[main.py]"]
  node_status_routes["Status routes<br/>[main.py]"]
  node_settings_routes["Device settings<br/>[main.py]"]
end

subgraph group_data["Persistent data"]
  node_db_access["Device data access<br/>[database.py]"]
end

subgraph group_practice["OOP practice"]
  node_oop_model["Device model exercise<br/>[smart_home_oop.py]"]
end

node_user(("Home user"))
node_postgres[("PostgreSQL")]
node_json_file["JSON file"]

node_user -->|"uses"| node_frontend
node_api_entry -->|"serves static files"| node_page
node_frontend -->|"sends requests"| node_api_entry
node_api_entry -->|"validates inputs"| node_validation
node_api_entry -->|"dispatches requests"| node_device_routes
node_api_entry -->|"dispatches requests"| node_status_routes
node_api_entry -->|"dispatches requests"| node_settings_routes
node_device_routes -->|"calls CRUD"| node_db_access
node_status_routes -->|"reads device"| node_db_access
node_settings_routes -->|"reads and updates"| node_db_access
node_db_access -->|"queries and updates"| node_postgres
node_oop_model -.->|"reads and writes"| node_json_file

click node_frontend "https://github.com/ihor-panchuk/smart_home/blob/main/frontend/script.js"
click node_page "https://github.com/ihor-panchuk/smart_home/blob/main/frontend/index.html"
click node_api_entry "https://github.com/ihor-panchuk/smart_home/blob/main/main.py"
click node_validation "https://github.com/ihor-panchuk/smart_home/blob/main/main.py"
click node_device_routes "https://github.com/ihor-panchuk/smart_home/blob/main/main.py"
click node_status_routes "https://github.com/ihor-panchuk/smart_home/blob/main/main.py"
click node_settings_routes "https://github.com/ihor-panchuk/smart_home/blob/main/main.py"
click node_db_access "https://github.com/ihor-panchuk/smart_home/blob/main/database.py"
click node_oop_model "https://github.com/ihor-panchuk/smart_home/blob/main/oop_practice/smart_home_oop.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_frontend,node_page,node_user toneBlue
class node_api_entry,node_validation,node_device_routes,node_status_routes,node_settings_routes,node_postgres toneAmber
class node_db_access toneMint
class node_oop_model toneRose
class node_json_file toneIndigo
```

## Components

### Browser interface

- [Device controls](https://github.com/ihor-panchuk/smart_home/blob/main/frontend/script.js): `frontend/script.js`
- [Frontend page](https://github.com/ihor-panchuk/smart_home/blob/main/frontend/index.html): `frontend/index.html`

### Device API

- [FastAPI application](https://github.com/ihor-panchuk/smart_home/blob/main/main.py): `main.py`
- [Request validation](https://github.com/ihor-panchuk/smart_home/blob/main/main.py): `main.py`
- [Device routes](https://github.com/ihor-panchuk/smart_home/blob/main/main.py): `main.py`
- [Status routes](https://github.com/ihor-panchuk/smart_home/blob/main/main.py): `main.py`
- [Device settings](https://github.com/ihor-panchuk/smart_home/blob/main/main.py): `main.py`

### Persistent data

- [Device data access](https://github.com/ihor-panchuk/smart_home/blob/main/database.py): `database.py`

### OOP practice

- [Device model exercise](https://github.com/ihor-panchuk/smart_home/blob/main/oop_practice/smart_home_oop.py): `oop_practice/smart_home_oop.py`

### Other components

- **Home user**
- **PostgreSQL**
- **JSON file**

## Connections

- Home user → Device controls: uses
- FastAPI application → Frontend page: serves static files
- Device controls → FastAPI application: sends requests
- FastAPI application → Request validation: validates inputs
- FastAPI application → Device routes: dispatches requests
- FastAPI application → Status routes: dispatches requests
- FastAPI application → Device settings: dispatches requests
- Device routes → Device data access: calls CRUD
- Status routes → Device data access: reads device
- Device settings → Device data access: reads and updates
- Device data access → PostgreSQL: queries and updates
- Device model exercise → JSON file: reads and writes
