@startuml classes ' Diagramme de classes — Application web Flashcards (Architecture : couche d'accès générique) skinparam classAttributeIconSize 0 skinparam classFontStyle bold ' ===== Domaine ===== class Card { - id : string - question : string - response : string - theme : string - tags : string[] - createdAt : Date - updatedAt : Date + Card(id, question, response, theme, tags) + validate() : void } ' ===== Abstraction générique d'accès aux données ===== interface CardRepository { + findAll() : Promise + findById(id : string) : Promise + findRandom() : Promise + findRandomByTheme(theme : string) : Promise + findThemes() : Promise + create(card : Card) : Promise + update(card : Card) : Promise + delete(id : string) : Promise } ' ===== Implémentations SGBD ===== class MysqlCardRepository { - connection : MysqlConnection + MysqlCardRepository(connection) } class MongoCardRepository { - collection : MongoCollection + MongoCardRepository(collection) } class "MysqlConnection" as ConnMysql { - host : string - port : number - user : string - password : string - database : string + query(sql : string, params : unknown[]) : Promise } class "MongoCollection" as ColMongo { + find(filter : object) : Promise + insertOne(doc : object) : Promise + updateOne(filter : object, update : object) : Promise + deleteOne(filter : object) : Promise } class DatabaseConfig { - driver : string + getActiveDriver() : string } ' ===== Service métier (dépend uniquement de l'abstraction) ===== class CardService { - repository : CardRepository + CardService(repository : CardRepository) + listCards() : Promise + getCard(id : string) : Promise + createCard(payload : NewCardPayload) : Promise + updateCard(id : string, payload : UpdateCardPayload) : Promise + deleteCard(id : string) : Promise + playRandom(theme? : string) : Promise + listThemes() : Promise } ' ===== Couche exposition (routes / contrôleur) ===== class CardController { + handleList(req, res) : Promise + handleGetById(req, res) : Promise + handleCreate(req, res) : Promise + handleUpdate(req, res) : Promise + handleDelete(req, res) : Promise + handlePlayRandom(req, res) : Promise + handleThemes(req, res) : Promise } class Factory { {static} buildCardRepository(config : DatabaseConfig) : CardRepository } ' ===== Relations ===== CardRepository <|.. MysqlCardRepository CardRepository <|.. MongoCardRepository MysqlCardRepository *-- ConnMysql : utilise > MongoCardRepository *-- ColMongo : utilise > CardService *-- CardRepository : <> utilise > CardService ..> Card : < crée/retourne CardController --> CardService : utilise Factory ..> CardRepository : <> construit Factory ..> CardService : construit @enduml