Abstract
I'm trying to figure out a solid, scalable, clean and practical architecture for react projects.
As a a playground I have a project with two Screen and a JSON server.
When I try to apply a clean, one-directed architecture, I end up with a very complex Structure.
(Here, a Screen stands for *a site, that is shown to the user if they open a URL)
Output on Screen
- Screen 1 contains component A (input/output of database information) and B (output of database information). It also shows a sidebar (that's supposed to be shown on all screens).
- Screen 2 contains the same component A with exactly the same features and component C (output of database information), and of course the sidebar.
Architecture
- Screen1 and Screen2 are implemented as Page1 and Page2.
- A Page combines the website template (sidebar, top bar) and a corresponding view. (Think of it as the application window of a word processor software)
- A view is the content I want to show to the user without the sidebar and top bar (think of it as the editing area in a word processor software)
- Component A: Props contain information and a callback method (e.g. how to submit information).
- Component B/C: Props contain information only.
I eventually end up with the inverted pyramid architecture below.
Explanation from top to bottom:
- There are business components A,B,C (like InputForm or StatusPanel). These consist of smaller general purpose components like submit button or input field.
- Each view uses the components it should show on screen
- Each component requires props (data and possibly callbacks).
- Component A is used in view 1 and view 2; To stay DRY, a generalized class/function is necessary to create the props:
PropsCreatorA
. - As stated above, I'm ultimately searching for an architecture to a much bigger project with more screens, so I added
PropsCreatorB
andPropsCreatorC
to emphasize how complex this gets, quickly.
- Component A is used in view 1 and view 2; To stay DRY, a generalized class/function is necessary to create the props:
- A database adapter is created once in the router and used throughout all pages (pages possibly rely on interfaces).
Problems
- Is this actually a good architecture?
- This feels like there's going to be a lot of overhead (many files, many folders for managing) just for showing two pages on screen.
- The
PropsCreator
s might contain callback functions making use of navigation (useNavigate
) - for example to move to a new screen after the input form in CompA was filled out. I.e. they need to know the pages. How would I incooperate that?