Skip to content

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš‡ Crowd Prediction

Python FastAPI React MongoDB License: MIT PRs Welcome

A sophisticated full-stack platform for real-time crowd monitoring, intelligent forecasting, and comprehensive analytics for transit operators.

πŸ“– Overview β€’ ✨ Features β€’ πŸ—οΈ Architecture β€’ πŸš€ Quick Start β€’ πŸ“Š API Documentation β€’ 🀝 Contributing β€’ πŸ“„ License


🌟 Overview

Crowd Prediction is an advanced transit analytics platform that revolutionizes crowd management through intelligent data collection and predictive modeling. The system empowers transit operators with real-time insights, enabling data-driven decisions to optimize service quality and passenger experience.

Built with cutting-edge technologies and modern architectural patterns, this platform seamlessly integrates real-time reporting, machine learning predictions, and comprehensive analytics into a cohesive, scalable solution.

✨ Features

πŸ”„ Real-time Capabilities

  • Live Crowd Reporting - Instant crowd level submissions from mobile and web interfaces
  • Dynamic Updates - Real-time data synchronization across all connected clients
  • Live Dashboards - Interactive visualizations updating in real-time

πŸ€– Intelligent Predictions

  • Machine Learning Models - Advanced algorithms for accurate crowd forecasting
  • Short-term Predictions - 15-60 minute crowd level predictions
  • Historical Analysis - Trend analysis and pattern recognition

πŸ“ˆ Analytics & Insights

  • Interactive Dashboards - Comprehensive analytics with drill-down capabilities
  • Heat Maps - Visual crowd density representations
  • Trend Analysis - Historical data analysis with actionable insights
  • Custom Reports - Configurable reporting for different stakeholder needs

πŸ” Security & Authentication

  • JWT Authentication - Secure token-based user authentication
  • Role-based Access - Granular permissions for different user types
  • Data Encryption - End-to-end data protection
  • API Security - Comprehensive security measures for all endpoints

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚    Backend      β”‚    β”‚   Database      β”‚
β”‚   (React)       │◄──►│   (FastAPI)     │◄──►│   (MongoDB)     β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ Single Page   β”‚    β”‚ β€’ REST API      β”‚    β”‚ β€’ Document      β”‚
β”‚   Application   β”‚    β”‚ β€’ Async I/O     β”‚    β”‚   Database      β”‚
β”‚ β€’ Real-time UI  β”‚    β”‚ β€’ ML Pipeline   β”‚    β”‚ β€’ Flexible      β”‚
β”‚ β€’ Responsive    β”‚    β”‚ β€’ Caching       β”‚    β”‚   Schema        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Backend

  • Framework: FastAPI (High-performance async web framework)
  • Language: Python 3.7+
  • Database: MongoDB (NoSQL for flexible data models)
  • ORM: Motor (Async MongoDB driver)
  • Web Server: Uvicorn (ASGI server)
  • Real-time: WebSockets (for live updates)
  • Data Validation: Pydantic
  • Task Queue: Celery with Redis (for background tasks)
  • Data Processing: Pandas, NumPy
  • Authentication: JWT with OAuth2
  • ML Framework: Scikit-learn, TensorFlow (for predictions)
  • Caching: Redis (for improved performance)
  • API Documentation: OpenAPI/Swagger

Frontend

  • Framework: React 18+ (Modern component-based UI)
  • Build Tool: Create React App
  • Styling: CSS3 with CSS Modules
  • State Management: React Context API
  • Charts: Chart.js, D3.js (for data visualization)
  • Real-time: WebSocket integration

DevOps & Tools

  • Version Control: Git with GitFlow workflow
  • Containerization: Docker & Docker Compose
  • CI/CD: GitHub Actions
  • Code Quality: Pre-commit hooks, ESLint, Black
  • Testing: Pytest, Jest, React Testing Library

πŸš€ Quick Start

πŸ“‹ Prerequisites

πŸ”§ Local Development Setup

1. Clone the Repository

git clone https://github.com/Surajit09636/Crowd_prediction.git
cd Crowd_prediction

2. Backend Setup

# Navigate to backend directory
cd Backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure environment variables
cp .env.example .env
# Edit .env with your MongoDB connection string and credentials

# Initialize database with sample data
python init_db.py

# Start development server
python server.py
# Or alternatively: uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

3. Frontend Setup

# Navigate to frontend directory (new terminal)
cd Frontend

# Install dependencies
npm install

# Start development server
npm start
# Frontend will be available at http://localhost:3000

4. Access the Application

πŸ“Š API Documentation

πŸ”Œ REST API Endpoints

Endpoint Method Description Authentication
/api/auth/login POST User authentication ❌
/api/auth/register POST User registration ❌
/api/stations GET Retrieve all stations βœ…
/api/stations/{id} GET Get station details βœ…
/api/crowd-reports POST Submit crowd report βœ…
/api/predictions/{station_id} GET Get predictions βœ…
/api/analytics/stations GET Analytics data βœ…

πŸ” Authentication

The API uses JWT (JSON Web Tokens) for authentication:

# Login to get token
curl -X POST "http://localhost:8000/api/auth/login" \
  -H "Content-Type: application/json" \
  -d '{"username": "your_username", "password": "your_password"}'

# Use token in subsequent requests
curl -X GET "http://localhost:8000/api/stations" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

πŸ§ͺ Testing

Backend Testing

cd Backend
pytest tests/ -v --cov=app --cov-report=html

Frontend Testing

cd Frontend
npm test -- --coverage --watchAll=false

Integration Testing

# Run both frontend and backend tests
./scripts/test-all.sh

🀝 Contributing

We welcome contributions from the community! Here's how you can help:

πŸš€ Getting Started with Development

  1. Fork the repository
  2. Clone your fork locally
  3. Create a feature branch: git checkout -b feature/amazing-feature
  4. Make your changes
  5. Test thoroughly
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Push to the branch: git push origin feature/amazing-feature
  8. Open a Pull Request

πŸ“ Development Guidelines

  • Follow PEP 8 for Python code
  • Use ESLint configuration for JavaScript
  • Write comprehensive tests for new features
  • Update documentation for API changes
  • Use conventional commit messages

πŸ› Reporting Issues

  • Use the GitHub issue tracker
  • Include detailed reproduction steps
  • Add appropriate labels (bug, enhancement, documentation)
  • Be respectful and constructive

πŸ“ Project Structure

Crowd_prediction/
β”œβ”€β”€ Backend/                 # Python FastAPI backend
β”‚   β”œβ”€β”€ app/                # Main application package
β”‚   β”‚   β”œβ”€β”€ api/           # API route handlers
β”‚   β”‚   β”œβ”€β”€ models/        # Database models
β”‚   β”‚   β”œβ”€β”€ schemas/       # Pydantic schemas
β”‚   β”‚   β”œβ”€β”€ services/      # Business logic
β”‚   β”‚   └── utils/         # Utility functions
β”‚   β”œβ”€β”€ tests/             # Backend tests
β”‚   └── requirements.txt   # Python dependencies
β”œβ”€β”€ Frontend/              # React frontend
β”‚   β”œβ”€β”€ src/              # Source code
β”‚   β”‚   β”œβ”€β”€ components/   # React components
β”‚   β”‚   β”œβ”€β”€ services/     # API services
β”‚   β”‚   └── utils/        # Utility functions
β”‚   β”œβ”€β”€ public/           # Static assets
β”‚   └── package.json      # Node dependencies
└── docs/                 # Documentation
    β”œβ”€β”€ API.md           # API documentation
    └── ARCHITECTURE.md  # Architecture guide

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2024 Crowd Prediction Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

πŸ™ Acknowledgments

πŸ”§ Technologies & Libraries

  • FastAPI - High-performance web framework
  • React - User interface library
  • MongoDB - NoSQL document database
  • Chart.js - Data visualization
  • JWT - Authentication standard

🌟 Inspiration

This project draws inspiration from modern transit systems and smart city initiatives worldwide, aiming to contribute to more efficient and passenger-friendly public transportation.


Made by Surajit | Arijit

⭐ Star this repo β€’ πŸ› Report issues β€’ πŸ“– Documentation

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages