SwachhNagar-Smart-Waste-Management-System

๐Ÿ—‘๏ธ เคธเฅเคตเคšเฅเค› เคจเค—เคฐ (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:

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

๐ŸŸก Staff

๐ŸŸข Citizen


๐Ÿ› ๏ธ 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


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:

๐Ÿ“… Collections

๐Ÿ—บ๏ธ Routes

๐Ÿš› Vehicles

๐Ÿ“ข Complaints (Citizen Reports)

๐Ÿ“Š Analytics

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

๐Ÿ‘ฅ Users (Admin only)


๐Ÿ”ง 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


๐Ÿค 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:

You ARE permitted to:

โš ๏ธ 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.