# piotrpdev/oko architecture

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

- Interactive diagram: https://gitdiagram.com/piotrpdev/oko
- Repository: https://github.com/piotrpdev/oko

## Overview

##### Main System Components
- Frontend:
- Code is located in the “frontend” directory.
- Built using Svelte and Vite with multiple routes/pages (Home, Login, Cameras, NotFound).
- Contains various UI component libraries and styling (Tailwind, Prettier, ESLint).
- Backend:
- Located in the “backend” directory.
- Written in Rust using frameworks like Axum.
- Contains submodules for database interactions (in the “src/db” folder) and web routing (in “src/web”).
- Contains SQL migrations, fixtures, tests, and utilities (e.g., WS utilities and a “camera-impersonator” tool), indicating database operations and real-time communication (possibly via websockets).
- Camera Module:
- Found in the “camera” directory.
- A Rust-based application with ESP32 configurations (e.g., Cargo.toml, build.rs, espflash.toml, and evidence of an “esp-camera-rs” dependency).
- Likely responsible for capturing images/video input locally.
- Landing Page:
- The “landing” folder holds static assets and an index.html serving as a marketing or public-facing page.
- Database:
- While not represented as a dedicated service, the presence of migrations, SQLx queries, and fixtures in the backend shows that a relational database is part of the architecture.
- CI/CD and Build Infrastructure:
- Presence of the “.github/workflows” directory shows automated deployments, testing, and release pipelines.
- Auxiliary Scripts and Tools:
- The “make.sh” script and various testing files are used for development routines like seeding data, running tests, and simulating camera input.

##### Out Component Interactions
- Frontend ↔ Backend:
- The frontend communicates with the backend via REST API endpoints, authentication routes, and possibly websockets for real-time updates.
- Backend ↔ Database:
- The backend uses SQLx for queries and migrations, interacting with a database to manage users, cameras, videos, permissions, and settings.
- Backend ↔ Camera Module:
- Although the integration details are internal, the backend likely receives camera data (images/videos) from the camera module and may send commands back (or monitor incoming streams).
- CI/CD Pipeline:
- An external flow showing automated testing, building, and deployment, which integrates into all modules of the project.

##### Important Architectural Patterns and Technologies
- Separation of concerns:
- The project is clearly partitioned into frontend, backend, and camera components.
- Modular and layered design:
- Within the backend, distinct modules handle data layer (db), web routing (“web” folder), and testing.
- Real-time Communication:
- The inclusion of WS (websocket) utility modules indicates a push-based update mechanism likely used for live camera feeds or notifications.
- OpenCV Integration:
- The README mentions OpenCV prerequisites, suggesting that image processing might be a part of the backend functionality.
- Use of modern web technologies like Svelte for a responsive and modular UI.

##### Final Recommendations
- Be very detailed: Break down each major component and, if necessary, include further internal subdivisions (e.g., showing the “db” and “web” submodules within the backend).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD and Dev Tools
    CI_CD["CI/CD Pipeline"]:::ci
    DEV1["Make Script"]:::tools
    DEV2["Tests"]:::tools

    %% Client-Side components
    subgraph "Client-Side"
        FRO["Frontend - Svelte/Vite UI"]:::frontend
        LAND["Landing Page - Marketing/Public Static Site"]:::landing
    end

    %% Server-Side Backend components
    subgraph "Server-Side - Backend"
        BACK["Backend - Rust/Axum API"]:::backend
        WebRouting["Web Routing (src/web)"]:::backend
        DBModule["Database Module (src/db)"]:::backend
    end

    %% Database and Camera Module
    DB["Database - SQLx Migrations"]:::database
    CAM["Camera Module - ESP32 Rust Application"]:::camera

    %% Connections from CI/CD Pipeline to major components
    CI_CD -->|"triggers"| FRO
    CI_CD -->|"triggers"| LAND
    CI_CD -->|"triggers"| BACK
    CI_CD -->|"triggers"| CAM

    %% Connections from Dev Tools to Backend
    DEV1 -->|"executes"| BACK
    DEV2 -->|"executes tests on"| BACK

    %% Client-Backend interaction
    FRO -->|"REST_API/WebSocket"| BACK
    LAND -->|"HTTP Requests"| BACK

    %% Internal Backend breakdown
    BACK -->|"handles routing"| WebRouting
    BACK -->|"invokes DB operations"| DBModule
    DBModule -->|"SQLx queries/migrations"| DB

    %% Backend and Camera Module interaction
    BACK -->|"sends/receives camera data"| CAM

    %% Click Events
    click FRO "https://github.com/piotrpdev/oko/tree/main/frontend/"
    click LAND "https://github.com/piotrpdev/oko/blob/main/landing/index.html"
    click BACK "https://github.com/piotrpdev/oko/tree/main/backend/"
    click WebRouting "https://github.com/piotrpdev/oko/tree/main/backend/src/web"
    click DBModule "https://github.com/piotrpdev/oko/tree/main/backend/src/db"
    click DB "https://github.com/piotrpdev/oko/tree/main/backend/migrations"
    click CAM "https://github.com/piotrpdev/oko/tree/main/camera/"
    click CI_CD "https://github.com/piotrpdev/oko/tree/main/.github/workflows/"
    click DEV1 "https://github.com/piotrpdev/oko/blob/main/make.sh"
    click DEV2 "https://github.com/piotrpdev/oko/tree/main/backend/tests/"

    %% Styles
    classDef ci fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef tools fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef frontend fill:#add8e6,stroke:#333,stroke-width:2px;
    classDef landing fill:#FFE4B5,stroke:#333,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef database fill:#FFDEAD,stroke:#333,stroke-width:2px;
    classDef camera fill:#FFB6C1,stroke:#333,stroke-width:2px;
```
