You have to start with the smallest and most conservative to the most "refactory" ones:
- figure out what enters and what exits from the program, and create a test suite that reflects every known combination
- move parts of main() to funcions
- figure out what variables can be converted from mutations to returned values
- move thr ifs(){} to maps, early returns and such
- figure out the database schemas from newly written data
- infer model relationships fro further writes
- attempt to implement some pattern design, even if its just dummy variables
Sometimes you even have to do it at the last stretch of time of your workday, and slowly the mess will become clearer, your test suit more exhaustive and comprehensive.
And at some point it will achieve feature parity with the legacy service
In part to maintain sanity in a toxic environment, and in part because I knew they just accepted it if it was handed to them.
https://yosefk.com/blog/people-can-read-their-managers-mind....
Either you’re successful AND your managers have an epiphany that you were right and they were wrong, or you fail and your managers will punish you for ignoring their instructions. It’s a risky strategy for an employee.