# destrex271/spmps architecture

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

- Interactive diagram: https://gitdiagram.com/destrex271/spmps
- Repository: https://github.com/destrex271/spmps

## Overview

##### Project type and purpose
- Embedded camera firmware and edge server code
- A machine-learning model for vehicle/plate detection
- A Node.js backend with REST API controllers (ANPR, parking, devices, user)
- A frontend “app” component (likely web or mobile UI)

##### File structure
- Top-level directories:
- app – UI layer (not expanded here, but houses the user-facing interface)
- backend – Node.js/Express REST API, controllers, Swagger docs, environment/config files, Dockerfile
- embedded – firmware for camera endpoints (camcode.ino) and an edge server sketch (server.ino), static HTML/CSS for the on-device server
- model – Python ML service (detect.py, db.py), serialized model.p, sample videos, requirements.txt
- Patterns:
- Clear separation of concerns: embedded edge code, ML model service, backend API, and frontend app
- RESTful controllers in backend, documented via Swagger
- Dockerfile in backend indicates containerized deployment
- Environment-based configuration (.env.example in backend & model)

##### Insights from README files
- backend/README and model/README likely describe how to run each service

a. Main components:
1. Embedded Camera Nodes
2. Edge Server on device
3. ML Model Service
4. Backend API Server
5. Database (configured via .env)
6. Frontend Application
7. External Services (e.g., Swagger UI / third-party notifications)
b. Relationships and interactions:
- Cameras capture video → Edge Server hosts endpoint → forwards frames to ML Model
- ML Model Service processes frames → returns detection & ANPR results → stored in Database via Backend API
- Frontend App queries Backend API for parking/vehicle data, displays status to users
- Controllers in Backend interact with Database; Swagger UI attached to Backend
c. Architectural patterns & principles:
- Microservices-style decomposition: separate ML service, API service, edge firmware
- RESTful API layer with clear controllers (parking, ANPR, devices, user)
- Containerization (Dockerfile) of backend for portability
- Environment-based configuration for secrets & endpoints
d. Key technologies & frameworks:
- Embedded: Arduino/C++ (`.ino`), lightweight HTTP server (app_httpd.cpp)
- ML: Python (detect.py), OpenCV/TensorFlow (via requirements.txt), custom model.p
- Backend: Node.js, Express, Swagger (swagger.js), Docker
- Frontend: (unspecified, in app/) likely React/Angular or mobile SDK

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Embedded Layer
    subgraph "Embedded Layer"
        direction TB
        Camera["Embedded Camera Node"]:::embedded
        EdgeServer["Edge Server on Device"]:::embedded
    end
    Camera -->|"sends frames"| EdgeServer

    %% ML Service
    ML["ML Model Service"]:::ml
    EdgeServer -->|"forwards frames"| ML

    %% Backend Service Container
    subgraph "Backend Service (Docker Container)"
        direction TB
        API["Backend API Server"]:::backend
        SwaggerUI["Swagger UI Documentation"]:::doc
        TestPage["Sample/Test Page for API"]:::backend
        DB["Database"]:::db
    end
    ML -->|"POST detection results"| API
    API -->|"stores data"| DB
    SwaggerUI -.->|"serves docs"| API
    TestPage -.->|"test calls"| API

    %% Frontend Layer
    UI["Frontend Application"]:::frontend
    UI -->|"API calls"| API

    %% Click Events
    click Camera "https://github.com/destrex271/spmps/tree/main/embedded/camera/camcode/"
    click EdgeServer "https://github.com/destrex271/spmps/tree/main/embedded/server/"
    click ML "https://github.com/destrex271/spmps/tree/main/model/"
    click API "https://github.com/destrex271/spmps/blob/main/backend/index.js"
    click SwaggerUI "https://github.com/destrex271/spmps/blob/main/backend/swagger.js"
    click TestPage "https://github.com/destrex271/spmps/blob/main/backend/test.html"
    click DB "https://github.com/destrex271/spmps/blob/main/backend/.env.example"
    click UI "https://github.com/destrex271/spmps/blob/main/app/README.md"

    %% Styles
    classDef embedded fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef ml fill:#90EE90,stroke:#000,stroke-width:1px
    classDef backend fill:#FFA500,stroke:#000,stroke-width:1px
    classDef frontend fill:#DDA0DD,stroke:#000,stroke-width:1px
    classDef db fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef doc fill:#F5F5F5,stroke:#000,stroke-width:1px
```
