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:
User
is an aggregate root, andFolder
andTodo
are aggregates ofUser
, correct? If, for example, I need to change the content of anAfazer
, I must do so throughUser
, right?- For some reason,
Folder
seems 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? (AUser
can delete/create folders). - Can
Folder
just referenceTodo
s 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 (Folder
andUser
would have the sameTodo
but in different locations), that feels like a no no
Now, more database-related questions:
-
Aren't
Folder
s andTodo
s 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
Folder
is an aggregate root, and thus it should have its own repository, and thus it should have its own table, then how would it reference theUser
it belongs to? Should theUser
reference theFolder
s it has, or should theFolder
reference its owner? -
Same questions for the
Todo
s, should they reference their owner, or shouldUser
reference 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