EGF2 Guide - Domain Modeling

I think it makes sense to start with a User model and proceed from there.

EGF2 comes with a User object pre-defined. We can expand it with more fields and edges if necessary, but we should not remove it unless we don't want to expose any user related APIs.

Here is how it looks, in pseudo JSON:

    “object_type”: “user”,
    “name”: HumanName
    “email”: “<string>”,
    “system”: “<string, SystemUser object ID>”,
    “verified”: Boolean

I think it is enough for a start. Looking at the specification of features it is clear that we need to support the following user roles:

  • Regular user, let's call the role CustomerRole
  • Admin user - AdminRole

Let's define the roles.

    “object_type”: “customer_role”,
    “user”: User
    “object_type”: “admin_role”,
    “user”: User

User's roles should be stored using roles edge of a User object. We usually refer to an edge using a simple notation <Object type>/<edge name>, for example User/roles. ACL support assumes that roles are store using this edge. We will use ACL in order to control access to objects and edges so we will use User/roles edge to store user's roles.

While we are at the user's part of it let's also add edges for the following bit - User/followers and User/follows.

That's enough for the users part, let's get to the meat of the system - Posts.

    “object_type”: “post”,
    “creator”: User,
    "image": File,
    "description": "<string>",

As you can see, we specify image property as a File. This object type is supported by EGF2 out of the box.

Users create posts, so we need an edge to store a list of posts created by a User. Edge User/posts should do just fine.

We will use AdminRole/offending_post edge to keep track of posts that were found offensive. Post/offended edge will hold a list of users that found this Post offensive.

Registered users can post comments for posts. Comment can be modelled as:

    “object_type”: “comment”,
    “creator”: User,
    "post": Post,
    "text": "<string>",

We will connect Posts to Comments using Post/comments edge.

One more thing. We need to decide how user's timeline should behave. There are at least two ways we can approach this:

  • For a particular user we can calculate timeline dynamically based on the list of users this particular user follows. This is feasible in case a single user follows not a large number of other users. If we get in to hundreds of follows this approach will be problematic due to performance issues.
  • We can add an edge User/timeline and create an edge every time a user that is being followed creates a Post. This approach will work well for GET requests but will require resources in case we get into situation when there are users with large number of followers.

We will take the second route as it scales better. There are a couple of consequences of this decision:

  • Timeline will only show posts that were added after a user has started following another user
  • Old posts will not be removed from the timeline when a user stops following another user.

Both consequences can be avoided at the cost of additional processing, but I don't think it is really necessary from the business logic standpoint.

Info about object and edges can (and I think should) be summarised in Model section of the system documentation, for more info see Suggested Documentation Format section of the EGF2 documentation.

That's it for domain modelling, at least for now. In the next post I will show you how what needs to be done to implement this model with EGF2.

comments powered by Disqus