r/learnprogramming • u/danish_mohiudin • 21d ago
Seniors?
How do you decide when a side project needs a more structured architecture?
I've noticed that small projects can become difficult to maintain once they grow beyond a few features.
For developers who've dealt with this, what were the first signs that your original architecture was becoming a problem?
6
Upvotes
6
u/Available_Safe1818 21d ago
> I've noticed that small projects can become difficult to maintain once they grow beyond a few features.
> For developers who've dealt with this, what were the first signs that your original architecture was becoming a problem?
You just noticed it yourself. What signs did you see?
1
u/roger_ducky 21d ago
Well, usually? It’s just “sticking with the current pattern” when it’s harder.
Usually it means you’re missing a thing somewhere that’d make it easy again.
1
u/rsham004 21d ago
When it's complex you need modular, reuse, permission, many users
Eg calc frameworks
1
u/joranstark018 21d ago
A sign is usually when things have too much responsibility, when components have multiple purposes to change.
It is always a judgment call, on one hand we try to avoid to over design things, we try to not optimise things prematurly, on the other hand we may anticipate that a project may grow and be suited for more layers of abstractions and a more complex architecture.
Try to work in iterations and have phases where you review the status of your project and reflect on what was good and what was not so good in the iteration, fix the most concerning issues and plan the other issues for later. When design choices are a recurring issue it may be a good time to rethink the design.
1
u/BrannyBee 21d ago
Its less of having strong rules for stuff like this, and more of having heuristics you follow.
Like you might hear as a beginner that when you make a website, using a Model-View-Controller set up and do that forever. But then, you have a piece of code that could go in the Model or Controller section... so what do you do...?
You can just make a decision and stick with it, which will lead to that issue you're running in to. You can re-evaluate what your definition of each category is (ie, maybe your "Model" is doing too much, and refactoring will put more of the functional stuff into the Controller section instead). Which again, can lead to more complications down the road.
You can make your MVC web app into a MVC+E (E isnt an official term, i just chose a random word "extra" for the hypothetical that is now something slightly different than whatever Ive been doing before).
The hard part about this is that no ones stopping you from modelling data in the View or making extra "groups", or doing things "wrong". Sometimes you pit code in the Controller and it doesnt work.... but putting it in the Model "fixes" it.... and only god knows why.... there's an issue, but it works and its Friday so you move on....
That's a huge trap to avoid, those temporary fixes compound. Yeah, maybe you decided MVC is the "correct" architecture for your app. But if you decide you need to stray from that architecture, have a good reason for it AND MAKE IT CONSISTENT. Dont just temporarily add another layer and move on. Go through everything, and move any old stuff that should go into that new layer from where it started. Being CONSISTENT is more important in many cases than following the "correct" architecture.
Design patterns are great, but dont treat them like laws. Theyre guides. If you have a web app set in an MVC design, dont force everything to fit that pattern if using another pattern is useful for a new problem. A program isnt one big problem, its many smaller problems, and design patterns arent just one big path to follow, you can cimbine them too.
Maybe you have have a ton of incoming requests to your web app, and you program an entry point specifically for those requests and a dispatcher to handle them, which then "feeds into" your MVC set up, maybe thats how you control outside requests or send different priviliged users to different home pages.... well, you've broken the rules, thats technically a Front Controller now, not an MVC. Literally no ones gonna yell at you or say its wrong, or laugh, you didnt break the rules.
Beginners always do this, and idk if anyones found a way to explain it properly... hopefully saying this helps... dont follow design patterns like dogma, treat them like morals. You have your pattern that works for your program/lifestyle, but then when your program is met with more complications, you re-evaluate things and grow.
Im not gonna mutilated the code to make server configs or some ither set of global configs "fit" into either a model, view, or controller sub group. Im gonna use a singleton.
Im not gonna use a thousand conditionals to handle both discounts on my website and customer payment info, Im gonna use the strategy pattern to encapsulate diferent behaviors I can easily use in multiple places
Im not gonna pollute my code with a shit load of boilerplate that the API im using demands that makes the code unreadable and impossible to work with. Im gonna make a facade that habdles that stuff, and use that where needed elsewhere.
A beginner web app might look like a perfectly organized Model View Controller with 3 files, but be an actual nightmare to work with or read because theyve followed the design pattern like dogma instead of a guide. A more experience version of that same app may look way more complicated than an MVC at first, because inside the M, V, and C is code that follows a facade, strategy pattern, has builder factories, singletons, etc etc. A big part of that is experience and that "feel" when you dont have a perfect place to put some code. If there isnt a correct place to put any guven piece of code, that should tell you that there's something wrong with your architecture, and complicating it may be the way to simplify things paradoxically
1
u/forestking101 21d ago
If you start dreading opening your own repository because you know fixing a simple bug will require untangling a massive spaghetti web then it is time.
1
u/aanzeijar 21d ago
Define "grow beyond a few features" and define "more structured architecture".
I don't worry about architecture until it gets to a few thousand lines of code, and "architecture" afterwards is splitting it into a few files. When having these discussions on this sub, the majority of learners are not comfortable with handling that amount of code in one file.
But we experienced folks also don't add "architecture" after the fact. We already structure our code while writing it. If I see something isn't working out, I change it immediately. A lot of that experience is in knowing what works and what doesn't and simply avoiding what doesn't work can carry a code base a long way.
1
u/iqisoverrated 21d ago edited 21d ago
Well, that's usually the point at which you redesign/refactor your project. When you have done that for one project you already know at what size this is a pain point for you. From this you can judge future projects based on whether they are likely to exceed a similar size or not whether it makes sense to have a bit more of a think on structure beforehand.
Different people have different pain thresholds.
For developers who've dealt with this, what were the first signs that your original architecture was becoming a problem?
There's many signs that can trigger a refactoring: When debugging gets time consuming. When I find myself duplicating code. When I find that values are hard coded in several places or configurations start to be too distributed. When I start adding kludges just for 'a few execptional cases'. When I come back to the code after a few weeks and go "WTF?" (i.e. it wasn't coded as readable as I thought it was while I was still in the flow of coding it)...and, of course, when the requirements shift and the intended benefit of the old architecture no longer aligns with the newly intended functionality.
A small project that grows should also give you pause to think: "Is that growth likely to continue?"
If it is then maybe easy extensibility should become part of your architecture.
1
u/notactuallyme93 21d ago
It always pays to notice your actual experience, rather than theories about organization.
If you spend longer time moving things around and cleaning up, than writing new code, when adding features - it is a sure sign that you need a more structured architecture. Or if you spend a long time looking for something, even though you just found a similar thing - like you need to implement a feature to delete a course with teachers and students, and want to write it similar to the code that deletes the other two. You spend a long time finding the code for deleting a teacher - but you don't learn anything that helps you finding the code for deleting a student. That is another sign that you need more structure.
Or you find that things are very similar, are implemented in very different ways - like coins and powerups that you can pickup in a game, have almost nothing in common, even though they should behave the exact same way.
Of if you find that you have to change things in several different places, every time you just want to add a single new thing.
Before thinking and talking about architecture, I like to compare the work to my physical desk, or my kitchen, or my garage. If every new sub-task requires me to clean up and reorganize my tools, then I need a better way of organizing things!
1
u/FatDog69 21d ago
Ask yourself: "Where is the Business Logic"? This usually happens when someone requests some changes and it is hard to find, or various business logic is spread all over the code.
Code often 'grows organically'. After some years you can predict what code is going to get a lot of change requests so you spend more time on design. But often you 'inherit' other peoples code for change requests.
1
u/UroborosJose 21d ago
When the cost of refactoring is lower than bugs caused my spaghetti code
Often you can always do the pragmatic approach
I’m not paid for artwork I’m paid for running software and no customer give a fuck about source code beauty
1
u/mredding 21d ago
You keep hitting the same wall, and now you're here. This is your intuition trying to tell you something. You need to go with that - don't fight it.
So let's think about it. What's causing your projects to stifle because they get to "a certain point"?
Maybe you're beyond the original scope of the project. If you planned for a big monstrosity from the start, you would have architected for that, instead you're growing into it. One software design philosophy says you code for the customers you have. When you start out, you have no customers, not even you - until you actually start using your own software... But the greater lesson here for you is you don't come out of the gate aiming for this distributed cloud platform.
And this leads to an interesting consequence we need to solve. What happens when the software outgrows its architecture? The industry consensus is you rewrite it for the customers you have. In other words, for you - you put your project down as v1, and you start designing a v2 with the new scope in mind from the start.
Then the fun part begins - how do you figure out a new design. I can't really help you with specificity, but you need to identify your complexity problems and find their solutions. You also have to be careful to not over-engineer. Loose coupling is usually a very good place to start. Your one big program is probably several different programs that should be coupled together indirectly - either as a parent-child process, or over pipes, or a bus.
You accept one complexity to scale in another.
1
u/DigitalMonsoon 21d ago
Typically once you have done this a few time and ended up getting stuck you start to learn cleaner development patterns. Then you can start with a better setup.
1
u/YetMoreSpaceDust 21d ago
When it gets difficult to maintain, then it's time to refactor. It's a side project, so refactor ruthlessly. Over time, you'll start to recognize, "oh yeah, this was difficult to maintain last time I did this, I should get ahead of it this time".
1
u/Good_Skirt2459 20d ago
Honestly, I do a lot of early restructuring. Sometimes I will even rewrite the architecture and just copy code over where I can.
1
u/Few-Celebration-2362 20d ago
I refactor small project architecture when it becomes difficult to maintain.