# babars98/smarthome architecture

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

- Interactive diagram: https://gitdiagram.com/babars98/smarthome
- Repository: https://github.com/babars98/smarthome

## Overview

SmartHome is a Python smart-home backend with client-side light and temperature monitoring and server-side schedule decisions. Each client samples its sensor, checks readings, sends qualifying readings and timestamps over TCP, and applies the server’s response to a GPIO-controlled light or fan. The server routes readings by sensor identifier and queries an external API for the decision. The tree also includes Blynk-related server code, but the sampled files do not establish how it is wired into the main workflow.

Main entry points: [`src/client/temprature_sensor_client.py`](https://github.com/babars98/smarthome/blob/main/src/client/temprature_sensor_client.py) (Temperature client), [`src/client/light_sensor_client.py`](https://github.com/babars98/smarthome/blob/main/src/client/light_sensor_client.py) (Light client), [`src/server/server_socket.py`](https://github.com/babars98/smarthome/blob/main/src/server/server_socket.py) (Server TCP socket), [`src/client/client_socket.py`](https://github.com/babars98/smarthome/blob/main/src/client/client_socket.py) (Client TCP socket)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Sensor clients"]
  node_light_client["Light client"]
  node_temp_client["Temperature client"]
  node_dht20["DHT20 driver<br/>[DHT20.py]"]
  node_light_logic["Light logic"]
  node_temp_logic["Temperature logic"]
  node_gpio["GPIO control<br/>[gpio.py]"]
  node_client_socket["Client TCP socket<br/>[client_socket.py]"]
  node_client_config["Client config<br/>[config.py]"]
end

subgraph group_server["TCP server"]
  node_server_socket["Server TCP socket<br/>[server_socket.py]"]
  node_server_config["Server config<br/>[config.py]"]
end

subgraph group_decisions["Schedule decisions"]
  node_light_handler["Light handler<br/>[light_sensor.py]"]
  node_temp_handler["Temperature handler<br/>[temp_sensor.py]"]
end

subgraph group_integrations["External integrations"]
  node_api_handler["HTTP API handler<br/>[api_handler.py]"]
  node_blynk_api["Blynk API module<br/>[blynk_api.py]"]
  node_blynk_lib["Blynk protocol<br/>[blynk_lib.py]"]
end

node_light_actor(("Light sensor device"))
node_temp_actor(("Temperature sensor device"))
node_external_api(("Schedule API"))
node_blynk_cloud(("Blynk Cloud"))

node_light_actor -->|"sensor input"| node_light_client
node_light_client -->|"checks level"| node_light_logic
node_light_client -->|"sends reading"| node_client_socket
node_light_client -->|"reads pin"| node_gpio
node_light_client -->|"reads settings"| node_client_config
node_light_logic -->|"sets output"| node_gpio
node_temp_actor -->|"sensor input"| node_dht20
node_temp_client -->|"reads measurement"| node_dht20
node_temp_client -->|"checks level"| node_temp_logic
node_temp_client -->|"sends reading"| node_client_socket
node_temp_client -->|"actuator path"| node_gpio
node_temp_logic -->|"sets output"| node_gpio
node_temp_client -->|"reads settings"| node_client_config
node_client_socket -->|"TCP reading"| node_server_socket
node_server_socket -->|"reads settings"| node_server_config
node_server_socket -->|"dispatches light"| node_light_handler
node_server_socket -->|"dispatches temperature"| node_temp_handler
node_light_handler -->|"requests decision"| node_api_handler
node_temp_handler -->|"requests decision"| node_api_handler
node_api_handler -->|"HTTP request"| node_external_api
node_external_api -->|"decision response"| node_api_handler
node_server_socket -->|"TCP response"| node_client_socket
node_blynk_lib -.->|"connects"| node_blynk_cloud

click node_light_client "https://github.com/babars98/smarthome/blob/main/src/client/light_sensor_client.py"
click node_temp_client "https://github.com/babars98/smarthome/blob/main/src/client/temprature_sensor_client.py"
click node_dht20 "https://github.com/babars98/smarthome/blob/main/src/client/DHT20.py"
click node_light_logic "https://github.com/babars98/smarthome/blob/main/src/client/light_businesslogic.py"
click node_temp_logic "https://github.com/babars98/smarthome/blob/main/src/client/temp_businesslogic.py"
click node_gpio "https://github.com/babars98/smarthome/blob/main/src/client/gpio.py"
click node_client_socket "https://github.com/babars98/smarthome/blob/main/src/client/client_socket.py"
click node_client_config "https://github.com/babars98/smarthome/blob/main/src/client/config.py"
click node_server_socket "https://github.com/babars98/smarthome/blob/main/src/server/server_socket.py"
click node_light_handler "https://github.com/babars98/smarthome/blob/main/src/server/light_sensor.py"
click node_temp_handler "https://github.com/babars98/smarthome/blob/main/src/server/temp_sensor.py"
click node_api_handler "https://github.com/babars98/smarthome/blob/main/src/server/api_handler.py"
click node_blynk_api "https://github.com/babars98/smarthome/blob/main/src/server/blynk_api.py"
click node_blynk_lib "https://github.com/babars98/smarthome/blob/main/src/server/blynk_lib.py"
click node_server_config "https://github.com/babars98/smarthome/blob/main/src/server/config.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_light_client,node_temp_client,node_dht20,node_light_logic,node_temp_logic,node_gpio,node_client_socket,node_client_config toneBlue
class node_server_socket,node_server_config toneAmber
class node_light_handler,node_temp_handler,node_external_api toneMint
class node_api_handler,node_blynk_api,node_blynk_lib toneRose
class node_light_actor,node_temp_actor,node_blynk_cloud toneIndigo
```

## Components

### Sensor clients

- [Light client](https://github.com/babars98/smarthome/blob/main/src/client/light_sensor_client.py): `src/client/light_sensor_client.py`
- [Temperature client](https://github.com/babars98/smarthome/blob/main/src/client/temprature_sensor_client.py): `src/client/temprature_sensor_client.py`
- [DHT20 driver](https://github.com/babars98/smarthome/blob/main/src/client/DHT20.py): `src/client/DHT20.py`
- [Light logic](https://github.com/babars98/smarthome/blob/main/src/client/light_businesslogic.py): `src/client/light_businesslogic.py`
- [Temperature logic](https://github.com/babars98/smarthome/blob/main/src/client/temp_businesslogic.py): `src/client/temp_businesslogic.py`
- [GPIO control](https://github.com/babars98/smarthome/blob/main/src/client/gpio.py): `src/client/gpio.py`
- [Client TCP socket](https://github.com/babars98/smarthome/blob/main/src/client/client_socket.py): `src/client/client_socket.py`
- [Client config](https://github.com/babars98/smarthome/blob/main/src/client/config.py): `src/client/config.py`

### TCP server

- [Server TCP socket](https://github.com/babars98/smarthome/blob/main/src/server/server_socket.py): `src/server/server_socket.py`
- [Server config](https://github.com/babars98/smarthome/blob/main/src/server/config.py): `src/server/config.py`

### Schedule decisions

- [Light handler](https://github.com/babars98/smarthome/blob/main/src/server/light_sensor.py): `src/server/light_sensor.py`
- [Temperature handler](https://github.com/babars98/smarthome/blob/main/src/server/temp_sensor.py): `src/server/temp_sensor.py`

### External integrations

- [HTTP API handler](https://github.com/babars98/smarthome/blob/main/src/server/api_handler.py): `src/server/api_handler.py`
- [Blynk API module](https://github.com/babars98/smarthome/blob/main/src/server/blynk_api.py): `src/server/blynk_api.py`
- [Blynk protocol](https://github.com/babars98/smarthome/blob/main/src/server/blynk_lib.py): `src/server/blynk_lib.py`

### Other components

- **Light sensor device**
- **Temperature sensor device**
- **Schedule API**
- **Blynk Cloud**

## Connections

- Light sensor device → Light client: sensor input
- Light client → Light logic: checks level
- Light client → Client TCP socket: sends reading
- Light client → GPIO control: reads pin
- Light client → Client config: reads settings
- Light logic → GPIO control: sets output
- Temperature sensor device → DHT20 driver: sensor input
- Temperature client → DHT20 driver: reads measurement
- Temperature client → Temperature logic: checks level
- Temperature client → Client TCP socket: sends reading
- Temperature client → GPIO control: actuator path
- Temperature logic → GPIO control: sets output
- Temperature client → Client config: reads settings
- Client TCP socket → Server TCP socket: TCP reading
- Server TCP socket → Server config: reads settings
- Server TCP socket → Light handler: dispatches light
- Server TCP socket → Temperature handler: dispatches temperature
- Light handler → HTTP API handler: requests decision
- Temperature handler → HTTP API handler: requests decision
- HTTP API handler → Schedule API: HTTP request
- Schedule API → HTTP API handler: decision response
- Server TCP socket → Client TCP socket: TCP response
- Blynk protocol → Blynk Cloud: connects
