Prerequisites
Before you begin, ensure you have the following installed:- Python 3.11+ - Backend runtime
- Node.js 18+ - Frontend runtime (if working on client)
- Redis - Session management and caching
- Africa’s Talking Account - Sandbox or production credentials
- ngrok - For local webhook testing (required for Voice/SMS/USSD)
Project Structure
Initial Setup
1. Clone the Repository
2. Backend Setup
Create Virtual Environment
Install Dependencies
fastapi- Web frameworkuvicorn- ASGI serverafricastalking- Africa’s Talking SDKsqlalchemy- Database ORMredis- Cachingpydantic-settings- Configuration management
3. Environment Configuration
The application usespydantic-settings for configuration management. Create a .env file in the server/ directory:
Secret keys can be generated using
python -c "import secrets; print(secrets.token_urlsafe(32))"4. Start Redis
Redis is required for caching and session management:5. Initialize Database
The application uses SQLite for development (PostgreSQL recommended for production):voicepact.db will be created with WAL mode enabled for concurrent access.
6. Frontend Setup (Optional)
Running the Application
Start the Backend Server
- API: http://localhost:8000
- Interactive docs: http://localhost:8000/docs
- Health check: http://localhost:8000/health
Development Server Features
The FastAPI server includes:- Auto-reload: Code changes trigger automatic restart
- Debug mode: Detailed error messages and stack traces
- CORS enabled: Configured for local frontend development
- Swagger UI: Interactive API documentation at
/docs - Async support: Non-blocking I/O for external API calls
Verify Installation
Test the server is running correctly:Development Workflow
Code Organization
The codebase follows FastAPI best practices:Configuration System
Settings are managed viaserver/app/core/config.py:Settings using pydantic-settings:
Database Access
The application uses async SQLAlchemy:Adding New Endpoints
- Create endpoint in
server/app/api/v1/endpoints/ - Define request/response models with Pydantic
- Add router to
server/app/api/v1/api.py - Test with
/docsinteractive UI
Debugging Tips
Enable Debug Logging
- Detailed stack traces in responses
- SQL query logging (with
DATABASE_ECHO=true) - Verbose application logs
Common Issues
Redis Connection Failed
Redis Connection Failed
Symptom: Application fails to start with Redis connection errorSolution:
Database Locked Error
Database Locked Error
Symptom:
database is locked error with SQLiteSolution: SQLite is configured with WAL mode, but ensure:- Only one server instance is running
- Database file has write permissions
- No manual SQLite connections are open
Import Errors
Import Errors
Symptom: Module not found errorsSolution:
Africa's Talking API Errors
Africa's Talking API Errors
Symptom: SMS or Voice calls failSolution:
- Verify
AT_API_KEYis set correctly in.env - Check API key has appropriate permissions
- For voice/webhooks, ensure ngrok is configured (see ngrok setup guide)
Using the Interactive Docs
FastAPI provides Swagger UI at http://localhost:8000/docs:- Navigate to any endpoint
- Click “Try it out”
- Fill in request parameters
- Execute and view response
- See generated curl command
Hot Reload
The development server supports hot reload:Performance Considerations
Development vs Production
Development mode includes:- ✅ Debug mode enabled
- ✅ Auto-reload on code changes
- ✅ Detailed error messages
- ✅ API documentation enabled
- ✅ SQLite database
- ✅ Verbose logging
- ❌ Debug mode disabled
- ❌ No auto-reload
- ❌ Generic error messages
- ❌ API docs disabled
- ✅ PostgreSQL database
- ✅ Error-level logging only
Local Resource Usage
- Memory: ~200MB baseline (increases with Whisper model size)
- CPU: Low idle, spikes during audio processing
- Disk: ~50MB + database size
- Network: Depends on Africa’s Talking API usage
Next Steps
Testing Guide
Learn how to write and run tests for VoicePact
ngrok Setup
Configure ngrok for webhook testing
API Reference
Explore the complete API documentation
Architecture
Understand the system architecture