# neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard architecture

> Architecture diagram of the GitHub repository neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard
- Repository: https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard

## Overview

##### Project Type and Purpose
- This is an IoT-enabled, full‐stack ALPR (Automated License Plate Recognition) system.
- The “edge” (Raspberry Pi + sensors + camera) captures and preprocesses images, sends them to Google Cloud for OCR, then relays results to a Node.js web dashboard.

##### File Structure
- Hardware/Edge side (Python)
– car.py, ocr_script.py, runner.py, test.py
– files/ (license_plates.csv, license_plates.json, ocr_result.txt)
- Cloud integration
– test.py or ocr_script.py calls Google Cloud Storage & Vision API
- Backend
– server.js, package.json, node_modules
- Frontend (public/)
– index.html, learn.html, main.html
– CSS: index.css, style.css
– JS: script.js
- Utility / orchestrator
– runner.py triggers the pipeline

##### README for Insights
- Hardware components: Camera, IR sensor, optional servo motor
- GCP services: Cloud Storage (images), Vision API (OCR)
- Dashboard: Node.js server (real-time updates), frontend files

##### Main Components
A. Hardware Layer (on‐premises / Raspberry Pi)
1. IR Sensor (Vehicle Detection)
2. Camera (Image Capture)
3. (Optional) Servo Motor (Gate Control)
4. Raspberry Pi – runs Python scripts
- runner.py (entry point)
- test.py (core ALPR logic)
- ocr_script.py (image preprocessing & GCP API calls)
- car.py (license‐plate detection helper)
- Local storage: files/license_plates.csv, JSON, text logs

B. Cloud Layer
1. Google Cloud Storage Bucket (stores captured images)
2. Google Cloud Vision API (OCR processing)

C. Backend Layer
1. Node.js Server (server.js)
- Receives processed plate data via HTTP/REST or WebSocket
- Serves API endpoints and static files

D. Frontend Layer
1. Public Folder – Dashboard UI
- index.html, learn.html, main.html
- style.css, index.css
- script.js (fetches data, updates UI in real time)

E. Data Stores & Logs
- Local CSV/JSON/text files on Pi
- (Future) External database

##### Interactions & Data Flow
1. IR Sensor → Raspberry Pi (GPIO event)
2. Raspberry Pi (runner.py) triggers Camera → captures image
3. test.py (orchestrator) → optional local preprocessing (car.py)
4. test.py/ocr_script.py → Upload image to Cloud Storage
5. Cloud Storage → Vision API (OCR call) → returns raw text
6. ocr_script.py → Text cleaning → Append to CSV/JSON + write ocr_result.txt
7. Python script → HTTP POST (JSON payload: plate, timestamp) → Node.js server
8. Node.js server → Broadcast via WebSocket/emit → Frontend script.js
9. Frontend (index.html) → Update UI with image, plate number, timestamp
10. (Optional) Node.js → GPIO control API → Pi → Servo Motor

##### Architectural Patterns & Principles
- Event‐driven pipeline on the edge (GPIO events → script triggers)
- Separation of concerns:
– Edge processing vs. Cloud OCR vs. Web interface
- REST/WebSocket for real‐time communication
- Modular Python code (runner, OCR module, detection helper)
- Static server + dynamic API in Node.js

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Hardware Layer
    subgraph "Hardware Layer"
        direction TB
        IR["IR Sensor"]:::hardware
        Cam["Camera"]:::hardware
        Pi["Raspberry Pi"]:::hardware
        Servo["Servo Motor (optional)"]:::hardware
        IR -->|"GPIO: Vehicle detected"| Pi
        Pi -->|"trigger runner.py"| Runner["runner.py"]:::hardware
        Runner -->|"start orchestration"| Test["test.py"]:::hardware
        Test -->|"helper detection"| Car["car.py"]:::hardware
        Test -->|"preprocess & GCP call"| OcrEdge["ocr_script.py"]:::hardware
        Test --> Cam
        Servo -.->|"conditional control"| Pi
        Pi -->|"log results"| FilesLog["Local Storage"]:::data
        subgraph "files/"
            direction TB
            CSV["license_plates.csv"]:::data
            JSON["license_plates.json"]:::data
            TXT["ocr_result.txt"]:::data
        end
        FilesLog --> CSV
        FilesLog --> JSON
        FilesLog --> TXT
    end

    %% Cloud Layer
    subgraph "Cloud Layer"
        direction TB
        GCS["Google Cloud Storage"]:::cloud
        Vision["Vision API"]:::cloud
        OcrEdge -->|"Upload image"| GCS
        GCS -->|"OCR request"| Vision
        Vision -->|"Return text"| OcrEdge
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        Server["Node.js Server"]:::backend
        Pkg["package.json & dependencies"]:::backend
        WS["WebSocket"]:::backend
        OcrEdge -->|"HTTP POST (plate, timestamp)"| Server
        Server -->|"broadcast"| WS
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        UI["Dashboard UI\n(index.html)"]:::frontend
        Learn["learn.html"]:::frontend
        Main["main.html"]:::frontend
        CSS1["index.css"]:::frontend
        CSS2["style.css"]:::frontend
        JS["script.js"]:::frontend
        Img["images/"]:::frontend
        WS --> JS
        JS --> UI
        JS --> Learn
        JS --> Main
    end

    %% Documentation
    Doc["Project Documentation"]:::data

    %% Click Events
    click Runner "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/runner.py"
    click Test "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/test.py"
    click OcrEdge "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/ocr_script.py"
    click Car "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/car.py"
    click CSV "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/files/license_plates.csv"
    click JSON "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/files/license_plates.json"
    click TXT "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/files/ocr_result.txt"
    click Server "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/server.js"
    click Pkg "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/package.json"
    click Pkg "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/package-lock.json"
    click Pkg "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/tree/master/node_modules/"
    click UI "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/public/index.html"
    click Learn "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/public/learn.html"
    click Main "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/public/main.html"
    click CSS1 "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/public/index.css"
    click CSS2 "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/public/style.css"
    click JS "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/public/script.js"
    click Img "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/tree/master/public/images/"
    click Doc "https://github.com/neslang-05/alpr-using-goggle-cloud-vision-api-on-raspberry-pi-4-with-a-web-dashboard/blob/master/readme.md"

    %% Styles
    classDef hardware fill:#ADD8E6,stroke:#000;
    classDef cloud fill:#FFA500,stroke:#000;
    classDef backend fill:#90EE90,stroke:#000;
    classDef frontend fill:#DDA0DD,stroke:#000;
    classDef data fill:#D3D3D3,stroke:#000;
```
