WARP.md
Documents development commands, architecture, and workflows for a FastAPI/Next.js monorepo with offline-first and multi-AI features.
What this file does
Documents development commands, architecture, and workflows for a FastAPI/Next.js monorepo with offline-first and multi-AI features.
When to use it
- Onboarding new developers to the project
- Setting up local development environment
- Understanding the multi-agent arbitration system
- Debugging offline mode or authentication issues
Assumes this stack
WARP.md
This file provides guidance to WARP (warp.dev) when working with code in this repository.
Development Commands
Quick Start Commands
# Start backend (FastAPI)
cd backend
python -m uvicorn backend.main:app --reload --host 127.0.0.1 --port 8000
# Start frontend (Next.js) - separate terminal
cd frontend
npm run dev
Backend Development
# Install dependencies
cd backend
pip install -r requirements.txt
# Run with specific configuration
python -m uvicorn backend.main:app --reload --port 8000
# Run tests
pytest -v --cov=. --cov-report=html
pytest tests/test_health.py -v # Single test file
# Type checking
mypy backend/ --config-file=mypy.ini
# Code formatting
black backend/
isort backend/
# Linting
flake8 backend/
Frontend Development
cd frontend
# Install dependencies
npm install
# Development server
npm run dev
# Build for production
npm run build
# Type checking
npm run typecheck
# Start production server
npm run start
Testing Commands
# Run all backend tests
cd backend && pytest tests/ -v
# Run frontend tests
cd frontend && npm test
# Run specific test scripts
python test_backend_health.py
python comprehensive_tester.py
python scripts/backend_smoke.py
Docker Commands
# Development with Docker Compose
docker-compose up -d
# Production deployment
export PRODUCTION=true
docker-compose -f docker-compose.yml up -d
# Stop services
docker-compose down
# View logs
docker-compose logs backend
docker-compose logs frontend
Database Commands
# Database status (works offline too)
curl http://127.0.0.1:8000/db/status
# Health check
curl http://127.0.0.1:8000/health
Architecture Overview
Technology Stack
Backend:
- Framework: FastAPI (Python 3.11+) with uvicorn
- Database: Supabase (PostgreSQL) with offline in-memory fallback
- Cache: Redis (optional)
- AI Services: OpenAI GPT-4, Google Gemini Pro
- Authentication: JWT tokens with Bearer authentication
Frontend:
- Framework: Next.js 14 with TypeScript
- Styling: Tailwind CSS + Material-UI
- State Management: React Context (AuthContext, OfflineContext)
- Charts: Chart.js with react-chartjs-2
- PWA: next-pwa with offline capabilities
Backend Architecture
The backend uses a modular router-based architecture with API versioning:
backend/
├── main.py # FastAPI app with all routers
├── config.py # Centralized configuration
├── routers/ # Feature-based API routes
│ ├── auth.py # Authentication & user management
│ ├── arbitration.py # Multi-AI decision engine
│ ├── rag.py # Retrieval-augmented generation
│ ├── transactions.py # Transaction CRUD operations
│ ├── multimodal.py # Voice, image, text processing
│ └── [20+ other specialized routers]
├── utils/ # Shared utilities
└── inmemory_store.py # Offline mode data storage
Key Architectural Patterns:
- API Versioning:
/v1/*and/v2/*endpoints for backward compatibility - Offline-First: Automatic fallback to in-memory store when Supabase unavailable
- Multi-Provider AI: Arbitration engine supporting OpenAI + Google Gemini
- Modular Routers: Each feature domain has its own router module
- Dependency Injection: Reusable dependencies for auth, database, etc.
Frontend Architecture
Provider Hierarchy (wraps all pages):
_app.tsx
├── AuthProvider # User authentication state
├── OfflineProvider # Network status & sync queue
├── ToastProvider # Notifications system
└── AppLayout # Navigation & status indicators
Key Frontend Patterns:
- Context-Based State: Auth, offline sync, and toast notifications
- Offline Queue: IndexedDB for storing operations when offline
- Progressive Sync: Background synchronization when connection restored
- API Client: Typed axios wrapper with error handling
- Route Protection: Dashboard requires authentication
AI Intelligence Layer
The project features a sophisticated Multi-Agent Arbitration System:
- Parallel Execution: Runs OpenAI and Gemini models simultaneously
- Strategy Engine:
first_success,heuristic_scoring,consensus, etc. - Explainability: Provides rationale and confidence scores for decisions
- Safety Layer: Pre/post moderation with PII detection
- Feedback Loop: User rating system for continuous improvement
Authentication System
Token Types:
expected-token→ Maps to test useruser123(development)localsecret→ Shared secret from.envfile- JWT tokens with configurable expiration
Auth Flow:
- Frontend login → backend validates credentials
- Backend issues JWT token
- Frontend stores token and includes in API requests
- Backend validates token via dependency injection
Offline Capabilities
Backend Offline Mode:
- Automatically enabled when
SUPABASE_URLmissing - Uses thread-safe in-memory store
- Supports full auth and transaction CRUD
- Seeds demo data on startup
Frontend Offline Mode:
- Detects network status via
navigator.onLine - Queues operations in IndexedDB
- Syncs automatically when connection restored
- Shows offline indicators in UI
Development Workflow
Environment Setup
- Copy
.env.exampleto.envand configure - For offline development, omit
SUPABASE_URLandSUPABASE_ANON_KEY - Backend auto-switches to in-memory mode when Supabase unavailable
Authentication Testing
# Test with shared secret
curl -H "Authorization: Bearer localsecret" http://127.0.0.1:8000/v1/profile
# Test with expected token
curl -H "Authorization: Bearer expected-token" http://127.0.0.1:8000/v1/profile
Adding New Features
- Backend: Create router in
backend/routers/, add tomain.py - Frontend: Add component in
components/, create page inpages/ - API Client: Extend
lib/api.tswith typed functions - Tests: Add tests for both backend and frontend
API Versioning Strategy
- v1: Stable API for core functionality
- v2: Enhanced features with backward compatibility
- v3: Future/experimental features
New features should start in v2/v3, then migrate to v1 once stable.
Common Troubleshooting
Port Conflicts
- Backend defaults to port 8000
- Frontend defaults to port 3000 (auto-selects 3001, 3002, etc.)
- Docker Compose uses same default ports
CORS Issues
- Development: Automatically includes localhost:3000-3010
- Production: Set
ALLOWED_ORIGINSenvironment variable - Debug endpoint:
GET /debug/cors
Offline Mode Issues
- Missing
SUPABASE_URLtriggers offline mode - Check
/db/statusendpoint to confirm mode - In-memory data resets on restart (by design)
Authentication Errors
- Verify
Authorization: Bearer <token>header format - Check token validity (expected-token, localsecret, or valid JWT)
/v1/profileendpoint requires authentication
Testing Strategy
Test Types
- Unit Tests:
pytestfor backend,jestfor frontend - Integration Tests: Full API workflow tests
- Smoke Tests: Basic connectivity and health checks
- Load Tests:
locustfile.pyfor performance testing
Test Files Location
- Backend tests:
backend/tests/ - Frontend tests:
frontend/__tests__/ - Integration tests: Root level (
test_*.py) - Smoke tests:
scripts/directory
Running Tests in Different Modes
# Online tests (requires Supabase)
SUPABASE_URL=<url> pytest
# Offline tests (uses in-memory store)
pytest # without SUPABASE_URL
# Specific test categories
pytest -m "not integration" # Skip integration tests
pytest tests/test_health.py # Single test file
This architecture provides a solid foundation for rapid development while maintaining production-readiness and scalability.
What's inside
7 sections: development commands, architecture overview, workflow, troubleshooting, testing strategy, plus code examples and file tree.
Change this for your project
- Replace
mohammed-Thameem-ansari/ASFwith your repository name - Replace
backend.main:appwith your FastAPI app module path - Replace
expected-tokenandlocalsecretwith your own auth tokens - Replace
SUPABASE_URLandSUPABASE_ANON_KEYwith your Supabase credentials
Where it goes
Save as AGENTS.md in your repository root. Read by Codex, Cursor and other agents that follow the AGENTS.md convention.
Worth borrowing
- Offline-first design with automatic fallback to in-memory store when Supabase is unavailable
- Multi-provider AI arbitration engine running OpenAI and Gemini in parallel with configurable strategies
- API versioning strategy (v1 stable, v2 enhanced, v3 experimental) for backward compatibility
Related Documents
Browser-only development
Guides AI assistants on an Electron + React + TypeScript desktop app for browsing and organizing AI-generated images locally.
Claude Agents — Reference & Recommendations
Catalogues 40+ Claude agents and marketing skills for building a cat adoption charity landing page, with a ready-to-paste prompt and backend API reference.
Golden DKG Prototype -- Master Plan
Defines an 8-phase implementation plan for a Rust prototype of the Golden non-interactive DKG protocol using BLS12-381 and tokio.
Swarms Examples Index
Lists 60+ example scripts for building single and multi-agent systems with the Swarms framework, organized by category and use case.