A full-stack application that provides AI-powered bicycle theft risk assessment for Toronto. The application combines historical theft data analysis with machine learning predictions to help cyclists make informed decisions about where to park their bikes.
This is a monorepo containing:
- Frontend- Next.js application with interactive maps and risk visualization
- Backend- FastAPI service with machine learning model for theft prediction
- Interactive Map- Click anywhere in Toronto to assess theft risk
- AI Risk Assessment- Machine learning model provides personalized risk predictions
- Historical Analysis- Analysis based on real Toronto Police theft data
- Personalized Risk- Factors in bike value, time of day, and lock type
- Modern UI- Clean, responsive interface with real-time updates
- Docker and Docker Compose
- Node.js 18+ (for local development)
- Python 3.9+ (for local development)
-
Clone and navigate to the project:
cd IBM-Z-Datathon -
Start the application:
docker-compose up --build
-
Access the application:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
The application will automatically load the bicycle theft data and ML model.
-
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
-
Run the FastAPI server:
uvicorn app.main:app --reload
-
Navigate to frontend directory:
cd frontend -
Install dependencies:
npm install
-
Create environment file:
cp .env.local.example .env.local # Edit .env.local with your API URL if different from localhost:8000 -
Run the development server:
npm run dev
GET /- Health checkGET /health- Detailed health statusPOST /predict- Risk prediction endpointGET /model/info- Model informationGET /docs- Swagger documentation
curl -X POST "http://localhost:8000/predict" \
-H "Content-Type: application/json" \
-d '{
"latitude": 43.6532,
"longitude": -79.3832,
"bike_price": 800,
"time_of_day": 18,
"day_of_week": "Friday",
"lock_type": "u-lock",
"location_type": "Street"
}'IBM-Z-Datathon/
├── backend/ # FastAPI backend
│ ├── app/
│ │ ├── main.py # FastAPI application
│ │ └── ml/ # ML models and utilities
│ │ ├── bike_theft_model.joblib
│ │ └── bike_prices_cache.pkl
│ ├── Dockerfile
│ └── requirements.txt
│
├── frontend/ # Next.js frontend
│ ├── src/
│ │ ├── app/ # Next.js app directory
│ │ ├── components/ # React components
│ │ └── lib/ # API client and utilities
│ ├── public/ # Static assets
│ ├── Dockerfile
│ └── package.json
│
├── docker-compose.yml # Docker orchestration
└── README.md
- Historical Theft Data: Toronto Police Service Public Safety Data Portal
- Geographic Data: OpenStreetMap via Leaflet
- Machine Learning: Pre-trained model based on historical patterns
- Next.js 15
- React 19
- TypeScript
- Tailwind CSS
- React Leaflet (for maps)
- Turf.js (for geospatial analysis)
- FastAPI
- Python 3.9+
- Scikit-learn
- Pandas
- Pydantic
- Uvicorn
Frontend (.env.local):
NEXT_PUBLIC_API_BASE_URL=http://localhost:8000
Backend:
# Set via Docker Compose or system environment
PYTHONPATH=/code
- API Health: Check the API health indicator in the header
- Hot Reload: Both frontend and backend support hot reloading in development
- Model Updates: Replace the
.joblibfile inbackend/app/ml/to update the model - Data Updates: Replace the CSV file in
frontend/public/to update historical data
- Port Conflicts: Ensure ports 3000 and 8000 are available
- Model Loading: Check that
bike_theft_model.joblibexists inbackend/app/ml/ - CORS Issues: Verify CORS settings in backend if accessing from different domains
- Data Loading: Ensure
bicycle-thefts.csvis infrontend/public/
# Reset containers
docker-compose down
docker-compose up --build
# Check logs
docker-compose logs backend
docker-compose logs frontend- Fork the repository
- Create a feature branch
- Make your changes
- Test locally with Docker
- Submit a pull request
This project is developed for the IBM Z Datathon hackathon.