CiTBIN Web Application
The CiTBIN Web Application is the primary user interface of the platform. It provides operators with a centralized dashboard for monitoring waste bins, managing devices, and viewing sensor data collected by the backend.
Built with Next.js, React, and TypeScript, the frontend communicates exclusively with the REST API exposed by the backend.
Features
- Interactive dashboard
- Waste bin overview
- Device management
- Live sensor data visualization
- Responsive user interface
- REST API integration
- Modern React component architecture
- TypeScript support
- Tailwind CSS styling
- Dark mode support (if enabled)
Technology Stack
| Component | Technology |
|---|---|
| Framework | Next.js |
| Language | TypeScript |
| UI Library | React |
| Styling | Tailwind CSS |
| HTTP Client | Fetch API |
| Package Manager | npm |
Architecture
FastAPI Backend
│
REST API
│
┌───────────────┴───────────────┐
│ │
React Components API Client
│ │
└───────────────┬───────────────┘
│
Next.js Application
│
Browser InterfaceThe frontend contains no business logic regarding sensor processing. All sensor decoding, MQTT communication, and database interactions are handled by the backend.
Project Structure
apps/web/
├── app/
│ ├── dashboard/
│ ├── devices/
│ ├── trashbins/
│ ├── settings/
│ └── layout.tsx
│
├── components/
│ ├── ui/
│ ├── dashboard/
│ ├── trashbin/
│ └── device/
│
├── lib/
│
├── public/
│
├── styles/
│
├── utils/
│
└── package.jsonApplication Structure
The application follows the Next.js App Router architecture.
Main areas include:
- Dashboard
- Waste Bin Management
- Device Management
- Settings
- Shared Components
- API Communication
- Utility Functions
Dashboard
The dashboard provides an overview of the entire system.
Typical information includes:
- Total waste bins
- Active devices
- Current fill levels
- Recent measurements
- System status
The dashboard should provide users with the most important information at a glance.
Waste Bin Management
The waste bin pages allow users to:
- View all waste bins
- Inspect individual bins
- View current fill level
- Display historical measurements
- Edit waste bin information
- Assign devices
Device Management
The device section provides functionality for managing installed sensor devices.
Typical operations include:
- View registered devices
- Display device information
- Check battery status
- Assign devices to waste bins
- Remove inactive devices
API Communication
The frontend communicates exclusively with the backend REST API.
Typical requests include:
GET /api/v1/trashbin
GET /api/v1/device
GET /api/v1/trashbin-data
POST /api/v1/deviceNo direct database access exists within the frontend.
Environment Variables
Create a local environment file.
cp .env.example .env.localTypical configuration includes:
NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1Installation
Install all dependencies.
npm installor
npm ciDevelopment
Start the development server.
npm run devOpen the application in your browser.
http://localhost:3000Hot reload is enabled by default.
Production Build
Create an optimized production build.
npm run buildStart the production server.
npm run startLinting
Run ESLint.
npm run lintKeeping the codebase lint-free ensures consistent formatting and improves maintainability.
Component Architecture
The frontend follows a component-based architecture.
Components should:
- remain reusable
- avoid duplicated logic
- receive data via props
- separate presentation from business logic
Shared UI elements belong in the common component directory, while page-specific components should remain close to their respective pages.
State Management
The application primarily relies on:
- React state
- React hooks
- API requests
Business logic should remain inside the backend whenever possible.
Styling
Styling is implemented using Tailwind CSS.
Recommended practices:
- Use utility classes whenever possible.
- Keep components responsive.
- Avoid inline styles.
- Reuse shared UI components.
Development Workflow
- Start the infrastructure.
- Start the backend API.
- Start the frontend.
- Verify API connectivity.
- Implement UI changes.
- Test responsive layouts.
- Commit your changes.
Troubleshooting
Backend cannot be reached
Verify that the backend is running and accessible.
http://localhost:8000/api/docsAlso check the configured API URL in .env.local.
Page does not update
Restart the development server.
npm run devClear the browser cache if necessary.
Build fails
Verify:
- Node.js version
- Installed dependencies
- Environment variables
- TypeScript errors
Run:
npm run lint
npm run buildRelated Documentation
- Root Documentation:
../../README.md - Backend Documentation:
../api/README.md - Infrastructure Documentation:
../../infrastructure/README.md
to the following class 12/3
- your main focus will be to upgrade/improve the web frontend