This is my first app with DDD in mind and now that (I hope) my simple domain is set up, I want to make sure everything's okay before I think about persistence.
type Todo = {
id: string,
content: string,
dateCreated: Date,
done: boolean
}
type Folder = {
id: string,
name: string,
todos: string[] // an array of Ids, they only hold reference to todos
}
type User = {
id: string,
username: Username,
email: Email,
password: Password,
folders: Record<string, Folder>,
todos: Record<string, Todo>
}
Here are the questions I have:
Useris an aggregate root, andFolderandTodoare aggregates ofUser, correct? If, for example, I need to change the content of anAfazer, I must do so throughUser, right?- For some reason,
Folderseems like a Value Object to me; it just holds a bunch of IDs. But I also feel like it should be an Entity because it has a lifecycle? (AUsercan delete/create folders). - Can
Folderjust referenceTodos by their IDs? That's no problem, right? Or do I have to map each of these IDs to an actual entity? But then, I'd have duplicates (FolderandUserwould have the sameTodobut in different locations), that feels like a no no
Now, more database-related questions:
-
Aren't
Folders andTodos also aggregate roots? So, they should have their own repositories and their own tables, correct? -
This is also my first time using a relational database, coming from NoSQL. If I am correct that
Folderis an aggregate root, and thus it should have its own repository, and thus it should have its own table, then how would it reference theUserit belongs to? Should theUserreference theFolders it has, or should theFolderreference its owner? -
Same questions for the
Todos, should they reference their owner, or shouldUserreference the todo it has?
So, when I map User to a persistence DTO, it would look something like:
{
id: string,
username: string,
email: string,
password: string,
folders: string[] // array of IDs, or again, as I asked, should the folder reference the user instead, or both?
todos: string[] // same question
}
a Folder would be mapped as such?:
{
id: string,
name: string,
ownerId: string, // ?
todos: string[]
}
I know these are really simple questions but I want to make sure I'm doing everything right so I can proceed to more complex domains.
Thank you so much
Aucun commentaire:
Enregistrer un commentaire