# aidrecabrera/polybin-app architecture

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

- Interactive diagram: https://gitdiagram.com/aidrecabrera/polybin-app
- Repository: https://github.com/aidrecabrera/polybin-app

## Overview

##### Main System Components

a) Frontend Layer:
- PWA Container (React + Vite)
- UI Components (shadcn/ui + TailwindCSS)
- Data Visualization (Recharts)
- Service Worker (VitePWA)
- Client-side Caching

b) Backend Layer (Supabase):
- Real-time Database
- Authentication Service
- REST API Endpoints
- WebSocket Connections

c) Data Stores:
- Alert Logs
- Bin Levels
- Disposal Logs
- Prediction Logs

##### Component Relationships

**[PWA Frontend] <---> [Supabase Client] <---> [Supabase Backend]**

- v
**[Service Worker] <--> [Browser Cache]**

##### Data Flow Patterns

Key flows:
- Real-time updates via Supabase Realtime
- Offline data access through Service Worker
- Push notifications path
- Audio alert system flow

##### Specific Implementation Details

Create sections for:

a) Monitoring Features:
- Bin level monitoring
- Disposal tracking
- Prediction analysis
- Alert system

b) PWA Features:
- Offline capability
- Push notifications
- Asset caching
- Installation flow

##### Detailed Component Breakdown

Frontend Structure (based on src/components):
**UI Layer**
- Charts
- Alert Historical
- Bin Historical
- Disposal Historical
- Prediction Charts
- Tables
- Dispose
- Prediction
- Core Components
- Recent Alerts
- Recent Disposal
- Recent Prediction

##### Integration with the physical Polybin system

Use standardized symbols:
- Rectangles for services
- Hexagons for external systems

This system design should reflect the application's focus on real-time monitoring, offline capabilities, and efficient data visualization while maintaining clarity about how all components interact to provide a seamless user experience.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Frontend["Frontend Layer"]
        direction TB
        PWA["PWA Container (React + Vite)"]:::frontend
        UI["UI Components"]:::frontend
        DataViz["Data Visualization"]:::frontend
        SW["Service Worker"]:::offline
        Cache["Browser Cache"]:::offline
        
        subgraph Components["Core Components"]
            direction TB
            RecentAlerts["Recent Alerts"]:::frontend
            RecentDisposal["Recent Disposal"]:::frontend
            RecentPred["Recent Prediction"]:::frontend
        end

        subgraph Charts["Data Visualization"]
            direction TB
            AlertChart["Alert Charts"]:::frontend
            BinChart["Bin Level Charts"]:::frontend
            DisposalChart["Disposal Charts"]:::frontend
            PredictionChart["Prediction Charts"]:::frontend
        end

        subgraph Tables["Data Tables"]
            direction TB
            DisposeTable["Disposal Tables"]:::frontend
            PredTable["Prediction Tables"]:::frontend
        end
    end

    subgraph Backend["Backend Layer (Supabase)"]
        direction TB
        SupaClient["Supabase Client"]:::backend
        Auth["Authentication Service"]:::backend
        API["REST API Endpoints"]:::backend
        WSConn["WebSocket Connections"]:::backend
        
        subgraph DataStores["Data Stores"]
            direction TB
            AlertDB[(Alert Logs)]:::database
            BinDB[(Bin Levels)]:::database
            DisposalDB[(Disposal Logs)]:::database
            PredictionDB[(Prediction Logs)]:::database
        end
    end

    %% Connections
    PWA <--> SupaClient
    SupaClient <--> Auth
    SupaClient <--> API
    SupaClient <--> WSConn
    SW <--> Cache
    Cache <--> PWA

    %% Data Store Connections
    API <--> AlertDB
    API <--> BinDB
    API <--> DisposalDB
    API <--> PredictionDB
    WSConn <--> AlertDB
    WSConn <--> BinDB
    WSConn <--> DisposalDB
    WSConn <--> PredictionDB

    %% Click Events
    click PWA "https://github.com/aidrecabrera/polybin-app/blob/main/src/main.tsx"
    click SW "https://github.com/aidrecabrera/polybin-app/blob/main/public/sw.js"
    click SupaClient "https://github.com/aidrecabrera/polybin-app/blob/main/src/client/supabaseClient.ts"
    click Auth "https://github.com/aidrecabrera/polybin-app/blob/main/src/lib/auth.ts"
    click RecentAlerts "https://github.com/aidrecabrera/polybin-app/blob/main/src/components/recent-alerts.tsx"
    click RecentDisposal "https://github.com/aidrecabrera/polybin-app/blob/main/src/components/recent-disposal.tsx"
    click RecentPred "https://github.com/aidrecabrera/polybin-app/blob/main/src/components/recent-prediction.tsx"
    click AlertChart "https://github.com/aidrecabrera/polybin-app/tree/main/src/components/charts/alert-historical/"
    click BinChart "https://github.com/aidrecabrera/polybin-app/tree/main/src/components/charts/bin-level/"
    click DisposalChart "https://github.com/aidrecabrera/polybin-app/tree/main/src/components/charts/disposal-historical/"
    click PredictionChart "https://github.com/aidrecabrera/polybin-app/tree/main/src/components/charts/prediction-chart/"
    click DisposeTable "https://github.com/aidrecabrera/polybin-app/tree/main/src/components/table/dispose/"
    click PredTable "https://github.com/aidrecabrera/polybin-app/tree/main/src/components/table/prediction/"

    %% Styles
    classDef frontend fill:#3b82f6,color:#fff
    classDef backend fill:#22c55e,color:#fff
    classDef database fill:#f97316,color:#fff
    classDef offline fill:#6b7280,color:#fff
    classDef realtime fill:#a855f7,color:#fff

    %% Legend
    subgraph Legend
        direction TB
        Frontend_["Frontend"]:::frontend
        Backend_["Backend"]:::backend
        Database_["Database"]:::database
        Offline_["Offline Components"]:::offline
        Realtime_["Realtime Features"]:::realtime
    end
```
