Skip to content

Latest commit

ย 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ—‘๏ธ เคธเฅเคตเคšเฅเค› เคจเค—เคฐ (SwachhNagar) โ€” Smart Waste Management System

เคธเฅเคตเคšเฅเค› เคจเค—เคฐ means "Clean City" in Hindi โ€” a fitting name for a platform that digitizes and streamlines urban waste collection, routing, and citizen reporting.

SwachhNagar is a full-stack web application for managing municipal waste operations. It provides a role-based dashboard for admins, field staff, and citizens to coordinate collection schedules, manage vehicles and routes, track complaints, and visualize analytics โ€” all in one platform.

TypeScript React Node.js


๐Ÿ“Œ Table of Contents


๐ŸŒŸ Overview

Urban waste management in Indian cities is largely undigitized โ€” collection schedules are inconsistent, citizens have no way to report issues, and municipal staff work without route optimization or tracking tools.

SwachhNagar addresses this by providing:

  • A centralized dashboard for admins to manage routes, vehicles, and staff
  • Digital scheduling so collection times are predictable and trackable
  • A citizen portal to submit complaints and receive notifications
  • Analytics & reports to measure collection efficiency over time

The app uses a React + TypeScript frontend and a Node.js + Express backend, with support for multiple authentication contexts and role-based access control.


โœจ Key Features

Feature Description
๐Ÿ” Role-Based Auth Separate access levels for Admin, Staff, and Citizen
๐Ÿ“… Collection Scheduling Create and manage waste pickup schedules by zone
๐Ÿ—บ๏ธ Route Management Define and optimize collection routes for field staff
๐Ÿš› Vehicle Management Track vehicles, assign to routes, monitor availability
๐Ÿ“ข Citizen Reporting Citizens can submit waste-related complaints and issues
๐Ÿ”” Notifications Status updates sent to citizens on complaint resolution
๐Ÿ“Š Analytics Dashboard Visual reports on collection rates, complaints, and performance
๐Ÿ‘ฅ User Management Admin can add/remove staff and citizen accounts

๐Ÿ‘ฅ User Roles

๐Ÿ”ด Admin

  • Full access to all modules
  • Manages staff accounts, routes, vehicles, and zones
  • Views analytics and generates reports
  • Reviews and resolves citizen complaints

๐ŸŸก Staff

  • Views assigned routes and schedules
  • Updates collection status (pending / in-progress / completed)
  • Receives task assignments from admin

๐ŸŸข Citizen

  • Registers and logs in to the portal
  • Submits waste collection complaints with location details
  • Tracks the status of their submitted reports
  • Receives notifications on resolution

๐Ÿ› ๏ธ Tech Stack

Frontend

Technology Purpose
React 18 UI component library
TypeScript Type-safe frontend code
Vite Fast build tool and dev server
React Router DOM Client-side routing
Axios HTTP client for API calls

Backend

Technology Purpose
Node.js JavaScript runtime
Express.js REST API framework
MongoDB (optional) Persistent database (demo uses in-memory seeds)
JWT Stateless authentication tokens

๐Ÿ“ Project Structure

waste_management_system/
โ”‚
โ”œโ”€โ”€ backend/                          # Node.js + Express REST API
โ”‚   โ”œโ”€โ”€ routes/                       # API route handlers
โ”‚   โ”‚   โ”œโ”€โ”€ auth.js                   # Login, register, token refresh
โ”‚   โ”‚   โ”œโ”€โ”€ collections.js            # Collection schedule CRUD
โ”‚   โ”‚   โ”œโ”€โ”€ routes.js                 # Route management
โ”‚   โ”‚   โ”œโ”€โ”€ vehicles.js               # Vehicle management
โ”‚   โ”‚   โ”œโ”€โ”€ complaints.js             # Citizen complaint CRUD
โ”‚   โ”‚   โ””โ”€โ”€ users.js                  # User management
โ”‚   โ”œโ”€โ”€ models/                       # Data models / schemas
โ”‚   โ”œโ”€โ”€ config.js                     # Server configuration
โ”‚   โ”œโ”€โ”€ config_fixed.js               # Alternate config variant
โ”‚   โ””โ”€โ”€ index.js                      # App entry point
โ”‚
โ”œโ”€โ”€ frontend/                         # React + TypeScript + Vite SPA
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ context/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AuthContext.tsx        # Primary auth context
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AuthContext_fixed.tsx  # Fixed/stable auth variant
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ AuthContext_backend.tsx# Backend-integrated auth variant
โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Dashboard.tsx      # Main admin/staff home
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Analytics.tsx      # Charts and performance reports
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Collections.tsx    # Schedule management
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Routes.tsx         # Route management
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Vehicles.tsx       # Vehicle management
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Complaints.tsx     # Citizen complaint tracking
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Users.tsx          # User management (admin)
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Notifications.tsx  # Notification center
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ shared/               # Reusable UI components
โ”‚   โ”‚   โ”œโ”€โ”€ main.tsx                  # App entry point
โ”‚   โ”‚   โ”œโ”€โ”€ main_fixed.tsx            # Alternate entry (App_fixed variant)
โ”‚   โ”‚   โ””โ”€โ”€ App_fixed.tsx             # Stable app variant
โ”‚   โ”œโ”€โ”€ index.html                    # HTML root (points to main_fixed.tsx)
โ”‚   โ””โ”€โ”€ vite.config.ts
โ”‚
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md

๐Ÿš€ Getting Started

Prerequisites

  • Node.js v18+ โ†’ Download
  • npm or yarn
  • (Optional) MongoDB for persistent storage โ€” demo works with in-memory seeds

1. Backend Setup

# Navigate to the backend directory
cd backend

# Install dependencies
npm install

# Start the development server
npm run dev
# or
node index.js

The backend will start on the port defined in backend/config.js. Check the terminal for the exact port (usually http://localhost:5000).


2. Frontend Setup

# Navigate to the frontend directory
cd frontend

# Install dependencies
npm install

# Start the Vite development server
npm run dev

The app will be available at http://localhost:5173.

Note: index.html currently points to src/main_fixed.tsx which renders the App_fixed variant. If you want to use the original main.tsx / App.tsx, update the <script> tag in index.html accordingly.


โš™๏ธ Environment & Configuration

Backend (backend/config.js)

PORT=5000
MONGO_URI=mongodb://localhost:27017/swacchnagar
JWT_SECRET=your_jwt_secret_key_here
NODE_ENV=development

Frontend โ€” Auth Token Keys

Different AuthContext implementations use different localStorage keys. Make sure you use a consistent one across your app:

Context File Token Key User Key
AuthContext.tsx token user
AuthContext_fixed.tsx auth_token user_data
AuthContext_backend.tsx token user

Use AuthContext_fixed.tsx for the most stable experience โ€” it is the default in main_fixed.tsx.


๐Ÿ–ฅ๏ธ Pages & Modules

๐Ÿ  Dashboard

The main landing page after login. Shows:

  • Summary stats: total collections today, pending complaints, active vehicles
  • Quick action buttons for common tasks
  • Recent activity feed

๐Ÿ“… Collections

  • View, create, edit, and delete collection schedules
  • Filter by zone, date, and status (Pending / In Progress / Completed)
  • Assign staff and vehicles to a schedule

๐Ÿ—บ๏ธ Routes

  • Define geographic collection routes by zone
  • View all routes on a list with assigned vehicle and staff
  • Edit or deactivate routes

๐Ÿš› Vehicles

  • Full vehicle inventory (truck number, type, capacity, status)
  • Mark vehicles as Active / Under Maintenance / Inactive
  • Assign to collection routes

๐Ÿ“ข Complaints (Citizen Reports)

  • Citizens submit complaints with title, description, and location
  • Admin/staff view all complaints with priority and status filters
  • Status lifecycle: Submitted โ†’ Under Review โ†’ Resolved
  • Resolution notes can be added before closing a complaint

๐Ÿ“Š Analytics

  • Charts showing collection completion rates over time
  • Complaint volume and resolution time trends
  • Vehicle utilization rates
  • Zone-wise performance breakdown

Note: The Analytics page reads auth tokens from context. If you see a "User token not found" error, ensure you are using the same AuthContext implementation throughout the app (see Troubleshooting).

๐Ÿ”” Notifications

  • System-generated notifications for key events
  • Citizen notifications when their complaints are updated
  • Staff notifications for new task assignments

๐Ÿ‘ฅ Users (Admin only)

  • View all registered users by role
  • Activate or deactivate accounts
  • Reset passwords

๐Ÿ”ง Troubleshooting

โŒ useAuth must be used within an AuthProvider

Cause: A component is calling useAuth() but is rendered outside the <AuthProvider>, or the app is mixing different AuthContext implementations.

Fix:

  1. Check index.html to see which entry file (main.tsx or main_fixed.tsx) is loaded
  2. Ensure all components import useAuth from the same context file
  3. Confirm the root App is wrapped with the matching <AuthProvider>

โŒ Analytics page shows blank or "User token not found"

Cause: The Analytics component reads the token using a key that doesn't match what the active AuthContext stores.

Fix: The token should come from the auth context directly:

const { token } = useAuth();

instead of localStorage.getItem('token').


โŒ Vite HMR errors after editing components

Cause: Hot Module Replacement can break when there are duplicate React context imports or circular dependencies.

Fix: Stop the dev server and restart:

npm run dev

๐Ÿ—บ๏ธ Roadmap

  • Live map view for real-time vehicle tracking (GPS integration)
  • Mobile-responsive PWA for field staff
  • SMS/WhatsApp notifications for citizens via Twilio
  • Route optimization using Google Maps / OSRM
  • Multi-city / multi-zone support
  • Export reports as PDF or Excel
  • Hindi language UI option

๐Ÿค Contributing

Contributions are welcome!

  1. Fork the repository
  2. Create a new branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m "feat: add your feature"
  4. Push and open a Pull Request

Please keep fixes scoped โ€” for example: fix(auth): normalize context imports.


เคธเฅเคตเคšเฅเค› เคจเค—เคฐ โ€” เคธเฅเคตเคšเฅเค› เคญเคพเคฐเคคเฅค Clean City, Clean India. ๐Ÿ‡ฎ๐Ÿ‡ณ


๐Ÿ“„ License

Copyright (c) 2025 Atul Singh. All Rights Reserved.

This project and its source code are the exclusive intellectual property of the author.

You are NOT permitted to:

  • Use, copy, or reproduce this code in any form
  • Modify, adapt, or create derivative works
  • Distribute, publish, or sublicense this code
  • Use this project for commercial or personal purposes
  • Deploy this application publicly or privately without explicit written permission from the author

You ARE permitted to:

  • View the source code for educational/learning reference only

โš ๏ธ Unauthorized use, reproduction, or distribution of this project, in whole or in part, may result in legal action.

For permissions or licensing inquiries, contact the author directly via GitHub.

About

๐Ÿ—‘๏ธ SwachhNagar โ€” Smart Waste Management System for urban municipalities built with MERN stack & TypeScript.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages