The Waste Management System backend is the central hub of the project, responsible for managing data, processing business logic, and providing APIs to the frontend, mobile application, and IoT devices. Built with Spring Boot, Gradle, and H2 Database, this backend ensures seamless communication between all system components.
The Waste Management System is a comprehensive solution for monitoring and managing waste collection. The backend is designed to:
-
IoT Integration:
- Receive real-time updates on bin statuses from IoT devices
- Process and store data in the H2 database
-
API Services:
- Provide REST APIs for the frontend and mobile application
-
Driver Functionality:
- Enable drivers to fetch bin statuses and navigate to bin locations using optimized routes
-
Real-Time System Connectivity:
- Facilitate continuous communication between IoT devices, the backend, and the user-facing applications
To run the backend application, ensure you have the following installed:
- Java (11 or later)
- Gradle (7.0 or later)
Clone the backend repository to your local machine:
git clone [email protected]:bronglil/Waste-Mangement-.git
cd Waste-Mangement-System
The backend uses an embedded H2 database by default. The configuration is located in the application.properties
file under src/main/resources
.
Default H2 configuration:
spring.application.name=garbagecollection
# Spring Boot: configure H2 datasource
spring.datasource.url=jdbc:h2:file:./database/main
spring.datasource.username=sa
spring.datasource.password=passpass
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.hibernate.ddl-auto=update
# Spring Boot: activate H2 console
spring.h2.console.enabled=true
spring.h2.console.path=/console
# APIs configuration
springdoc.api-docs.path=/v3/api-docs
springdoc.swagger-ui.path=/swagger-ui.html
springdoc.swagger-ui.enabled=true
springdoc.api-docs.enabled=true
# Security configuration
spring.security.user.name=admin
spring.security.user.password=admin123
# JWT secret
jwt.secret=dK3yqWbvX9Zp2mNcR5tJ7hFgE4nM8sBaL6wY1xV0jH4uQ9kD2pT5nR8mC3fA7vB
# Server configuration
server.address=0.0.0.0
server.port=8080
You can access the H2 database console at: http://localhost:8080/h2-console
- JDBC URL: jdbc:h2:file:./database/main
- Username: sa
- Password: passpass
Build the project using Gradle:
./gradlew build
Start the backend server:
./gradlew bootRun
The backend will be available at http://localhost:8080
- Real-Time Monitoring: Receives and processes bin updates from IoT devices
- API Services: Provides endpoints for the frontend and mobile app
- Driver Functionality: Supports route optimization and bin status updates
- Embedded Database: Utilizes H2 for quick and lightweight data storage
The backend of the Waste Management System provides various RESTful APIs for managing users, administrators, drivers, vehicles, bins, routing, and dashboard metrics. Below is a detailed list of endpoints categorized by their functionality.
-
POST
/api/auth/signup
- Sign up users.
-
POST
/api/auth/login
- Log in users.
-
GET
/api/admin/{id}
- Get admin by ID.
-
PUT
/api/admin/{id}
- Update admin by ID.
-
DELETE
/api/admin/{id}
- Delete admin by ID.
-
PUT
/api/admin/update_driver/{id}
- Update driver by ID.
-
POST
/api/admin/create_driver
- Add a new driver.
-
GET
/api/admin
- Get all admins.
-
GET
/api/admin/{name}
- Get admin by name.
-
GET
/api/admin/get_drivers
- Get all drivers.
-
GET
/api/admin/get_driver/{id}
- Get a single driver by ID.
-
GET
/api/admin/admins
- Get all admins.
-
DELETE
/api/admin/remove_driver/{id}
- Delete a driver by ID.
-
GET
/api/vehicles/{id}
- Get vehicle by ID.
-
PUT
/api/vehicles/{id}
- Update vehicle by ID.
-
DELETE
/api/vehicles/{id}
- Delete vehicle by ID.
-
GET
/api/vehicles
- Get all vehicles.
-
POST
/api/vehicles
- Add a new vehicle.
-
GET
/api/drivers/{id}
- Get a single driver by ID.
-
PUT
/api/drivers/{id}
- Update a driver by ID.
-
DELETE
/api/drivers/{id}
- Delete a driver by ID.
-
GET
/api/drivers
- Get all drivers.
-
POST
/api/drivers
- Add a new driver.
-
GET
/api/drivers/name/{name}
- Get drivers by name.
-
GET
/api/drivers/available-drivers
- Get all available drivers.
-
GET
/api/bins/{id}
- Get bin by ID.
-
PUT
/api/bins/{id}
- Update bin by ID.
-
DELETE
/api/bins/{id}
- Delete bin by ID.
-
PATCH
/api/bins/{id}
- Partially update bin by ID.
-
GET
/api/bins
- Get all bins.
-
POST
/api/bins
- Add a new bin.
-
POST
/api/bins/location
- Add or update bin location.
- GET
/api/routes/shortest
- Get the shortest route for waste collection.
- GET
/api/dashboard/metrics
- Get dashboard metrics for monitoring system performance.
We welcome contributions! To contribute:
- Fork the repository
- Create a feature branch
- Submit a pull request with your changes
This project is licensed under the MIT License.
src/main/java/com/example/garbagecollection/
├── config/
│ └── DatabaseConfig.java # Configuration for database connections
├── controller/
│ ├── BinController.java # REST API for managing bins
│ └── DriverController.java # REST API for managing drivers
| └── vehicleController.java # REST API for managing vehicles
├── dto/
│ ├── BinRequestDTO.java # Data Transfer Object for bin requests
│ └── DriverRequestDTO.java # Data Transfer Object for driver requests
| └── vehicleRequestDTO.java
├── entity/
│ ├── Bin.java # Entity class representing bins
│ └── Driver.java # Entity class representing drivers
| └── vehicle.java
├── exception/
│ └── CustomExceptionHandler.java# Global exception handling
├── repository/
│ ├── BinRepository.java # Repository for bin-related database operations
│ └── DriverRepository.java # Repository for driver-related database operations
| └── vehicleRepository.java
├── service/
│ ├── BinService.java # Interface for bin services
│ ├── BinServiceImpl.java # Implementation of bin services
│ ├── DriverService.java # Interface for driver services
│ └── DriverServiceImpl.java # Implementation of driver services
│ └── VehicleServiceImpl.java
│ ├── VehicleService.java
├── util/
│ └── GeoUtils.java # Utility class for geospatial calculations
└── GarbageCollectionApplication.java # Main application entry point