CiTBIN
Smart IoT waste monitoring platform powered by mioty, MQTT, FastAPI, and Next.js.
Overview
CiTBIN is an IoT platform for monitoring public waste bins using wireless sensors. Sensor data is transmitted through a mioty network, forwarded via MQTT, processed by a FastAPI backend, stored in PostgreSQL, and visualized through a modern Next.js web application.
The project was developed as part of an initiative at the Hohentwiel Gewerbeschule Singen.
The project will be published under the following adress: https://citbin.sybit.education
Its modular architecture allows developers to easily integrate new sensor types, waste bin models, and visualization features while keeping the system maintainable and scalable.
Features
- Real-time waste bin monitoring
- mioty sensor integration
- MQTT-based communication
- Automatic payload decoding
- Device management
- Historical measurement storage
- Interactive web dashboard
- REST API
- Automatic database migrations
- Docker development environment
- Sensor simulator
- Extensible architecture for additional sensor types
Architecture
+----------------------+
| mioty Sensors |
+----------+-----------+
|
mioty Network
|
v
MQTT Message Broker
|
v
+----------------------+
| FastAPI Backend |
| MQTT Client & Parser |
+----------+-----------+
|
Payload Processing Engine
|
+--------------+--------------+
| |
v v
PostgreSQL Database REST API
|
|
v
Next.js Web FrontendHow It Works
The complete data flow is illustrated below.
- A mioty sensor periodically measures the fill level of a waste bin.
- The measurement is transmitted over the mioty network.
- The network forwards the payload to an MQTT broker.
- The backend subscribes to the configured MQTT topics.
- Incoming payloads are decoded.
- The correct sensor implementation processes the payload.
- Device information is validated.
- Measurements are stored inside PostgreSQL.
- The REST API exposes the processed data.
- The web frontend visualizes the latest information.
Repository Structure
citbin/
├── apps/
│ ├── api/
│ │ ├── api/
│ │ ├── routers/
│ │ ├── models/
│ │ ├── modules/
│ │ ├── migrations/
│ │ └── tests/
│ │
│ ├── web/
│ │ ├── app/
│ │ ├── components/
│ │ ├── utils/
│ │ └── styles/
│ │
│ └── simulator/
│
├── infrastructure/
│
├── docs/
│
└── README.mdProject Components
Backend (apps/api)
The backend is built with FastAPI and is responsible for all business logic.
Responsibilities include:
- MQTT communication
- Payload decoding
- Device management
- Waste bin management
- Database access
- REST API
- Automatic migrations
- Sensor abstraction
- Logging
More information can be found in:
apps/api/README.mdFrontend (apps/web)
The frontend is developed using Next.js, React, and TypeScript.
It provides:
- Interactive dashboard
- Waste bin overview
- Administrative tools
- Device management
- Live status information
- Responsive design
Documentation:
apps/web/README.mdInfrastructure
The infrastructure directory contains everything required for local development and deployment.
Included services:
- PostgreSQL
- Docker Compose
- Environment configuration
Documentation:
infrastructure/README.mdDocs
The documentation files in the docs folder can be viewed as a website.
cd docs/
npm install # Einmal am Anfang
npm run docs:devSimulator
The simulator generates artificial sensor payloads for development and testing.
It enables backend development without requiring physical mioty hardware.
Technology Stack
Backend
- Python 3.11+
- FastAPI
- SQLModel
- SQLAlchemy
- Alembic
- PostgreSQL
- Uvicorn
- Paho MQTT
Frontend
- Next.js
- React
- TypeScript
- Tailwind CSS
Infrastructure
- Docker
- Docker Compose
Communication
- MQTT
- REST API
- HTTP
- JSON
Getting Started
Requirements
Install the following software before starting development.
| Software | Version |
|---|---|
| Python | 3.11+ |
| Node.js | 20+ |
| Docker | Latest |
| Git | Latest |
| UV | Recommended |
Clone the Repository
git clone https://github.com/your-organization/citbin.git
cd citbinStart the Infrastructure
cd infrastructure
docker compose up -dThis starts the required services, including PostgreSQL.
Start the Backend
cd apps/api
cp .env.example .env
uv sync
uv run uvicorn app:app --reloadThe backend automatically:
- connects to PostgreSQL
- executes pending database migrations
- connects to the MQTT broker
- subscribes to configured topics
- starts the REST API
API documentation:
http://localhost:8000/api/docsStart the Frontend
cd apps/web
npm install
npm run devOpen:
http://localhost:3000Development Workflow
Typical workflow:
- Start Docker services.
- Start the backend.
- Start the frontend.
- Connect a simulator or real mioty sensor.
- Verify incoming MQTT messages.
- Observe decoded measurements.
- Check the web dashboard.
Environment Variables
Each application contains a .env.example.
Copy it before running the application.
cp .env.example .envDatabase Migrations
Apply migrations:
uv run alembic upgrade headCreate a migration:
uv run alembic revision --autogenerate -m "Description"Rollback:
uv run alembic downgrade -1Documentation
Additional documentation is available in the docs/ directory, including project organization, software development, hardware integration, operational notes, and meeting protocols.
Acknowledgements
CiTBIN combines modern web technologies with low-power IoT communication to demonstrate a scalable smart-city solution for waste management.
Core technologies include:
- FastAPI
- Next.js
- PostgreSQL
- Docker
- MQTT
- mioty
- SQLModel
- Alembic