Spaces:
Sleeping
WhatsApp Clone
Overview
This is a Flask-based WhatsApp clone application that provides real-time messaging functionality with features like group chats, file sharing, voice message recording, and online/offline status tracking. The application uses a traditional server-side architecture with SQLAlchemy for database operations and real-time updates through client-side polling.
User Preferences
Preferred communication style: Simple, everyday language.
System Architecture
The application follows a traditional web application architecture with:
- Frontend: Server-side rendered HTML templates with vanilla JavaScript for interactivity
- Backend: Flask web framework with SQLAlchemy ORM for database operations
- Database: SQLite (default) with PostgreSQL support through environment configuration
- File Storage: Local filesystem storage for uploaded files
- Real-time Updates: Client-side polling mechanism for message updates
Key Components
Backend Components
Flask Application (
app.py
)- Main application configuration and setup
- Database initialization with SQLAlchemy
- File upload configuration (100MB max, multiple file types supported)
- Session management with secret key configuration
Database Models (
models.py
)- User model with unique ID generation system
- Conversation model supporting both private and group chats
- ConversationParticipant model for managing chat memberships
- Message model for storing chat messages (incomplete in current codebase)
- MessageSeen model for tracking message read status (referenced but not fully implemented)
Routes (
routes.py
)- RESTful API endpoints for user registration, messaging, and file operations
- File upload/download handling with MIME type detection
- Authentication and session management
- Conversation and message management endpoints
Frontend Components
Templates (
templates/
)- Landing page for user onboarding
- Registration form for new user signup
- Main chat interface with sidebar and message area
- Settings page for user account management
Static Assets (
static/
)- CSS styling with responsive design and mobile support
- JavaScript modules for chat functionality, file handling, and audio recording
- Modular architecture with separate files for different features
Data Flow
- User Registration: Users register with name and email, receiving an auto-generated 8-character unique ID
- Authentication: Session-based authentication using Flask sessions
- Conversation Creation: Users can create private or group conversations (3-10 members)
- Message Exchange: Real-time messaging through client-side polling mechanism
- File Sharing: Upload and download files with automatic MIME type detection and icon assignment
- Voice Messages: Web Audio API integration for recording and playback (in development)
External Dependencies
Backend Dependencies
- Flask: Web framework for application structure
- SQLAlchemy: ORM for database operations with declarative base
- Werkzeug: WSGI utilities and security features
- ProxyFix: Middleware for handling proxy headers
Frontend Dependencies
- Bootstrap 5.3.0: CSS framework for responsive UI design
- Font Awesome 6.0.0: Icon library for UI elements
- Web Audio API: Browser API for voice recording functionality
Database Support
- SQLite: Default database for development and simple deployments
- PostgreSQL: Production database support through DATABASE_URL environment variable
Deployment Strategy
The application is designed for flexible deployment with:
- Environment Configuration: Database and session secrets configurable via environment variables
- Proxy Support: ProxyFix middleware for deployment behind reverse proxies
- File Storage: Local filesystem storage with configurable upload directory
- Database Migration: Automatic table creation on application startup
- Debug Mode: Configurable debug mode for development vs. production
Key Configuration Options
DATABASE_URL
: Database connection string (defaults to SQLite)SESSION_SECRET
: Secret key for session managementUPLOAD_FOLDER
: Directory for file uploadsMAX_CONTENT_LENGTH
: Maximum file upload size (100MB default)
The architecture supports both development environments (with SQLite and debug mode) and production deployments (with PostgreSQL and proxy configuration). The modular JavaScript architecture and responsive CSS design ensure compatibility across different devices and screen sizes.