# owenz0523/pet-feeder architecture

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

- Interactive diagram: https://gitdiagram.com/owenz0523/pet-feeder
- Repository: https://github.com/owenz0523/pet-feeder

## Overview

##### Project Overview
- PiPaws is an integrated project that seamlessly blends software and hardware. Its purpose is to let pet owners remotely dispense food using a web application while recording video (camera) feedback and feeding data.
- The system involves a frontend built with React.js/Tailwind.css, a backend implemented with Node.js and Python scripts, hardware control on a Raspberry Pi (using RPi.GPIO and Picamera libraries), and Firebase for authentication and data management.

##### Major Components
a. Frontend Web Application:
- User interface built with React.js. Indicate key pages such as Home, About, Account, Camera, and SignIn.
- Mention the use of Tailwind.css for styling and that Firebase is integrated for login/authentication and as the database.
- User interactions such as initiating food dispensing and viewing feeding logs.

b. Backend Services:
- Node.js Server (“server.js”) and related modules (like gpio.js) that likely act as the API layer communicating with frontend requests.
- Python service components such as camera.py, stepper.py, and test.py, which handle hardware-specific operations like image processing using the Picamera library and controlling rotational motors via GPIO.
- Integration between these services (for example, a Node.js process invoking or coordinating with Python scripts to operate hardware elements).

c. Hardware Control Module:
- Raspberry Pi’s role as the central hub for hardware connectivity.
- Camera sensor for capturing video/images during feeding and the motor control (through stepper.py) for dispensing food.
- How Raspberry Pi’s GPIO channels are used to interface with both the camera and the feeding mechanism (rotational motor).

d. External Services:
- Firebase for authentication and database services (storing feeding data, user credentials, etc.).

##### Relationships and Interactions
- From the Frontend (React app) to the Backend (Node.js server/API) for user commands (e.g., “Dispense Food” requests).
- From the Backend to the Hardware module (Python scripts running on the Raspberry Pi) indicating control commands for the motor and camera activation.
- From the Hardware module back to the Backend if there are status updates or processed data (e.g., image capture results).
- From the Frontend and Backend to Firebase for authentication and data persistence.
- Separation of concerns: UI/UX in the frontend, hardware interfacing in the backend/Python modules, and external cloud services for data management.

##### Architectural Patterns and Principles
- That the project uses a separation between the user interface and business logic through clearly partitioned frontend and backend folders.
- The design follows a service-oriented approach where the backend orchestrates hardware functionalities and interacts with external services.
- Modularity—each Python script (for camera, motor control, etc.) and Node.js component represents a specific responsibility.
- Patterns such as API-driven communication between components and event-driven triggers (e.g., activating the camera when food is dispensed).

##### Technologies, Frameworks, and Libraries
- Frontend: React.js, Tailwind.css, Firebase integration.
- Backend: Node.js (server.js, gpio.js), npm for package management.
- Hardware Control: Python scripts using the Picamera library and RPi.GPIO modules.
- Deployment: Instructions mention a Flask web application in the README (possibly for local testing), though the core backend for hardware communication appears to be Node and Python.
- Git as version control and possibly additional setup using requirements.txt (for Python dependencies).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend (React Application)"
        FE_Main["React App UI"]:::frontend
        FE_Home["Home"]:::frontend
        FE_About["About"]:::frontend
        FE_Account["Account"]:::frontend
        FE_Camera["Camera"]:::frontend
        FE_SignIn["SignIn"]:::frontend
        FE_Tailwind["Tailwind & Styling"]:::frontend
        FE_Firebase["Firebase Integration"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Node.js API)"
        BE_Server["Server (server.js)"]:::backend
        BE_GPIO["GPIO Module (gpio.js)"]:::backend
        BE_Package["Package.json"]:::backend
        BE_PackageLock["Package-lock.json"]:::backend
    end

    %% Hardware Control Layer
    subgraph "Hardware Control (Python Scripts)"
        HC_Camera["Camera Operations (camera.py)"]:::hardware
        HC_Motor["Motor Controller (stepper.py)"]:::hardware
        HC_Test["Test Module (test.py)"]:::hardware
    end

    %% External Service
    Firebase_DB["Firebase (Auth & DB)"]:::firebase

    %% Connections
    FE_Main -->|"DispenseFoodRequest"| BE_Server
    FE_Home --> FE_Main
    FE_About --> FE_Main
    FE_Account --> FE_Main
    FE_Camera --> FE_Main
    FE_SignIn --> FE_Main
    FE_Tailwind -.-> FE_Main
    FE_Firebase -.-> FE_Main

    BE_Server -->|"InvokesGPIO"| BE_GPIO
    BE_Server -->|"TriggerCamera"| HC_Camera
    BE_Server -->|"TriggerMotor"| HC_Motor
    HC_Camera -->|"CaptureStatus"| BE_Server
    HC_Motor -->|"DispenseStatus"| BE_Server
    BE_Server -->|"LogsData"| Firebase_DB
    FE_Main -->|"AuthData"| Firebase_DB

    %% Click Events - Frontend
    click FE_Home "https://github.com/owenz0523/pet-feeder/blob/main/front-end/src/pages/Home.js"
    click FE_About "https://github.com/owenz0523/pet-feeder/blob/main/front-end/src/pages/About.js"
    click FE_Account "https://github.com/owenz0523/pet-feeder/blob/main/front-end/src/pages/Account.js"
    click FE_Camera "https://github.com/owenz0523/pet-feeder/blob/main/front-end/src/pages/Camera.js"
    click FE_SignIn "https://github.com/owenz0523/pet-feeder/blob/main/front-end/src/pages/SignIn.js"
    click FE_Tailwind "https://github.com/owenz0523/pet-feeder/blob/main/front-end/tailwind.config.js"
    click FE_Tailwind "https://github.com/owenz0523/pet-feeder/blob/main/front-end/src/home.css"
    click FE_Firebase "https://github.com/owenz0523/pet-feeder/blob/main/front-end/src/firebase.js"

    %% Click Events - Backend
    click BE_Server "https://github.com/owenz0523/pet-feeder/blob/main/back-end/server.js"
    click BE_GPIO "https://github.com/owenz0523/pet-feeder/blob/main/back-end/gpio.js"
    click BE_Package "https://github.com/owenz0523/pet-feeder/blob/main/back-end/package.json"
    click BE_PackageLock "https://github.com/owenz0523/pet-feeder/blob/main/back-end/package-lock.json"

    %% Click Events - Hardware Control
    click HC_Camera "https://github.com/owenz0523/pet-feeder/blob/main/back-end/camera.py"
    click HC_Motor "https://github.com/owenz0523/pet-feeder/blob/main/back-end/stepper.py"
    click HC_Test "https://github.com/owenz0523/pet-feeder/blob/main/back-end/test.py"

    %% Styles
    classDef frontend fill:#D6E9C6,stroke:#3C763D,stroke-width:2px,color:#3C763D;
    classDef backend fill:#D9EDF7,stroke:#31708F,stroke-width:2px,color:#31708F;
    classDef hardware fill:#F2DEDE,stroke:#A94442,stroke-width:2px,color:#A94442;
    classDef firebase fill:#FCF8E3,stroke:#8A6D3B,stroke-width:2px,color:#8A6D3B;
```
