Skip to content

immnlshn/DonationBox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

103 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

DonationBox

A Raspberry Pi-based interactive donation system with real-time voting capabilities, GPIO hardware control, and a modern web interface.

๐ŸŽฏ Overview

DonationBox is a full-stack application designed for physical donation boxes that allow donors to vote on different categories while making their donations. The system features:

  • Interactive Voting: Donors can choose between multiple categories when donating
  • Real-time Updates: WebSocket-based communication for instant feedback
  • Hardware Integration: GPIO control for physical buttons, sensors, and displays
  • Visual Dashboard: Modern React-based frontend displaying voting results and donation statistics
  • Mock Mode: Full development support without physical hardware

๐Ÿ”ฉ Hardware Reproducibility

This project is designed with reproducability in mind. A detailed, step-by-step guide for rebuilding the physical dontation box is available on Hackster.

The Hackster project documents the complete hardware setup, including required components, wiring diagram, enclosure construction and assembly instructions.

To reproduce the hardware setup pf this project, please follow the instructions provided in this guide:
โžก๏ธHardware build guide on Hackster

This separation allows the GitHub repository to focus on software development and deployment, while all hardware-related documentation is maintained in a dedicated and easily accessible format.

๐Ÿ—๏ธ Architecture

The project consists of two main components:

Backend (FastAPI)

  • RESTful API for managing votes, categories, and donations
  • WebSocket server for real-time communication
  • GPIO service for Raspberry Pi hardware control
  • SQLite database with Alembic migrations
  • Async/await architecture for optimal performance

Frontend (React + Vite)

  • Modern, responsive UI built with React 19
  • Real-time data visualization
  • QR code integration for charity information
  • Animated voting results display

๐Ÿ“‹ Features

  • โœ… Create and manage voting campaigns with multiple categories
  • โœ… Track donations in real-time with category association
  • โœ… Display voting results as they happen
  • โœ… WebSocket support for live updates across all connected clients
  • โœ… GPIO integration for physical buttons and sensors
  • โœ… Mock GPIO mode for development without hardware
  • โœ… Debug endpoints for testing and development
  • โœ… Database migrations with Alembic
  • โœ… CORS support for frontend-backend communication
  • โœ… Comprehensive logging system

๐Ÿš€ Quick Start

Prerequisites

  • Backend:

    • Python 3.10 or higher (tested with Python 3.14)
    • pip package manager
    • Raspberry Pi with GPIO pins (for production) or any system (for development)
  • Frontend:

    • Node.js 16+ and npm/yarn
    • Modern web browser

โš™๏ธ Installation

The full installation and deployment process is documented in the dedicated README inside the deploy/ directory. This includes instructions for configuring the Raspberry Pi environment, installing dependencies, setting environment variables, and running the required deployment scripts.

Please follow the steps described in the deployment README and execute the provided scripts as outlined to ensure a correct and reproducible installation.

๐Ÿ“– API Documentation

Once the backend is running, visit:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

๐ŸŽฎ Usage

Creating & Managing a Voting Campaign

Once the frontend is running, visit: http://localhost:5173/management

This leads to a management site, where active votes can be started and managed.

Hardware Integration

For Raspberry Pi deployment:

  1. Set ENABLE_GPIO=true in your .env file
  2. Set PIN_FACTORY=native for production hardware
  3. Configure GPIO pins in the GPIOService.py
  4. Connect physical buttons/sensors to the configured pins

Development Without Hardware

The system includes a mock GPIO mode that allows full development and testing without physical hardware:

  • Set ENABLE_GPIO=false or PIN_FACTORY=mock
  • Use debug endpoints to simulate GPIO events
  • WebSocket connections work identically to production

๐Ÿ—‚๏ธ Project Structure

DonationBox/
โ”œโ”€โ”€ backend/                               # FastAPI backend
โ”‚   โ”œโ”€โ”€ alembic/                           # Database migrations (Alembic)
โ”‚   โ”‚   โ””โ”€โ”€ versions/                      # Migration versions (schema history)
โ”‚   โ”œโ”€โ”€ core/                              # Core infrastructure (config, DI, lifecycle, logging)
โ”‚   โ”œโ”€โ”€ gpio/                              # Raspberry Pi GPIO integration
โ”‚   โ”‚   โ””โ”€โ”€ components/                    # GPIO hardware components (button, coin validator, etc.)
โ”‚   โ”œโ”€โ”€ models/                            # SQLAlchemy ORM models
โ”‚   โ”œโ”€โ”€ repositories/                      # Data access layer (CRUD + queries)
โ”‚   โ”œโ”€โ”€ routes/                            # API endpoints (REST + WebSocket)
โ”‚   โ”œโ”€โ”€ schemas/                           # Pydantic schemas (request/response DTOs)
โ”‚   โ”œโ”€โ”€ services/                          # Business logic layer
โ”‚   โ”‚   โ”œโ”€โ”€ category/                      # Category management logic
โ”‚   โ”‚   โ”œโ”€โ”€ donation/                      # Donation creation + aggregation + events
โ”‚   โ”‚   โ”œโ”€โ”€ voting/                        # Voting logic + result aggregation
โ”‚   โ”‚   โ””โ”€โ”€ websocket/                     # WebSocket connections + broadcasting
โ”‚   โ”œโ”€โ”€ app.py                             # Application entry point (FastAPI app)
โ”‚   โ””โ”€โ”€ requirements.txt                   # Python dependencies
โ”‚
โ”œโ”€โ”€ deploy/                                # Deployment assets
โ””โ”€โ”€ frontend/                              # React frontend (Vite)
    โ”œโ”€โ”€ public/                            # Public static files
    โ”œโ”€โ”€ src/                               # Frontend source code
    โ”‚   โ”œโ”€โ”€ assets/                        # Images, icons, etc.
    โ”‚   โ”œโ”€โ”€ components/                    # UI components
    โ”‚   โ”œโ”€โ”€ services/                      # REST + WebSocket clients
    โ”‚   โ”œโ”€โ”€ state/                         # Global state management
    โ”‚   โ”œโ”€โ”€ App.jsx                        # Main application component
    โ”‚   โ”œโ”€โ”€ AppRouter.jsx                  # Client-side routing
    โ”‚   โ””โ”€โ”€ main.jsx                       # Application entry point
    โ”œโ”€โ”€ package.json                       # Node.js dependencies & scripts
    โ””โ”€โ”€ vite.config.js                     # Vite configuration

๐Ÿ”ง Configuration

Backend Environment Variables

Variable Default Description
APP_NAME "FastAPI" Application name
ENV "production" Environment (development/production)
DEBUG false Enable debug mode
LOG_LEVEL "INFO" Logging level (DEBUG/INFO/WARNING/ERROR)
DATABASE_URL "sqlite:///./backend/database.db" Database connection string
ALLOWED_ORIGINS [] CORS allowed origins
ENABLE_GPIO false Enable GPIO hardware control
PIN_FACTORY "mock" GPIO pin factory (mock/native)

๐Ÿ› ๏ธ Development

Backend Development

cd backend

# Activate virtual environment
source .venv/bin/activate

# Run with auto-reload
python -m uvicorn backend.app:app --reload --host 0.0.0.0 --port 8000

# Create a new migration
alembic revision --autogenerate -m "Description of changes"

# Apply migrations
alembic upgrade head

# Run linting (if configured)
pylint backend/

Frontend Development

cd frontend

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

# Run linter
npm run lint

๐Ÿ“ License

MIT License

This project is licensed under the MIT License. You are free to use, modify, and distribute this software under the conditions stated in the LICENSE file.

๐Ÿ“ง Contact

This project is part of a university group project at the University of Cologne and the Cologne Institute for Information Systems (CIIS), conducted within the course Sustainable Digital Innovation Lab (SDIL) by the following contributors:

๐Ÿ™ Acknowledgments


Made with โค๏ธ for interactive charitable giving

About

This project is part of a university group project at the University of Cologne and the Cologne Institute for Information Systems (CIIS), conducted within the course Sustainable Digital Innovation Lab (SDIL) . It's a hardware donation system for a RaspberryPI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors