A production-ready microservice for analyzing bike sharing networks using community detection algorithms. Built with FastAPI, this service provides RESTful endpoints to detect communities in mobility networks using the Louvain algorithm.
- RESTful API for community detection analysis
- Louvain Algorithm implementation for efficient community detection
- Docker Support for containerized deployment
- CI/CD Pipeline with automated testing and linting
- Production-Ready with proper error handling and logging
Health check endpoint
- Response:
{"message": "Mobility Network API is running. Go to /docs for Swagger UI."}
Analyze the bike sharing network and detect communities
- Response:
{
"status": "success",
"algorithm": "Louvain",
"results": {
"modularity_score": 0.42,
"total_communities_detected": 5,
"total_nodes": 234
}
}Interactive Swagger UI for API documentation
- Python 3.9 or higher
- Docker (optional, for containerized deployment)
- Clone the repository
git clone <repository-url>
cd <repository-folder>- Install dependencies
pip install -r requirements.txt- Run the application
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload- Access the API
- API: http://localhost:8000
- Interactive Docs: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
docker build -t mobility-network-api .docker run -p 8000:8000 mobility-network-apiThe API will be available at http://localhost:8000
pytest -vpytest --cov=app --cov-report=htmlflake8 . --count --statistics --max-line-length=120.
├── app/
│ ├── __init__.py # Application package initialization
│ ├── main.py # FastAPI application and endpoints
│ └── processing.py # Graph processing and community detection
├── data/
│ └── Databike.csv # Bike sharing dataset
├── tests/
│ └── test_main.py # Unit tests
├── .github/
│ └── workflows/
│ └── ci_pipeline.yml # GitHub Actions CI/CD pipeline
├── Dockerfile # Container configuration
├── requirements.txt # Python dependencies
├── pytest.ini # Pytest configuration
└── README.md # This file
The Louvain method is a greedy optimization algorithm that:
- Maximizes modularity to detect communities
- Runs in O(n log n) time complexity
- Provides hierarchical community structure
Modularity Score: Measures the quality of community division (range: -0.5 to 1.0)
- Higher values indicate stronger community structure
- Values > 0.3 typically indicate significant community structure
The project uses bike sharing data (Databike.csv) with the following structure:
- departure_id: Starting station ID
- return_id: Ending station ID
- Each row represents a bike trip between two stations
For performance, the API loads a subset of 1000 trips during initialization.
The project includes a GitHub Actions workflow that:
- ✅ Sets up Python environment
- ✅ Installs dependencies
- ✅ Runs automated tests with pytest
- ✅ Performs code linting with flake8
- ✅ Builds Docker image to validate Dockerfile
- Chintan Limbachiya (B22ME036)
- Avinash Kumar (B22ME014)
- Sumit (B22CH037)
- Shashwat Meena (B22BB037)
This project was created as part of an academic assignment.
- Add support for Girvan-Newman algorithm
- Implement graph visualization endpoints
- Add support for larger datasets with pagination
- Implement caching for frequently analyzed networks
- Add authentication and rate limiting