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

Entities the theory

Entities the theory

The underlying theory for Entities

Cbb9cafe03e785d80a9aa973c5e43c44?s=128

Thanos Polychronakis

December 04, 2014
Tweet

Transcript

  1. Entities Entities The Theory The Theory

  2. 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
  3. The MVC bankruptcy The MVC bankruptcy @thanpolas

  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. Ok, now what? Ok, now what? @thanpolas

  12. Decouple Decouple Separate Separate Draw Lines Draw Lines @thanpolas

  13. Meet Meet MVCe MVCe @thanpolas

  14. @thanpolas

  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 @thanpolas
  16. Core Principles Core Principles Human readable API Normalised Input Normalised

    Output @thanpolas
  17. 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
  18. Core Principles Core Principles Normalised Input Normalised Input userEnt.create({ firstName:

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

    "id": "3kdp349r7fhw", "firstName": "Thanasis", "lastName": "Polychronakis", "email": "thanpolas@gmail.com", } Aggregates datasets Normalizes db idiomacies Consistency @thanpolas
  20. CRUD API CRUD API @thanpolas

  21. The CRUD Primitives The CRUD Primitives create() read() readOne() readLimit()

    update() delete() count() @thanpolas
  22. it depends™ it depends™ Validations Validations @thanpolas

  23. 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
  24. NO NO Are entities only for Are entities only for

    the backend? the backend? @thanpolas
  25. REMEMBER REMEMBER Entities are Entities are Normalizers Aggregators Pipes Your

    business logic @thanpolas