SafeCity is a comprehensive full-stack web application designed for real-time incident reporting, location-based safety analysis, community moderation, and intelligent safety alerts. Built to empower communities through data-driven safety awareness and collaborative incident management.
β Production-ready platform with advanced authentication, admin moderation, email notifications, and Google Maps integration.
- Secure Login/Registration with bcrypt password hashing
- Forgot Password with OTP email verification
- Account Security with automatic lockout after failed attempts
- JWT-based session management
- GDPR Compliant data consent management
- Role-based Access Control (Admin, Moderator, User)
- Incident Moderation - Approve, reject, or flag reports
- User Management - Ban/unban users, role assignments
- Real-time Dashboard with comprehensive statistics
- Recent Activity Monitoring
- Interactive Map Selection with Google Maps integration
- GPS Location Detection for precise incident reporting
- Category-based Classification (Theft, Harassment, Emergency, etc.)
- Anonymous Reporting option
- Photo Upload Support (optional)
- Automatic Timestamp & Geolocation
- Real-time Safety Zones (Red/Yellow/Green indicators)
- Location-based Risk Assessment using historical data
- Interactive Safety Map with incident visualization
- Distance-based Incident Filtering
- Safety Level Calculations based on recent incidents
- Live Danger Alerts within customizable radius
- 30-second Auto-refresh for new incidents
- Proximity-based Notifications
- Emergency Alert Broadcasting
- OTP Verification for password reset
- Beautiful HTML Email Templates
- Gmail Integration with App Passwords
- Welcome & Safety Notifications
| Page | Purpose | Features |
|---|---|---|
dashboard.html |
Main hub & navigation | User dashboard, quick access to all features |
login.html |
User authentication | Login, forgot password with OTP |
signup.html |
User registration | Account creation with GDPR consent |
index.html |
Incident reporting | Interactive map, form submission, GPS detection |
safety.html |
Safety analysis | Real-time safety map, incident visualization |
admin.html |
Admin dashboard | Moderation tools, user management, statistics |
profile.html |
User profile | Account settings, data management |
privacy.html |
Privacy policy | GDPR compliance, data usage information |
For detailed setup instructions including Google Maps API, MongoDB Atlas, Gmail integration, and all required configurations, see our comprehensive setup guide:
π SETUP.md - Complete Configuration Guide
This guide covers:
- ποΈ MongoDB Atlas database setup
- πΊοΈ Google Maps API configuration
- π§ Gmail email service setup
- π JWT and security configuration
- π First-time application setup
- π§ Development vs Production settings
- π¨ Troubleshooting common issues
- Entry point of the app
- Navigation to:
- π¨ Report Incident
- π Analyze Area Safety
- Shows logged-in user name (optional)
- User Registration (
signup.html)- Email, username, password
- Stores hashed password using bcrypt
- User Login (
login.html)- Verifies credentials and starts session
- Session-based or JWT-based login system
- Required to report incidents or access safety data
- Basic auth middleware in backend protects routes
- Users can report incidents by:
- Using live GPS location
- Or manually selecting location on a map
- Fields:
- Title
- Category (e.g., Theft, Harassment)
- Description
- Auto-stores:
- Latitude, Longitude
- Timestamp
- Reporting User ID
- Interactive Google Map
- Click on location:
- View recent incidents
- Check safety level:
- π₯ Red β High danger
- π¨ Yellow β Alert zone
- π© Green β Safe zone
- Uses browser geolocation to detect user position
- Every 30 seconds:
- Checks if new incident occurred within 1km
- Shows on-screen alert with details
- Node.js (v14 or higher)
- MongoDB Atlas account
- Google Cloud Platform account (for Maps API)
- Gmail account (for email services)
-
Clone the repository
git clone https://github.com/Chanu716/Safe-City.git cd Safe-City -
Install dependencies
npm install
-
Environment Setup
cp .env.example .env # Edit .env with your actual credentials -
Database Setup
npm run init-db
-
Start the application
npm start # or node app.js -
Access the application
- Main Dashboard:
http://localhost:3000 - Report Incident:
http://localhost:3000/index.html - Safety Analysis:
http://localhost:3000/safety.html
- Main Dashboard:
- Create your account through the signup page
- Grant admin privileges - See SETUP.md for detailed instructions
- Access admin dashboard at
http://localhost:3000/admin.html
Create a .env file in the root directory:
# Database
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/safecity
# Authentication
JWT_SECRET=your-super-secure-jwt-secret
JWT_EXPIRE=7d
# Email Services (for forgot password)
EMAIL_USER=your-email@gmail.com
EMAIL_PASSWORD=your-gmail-app-password
# Google Maps
GOOGLE_MAPS_API_KEY=your-google-maps-api-key
GOOGLE_MAPS_MAP_ID=your-map-id
# Application
NODE_ENV=development
PORT=3000For step-by-step instructions on configuring all external services:
π SETUP.md - Complete Setup Guide
Includes detailed instructions for:
- Google Maps API: Enable APIs, create keys, set restrictions, configure Map IDs
- Gmail Integration: 2FA setup, App Password generation, email testing
- MongoDB Atlas: Account creation, cluster setup, user management, network configuration
- Security Configuration: JWT secrets, environment variables, production settings
# Resolve database index conflicts
npm run init-dbFor detailed setup and configuration: SETUP.md
For database migration instructions: MIGRATION.md
| Layer | Technologies |
|---|---|
| Frontend | HTML5, CSS3, Vanilla JavaScript, Google Maps JavaScript API |
| Backend | Node.js, Express.js, RESTful APIs |
| Authentication | JWT, bcrypt, OTP email verification |
| Database | MongoDB Atlas, Mongoose ODM |
| Email Services | Nodemailer, Gmail SMTP |
| Security | HTTPS, CORS, Input validation, Rate limiting |
| Maps & Location | Google Maps API, Places API, Geolocation API |
| Real-time Features | Server-Sent Events, WebSocket-ready architecture |
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend API β β Database β
β β β β β β
β β’ Dashboard βββββΊβ β’ Auth Routes βββββΊβ β’ User Records β
β β’ Report Form β β β’ Incident API β β β’ Incidents β
β β’ Safety Map β β β’ Admin Panel β β β’ Moderation β
β β’ Admin Panel β β β’ Email Service β β β’ Sessions β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β
β βββββββββββββββββββ
βββββββββββββββΊβ External APIs β
β β
β β’ Google Maps β
β β’ Gmail SMTP β
β β’ Geolocation β
βββββββββββββββββββ
- Password Security: bcrypt hashing with salt rounds
- Account Protection: Automatic lockout after failed login attempts
- JWT Security: Secure token-based authentication
- Input Validation: Server-side validation for all user inputs
- CORS Protection: Configured for secure cross-origin requests
- GDPR Compliance: User consent management and data export
- Admin Protection: Role-based access control
- API Security: Rate limiting and request validation
Safe-City/
βββ π public/ # Frontend assets
β βββ π css/
β β βββ style.css # Global styles and responsive design
β βββ π js/
β β βββ auth.js # Authentication frontend logic
β β βββ profile.js # User profile management
β β βββ report.js # Incident reporting functionality
β β βββ safety.js # Safety analysis and real-time alerts
β β βββ admin-dashboard.js # Admin panel functionality
β β βββ maps-config.js # Google Maps configuration
β βββ dashboard.html # Main dashboard
β βββ index.html # Incident reporting page
β βββ login.html # Login with forgot password
β βββ signup.html # Registration with GDPR consent
β βββ safety.html # Safety analysis and maps
β βββ admin.html # Admin moderation panel
β βββ profile.html # User profile management
β βββ privacy.html # Privacy policy and GDPR compliance
β βββ security.html # Security information
βββ π routes/ # API routes
β βββ auth.js # Authentication & user management
β βββ incidents.js # Incident CRUD operations
β βββ admin.js # Admin panel APIs
βββ π models/ # Database schemas
β βββ User.js # User model with roles & security
β βββ Incident.js # Incident model with moderation
βββ π middleware/ # Express middleware
β βββ auth.js # JWT authentication
β βββ consent.js # GDPR compliance middleware
βββ π utils/ # Utility modules
β βββ emailService.js # Email sending functionality
βββ π scripts/ # Database initialization scripts
β βββ init-db.js # Database setup and migration
βββ π tests/ # Test files
β βββ migration.test.js # Database migration tests
βββ π app.js # Express server setup
βββ π .env.example # Environment template
βββ π SETUP.md # Complete setup guide
βββ π MIGRATION.md # Database migration guide
βββ π README.md # This file
POST /api/auth/signup- User registrationPOST /api/auth/login- User loginPOST /api/auth/logout- User logoutGET /api/auth/me- Get current userPOST /api/auth/forgot-password- Request password resetPOST /api/auth/verify-otp- Verify OTP codePOST /api/auth/reset-password- Reset password with OTP
GET /api/incidents- Get approved incidentsPOST /api/incidents- Report new incidentGET /api/incidents/nearby- Get incidents near locationGET /api/incidents/recent- Get recent incidents for alerts
GET /api/admin/stats- Dashboard statisticsGET /api/admin/incidents/pending- Pending moderationPOST /api/admin/incidents/:id/approve- Approve incidentPOST /api/admin/incidents/:id/reject- Reject incidentGET /api/admin/users- User managementPOST /api/admin/users/:id/ban- Ban userPOST /api/admin/users/:id/unlock- Unlock account
- π± Mobile App with React Native
- π Push Notifications for real-time alerts
- π€ AI-powered incident categorization
- π Advanced Analytics dashboard
- π Multi-language support
- π Social Media integration
- πΈ Image Upload for incident reports
- π¨ Emergency Services integration
- πΊοΈ Offline Map support
- π Predictive Safety modeling
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, email charmiseera07@gmail.com or call 9182789929.
Built with β€οΈ for safer communities