# baqs/pyezviz architecture

> Architecture diagram of the GitHub repository baqs/pyezviz, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/baqs/pyezviz
- Repository: https://github.com/baqs/pyezviz

## Overview

##### Project type and purpose
- This is an open-source Python CLI/library package (pyezvizapi) that wraps the undocumented Ezviz IoT camera/light-bulb REST/MQTT/RTSP APIs.
- Its purpose is to allow users (via CLI or programmatic import) to authenticate with Ezviz, list devices, query status, toggle lights, and stream or fetch RTSP camera feeds.

##### File structure
- Top-level:
- setup.py, requirements.txt, MANIFEST.in ⇒ packaging & dependencies
- README.md, LICENSE.md ⇒ documentation
- .github/ ⇒ CI/CD workflows (PyPI publishing)
- examples/ ⇒ sample usage
- pyezvizapi/ (core library):
- __main__.py ⇒ CLI entrypoint (click/argparse)
- client.py ⇒ orchestrates auth + requests
- api_endpoints.py ⇒ URL definitions for REST calls
- camera.py, light_bulb.py, cas.py ⇒ device-specific logic
- mqtt.py ⇒ MQTT broker connection for real-time events
- utils.py ⇒ JSON parsing, signing, encryption
- constants.py ⇒ mappings (switch numbers → names)
- exceptions.py ⇒ error classes
- tests/ (not shown above but referred in README) ⇒ pytest/tox suite and sample JSON in tests/data/.

##### README for insights
- CLI commands: pyezvizapi -u USER -p PASS [devices/camera/light] [status/toggle]
- Under the hood: HTTP(S) to EzvizLife API servers, optionally RTSP for live streams, MQTT for push events.
- Region override (–r) for alternative base URLs.
- No official docs; endpoints reverse-engineered.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "pyezvizapi Package"
        CLI["CLI Entrypoint\n(__main__.py)"]:::internal
        Client["Auth & Request Manager\n(client.py)"]:::internal
        API["API Endpoints Registry\n(api_endpoints.py)"]:::internal
        subgraph "Device Modules"
            Camera["Camera Module\n(camera.py)"]:::internal
            Light["Light Bulb Module\n(light_bulb.py)"]:::internal
            CAS["CAS Module\n(cas.py)"]:::internal
        end
        MQTT["MQTT Interface\n(mqtt.py)"]:::internal
        Utils["Utils\n(utils.py)"]:::internal
        Const["Constants\n(constants.py)"]:::internal
        Excp["Exceptions\n(exceptions.py)"]:::internal
    end

    subgraph "External Services"
        REST["Ezviz REST API"]:::external
        MQTTb["Ezviz MQTT Broker"]:::external
        RTSP["Local RTSP Stream"]:::external
    end

    subgraph "CI/CD & Publishing"
        CI["GitHub Actions\n(publish to PyPI)"]:::ci
        PyPI["PyPI Registry"]:::external
    end

    subgraph "Project Packaging & Docs"
        Setup["Packaging Config"]:::ci
        Doc["Documentation"]:::ci
        Examples["Example Usage"]:::ci
    end

    CLI -->|"invokes"| Client
    Client -->|"uses endpoints"| API
    Client -->|"HTTP/HTTPS JSON"| REST
    REST -->|"JSON response"| Client
    Client -->|"parses with"| Utils
    Utils -->|"helpers for parsing/signing"| Client
    Client -->|"device logic"| Camera
    Client -->|"device logic"| Light
    Client -->|"device logic"| CAS
    Camera -->|"RTSP (UDP/TCP)"| RTSP
    Client -->|"MQTT SUBSCRIBE"| MQTT
    MQTT -->|"MQTT events"| MQTTb
    Setup -->|triggers| CI
    Doc -->|triggers| CI
    CI -->|"publish"| PyPI

    click CLI "https://github.com/baqs/pyezviz/blob/master/pyezvizapi/__main__.py"
    click Client "https://github.com/baqs/pyezviz/blob/master/pyezvizapi/client.py"
    click API "https://github.com/baqs/pyezviz/blob/master/pyezvizapi/api_endpoints.py"
    click Camera "https://github.com/baqs/pyezviz/blob/master/pyezvizapi/camera.py"
    click Light "https://github.com/baqs/pyezviz/blob/master/pyezvizapi/light_bulb.py"
    click CAS "https://github.com/baqs/pyezviz/blob/master/pyezvizapi/cas.py"
    click MQTT "https://github.com/baqs/pyezviz/blob/master/pyezvizapi/mqtt.py"
    click Utils "https://github.com/baqs/pyezviz/blob/master/pyezvizapi/utils.py"
    click Const "https://github.com/baqs/pyezviz/blob/master/pyezvizapi/constants.py"
    click Excp "https://github.com/baqs/pyezviz/blob/master/pyezvizapi/exceptions.py"
    click Setup "https://github.com/baqs/pyezviz/blob/master/setup.py"
    click Setup "https://github.com/baqs/pyezviz/blob/master/requirements.txt"
    click Setup "https://github.com/baqs/pyezviz/blob/master/MANIFEST.in"
    click Doc "https://github.com/baqs/pyezviz/blob/master/README.md"
    click Doc "https://github.com/baqs/pyezviz/blob/master/LICENSE.md"
    click CI "https://github.com/baqs/pyezviz/blob/master/.github/workflows/python-publish.yml"
    click Examples "https://github.com/baqs/pyezviz/blob/master/examples/schedule_example.txt"

    classDef internal fill:#cce5ff,stroke:#1f77b4,color:#000
    classDef external fill:#d4edda,stroke:#2ca02c,color:#000
    classDef ci fill:#fff3cd,stroke:#ff7f0e,color:#000
```
