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

How Fervo builds web apps

How Fervo builds web apps

Magnus Nordlander

May 11, 2016
Tweet

More Decks by Magnus Nordlander

Other Decks in Programming

Transcript

  1. Magnus Nordlander • PHP consultant and CEO with Fervo •

    Worked with PHP for well over 10 year, Symfony for over 9 years.
  2. • Small consultancy specialized in 
 modern PHP, Symfony in

    particular • Three PHP consultants, two
 Symfony certed • Read more at fervo.se
  3. Preface • I’m gonna introduce a lot of concepts •

    I could easily spend 45 minutes per concept or do a multi-day workshop on this • My goal is to pique your interest, so that you want to learn more
  4. Preface • Small projects require less structure • Some of

    the advice within this presentation is more appropriate for large projects • Your mileage may vary
  5. Tech Stack • PHP 7 is generally recommended, subsetphp is

    interesting • HHVM has been promising for a long time, but as PHP7 has become better, the need has diminished • Linux is generally recommended for servers • We prefer Postgres, but MySQL is fine too
  6. Tech Stack • Redis is great • Several mature Document

    oriented databases, but which one to choose depends • ElasticSearch is awesome for search • We love Heroku, and we're fond of AWS.
  7. Tech Stack • We're all using Docker for our dev

    environments • Docker for Mac is interesting, but not good enough yet • Docker in production is very interesting, and we hope to use it in a client project soon
  8. Tech Stack • We generally recommend php-fpm • There have

    been interesting developments for a long time in serving requests from within PHP • Leach (0MQ) • ReactPHP / PHP-PM • PHPFastCGI
  9. Development methodology • We don't believe in waterfall • We

    generally recommend BDD, both Story BDD and Spec BDD • Communication and collaboration is key
  10. BDD • Behavior driven development • TDD “done right” •

    TDD + DDD + OOA&D => BDD • Many pay lip service to testing, BDD gives immediate rewards, encouraging adoption
  11. Story BDD • Capture business requirements in a testable format

    • Written in business readable, ubiquitous language • Behat is a great tool for Story BDD, just make sure you run Behat 3
  12. Spec BDD • Specifies what a class should do and

    how it should interact with other classes • PHPSpec is excellent • Makes it painfully obvious when you’re violating SOLID
  13. Software architecture • Your domain code is at the center

    of your application • Web framework for integrating your domain code with the web • CLI framework for giving your domain code a CLI
  14. Domain code • Written like a library • We generally

    recommend Command-Query Separation • We also generally recommend using events • Commands and events are messages
  15. Domain code • Take a DDD approach to modeling your

    domain • Analyze your problem domain, create a model • Entities, Value objects, Aggregates, Domain events, Services, Repositories and Factories • Event storming looks cool, but we’ve never had the opportunity to do it
  16. Messages • Imagine you’re the emperor of Rome. You like

    to sit in your palace. • When your army has conquered new territory, you are passed a scroll with the details of the event • When you need to quash a rebellion to maintain pax romana, you send a scroll with your command to the governor
  17. Messages • Messages differ mainly in intent • Events are

    informative in nature, and they are passed to anyone whom they concern • Commands are imperative in nature, and they are only passed to their respective command handler
  18. –The Office “Look, it doesn't take a genius to know

    that any organization thrives when it has two leaders. Go ahead, name a country that doesn't have two presidents. A boat that sets sail without two captains. Where would Catholicism be without the popes?
  19. Messages • Messages are just small PHP class instances that

    can be passed around • Immutability is king • Messages do not have return values
  20. Messages • To handle a message, we use a message

    bus • Commands are handled by a command bus • Exactly one handler per command • Events are handled by an event bus • Zero or more event listeners
  21. SimpleBus • Message bus library written by Matthias Noback •

    Messages and handlers are just your own PHP classes • Also supports asynchronous message handling
  22. Specification Pattern • All members who have the gold status

    • SELECT * FROM members WHERE status = ‘gold’
  23. Specification Pattern • Not very object oriented • Ties your

    query builder to both your database engine and your database scheme • Imagine having to implement a rules engine
  24. Web frameworks • Integrate your domain code into the web

    • A controller takes an HTTP request, returns an HTTP response • Thin glue to your domain • Your domain code does not have any dependencies on your web framework
  25. Web frameworks • Modern frameworks are many things • In

    Symfony, the web framework is really only HttpKernel and HttpFoundation • Web related components (security, form) • Glue components (dependency injection) • Misc (yaml, ldap)
  26. Frameworks • Depending on one of the miscellaneous components is

    fine if it makes sense. • In Symfony, we have the concept of a bundle, which integrates a library with the framework • Your domain code is a library
  27. Dependency Injection • Separate your domain code and your bundle

    • Your domain code should know nothing of your DI container • Most of your bundle should know nothing of your DI container • Bundle extension and compiler passes mostly
  28. Dependency Injection • Symfony controller base class is not a

    good role model • Luckily, it’s optional
  29. Contact • @drrotmos on Twitter • [email protected] • Want help?

    We’re a consultancy, so give me a call • https://www.fervo.se