Shared Models

This directory contains shared Pydantic models used for API communication between the voicebot and server components.

Structure

  • models.py: Contains all shared Pydantic models organized into logical sections:
    • Core Data Models (persistence and API communication)
    • HTTP API Request/Response Models
    • WebSocket Message Models
    • WebRTC Signaling Models (specific to voicebot)
    • Data Persistence Models

Usage

Both the server/ and voicebot/ components import these shared models to ensure consistent data validation and type safety across the entire application.

In Server (server/main.py):

from shared.models import (
    SessionModel,
    LobbyCreateResponse,
    AdminActionResponse,
    # ... other models
)

In Voicebot (voicebot/main.py):

from shared.models import (
    WebSocketMessageModel,
    JoinStatusModel,
    LobbyStateModel,
    AddPeerModel,
    # ... other models
)

Benefits

  1. Consistency: Both components use the same data structures
  2. Type Safety: Pydantic validation prevents runtime errors
  3. Documentation: Models serve as living documentation of the API
  4. Maintainability: Changes to data structures only need to be made in one place
  5. Validation: Automatic validation of incoming/outgoing data

Model Categories

Core Data Models

  • LobbyModel: Core lobby structure
  • SessionModel: Core session structure
  • ParticipantModel: Participant information

HTTP API Models

  • AdminNamesResponse, AdminActionResponse: Admin endpoints
  • LobbiesResponse, SessionResponse: Lobby/session endpoints
  • LobbyCreateRequest, LobbyCreateResponse: Lobby creation

WebSocket Models

  • WebSocketMessageModel: Base WebSocket message structure
  • JoinStatusModel, UserJoinedModel: User events
  • LobbyStateModel: Lobby state updates
  • UpdateModel: Generic updates

WebRTC Signaling Models

  • AddPeerModel, RemovePeerModel: Peer management
  • SessionDescriptionModel: WebRTC session descriptions
  • IceCandidateModel: ICE candidate exchange