A comprehensive FastAPI REST API backend for a Gen-Z-focused Android app that summarizes conversations from multiple platforms (WhatsApp, Instagram, Discord) and generates short voice message summaries using ElevenLabs TTS. The backend also integrates with ElevenLabs' conversational assistant and Google Calendar for event management.
- WhatsApp: Parse chat exports and extract conversations
- Instagram: Process direct messages and group chats
- Discord: Handle server conversations and DMs
- Extensible: Easy to add new platforms
- Personality Analysis: Automatically analyze communication patterns
- Voice Assignment: Assign ElevenLabs voices based on personality traits
- Relationship Context: Track relationship types (family, friends, colleagues)
- Trust Scoring: Calculate trust levels based on interaction history
- Interest Tracking: Identify topics and interests from conversations
- Context-Aware: Uses user profiles for personalized summaries
- Personality Preservation: Maintains individual communication styles
- Relationship Dynamics: Highlights social interactions and dynamics
- Tone Analysis: Analyzes conversation mood and emotional context
- Personality-Based Voices: Automatically select voices based on user traits
- Emotion Detection: Adjust voice settings based on emotional content
- Custom Voice Settings: Stability, similarity boost, and style adjustments
- Batch Processing: Generate multiple audio files efficiently
- ElevenLabs Assistant: Conversational AI with personality context
- Calendar Management: Create and manage events via Google Calendar
- User Context: Assistant uses conversation history and user profiles
- Multi-Platform Context: Access to conversations across all platforms
- Automatic API Documentation: Interactive Swagger UI at
/docs - Type Safety: Full type hints and Pydantic validation
- Async Support: High-performance async/await operations
- Dependency Injection: Clean service and repository injection
- OpenAPI 3.0: Standard API specification
cc-backend/
├── app.py # Main FastAPI application
├── main.py # Application entry point
├── config.py # Configuration management
├── api/
│ ├── models.py # Pydantic models for validation
│ ├── dependencies.py # Dependency injection
│ └── routers/ # Modular route organization
│ ├── conversations.py # Conversation endpoints
│ ├── users.py # User profile endpoints
│ ├── assistant.py # AI assistant endpoints
│ ├── audio.py # Audio file endpoints
│ └── voices.py # ElevenLabs voice endpoints
├── database/ # Supabase integration
├── services/ # Business logic
└── requirements.txt # Dependencies
- ConversationSession: Multi-platform conversation sessions
- PlatformMessage: Generic message model for any platform
- MainUser: App owner with platform connections
- UserProfile: Profiles for people the main user talks to
- Summary: AI-generated summaries with personality context
- AudioFile: Generated TTS audio files with voice settings
- AssistantSession: Assistant conversation sessions
- CalendarEvent: Google Calendar events
- PlatformIntegration: Platform connection settings
- Personality traits (friendly, professional, humorous, etc.)
- Communication style (emoji-heavy, formal, casual, etc.)
- Interests and preferred topics
- Relationship type and trust score
- Voice preferences and settings
- Interaction frequency and history
- Multi-platform message parsing
- User profile creation and updates
- Personality analysis and trait extraction
- Relationship type detection
- Trust score calculation
- Context-aware summarization using user profiles
- Personality-preserving dialogue generation
- Tone and emotion analysis
- Key update extraction
- Relationship dynamics analysis
- Personality-based voice selection
- Emotion-aware voice settings
- Batch audio generation
- Voice cloning and management
- User voice preference management
- ElevenLabs conversational assistant
- Google Calendar integration
- User context integration
- Multi-platform conversation access
- Python 3.8+
- Supabase account (PostgreSQL database)
- ElevenLabs API key
- OpenAI API key
- Google Calendar API (optional)
- Clone the repository
git clone <repository-url>
cd cc-backend- Install dependencies
pip install -r requirements.txt-
Set up Supabase
- Create a new project at supabase.com
- Get your project URL and anon key from Settings > API
- The database tables will be created automatically on first run
-
Set up environment variables
cp env.example .envpip uninstall Flask Flask-CORS Flask-RESTful
pip install fastapi uvicorn[standard] python-multipart httpx pydantic-settingsEdit .env with your configuration:
# Database Configuration (Supabase PostgreSQL)
SUPABASE_URI=https://your-project-ref.supabase.co
SUPABASE_API_KEY=your-supabase-anon-key
# API Keys (Required)
ELEVENLABS_API_KEY=your_elevenlabs_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
# Google Calendar (optional)
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URI=http://localhost:8000/api/assistant/calendar/callback
# File Storage
UPLOAD_FOLDER=uploads
AUDIO_FOLDER=audio
# FastAPI Configuration
FASTAPI_DEBUG=true
FASTAPI_HOST=0.0.0.0
FASTAPI_PORT=8000
SECRET_KEY=your-secret-key-here
# CORS Configuration
CORS_ORIGINS=http://localhost:3000,http://127.0.0.1:3000
CORS_ALLOW_CREDENTIALS=true- Test the migration
python test_fastapi_migration.py- Run the application
# Development
python main.py
# Or directly with uvicorn
uvicorn app:app --reload --host 0.0.0.0 --port 8000The API will be available at http://localhost:8000
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Health Check: http://localhost:8000/api/health
POST /api/conversations/upload
Content-Type: application/json
{
"platform": "whatsapp",
"main_user": "john_doe",
"group_name": "Family Group",
"conversation_type": "group",
"messages": [
{
"sender": "mom",
"content": "Hey everyone! How's your day going?",
"isGroup": true,
"conversationName": "Family Group",
"appId": "com.whatsapp.app",
"timestamp": 1751167953
}
]
}New JSON Format (Recommended):
{
"platform": "whatsapp",
"main_user": "john_doe",
"group_name": "Keanu Czirjak",
"conversation_type": "individual",
"messages": [
{
"sender": "Keanu Czirjak",
"content": "How are you",
"isGroup": false,
"conversationName": "Keanu Czirjak",
"appId": "com.whatsapp.app",
"timestamp": 1751167953
},
{
"sender": "Keanu Czirjak",
"content": "I am in london this week",
"isGroup": false,
"conversationName": "Keanu Czirjak",
"appId": "com.whatsapp.app",
"timestamp": 1751167980
},
{
"sender": "Keanu Czirjak",
"content": "let me know if i can see you soon",
"isGroup": false,
"conversationName": "Keanu Czirjak",
"appId": "com.whatsapp.app",
"timestamp": 1751167980
}
]
}Message Format Fields:
sender: The name/username of the message sendercontent: The message text contentisGroup: Boolean indicating if this is a group conversationconversationName: Name of the conversation/groupappId: Platform-specific app identifier (e.g., "com.whatsapp.app")timestamp: Unix timestamp of the message (integer)
Legacy Format (Still Supported):
{
"platform": "whatsapp",
"main_user": "john_doe",
"group_name": "Family Group",
"conversation_type": "group",
"messages": [
{
"username": "mom",
"content": "Hey everyone! How's your day going?",
"timestamp": "2024-01-15T10:30:00Z",
"type": "text"
}
]
}POST /api/conversations/upload-file
Content-Type: multipart/form-data
file: [WhatsApp chat export .txt file]
main_user: john_doe
group_name: Family GroupPOST /api/conversations/{session_id}/summarize
Content-Type: application/json
{
"include_personality": true,
"include_relationships": true,
"summary_length": "medium"
}POST /api/conversations/{session_id}/generate-audio
Content-Type: application/json
{
"voice_settings": {
"stability": 0.5,
"similarity_boost": 0.75
},
"include_emotions": true
}GET /api/users/profiles?page=1&per_page=10&platform=whatsappPUT /api/users/profiles/{profile_id}
Content-Type: application/json
{
"display_name": "Mom",
"voice_id": "voice_id_here",
"personality_traits": ["caring", "organized"],
"relationship_type": "family",
"trust_score": 0.9
}GET /api/audio/{session_id}GET /api/audio/{session_id}/{filename}POST /api/assistant/chat
Content-Type: application/json
{
"message": "What did my family talk about yesterday?",
"include_calendar": true,
"include_user_profiles": true
}POST /api/assistant/calendar/events
Content-Type: application/json
{
"main_user_id": 1,
"title": "Family Dinner",
"start_time": "2024-01-20T18:00:00Z",
"end_time": "2024-01-20T20:00:00Z",
"description": "Weekly family dinner",
"location": "Home"
}GET /api/voices/python test_fastapi_migration.pypython test_supabase_integration.py# Health check
curl http://localhost:8000/api/health
# List conversations
curl http://localhost:8000/api/conversations/
# Upload conversation
curl -X POST "http://localhost:8000/api/conversations/upload" \
-H "Content-Type: application/json" \
-d '{"platform": "whatsapp", "group_name": "Test Group", "main_user": "test_user", "messages": []}'FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]FASTAPI_DEBUG=false
FASTAPI_HOST=0.0.0.0
FASTAPI_PORT=8000
CORS_ORIGINS=https://yourdomain.com
SECRET_KEY=your-production-secret-key
ALLOWED_HOSTS=yourdomain.com- FastAPI Migration Guide - Detailed migration documentation
- Database Migration Guide - Supabase integration details
- API Documentation - Interactive API docs
# Format code
black .
# Lint code
flake8 .- Create a new router in
api/routers/ - Add Pydantic models in
api/models.py - Add dependencies in
api/dependencies.py - Include the router in
app.py
- Create service class in
services/ - Add dependency injection in
api/dependencies.py - Use in routers with dependency injection
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues or questions:
- Check the FastAPI Migration Guide
- Review the API documentation at
/docs - Check application logs
- Verify environment configuration