This file provides guidance to Claude Code (claude.ai/code) when working with the BidScents backend code.
# Install dependencies
pip install -r requirements.txt
# Start local infrastructure (Redis & Typesense)
docker compose up -d
# Run development server
fastapi dev app/main.py
# Alternative production server
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload# Run all tests (integration by default)
pytest
# Run unit tests only
pytest -m unit
# Run integration tests only
pytest -m integration
# Run end-to-end tests only
pytest -m e2e
# Run smoke tests
pytest -m smoke
# Generate coverage report
pytest --cov=app --cov-report=html# Use local testing environment
export TESTING="1"
# Repopulate search index
python -m scripts.populate_typesense
# Clear Redis cache
redis-cli FLUSHDB
# Database migrations
python -m scripts.migrate_db- Framework: FastAPI with async/await support
- Database: Supabase (PostgreSQL) with realtime subscriptions
- Cache Layer: Redis (local development) / Upstash Redis (production)
- Search Engine: Typesense for full-text and faceted search
- Authentication: Supabase Auth with JWT tokens
- Real-time: WebSockets for live bidding and messaging
- Notifications: Expo push notifications
- Containerization: Docker Compose for local services
backend/app/
├── main.py # FastAPI application entry point
├── core/ # Core configuration and utilities
│ ├── container.py # Dependency injection container
│ └── utils.py # Common utilities
├── domain/ # Business entities and rules
│ ├── entities/ # Domain entities (User, Listing, Auction, etc.)
│ ├── base.py # Base classes and enums
│ └── exceptions.py # Domain-specific exceptions
├── infrastructure/ # External concerns
│ ├── repositories/ # Data access layer
│ │ ├── base.py # Repository interfaces
│ │ └── supabase/ # Supabase implementations
│ ├── external/ # External service clients
│ │ ├── auth_client.py
│ │ ├── cache_client.py
│ │ ├── search_client.py
│ │ └── notification_client.py
│ ├── cache/ # Caching infrastructure
│ ├── search/ # Search infrastructure
│ └── websockets/ # WebSocket infrastructure
├── services/ # Business logic layer
│ ├── auth_service.py
│ ├── listing_service.py
│ ├── auction_service.py
│ ├── user_service.py
│ ├── message_service.py
│ ├── transaction_service.py
│ └── notification_service.py
└── api/ # API layer
├── deps.py # FastAPI dependencies
└── v1/ # API version 1
├── api.py # Router aggregation
├── models/ # Pydantic models for API
└── routers/ # FastAPI route handlers
- Centralized service initialization in
core/container.py - Single source of truth for all dependencies
- Supports both local (testing) and production configurations
- Handles environment-specific client initialization
- Abstract repository interfaces in
infrastructure/repositories/base.py - Concrete implementations for Supabase in
infrastructure/repositories/supabase/ - Domain entities converted from/to database models
- Supports caching and search integration
- Business logic encapsulated in service classes
- Services depend on repositories and external clients
- Handle complex workflows like auction bidding, messaging
- Implement cache invalidation strategies
- FastAPI routers handle HTTP concerns only
- Pydantic models for request/response validation
- Dependency injection for service access
- Proper error handling and status codes
The application requires these environment variables:
Database & Auth:
SUPABASE_URL=your-supabase-url
SUPABASE_ANON_KEY=your-supabase-anon-key
MESSAGE_ENCRYPTION_KEY=your-encryption-keyCache (Production):
REDIS_URL=your-upstash-redis-url
REDIS_TOKEN=your-upstash-tokenCache (Local Testing):
TESTING=1
REDIS_URL=redis://localhost:6379Search Engine:
TYPESENSE_HOST=localhost
TYPESENSE_PORT=8108
TYPESENSE_PROTOCOL=http
TYPESENSE_API_KEY=dev-api-key- Define domain entities in
domain/entities/ - Create repository interface and implementation
- Implement business logic in service layer
- Add Pydantic models for API in
api/v1/models/ - Create router endpoints in
api/v1/routers/ - Update dependency container if needed
- Add comprehensive tests
- All database operations go through repository pattern
- Use domain entities, not database models directly
- Implement proper error handling for database exceptions
- Consider caching strategy for read operations
- Cache frequently accessed data (user profiles, listing details)
- Implement cache invalidation on data updates
- Use structured cache keys for easy management
- Consider cache warming for critical data
- Index data changes in Typesense automatically
- Use service layer to coordinate database and search updates
- Implement fallback strategies for search failures
- Keep search schema in sync with domain models
- WebSocket manager handles connection lifecycle
- Broadcast updates to relevant connected clients
- Integrate with notification service for offline users
- Handle connection drops gracefully
- Unit tests for isolated business logic
- Integration tests for service interactions with real dependencies
- E2E tests for complete user workflows
- Use local Docker services for consistent test environment
- Always run
docker compose up -dfor Redis and Typesense - Set
TESTING=1environment variable for local services - Use
.env.localfor local development configuration - Repopulate Typesense after database changes
- Use async/await consistently throughout the codebase
- Implement proper database indexing for queries
- Cache expensive computations and frequent queries
- Use connection pooling for external services
- Validate all inputs using Pydantic models
- Use Supabase RLS policies for data access control
- Encrypt sensitive data like messages
- Implement proper authentication and authorization
- Use domain-specific exceptions
- Implement proper HTTP status codes
- Log errors with sufficient context
- Return user-friendly error messages
- FastAPI runs on Uvicorn ASGI server
- Redis cache layer for performance
- Typesense for search capabilities
- Supabase handles database and authentication
- Docker Compose for local development
- Environment-specific configurations via container