# dominickdemilio/smart-room-cam architecture

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

- Interactive diagram: https://gitdiagram.com/dominickdemilio/smart-room-cam
- Repository: https://github.com/dominickdemilio/smart-room-cam

## Overview

##### Project type and purpose
- This is a lightweight full-stack Python application for a Raspberry Pi.
- Purpose: Acquire live video from a Pi camera, run motion detection and object recognition, and stream to a web browser via Flask.

##### File structure
- Top-level:
- main.py – application entry point that starts the Flask server and ties together modules
- app/ – core Python modules
– camera_stream.py: captures frames from the Pi camera and exposes them as a video feed
– motion_detector.py: processes frames and flags motion events
– recognizer.py: runs an AI model (OpenCV or pretrained) to detect humans or faces
- static/ – client-side assets (style.css)
- templates/ – HTML templates (index.html) used by Flask to render the UI
- tests/ – unit tests for camera module

##### Key insights from README
- Built with Python, OpenCV, Flask
- Features: live streaming, modular AI processing (motion detection, recognition)
- Future plans: Dockerization, authentication

##### Main components and their relationships
a. Hardware layer
– Raspberry Pi with attached camera module
b. Processing layer (inside Pi)
- CameraStream component: pulls raw frames from hardware
- MotionDetector component: analyzes frames for movement
- Recognizer component: runs AI inference on frames
c. Application layer
- Flask Web Server (main.py)
– Routes:
/             → serves index.html
/video_feed  → streams MJPEG from camera_stream.py
– Injects motion status or recognition results into the stream or separate endpoints
d. Presentation layer
– Browser client requesting HTML, CSS, and MJPEG stream over HTTP
e. (Future) Deployment layer
– Docker container wrapping the above
– Optional external auth service if exposing remotely

##### Architectural patterns and design principles
- Modular design: each processing step is isolated in its own Python module
- Pipeline pattern: camera → motion detector → recognizer → stream
- Single-process, multi-modular architecture – simplicity over microservices for a Pi
- Clear separation of concerns: acquisition, processing, web serving, presentation

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Raspberry Pi"
        direction TB
        CameraModule["Camera Module"]:::hardware
        CameraStream["camera_stream.py"]:::processing
        MotionDetector["motion_detector.py"]:::processing
        Recognizer["recognizer.py"]:::processing
        AppInit["app/__init__.py"]:::processing
        FlaskServer["Flask Web Server<br>(main.py)"]:::webserver
        Templates["templates/index.html"]:::webserver
        Static["static/style.css"]:::webserver

        CameraModule -->|"frame data"| CameraStream
        CameraStream -->|"frame data"| MotionDetector
        MotionDetector -->|"filtered frames"| Recognizer
        CameraStream -->|"/video_feed (MJPEG)"| FlaskServer
        FlaskServer -->|"serves"| Templates
        FlaskServer -->|"serves"| Static
    end

    WebBrowser["Web Browser"]:::client
    FlaskServer <-->|"HTTP: HTML, CSS, MJPEG stream"| WebBrowser

    Tests["Unit Tests<br>(tests/test_camera.py)"]:::aux --> CameraStream
    Requirements["requirements.txt"]:::aux --> FlaskServer

    click CameraStream "https://github.com/dominickdemilio/smart-room-cam/blob/main/app/camera_stream.py"
    click MotionDetector "https://github.com/dominickdemilio/smart-room-cam/blob/main/app/motion_detector.py"
    click Recognizer "https://github.com/dominickdemilio/smart-room-cam/blob/main/app/recognizer.py"
    click FlaskServer "https://github.com/dominickdemilio/smart-room-cam/blob/main/main.py"
    click Static "https://github.com/dominickdemilio/smart-room-cam/blob/main/static/style.css"
    click Templates "https://github.com/dominickdemilio/smart-room-cam/blob/main/templates/index.html"
    click Tests "https://github.com/dominickdemilio/smart-room-cam/blob/main/tests/test_camera.py"
    click Requirements "https://github.com/dominickdemilio/smart-room-cam/blob/main/requirements.txt"
    click AppInit "https://github.com/dominickdemilio/smart-room-cam/blob/main/app/__init__.py"

    classDef hardware fill:#FFD966,stroke:#BF9000,stroke-width:1px
    classDef processing fill:#D9EAD3,stroke:#6AA84F,stroke-width:1px
    classDef webserver fill:#C9DAF8,stroke:#3D85C6,stroke-width:1px
    classDef client fill:#F4CCCC,stroke:#CC0000,stroke-width:1px
    classDef aux fill:#EAD1DC,stroke:#C27BA0,stroke-width:1px
```
