# angelgpaulin/smart-waste-sorter architecture

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

- Interactive diagram: https://gitdiagram.com/angelgpaulin/smart-waste-sorter
- Repository: https://github.com/angelgpaulin/smart-waste-sorter

## Overview

##### Project Type and Purpose
- This is a full-stack, microservice-style recycling management system.
- It comprises four modules:
- A mobile client (Flutter/Dart)
- A web frontend (Next.js/React)
- A RESTful API backend (NestJS + PostgreSQL)
- An AI classification service (Python + FastAPI + CNN model)
- The goal is to let users scan and classify waste, manage recycling routes, view analytics, and administer the system.

##### File Structure
- Top-level folders map to modules:
- Recycling_CNN_IA → Python IA microservice
- Recycling_Nest_Backend → NestJS API
- Recycling_Next_Frontend → Next.js web frontend
- reciclaje_app_backend/postgres → PostgreSQL data volume
- IA folder contains: FastAPI app.py, CNN model loader, Dockerfile, docker-compose.yml, helper scripts for dataset processing, static uploads.
- Nest backend is organized by domain modules (auth, users, bin-waste-type, collection, etc.), uses JWT guard/strategy, TypeORM entities, DTOs. Has its own docker-compose.
- Frontend is a Next.js 13 “app” directory structure, global CSS, middleware, API helper, constants.
- PostgreSQL storage under reciclaje_app_backend holds the database state (managed via Docker volume).

##### README Insights
- Confirms four modules, technology stacks, run instructions, integration points.
- IA runs as a microservice consumed by the mobile or backend.
- Backend exposes REST endpoints for user, route, recycling history management.
- Frontend is an admin/analytics dashboard; mobile app leverages same APIs.

##### Components
a. Main Components
1. Mobile App (Flutter/Dart)
2. Web Frontend (Next.js/React)
3. API Backend (NestJS/TypeScript)
4. AI Service (FastAPI + CNN model)
5. Database (PostgreSQL)
6. (Optional) GitHub Actions / CI pipeline
b. Relationships & Data Flows
– Mobile App ↔→ Backend API (HTTP/JSON)
– Web Frontend ↔→ Backend API (HTTP/JSON)
– Backend API →→ PostgreSQL (via TypeORM)
– Backend API ↔→ AI Service (HTTP/JSON for image classification)
– Mobile App may call AI Service directly for on-demand classification
– Docker Compose orchestrates Backend + IA + Postgres
– GitHub (.github/CODEOWNERS) triggers CI/CD on push
c. Architectural Patterns & Principles
– Microservices: IA separate from core API
– Modular monolith (NestJS modules per domain)
– MVC‐like layering inside Nest (controllers → services → repositories/entities)
– Infrastructure as code: docker-compose for multi-container setup
d. Key Technologies / Libraries
– NestJS, TypeORM, JWT Auth Guard
– FastAPI, TensorFlow/Keras CNN model (`modelo_residuos.h5`)
– Next.js 13 (App Directory), React, fetch/axios in lib/api.ts
– Docker, Docker Compose, Git LFS for large model

##### Detail
- Volume mounts: e.g., Postgres data directory under reciclaje_app_backend/postgres.
- External dependencies (OpenAI API key for IA, Git LFS).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Tier
    subgraph "Client Tier"
        MobileApp["Mobile App (Flutter/Dart)"]:::ui
        NextFrontend["Next.js Frontend"]:::ui
    end

    %% Docker Compose Boundary
    subgraph "Docker Compose"
        subgraph "Services"
            Backend["NestJS API (Port: 3000)"]:::service
            AIService["AI Service (FastAPI) (Port: 8000)"]:::service
        end
        Postgres[(PostgreSQL)]:::database
    end

    %% CI/CD
    GitHub["GitHub CI/CD"]:::ci

    %% Connections
    MobileApp -->|HTTP/JSON| Backend
    NextFrontend -->|HTTP/JSON| Backend
    MobileApp -->|HTTP/JSON| AIService
    Backend -->|HTTP/JSON| AIService
    Backend -->|TypeORM| Postgres

    %% Click Events for Component Mapping
    click NextFrontend "https://github.com/angelgpaulin/smart-waste-sorter/tree/main/Recycling_Next_Frontend"
    click Backend "https://github.com/angelgpaulin/smart-waste-sorter/tree/main/Recycling_Nest_Backend"
    click AIService "https://github.com/angelgpaulin/smart-waste-sorter/tree/main/Recycling_CNN_IA"
    click Postgres "https://github.com/angelgpaulin/smart-waste-sorter/tree/main/reciclaje_app_backend/postgres"
    click GitHub "https://github.com/angelgpaulin/smart-waste-sorter/blob/main/.github"

    %% Styles
    classDef ui fill:#E0F7FA,stroke:#006064,color:#006064
    classDef service fill:#E8F5E9,stroke:#2E7D32,color:#2E7D32,stroke-width:2px
    classDef database fill:#FFF3E0,stroke:#EF6C00,color:#E65100,stroke-width:2px
    classDef ci fill:#F3E5F5,stroke:#6A1B9A,color:#4A148C,stroke-width:2px
```
