Merging two big Symfony based applications - SymfonyCon 2017

40
What we learned by merging two big Symfony based applications Ivo Lukač @ SymfonyCon 2017, Cluj

Transcript of Merging two big Symfony based applications - SymfonyCon 2017

Page 1: Merging two big Symfony based applications - SymfonyCon 2017

What we learned by merging two big Symfony based

applications Ivo Lukač @ SymfonyCon 2017, Cluj

Page 2: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

• Ivo Lukač, co-founder of Netgen Also: developer, site builder, architect, consultant, project manager, evangelist, speaker, event organiser, business developer, …

• Netgen, web agency, Croatia, ~20 employees

• 15 years of experience building complex content-centric web solutions, using eZ Publish since 2004, Symfony since 2013.

About me

Page 3: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Page 4: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Web Summer Camp

Page 5: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

HOW THIS STORY STARTED

Page 6: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

• Clients are demanding better mixing of content and commerce features

• Our stack:

• Content managed with eZ Publish / eZ Platform

• eCommerce features implemented with Sylius

CMS + eCommerce

Page 7: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

• eZ Publish CMS open-sourced in 1999 by eZ Systems from Norway

• Complete refactoring started in 2011

• eZ Platform, the new generation based on Symfony, released in 2015

• Flexible and customisable content model still the key feature

Page 8: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

• Sylius - modern eCommerce based on Symfony2, founded in 2011 by Paweł Jędrzejewski

• Modern coding standards, SOA, independent components as bundles, IoC, BDD

• Version 1.0 stable released in 2017

Page 9: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Page 10: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

INTEGRATION NEEDED!

Page 11: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Loose integration

• A usual approach for integrating 2 or more systems is by establishing remote connections via standard protocols (e.g. http)

• Remote systems are treated as black boxes and completely independent

• Lastest buzzwords: “microservices” and “serverless”

Page 12: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Symfony - common denominator

• Both eZ and Sylius use Symfony full stack as their baseline, they have the same:database access, template engine, service container, logging, events, caching, security, mailing, assets, environment configuration, translation, …

Page 13: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Tight integration

• If 2 systems are built on the same framework and use a lot of the same components - there is a possibility to tightly integrate them on the same application instance

• Suggesting new buzzword: “coupling the decoupled”

Page 14: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

In 2015 we got a suitable project. Our partner Locastic helped with Sylius knowhowFirst integration was based on:- eZ Publish 2014.11 - Sylius 0.14 - Symfony 2.5

Page 15: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Page 16: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Repos

• github.com/netgen/ezpublish-community-sylius Symfony application with merged Sylius and eZ Publish

• github.com/netgen/NetgenEzSyliusBundle provides features that glue eZ and Sylius together

Page 17: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

In the meanwhile

• eZ Platform v1 was released, Sylius v1 was released, so we are at the moment working on the new integration:

• ezplatform-sylius - new app repo, WiP

• ezpublish-community-sylius - deprecated

• NetgenEzSyliusBundle - master branch to be tagged as version 2

Page 18: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

NetgenEzSyliusBundle - the glue

• Field type for linking Sylius products inside eZ Platform content objects (translatable, sortable, removable)

• Replacing Sylius product routes with related eZ Platform content routes

• User provider(s)

• Authentication success handler

Page 19: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Working as expected?

• Twig template extend feature makes it easy to integrate front side templates

• Database configuration can use the same parameters

• Dependency injection and service container make it trivial to use “the other system’s” features

Page 20: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

LETS TALK ABOUT CHALLENGES

Page 21: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

1. Composing2. Routing3. Authentication4. Authorization5. Admin interface

Main challenges

Page 22: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

1. Composing

• Even if both systems are full stack Symfony it is possible to run into problems during composing the app. Remember we are talking about merging 2 big apps with many dependencies

• Some dependencies could conflict (e.g. Doctrine)

• Fix choices:- wait for the next release (create PRs to speed this up)- some composer magic could help

Page 23: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

1. Composing

• It could happen that both systems support different Symfony versions (Sylius 1.0 beta dropped support for Symfony 2 while eZ was still not working with Symfony 3)

• Fix choices:- basically nothing, just waiting - Sylius created a temporary BC branch:"sylius/sylius":"dev-revert-symfony3-updatedas1.0"

Page 24: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

2. Routing

• If any of the systems doesn’t use the system router, they should support the Chain router well (we had a related bug in Sylius needed to be solved)

• One side should be prefixed:sylius:resource:"sylius_routing.yml"prefix:%ez_sylius.shop_path_prefix%

Page 25: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

3. Authentication

• Authenticating users separately should work

• Sylius 0.* used FOSUserBundle,

• Sylius 1.* uses custom user providers (plural !!!)

• eZ uses custom user provider

Page 26: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

3. SSO Authentication

• For SSO a security event listener is needed for authenticating the user with both providers

• eZ Publish used the user class directly (not the interface) so we couldn’t pass the Sylius user class: we created a PR to be able to do this eventually

Page 27: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

4. Authorisation

• For authorisation to work a user object from one system needs to be connected (treated as same) to the related user object in another system

• If possible avoid the need for authorisation on both sides.

• For example, in our first project we need to connect the admin users from both system but the site users didn’t have to be authorised on eZ, only on Sylius

Page 28: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

4. Connecting related users

• To allow manual connecting of users we implemented a script:ezsylius:user:connect<sylius-user-type><sylius-user-email><ez-user-login>

• Of course, a post update/create user event support would be a nicer solution

Page 29: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

4. Trouble with Sylius 1.*

• For Sylius 1.* lot of refactoring was done with lot of BC brakes. One of the things was the user management part: admin users and normal users got completely separated.

• Our authentication and authorisation needed to be done from scratch - we implemented a composite user provider to handle all providers

Page 30: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

5. User interface

• If authentication and admin users authorisation is working there is a chance to even merge the admin interface

• In most cases probably not a straight forward to do due to different UI frontend architectures. We needed to do a PR to Sylius and also use bundle inheritance

Page 31: Merging two big Symfony based applications - SymfonyCon 2017
Page 32: Merging two big Symfony based applications - SymfonyCon 2017
Page 33: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Pros

• With both systems working on the same instance the possibility to mesh up things are much bigger

• Provides a single admin interface

• Problems could be spotted earlier, while in development

Page 34: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Cons

• Complexity, good expertise on both systems needed

• Depending on 2 roadmaps instead of 1

• Might be performance issues, at least when doing composer update, due to lot of dependencies

Page 35: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

What we learned?

• A lot about Symfony and Composer :)

• To appreciate good roadmaps, semantic versioning, extensible code

• Symfony does a lot of lifting

Page 36: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

MAYBE ALL THIS WILL GET DEPRECATED WITH FLEX :)

Page 37: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

If you need something similar

• Have expertise on Symfony and both systems you want to merge

• Check if both roadmaps and release cycles are aligned

• Check if PRs are merged in reasonable time

• Check what licensing you need to apply

Page 38: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

Conclusion

• Tightly integrating 2 systems is probably an overkill in lot of situations

• Could be worth the effort if you need:

• access to all underlaying features

• a single UI

• SSO and complex authorisation

Page 39: Merging two big Symfony based applications - SymfonyCon 2017

www.netgenlabs.com

DO YOU HAVE A SIMILAR USE CASE?

Page 40: Merging two big Symfony based applications - SymfonyCon 2017

Thank you!

[email protected]/twitterilukac.com/facebookilukac.com/linkedin