Lurker News
I have to find a strategy to fix this development team without managing them directly. Here is an overview:

- this code generates more than 20 million dollars a year of revenue
- it runs on PHP
- it has been developed for 12 years directly on production with no source control ( hello index-new_2021-test-john_v2.php )
- it doesn't use composer or any dependency management. It's all require_once.
- it doesn't use any framework
- the routing is managed exclusively as rewrites in NGInX ( the NGInX config is around 10,000 lines )
- no code has ever been deleted. Things are just added . I gather the reason for that is because it was developed on production directly and deleting things is too risky.
- the database structure is the same mess, no migrations, etc... When adding a column, because of the volume of data, they add a new table with a join.
- JS and CSS is the same. Multiple versions of jQuery fighting each other depending on which page you are or even on the same page.
- no MVC pattern of course, or whatever pattern. No templating library. It's PHP 2003 style.
- In many places I see controllers like files making curl requests to its own rest API (via domain name, not localhost) doing oauth authorizations, etc... Just to get the menu items or list of products...
- no caching ( but there is memcached but only used for sessions ...)
- team is 3 people, quite junior. One backend, one front, one iOS/android. Resistance to change is huge.
- productivity is abysmal which is understandable. The mess is just too huge to be able to build anything.
This business unit has a pretty aggressive roadmap as management and HQ has no real understanding of these blockers. And post COVID, budget is really tight.
I know a full rewrite is necessary, but how to balance it?

Comments (676) 322 threads

Earlier comments
that_guy_iain1 reply#
> I know a full rewrite is necessary, but how to balance it?

A full rewrite of a functional 12-year old application? Yea, you're going to waste years and deliver something that is functionaly worse than what you have. It took 12-years to build it would realistically take years to rebuild. Fixing this will take years and honestly some serious skill.
What you want to do is build something in front of your mudball application. For the most part your application will be working. It's just a mudball.
Step 0. Make management and HQ understand the state of the application. To do this I would make a presentation explaining and showing best practices from various project docs and then show what you have. Without this step, everything else is pointless.
If they don't understand how bad it is. You will fail. Failure is the only option.
If the team is not willing to change and you're not able to force change then you're going to fail.
So once you have the ability to implement changes.
Step 1. Add version control.
Step 2. Add a deployment process to stop coding developing in production.
Step 3. Standardise the development env.
If you have views and not intermingled php & html:
Step 4. Start a new frontend and create endpoints that reuse the original code to return json for all the variables.
If not:
Step 4. Add views. Copy all the html into another file and then make a note of the variables. Step 5. Start a new frontend and create endpoints that reuse the original code to return json for all the variables.
... Carry on moving things over to the new frontend until everything is in the frontend.
Probably a year later.
Step 6. When adding new functionality you can either rewrite that section, do a decorator approach, or edit the original functionality.
That's without fixing the database mess or infra mess.

yazaddaruvala#
The approach outlined above is the approach I would take (and have previously taken). Some details that I personally think are important:

Step 0. Setup typescript with version control for your current JS mess.
Step 1. FWIW, with ReactDOM.renderToString you can use JSX as your template engine.
Step 2. Move all of your PHP views to JSX views, PHP keeps returning JSON.
Step 3. Abuse component.unmount(); component = ReactDOM.createRoot(…); to get components with view state, but also can get updated by regular JS events that require a rerender just like you would with the legacy jQuery code.
Step 4. Keep pushing more of the logic from the legacy jQuery code and PHP code into React/Typescript. You’ll find that the React components will keep getting grouped and you can start to compose more of the widgets together.
Step 5. You end up with one big React app, minimal PHP (that is easy to test), and a decision about how to manage your state.
At this point it’ll be in shape to not need a lot of attention. Truly, the DB mess will figure itself out as your PHP continually becomes minimal and well tested.

whattodochange5 replies#
Thank you for so many suggestions. The main issue is productivity within a context where the company is trying to reinvent itself in terms of marketing and business model. This has for consequence that many new big features are being requested and promised by management to headquarters. But in the last years, all bug evolutions have been failures. That's why I've been asked to intervene. I love the idea of the strangler pattern associated with big unit testing coverage.
toast0#
> This has for consequence that many new big features are being requested and promised by management to headquarters. But in the last years, all bug evolutions have been failures. That's why I've been asked to intervene. I love the idea of the strangler pattern associated with big unit testing coverage.

The first thing that needs to be strangled is unachievable management promises. Figure out how to get local management to not write checks the tiny team can't cash. A team of 3 juniors will likely overestimate their ability to deliver, so you've probably got to teach them to say no to things they can't do also.

aintmeit#
It's pretty risky to delete code you don't understand. Is it harming you if you don't refactor?
bazoom421 reply#
What is a bug evolution? Do you mean a bug fix?
McP#
"big evolution"

"u" is next to "i" on many keyboards.

wrycoder1 reply#
You may be interested in this article:

https://medium.com/@kris-nova/organic-and-mechanistic-system...
What you are dealing with is organically grown software. No one really understands it, and it's likely to be fragile.
I agree with all those here that say the first thing to do is to introduce version control. You don't want to break that money machine without a way to revert.
Second, introduce some lightweight form of code review, but don't tick people off.
Third, if you want to do something like revise the user interface, consider adding an API to the existing organic code base, and build the new UI with that API. Generally, take that approach and avoid jamming something into the middle of the existing code that no one fully understands.

n0nagn#
I agree with this. I built an open source package that should work for you in this situation with no version control in it. https://github.com/n0nag0n/commie2 Get this installed internally and then start doing some "lightweight" code reviews. Your other team members can get emails about any comments you make and it'll be lightweight collaboration.
mkurzeja#
I had the chance to work with Strangler Pattern in multiple projects, and in general this is a good idea.

The thing I'd suggest taking a look at is the database. You really need to make sure the new part is not based on the old data model.
You can take a look at "getting started with DDD when surrounded by legacy systems" by Eric Evans - available for free and only 21 pages long. Our implementation of one of the suggested approaches failed in one project, but in retrospective, I think it was caused by the business not putting enough effort into the rewrite.
In general, on the high level it's very important to make the product vision, data model, processes clear and well thought. Without this, you will always get to a bad codebase within a couple of years.

johnorourke#
Create a 'risk register', or 'service schedule' - we use this for building service contracts, where you list out all the things that need to be done or might happen (from backups to support requests), and put a rough cost on them all. We put a min and max cost on each item, and the number of times per year it might happen.

That gives you an annual maintenance cost which will include, say "every 2 years something goes badly wrong with the flargle blargle, and costs $10,000 to fix", or "every 3 days we have to clear out the wurble gurble to stop it all crashing".
Finally, you put together the same thing but for a re-written version, or even with some basic improvements as others have suggested, and hopefully you see a lower total cost of maintenance.
At that point, you can weigh up the cost of either a rewrite or incremental improvements in actual dollars.

Load more comments