3. Models represent a schema
Models are FAT
Business logic leaks to Controllers
Handling of higher level operations
MVC is not enough today
The MVC bankruptcyThe MVC bankruptcy
4. Active Record (Single Table)
Validations
Relations
Methods (db related)
It's an ORM configuration
The MVC bankruptcyThe MVC bankruptcy
Models represent a schemaModels represent a schema
5. You gotta see it to believe it
Ok, I bet you've seen it!
It's ugly
It's not entirely the Model's fault
Decouple
The Model bankruptcyThe Model bankruptcy
Models are FAT (core models > 4k lines)Models are FAT (core models > 4k lines)
6. Send verification email
Perform multiple table OPs
Talk to services
memcache
pupsub
redis
The MVC bankruptcyThe MVC bankruptcy
Business logic leaks to ControllersBusiness logic leaks to Controllers
7. The MVC bankruptcyThe MVC bankruptcy
Business logic leaks to ControllersBusiness logic leaks to Controllers
How do you run the operation from a
Cron Job?
Back office?
API?
CLI?
How do you test?
8. Multiple tables involved
Multiple Services involved
Complex Auth Schemes
Real Time
The MVC bankruptcyThe MVC bankruptcy
Handling of higher level operationsHandling of higher level operations
9. Way more complex flows
Service oriented design
SaaS / PaaS Infrastructure
Multiple inputs
The MVC bankruptcyThe MVC bankruptcy
MVC is not enough todayMVC is not enough today
15. Think of Entities as...Think of Entities as...
Pipes
Data transformers
Operation plexers
Switches
Adaptors
Aggregators
Entities are inspired by the Service Layer design pattern
17. Core PrinciplesCore Principles
Human readable APIHuman readable API
userEnt.create(udo);
userEnt.delete(uid);
userEnt.sendMessage(fromId, toId, message);
videoEnt.process(videoPath);
Methods that make sense
Think action not operation
18. Core PrinciplesCore Principles
Normalised InputNormalised Input
userEnt.create({
firstName: "Thanasis",
lastName: "Polychronakis",
email: "thanpolas@gmail.com",
});
Well documented expectations
No need to be validated
23. ValidationsValidations
Is there an ORM CRUD OP?
Perform actions before or after ORM?
Do you trust your input?
Outside world?
Internal invocation?
Better not to trust anybody
24. Are entities only forAre entities only for
the backend?the backend?
NONO