A FastAPI-based backend for a travel restaurant review application with location-based services and menu translation features.
- π JWT Authentication - User registration and login
- π Location Services - Find nearby restaurants with reviews
- β Review System - Rate restaurants and vote on reviews
- π Menu Translation - Upload menu photos with mock translation
- π File Storage - Configurable storage (local/S3)
- ποΈ PostgreSQL Database - Robust data persistence
- π API Documentation - Auto-generated with FastAPI
POST /auth/register- Register new userPOST /auth/login- Login user
GET /locations- Get nearby locationsGET /locations/{id}/reviews- Get location reviewsPOST /locations/{id}/reviews- Create reviewPOST /locations/{id}/review/{review_id}/rate- Rate review
POST /menus/upload-photo- Upload menu photoGET /locations/{id}/menus- Get location menus
- Python 3.10+
- PostgreSQL database
- pip or poetry for package management
-
Clone and navigate to the project:
cd Bapful -
Install dependencies:
pip install -r requirements.txt
-
Set up PostgreSQL database:
# Create database createdb bapful_db -
Configure environment:
# Copy environment template cp .env.example .env # Edit .env with your database credentials DATABASE_URL=postgresql://username:password@localhost:5432/bapful_db
-
Initialize database migrations:
alembic revision --autogenerate -m "Initial migration" alembic upgrade head -
Run the server:
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
The API will be available at:
- API: http://localhost:8000
- Docs: http://localhost:8000/docs
- Health: http://localhost:8000/health
app/
βββ __init__.py
βββ main.py # FastAPI app and configuration
βββ config.py # Settings and configuration
βββ database.py # Database connection and session
βββ models.py # SQLAlchemy models
βββ schemas.py # Pydantic schemas
βββ auth.py # Authentication logic
βββ storage.py # File storage abstraction
βββ services.py # Business logic services
βββ routes/
βββ __init__.py
βββ auth.py # Authentication routes
βββ locations.py # Location and review routes
βββ menus.py # Menu upload routes
Key configuration options in .env:
# Database
DATABASE_URL=postgresql://username:password@localhost:5432/bapful_db
# JWT Authentication
JWT_SECRET_KEY=your-secret-key
JWT_EXPIRATION_HOURS=24
# File Storage
UPLOADS_DIR=uploads
MAX_FILE_SIZE=10485760The application uses an abstract storage interface that can be easily switched between local and S3 storage:
# Current: Local storage
fileStorage = LocalFileStorage()
# Future: Switch to S3
fileStorage = S3FileStorage(bucketName="my-bucket")- Menu Translation: Currently returns mock translated data
- Location Data: Uses hardcoded sample locations
- Ready for Integration: Easily replaceable with real services
- Scalable Schema: Designed for growth with proper indexing
- Relationships: Proper foreign keys and joins
- Migration Support: Alembic for schema evolution
- Add models in
models.py - Create schemas in
schemas.py - Implement business logic in
services.py - Add routes in appropriate route files
- Update tests and documentation
Here's the typical workflow when you need to change your database schema:
-
Modify your models in
app/models.py:# Add a new field to an existing model class Location(Base): # ... existing fields ... new_field = Column(String, nullable=True)
-
Generate migration:
alembic revision --autogenerate -m "Add new_field to Location"- Alembic compares your models to the current database
- Creates a migration file in
alembic/versions/ - The file contains the SQL commands to update your schema
-
Apply the migration:
alembic upgrade head
- Executes the migration against your database
- Updates the database schema to match your models
# Generate migration
alembic revision --autogenerate -m "Description"
# Apply migration
alembic upgrade head
# Rollback one migration
alembic downgrade -1
# View migration history
alembic history
# Check current database version
alembic current- Environment Variables: Set secure values for JWT_SECRET_KEY
- Database: Configure production PostgreSQL with connection pooling
- File Storage: Switch to S3 for scalability
- CORS: Configure appropriate origins
- Logging: Set up centralized logging
- Rate Limiting: Add rate limiting middleware
- Health Monitoring: Implement comprehensive health checks
Use the interactive docs at /docs or test with curl:
# Register user
curl -X POST "http://localhost:8000/auth/register" \
-H "Content-Type: application/json" \
-d '{"name":"John Doe","email":"john@example.com","password":"secret123"}'
# Get nearby locations
curl "http://localhost:8000/locations?lat=48.8566&lng=2.3522&radius=1000"