# NEDA Backend NEDA is a real-time group voice communication backend designed for wearable devices (e.g., smartwatches). It enables secure, low-latency push-to-talk audio communication within isolated groups. This repository contains the FastAPI backend, realtime control layer, and database schema. --- # โœจ Features - Real-time push-to-talk voice groups - Single active speaker per group - Secure group isolation - Role-based group permissions - Admin-managed membership - Redis-based realtime state - LiveKit media integration - Async PostgreSQL (SQLAlchemy) - Alembic migrations - WebSocket signaling layer --- # ๐Ÿงฑ Architecture NEDA follows a **domain-oriented layered modular monolith** architecture. ``` core/ shared infrastructure db/ database & redis domains/ business domains integrations/ external services alembic/ migrations ``` Domains: - users - groups - realtime - auth - admin This design keeps domain logic isolated and allows future service extraction. --- # ๐ŸŽ™๏ธ Realtime Model - Audio media โ†’ LiveKit - Signaling โ†’ WebSocket (FastAPI) - State โ†’ Redis - Persistence โ†’ PostgreSQL Active speaker is stored in Redis: ``` speaker:{group_id} = user_id ``` Presence: ``` presence:{group_id} = set(user_ids) ```` --- # ๐Ÿ‘ฅ Roles System role (User): - `admin` - `user` Group role (GroupMember): - `group_manager` (exactly one per group) - `member` Only admins can: - create groups - assign group manager - add/remove members Group managers have realtime authority only (speaker control). --- # ๐Ÿ—„๏ธ Database Core entities: - User - Group - GroupMember - Session - GroupVoiceSession - SpeakerHistory Rules: - soft delete for main entities - single active group_manager per group - unique membership (user, group) --- # ๐Ÿš€ Running with Docker ```bash docker compose up --build ```` Services: * API โ†’ [http://localhost:8000](http://localhost:8000) * Docs โ†’ [http://localhost:8000/docs](http://localhost:8000/docs) * LiveKit โ†’ [http://localhost:7880](http://localhost:7880) * Postgres โ†’ 5432 * Redis โ†’ 6379 --- # โš™๏ธ Environment `.env` ``` APP_NAME=NEDA SECRET_KEY=change-me POSTGRES_DB=neda POSTGRES_USER=neda_user POSTGRES_PASSWORD=neda_pass DATABASE_URL=postgresql+asyncpg://neda_user:neda_pass@postgres:5432/neda REDIS_URL=redis://redis:6379/0 LIVEKIT_API_KEY=neda_key LIVEKIT_API_SECRET=neda_secret LIVEKIT_HOST=http://livekit:7880 ``` --- # ๐Ÿงช Development Setup Create venv and install: ```bash pip install -r requirements.txt ``` Run API: ```bash uvicorn neda.main:app --reload ``` --- # ๐Ÿ“œ Migrations (Alembic) Init (first time): ```bash alembic init alembic ``` Create migration: ```bash alembic revision --autogenerate -m "init" ``` Apply: ```bash alembic upgrade head ``` --- # ๐Ÿ”Œ Realtime Flow Request to speak: 1. Client โ†’ WS `REQUEST_TALK` 2. Backend โ†’ Redis `SET NX speaker:{group}` 3. If granted โ†’ LiveKit publish token 4. Others โ†’ subscribers 5. Release โ†’ Redis delete --- # ๐Ÿงญ Project Structure ``` domains/ users/ groups/ realtime/ auth/ admin/ ``` Each domain contains: * models * schemas * repo * service * api --- # ๐Ÿง  Design Principles * realtime state outside DB * single responsibility domains * admin control plane * Redis for locks/presence * DB for long-term truth * media separated from signaling --- # ๐Ÿ“ก Future Scaling The architecture supports: * realtime service extraction * horizontal scaling * sharded groups * multi-tenant deployments