A FastAPI backend service that provides McDonald's outlet location data for Malaysia, with geocoding, search, and AI-powered chatbot capabilities.
- Outlet Data API: Access McDonald's Malaysia outlet information including locations, operating hours, and services
- Geocoding: Convert addresses to coordinates using Nominatim
- Search: Find outlets by location, services, or within a radius
- AI Chatbot: Natural language queries about McDonald's outlets (Gemini AI integration)
- Caching: Efficient response caching for improved performance
- CORS Support: Ready for frontend integration
- Framework: FastAPI (Python 3.9+)
- Geocoding: Geopy with Nominatim
- AI: Google Gemini API
- Database: SQLite (optional PostgreSQL support)
- Deployment: Render
- Python 3.9 or higher
- pip package manager
- Google API key (for Gemini chatbot - optional)
- Clone the repository:
git clone https://github.com/yourusername/geolocation-mcdscrapper.git
cd geolocation-mcdscrapper
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
cp env.example .env
Edit .env
and configure:
# API Configuration
ENVIRONMENT=development
LOG_LEVEL=info
DEBUG=true
# CORS (set your frontend URL in production)
CORS_ORIGINS=*
# Geocoding
GEOCODING_PROVIDER=nominatim
NOMINATIM_USER_AGENT=mcdonalds-malaysia-api
# Chatbot (optional)
CHATBOT_PROVIDER=gemini
GOOGLE_API_KEY=your_google_api_key_here
python main.py
Or using uvicorn directly:
uvicorn main:app --reload --host 0.0.0.0 --port 8000
The API will be available at: http://localhost:8000
uvicorn main:app --host 0.0.0.0 --port $PORT
Once running, access the interactive API documentation:
- Swagger UI:
http://localhost:8000/docs
- ReDoc:
http://localhost:8000/redoc
GET /health
- Health checkGET /outlets
- List all outletsGET /outlets/{id}
- Get specific outletGET /outlets/search
- Search outletsGET /outlets/nearby
- Find nearby outletsPOST /chat
- AI chatbot for outlet queries
This project is configured for easy deployment on Render.
-
Push your code to GitHub
-
Create a new Web Service on Render:
- Connect your GitHub repository
- Render will auto-detect the
render.yaml
configuration
-
Set environment variables in Render dashboard:
GOOGLE_API_KEY
(if using chatbot)CORS_ORIGINS
(your frontend URL)
-
Deploy! Render will:
- Install dependencies from
requirements.txt
- Start the server using the configured start command
- Install dependencies from
If deploying manually:
- Build Command:
pip install -r requirements.txt
- Start Command:
uvicorn main:app --host 0.0.0.0 --port $PORT
For PostgreSQL support:
- Update
.env
:
DATABASE_URL=postgresql://user:pass@host:port/dbname
- Run migrations:
python migrate_db.py
python scraper_runner.py
python setup_env.py
├── src/
│ ├── api/ # FastAPI app and routes
│ ├── chatbot/ # AI chatbot integration
│ ├── database/ # Database models and queries
│ ├── geocoding/ # Geocoding services
│ └── scraper/ # Data scraping utilities
├── scripts/ # Utility scripts
├── main.py # Application entry point
├── requirements.txt # Python dependencies
├── render.yaml # Render deployment config
└── README.md # This file
Variable | Description | Required | Default |
---|---|---|---|
ENVIRONMENT |
Environment mode | No | development |
LOG_LEVEL |
Logging level | No | info |
DEBUG |
Debug mode | No | false |
CORS_ORIGINS |
Allowed CORS origins | No | * |
GEOCODING_PROVIDER |
Geocoding service | No | nominatim |
NOMINATIM_USER_AGENT |
User agent for Nominatim | No | mcdonalds-api |
CHATBOT_PROVIDER |
AI provider | No | gemini |
GOOGLE_API_KEY |
Google API key for Gemini | No | - |
DATABASE_URL |
PostgreSQL connection string | No | - |
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License.
For connecting your frontend application to this API, see the Frontend Connection Guide.
For issues and questions:
- Open an issue on GitHub
- Check existing issues for solutions
- Review API documentation at
/docs