tsompanis
tsompanis

Reputation: 344

Two projects share same entities - how to maintain code?

We have a project broken in two parts - API and Frontend.
Both are written in Symfony 3.4 and both are in different servers as well as git repositories.
As you may already know, Symfony uses bundles, with every bundle having it's own Entities.
Both of our project use the same Entities from bundles, plus the frontend one has extras.

At the moment, to maintain the entities it's somewhat hard since every change we do in one of the Entities must be aligned with the other project's entities.

I was thinking to use submodules feature from git to keep them both up-to-date, but then, what about the other folders inside the bundles? Like Services and Controllers? I just want to keep track of Entities so when we make a change both projects (or whoever) will be able to have those without us, having to copy-paste stuff.

What are you thinking and what are you suggesting?

Here's an example of the structure. I hope it's readable


Project A          Project B
-Bundle 1          -Bundle 1
---Entities        --- Entities

-Bundle 2          -Bundle 2
---Entities        ---Entities
---Services

-Bundle 3          -Bundle 3
---Entities        ---Entities
                   ---Services

                   -Bundle 4

Upvotes: 5

Views: 1088

Answers (2)

sensorario
sensorario

Reputation: 21620

Move entities and/or shared parts inside another repository and consider start using git submodules or git subtree. Using this trick you can add a git repository inside another. And you can also update shared content committing and pushing from the submodule.

Upvotes: 1

Gregoire Ducharme
Gregoire Ducharme

Reputation: 1108

There is some options, you could use you're API to get data on your Frontend meaning you would only need your entities in yourAPI bundle.

Or you could have your entities in a third project being only one bundle with entities. Bundle that you would add to the two other projects with Composer

https://knpuniversity.com/screencast/question-answer-day/create-composer-package

Upvotes: 3

Related Questions