- Created shared/models.py with all common Pydantic models - Updated voicebot/main.py to use shared models and remove dd.get() calls - Updated server/main.py to use shared models - Fixed lobby_state message handling with proper validation - Updated Dockerfiles to include shared/ directory - Added comprehensive documentation and migration guide Benefits: - Type safety across both components - Consistent data validation - Eliminated unsafe dictionary access patterns - Centralized model definitions for easier maintenance
2.1 KiB
2.1 KiB
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
- Consistency: Both components use the same data structures
- Type Safety: Pydantic validation prevents runtime errors
- Documentation: Models serve as living documentation of the API
- Maintainability: Changes to data structures only need to be made in one place
- Validation: Automatic validation of incoming/outgoing data
Model Categories
Core Data Models
LobbyModel
: Core lobby structureSessionModel
: Core session structureParticipantModel
: Participant information
HTTP API Models
AdminNamesResponse
,AdminActionResponse
: Admin endpointsLobbiesResponse
,SessionResponse
: Lobby/session endpointsLobbyCreateRequest
,LobbyCreateResponse
: Lobby creation
WebSocket Models
WebSocketMessageModel
: Base WebSocket message structureJoinStatusModel
,UserJoinedModel
: User eventsLobbyStateModel
: Lobby state updatesUpdateModel
: Generic updates
WebRTC Signaling Models
AddPeerModel
,RemovePeerModel
: Peer managementSessionDescriptionModel
: WebRTC session descriptionsIceCandidateModel
: ICE candidate exchange