--- id: er-diagram title: Modèle de Données sidebar_label: Modèle de Données description: Diagramme entité-relation de la base de données Veza Platform keywords: [veza, database, er, diagram, postgresql, schema] --- # 🗄️ Modèle de Données > **Diagramme entité-relation** de la base de données PostgreSQL de Veza Platform ## 📊 Vue d'Ensemble Le modèle de données de Veza Platform est conçu pour supporter les fonctionnalités de streaming audio, chat temps réel, et collaboration musicale avec une architecture scalable et performante. ```mermaid erDiagram USERS { uuid id PK string username UK string email UK string password_hash string first_name string last_name string avatar_url string bio boolean is_verified boolean is_active timestamp last_login timestamp created_at timestamp updated_at } PLAYLISTS { uuid id PK uuid user_id FK string name string description string cover_url boolean is_public boolean is_collaborative integer track_count integer duration_seconds timestamp created_at timestamp updated_at } TRACKS { uuid id PK string title string artist string album string genre integer duration_seconds integer bitrate string format string file_path string file_hash integer file_size string waveform_data json metadata boolean is_processed timestamp created_at timestamp updated_at } PLAYLIST_TRACKS { uuid playlist_id FK uuid track_id FK integer position timestamp added_at uuid added_by FK } ROOMS { uuid id PK string name string description uuid owner_id FK boolean is_public boolean is_active integer max_users integer current_users string room_code timestamp created_at timestamp updated_at } ROOM_USERS { uuid room_id FK uuid user_id FK string role timestamp joined_at timestamp last_seen } MESSAGES { uuid id PK uuid room_id FK uuid user_id FK string content string message_type json metadata uuid reply_to FK boolean is_edited timestamp created_at timestamp updated_at } SESSIONS { uuid id PK uuid user_id FK string token_hash string ip_address string user_agent timestamp expires_at timestamp created_at } UPLOADS { uuid id PK uuid user_id FK string filename string original_name string file_path integer file_size string mime_type string status json processing_metadata timestamp created_at timestamp completed_at } COLLABORATIONS { uuid id PK uuid playlist_id FK uuid user_id FK string permission timestamp invited_at timestamp accepted_at timestamp expires_at } ANALYTICS { uuid id PK uuid user_id FK string event_type json event_data string ip_address string user_agent timestamp created_at } USERS ||--o{ PLAYLISTS : owns USERS ||--o{ ROOMS : owns USERS ||--o{ MESSAGES : sends USERS ||--o{ SESSIONS : has USERS ||--o{ UPLOADS : uploads USERS ||--o{ COLLABORATIONS : participates USERS ||--o{ ANALYTICS : generates PLAYLISTS ||--o{ PLAYLIST_TRACKS : contains TRACKS ||--o{ PLAYLIST_TRACKS : belongs_to ROOMS ||--o{ ROOM_USERS : has USERS ||--o{ ROOM_USERS : joins ROOMS ||--o{ MESSAGES : contains MESSAGES ||--o{ MESSAGES : replies_to PLAYLISTS ||--o{ COLLABORATIONS : shared_via ``` ## 🔑 Clés et Index ### Clés Primaires - **USERS.id** : UUID v4 pour l'unicité globale - **PLAYLISTS.id** : UUID v4 pour l'unicité globale - **TRACKS.id** : UUID v4 pour l'unicité globale - **ROOMS.id** : UUID v4 pour l'unicité globale - **MESSAGES.id** : UUID v4 pour l'unicité globale ### Clés Étrangères - **PLAYLISTS.user_id** → **USERS.id** - **PLAYLIST_TRACKS.playlist_id** → **PLAYLISTS.id** - **PLAYLIST_TRACKS.track_id** → **TRACKS.id** - **ROOMS.owner_id** → **USERS.id** - **MESSAGES.room_id** → **ROOMS.id** - **MESSAGES.user_id** → **USERS.id** ### Index de Performance ```sql -- Index sur les requêtes fréquentes CREATE INDEX idx_users_username ON users(username); CREATE INDEX idx_users_email ON users(email); CREATE INDEX idx_playlists_user_id ON playlists(user_id); CREATE INDEX idx_playlists_public ON playlists(is_public); CREATE INDEX idx_tracks_title ON tracks(title); CREATE INDEX idx_tracks_artist ON tracks(artist); CREATE INDEX idx_messages_room_id ON messages(room_id); CREATE INDEX idx_messages_created_at ON messages(created_at); CREATE INDEX idx_sessions_user_id ON sessions(user_id); CREATE INDEX idx_sessions_expires_at ON sessions(expires_at); ``` ## 📈 Stratégies de Scaling ### Partitioning - **MESSAGES** : Partition par `room_id` (hash) - **ANALYTICS** : Partition par `created_at` (monthly) - **SESSIONS** : Partition par `user_id` (hash) ### Read Replicas - **USERS, PLAYLISTS, TRACKS** : Lectures sur répliques - **MESSAGES, ANALYTICS** : Lectures sur répliques dédiées - **SESSIONS** : Lectures sur réplique en mémoire ### Caching - **USERS** : Cache Redis (TTL: 1h) - **PLAYLISTS** : Cache Redis (TTL: 30min) - **TRACKS metadata** : Cache Redis (TTL: 2h) - **ROOMS** : Cache Redis (TTL: 15min) ## 🔒 Sécurité des Données ### Chiffrement - **password_hash** : bcrypt (cost 12) - **file_path** : Chiffré avec AES-256 - **metadata** : Chiffré avec AES-256 - **Sessions** : Tokens JWT signés ### Rétention - **SESSIONS** : Suppression automatique après expiration - **ANALYTICS** : Rétention 2 ans, archivage mensuel - **UPLOADS** : Nettoyage des fichiers échoués après 24h ### Audit - **Logs d'accès** : Tous les accès aux données sensibles - **Modifications** : Historique des changements critiques - **Suppressions** : Soft delete avec audit trail ## 📊 Métriques et Monitoring ### Métriques Clés - **Taille de la DB** : Croissance quotidienne - **Requêtes/seconde** : Par table et par type - **Latence** : P50, P95, P99 par requête - **Connexions** : Pool de connexions actives ### Alertes - **Taille DB** : > 80% de l'espace alloué - **Latence** : P95 > 500ms - **Erreurs** : > 1% des requêtes - **Connexions** : > 90% du pool ## 🔄 Migrations ### Stratégie - **Versioning** : Numérotation séquentielle - **Rollback** : Chaque migration réversible - **Testing** : Validation sur données de test - **Deployment** : Migration progressive ### Exemple de Migration ```sql -- Migration 001: Create users table CREATE TABLE users ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), username VARCHAR(50) UNIQUE NOT NULL, email VARCHAR(255) UNIQUE NOT NULL, password_hash VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT NOW(), updated_at TIMESTAMP DEFAULT NOW() ); -- Index pour performance CREATE INDEX idx_users_username ON users(username); CREATE INDEX idx_users_email ON users(email); ``` ## 📚 Voir Aussi - [Architecture Système](/docs/architecture/system) - [Backend Go API](/docs/backend/go-api) - [API Reference](/docs/api-reference/openapi) --- **Dernière mise à jour** : 2025-09-13 **Version** : 0.3.0 **Maintenu par** : Veza Platform Team