Skip to content

namsengi11/Bapful

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

62 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bapful API

A FastAPI-based backend for a travel restaurant review application with location-based services and menu translation features.

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

API Endpoints

Authentication

  • POST /auth/register - Register new user
  • POST /auth/login - Login user

Locations & Reviews

  • GET /locations - Get nearby locations
  • GET /locations/{id}/reviews - Get location reviews
  • POST /locations/{id}/reviews - Create review
  • POST /locations/{id}/review/{review_id}/rate - Rate review

Menu Translation

  • POST /menus/upload-photo - Upload menu photo
  • GET /locations/{id}/menus - Get location menus

Setup Instructions

Prerequisites

  • Python 3.10+
  • PostgreSQL database
  • pip or poetry for package management

Installation

  1. Clone and navigate to the project:

    cd Bapful
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up PostgreSQL database:

    # Create database
    createdb bapful_db
  4. Configure environment:

    # Copy environment template
    cp .env.example .env
    
    # Edit .env with your database credentials
    DATABASE_URL=postgresql://username:password@localhost:5432/bapful_db
  5. Initialize database migrations:

    alembic revision --autogenerate -m "Initial migration"
    alembic upgrade head
  6. Run the server:

    python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

The API will be available at:

Project Structure

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

Configuration

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=10485760

Architecture Notes

File Storage

The 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")

Mock Services

  • Menu Translation: Currently returns mock translated data
  • Location Data: Uses hardcoded sample locations
  • Ready for Integration: Easily replaceable with real services

Database Design

  • Scalable Schema: Designed for growth with proper indexing
  • Relationships: Proper foreign keys and joins
  • Migration Support: Alembic for schema evolution

Development

Adding New Features

  1. Add models in models.py
  2. Create schemas in schemas.py
  3. Implement business logic in services.py
  4. Add routes in appropriate route files
  5. Update tests and documentation

Database Migrations

Workflow Example

Here's the typical workflow when you need to change your database schema:

  1. 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)
  2. 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
  3. Apply the migration:

    alembic upgrade head
    • Executes the migration against your database
    • Updates the database schema to match your models

Common Commands

# 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

Production Considerations

  1. Environment Variables: Set secure values for JWT_SECRET_KEY
  2. Database: Configure production PostgreSQL with connection pooling
  3. File Storage: Switch to S3 for scalability
  4. CORS: Configure appropriate origins
  5. Logging: Set up centralized logging
  6. Rate Limiting: Add rate limiting middleware
  7. Health Monitoring: Implement comprehensive health checks

API Testing

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"

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors