Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Entities the theory

Entities the theory

The underlying theory for Entities

Avatar for Thanos Polychronakis

Thanos Polychronakis

December 04, 2014
Tweet

More Decks by Thanos Polychronakis

Other Decks in Technology

Transcript

  1. Who am I Working for over 3 years on Node.js

    Authored >40 NPM packages Contributed to even more CTO Insight Replay Founder netscan.co @thanpolas
  2. Models represent a schema Models are FAT Business logic leaks

    to Controllers Handling of higher level operations MVC is not enough today The MVC bankruptcy The MVC bankruptcy @thanpolas
  3. Active Record (Single Table) Validations Relations Methods (db related) It's

    an ORM configuration The MVC bankruptcy The MVC bankruptcy Models represent a schema Models represent a schema @thanpolas
  4. 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 bankruptcy The Model bankruptcy Models are FAT (core models > 4k lines) Models are FAT (core models > 4k lines) @thanpolas
  5. Send verification email Perform multiple table OPs Talk to services

    ​memcache pupsub redis The MVC bankruptcy The MVC bankruptcy Business logic leaks to Controllers Business logic leaks to Controllers @thanpolas
  6. The MVC bankruptcy The MVC bankruptcy Business logic leaks to

    Controllers Business logic leaks to Controllers How do you run the operation from a Cron Job? Back office? API? CLI? How do you test? @thanpolas
  7. Multiple tables involved Multiple Services involved Complex Auth Schemes Real

    Time The MVC bankruptcy The MVC bankruptcy Handling of higher level operations Handling of higher level operations @thanpolas
  8. Way more complex flows Service oriented design SaaS / PaaS

    Infrastructure Multiple inputs The MVC bankruptcy The MVC bankruptcy MVC is not enough today MVC is not enough today @thanpolas
  9. 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 @thanpolas
  10. Core Principles Core Principles Human readable API Human readable API

    userEnt.create(udo); userEnt.delete(uid); userEnt.sendMessage(fromId, toId, message); videoEnt.process(videoPath); Methods that make sense Think action not operation @thanpolas
  11. Core Principles Core Principles Normalised Input Normalised Input userEnt.create({ firstName:

    "Thanasis", lastName: "Polychronakis", email: "[email protected]", }); Well documented expectations No need to be validated @thanpolas
  12. Core Principles Core Principles Normalized Output Normalized Output console.log(udoOut); {

    "id": "3kdp349r7fhw", "firstName": "Thanasis", "lastName": "Polychronakis", "email": "[email protected]", } Aggregates datasets Normalizes db idiomacies Consistency @thanpolas
  13. Validations Validations 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 @thanpolas
  14. NO NO Are entities only for Are entities only for

    the backend? the backend? @thanpolas