# ebenkouao/smartcctv-camera architecture

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

- Interactive diagram: https://gitdiagram.com/ebenkouao/smartcctv-camera
- Repository: https://github.com/ebenkouao/smartcctv-camera

## Overview

##### Project Type & Purpose
- It is an IoT surveillance system built for the Raspberry Pi with live video streaming and face recognition.
- The system captures a live video feed, performs face recognition (using OpenCV/face_recognition libraries), and even provides a touchscreen-controlled servo to rotate the camera.
- Notifications (via Email) are mentioned in the README to alert users when a known/unknown person is detected.

##### Main Components
a. Camera Module:
– Represented primarily by camera.py.
– It handles capturing image/video input from the Raspberry Pi Camera Module.
b. Face Recognition Engine:
– Implemented in the scripts: facerec_pi_test.py and facerec_pi_test_profiles.py.
– Use of external libraries (like dLib and face_recognition) for detecting and recognizing faces.
c. Servo Control Module:
– Shown as servo.py.
– Controls the mechanical movement (pan/rotate) of the camera, likely via a touchscreen interface.
d. Web Server & Streaming Interface:
– main.py acts as the orchestration layer to start the streaming and possibly coordinate the different modules.
– The "templates" directory (with index.html) is used for rendering the live feed to the client’s browser, showing how the UI is served.
e. Profiles/Data Persistence:
– The "profiles" directory contains saved profiles/databases for recognized faces.
f. Static Assets:
– The "img" directory holding screenshots and images that support documentation and UI aesthetics.

##### Relationships and Interactions
- main.py is the central controller – it initializes the camera, starts the web stream, and ties in the facial recognition.
- The Camera Module (camera.py) feeds video frames to the Face Recognition Engine.
- The Face Recognition scripts process the captured frames – compare against stored profiles (from the "profiles" directory), and trigger notifications.
- The Servo Control (servo.py) component is used to mechanically adjust the camera view, which may be activated based on user input (possibly integrated via the touchscreen) or automatic triggers.
- The Web Server component serves the live streaming feed using the template (templates/index.html), making the camera accessible from any device.

##### Architectural Patterns & Design Principles
- Separation of Concerns: Each main functionality (capturing image, face recognition, servo control, web serving) is handled in its own script/module.
- Modular Design: With separate Python files for camera, facial recognition tests, servo control, and a distinct profiles repository for data, the architecture encourages maintainability and future extensions.
- Use of External Libraries: Integration of established libraries (OpenCV, face_recognition) is central to the face detection/recognition functionality.

##### Final Touches
- Every component is clearly labeled.
- Keep it detailed but clear – list out every logical module and connection as derived from the project file structure and README.

## Diagram (Mermaid)

```mermaid
graph TD
    A["Main Controller (main.py)"]:::core
    B["Camera Module (camera.py)"]:::core
    subgraph "Face Recognition Engine"
        FR1["facerec_pi_test.py"]:::module
        FR2["facerec_pi_test_profiles.py"]:::module
    end
    D["Servo Control Module (servo.py)"]:::core
    E["Web Server (templates/index.html)"]:::web
    F["Profiles/Data Store (profiles)"]:::repo
    G["Static Assets (img)"]:::repo

    A -->|"initialize_camera"| B
    B -->|"video_frames"| FR1
    B -->|"video_frames"| FR2
    FR1 -->|"recognition_data"| A
    FR2 -->|"recognition_data"| A
    FR1 -->|"profile_lookup"| F
    FR2 -->|"profile_lookup"| F
    A -->|"control_commands"| D
    A -->|"live_feed_control"| E
    E -->|"uses_assets"| G

    click A "https://github.com/ebenkouao/smartcctv-camera/blob/master/main.py"
    click B "https://github.com/ebenkouao/smartcctv-camera/blob/master/camera.py"
    click FR1 "https://github.com/ebenkouao/smartcctv-camera/blob/master/facerec_pi_test.py"
    click FR2 "https://github.com/ebenkouao/smartcctv-camera/blob/master/facerec_pi_test_profiles.py"
    click D "https://github.com/ebenkouao/smartcctv-camera/blob/master/servo.py"
    click E "https://github.com/ebenkouao/smartcctv-camera/blob/master/templates/index.html"
    click F "https://github.com/ebenkouao/smartcctv-camera/tree/master/profiles"
    click G "https://github.com/ebenkouao/smartcctv-camera/tree/master/img"

classDef core fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
classDef web fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
classDef repo fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
classDef module fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
