# trashtrackteam/trashtrack architecture

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

- Interactive diagram: https://gitdiagram.com/trashtrackteam/trashtrack
- Repository: https://github.com/trashtrackteam/trashtrack

## Overview

##### Main Components Identification

a. Mobile Application (apps/app)
- Frontend UI built with React, Ionic, and Capacitor
- User-facing interface for waste bin locations and complaints
- Operator dashboard for management

b. Backend Server (apps/api)
- NestJS-based REST API
- Prisma ORM with PostgreSQL database
- Authentication and business logic handling

c. IoT Devices (apps/iot)
- ESP-based hardware implementation
- Sensor integration for waste monitoring
- Real-time data collection

**[Mobile Application Layer]**

- Public User Interface
- Waste Bin Locator
- Complaint System
- Report Viewer

- Operator Dashboard
- Waste Management
- Analytics
- User Management

- ↕️ REST API Calls

**[Backend Server Layer]**

- API Controllers
- User Management
- Trash Bin Management
- Reports & Feedback
- History Tracking

- Database (PostgreSQL)
- User Data
- Trash Bin Data
- Reports
- Analytics

- IoT Integration Service

- ↕️ IoT Communication

**[IoT Device Layer]**

- Sensors
- Capacity Sensors
- Other Monitoring Sensors

- Control Systems
- Data Transmission Module

##### Key Interactions to Highlight

a. Data Flow:
- IoT devices → Backend Server (real-time monitoring)
- Backend Server → Mobile App (status updates)
- Mobile App → Backend Server (user actions)

b. Authentication Flow:
- User login/registration process
- Operator authentication
- API security layer

c. Real-time Operations:
- Waste bin status monitoring
- Report submission and tracking
- Analytics data collection

##### Additional Elements

a. External Services:
- File storage for images
- Push notification system
- Maps integration

b. Security Layers:
- API authentication
- Data encryption
- User role management

##### Implementation Details

- NestJS modular architecture
- Prisma ORM integration
- React/Ionic frontend structure
- IoT device communication protocols
- RESTful API endpoints organization

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Mobile
        UI["Public User Interface"]
        OD["Operator Dashboard"]
        
        subgraph "Public Interface Components"
            WL["Waste Bin Locator"]
            CS["Complaint System"]
            RV["Report Viewer"]
        end
        
        subgraph "Operator Components"
            WM["Waste Management"]
            AN["Analytics"]
            UM["User Management"]
        end
        
        UI --> WL & CS & RV
        OD --> WM & AN & UM
    end
    
    subgraph Backend
        API["API Controllers"]
        DB[(PostgreSQL)]
        IIS["IoT Integration Service"]
        
        subgraph "API Components"
            UMC["User Management Controller"]
            TMC["Trash Bin Management Controller"]
            RFC["Reports & Feedback Controller"]
            HTC["History Tracking Controller"]
        end
        
        subgraph "Database"
            UD["User Data"]
            TD["Trash Bin Data"]
            RD["Reports"]
            AD["Analytics"]
        end
        
        API --> UMC & TMC & RFC & HTC
        UMC & TMC & RFC & HTC --> DB
        DB --> UD & TD & RD & AD
    end
    
    subgraph IoT
        SEN["Sensors"]
        CS2["Control Systems"]
        
        subgraph "Sensor Components"
            CAP["Capacity Sensors"]
            OMS["Other Monitoring Sensors"]
        end
        
        subgraph "Control Components"
            DTM["Data Transmission Module"]
        end
        
        SEN --> CAP & OMS
        CS2 --> DTM
    end
    
    Mobile <--> Backend
    Backend <--> IoT
    
    %% Click Events
    click UI "https://github.com/trashtrackteam/trashtrack/tree/main/apps/app/src/pages/complain/"
    click OD "https://github.com/trashtrackteam/trashtrack/tree/main/apps/app/src/pages/operator/"
    click API "https://github.com/trashtrackteam/trashtrack/tree/main/apps/api/src/model/"
    click DB "https://github.com/trashtrackteam/trashtrack/blob/main/apps/api/prisma/schema.prisma"
    click UMC "https://github.com/trashtrackteam/trashtrack/tree/main/apps/api/src/model/user/"
    click TMC "https://github.com/trashtrackteam/trashtrack/tree/main/apps/api/src/model/trash-bin/"
    click RFC "https://github.com/trashtrackteam/trashtrack/tree/main/apps/api/src/model/report/"
    click HTC "https://github.com/trashtrackteam/trashtrack/tree/main/apps/api/src/model/history/"
    click IoT "https://github.com/trashtrackteam/trashtrack/tree/main/apps/iot/main/"
    click DTM "https://github.com/trashtrackteam/trashtrack/blob/main/apps/iot/prototype/prototype.ino"
    
    %% Styling
    classDef mobile fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef iot fill:#e67e22,stroke:#d35400,color:white
    classDef database fill:#95a5a6,stroke:#7f8c8d,color:white
    
    class UI,OD,WL,CS,RV,WM,AN,UM mobile
    class API,IIS,UMC,TMC,RFC,HTC backend
    class SEN,CS2,CAP,OMS,DTM iot
    class DB,UD,TD,RD,AD database
```
