Sunday, 16 June 2019

Component-Based Design: Any real world examples?

Hi Reddit, after getting a frustrated with the folder structure of one of my projects I went down the 'code organization' rabbit hole. After reading many blog posts/articles it seems like seperating your app into components is the most highly regarded technique for a maintainable folder structure. But I am having trouble conceptualizing what constitutes a component - at first I tried to implement this by creating folders (components) for each 'entity' I had (i.e. User) and I put the mongoose model, route controllers and use-cases files in there.Aside: Use cases are the business logic of the application, they take in input from the route controllers and the orchestrate the flow of data to and from the models. The route controllers then adapts the response to an object it can send back to the HTTP caller.While implementing this I came into a lot of issues. One of the issues was that all of the components ended up being really tightly coupled to each other due to the fact that Use Cases in the vast majority of cases uses multiple models (due to relationships between data). A more crippling issue was cyclical dependencies which I think was due to the components being tightly coupled, I did eventually manage to resolve it but I cant really remember how and it was pretty hacky.I came to the conclusion that seperating by entity was a bad idea, but I am still not sure how to seperate my backend into components.I use Angular a lot, so I also considered that I could take some ideas of how components work from there, but when I thought about it - components are only used for the UI. All the data stuff is done the 'normal' way by seperating them by 'kind' - ie. having a models and services folder. So this doesn't help me when it comes to backend applications.So I was wondering if there are any real world examples that takes this Component based approach that I could take a look at (can be conceptual designs or open source code). Or maybe I should just stick with seperating files by 'kind' with folders like models, use-cases, controllers etc.​Any guidance on this would be much appreciated, many thanks in advance :)

Submitted June 16, 2019 at 01:15PM by Devstackr

No comments:

Post a Comment