diff --git a/apps/studio-next/docs/architecture.md b/apps/studio-next/docs/architecture.md new file mode 100644 index 000000000..a3c7a0c7a --- /dev/null +++ b/apps/studio-next/docs/architecture.md @@ -0,0 +1,156 @@ +# Studio Architecture Considerations + +Studio is an isomorphic application built on top of the [Next.js](nextjs) framework. + +## Routing + +Routing is handled by the Next.js framework. Please have a look at [the documentation](https://nextjs.org/docs/app/building-your-application/routing) to better understand how it works. + +As a rule of thumb, every UI state that could be worth sharing with others, deserves its own URL and therefore its own route. + +## Separation of concerns + +### Components + +> **Warning:** We should never ever put business logic on components. + +Components **must** be loosely-coupled pieces that could be easily integrated into another application without having to change anything on them. They live in the `src/components` directory. + +A good way to know if your component is tightly coupled to Studio, is to put it as is in the design system. If your component is importing some Studio-specific stuff, fetching or sending data, or the like, chances are your component is thightly coupled. + +#### Don't do this: + +```jsx +export default function Sidebar() { + const items = [ + { icon: ..., title: ..., onClick: ... }, + ... + ] + + return ( + + ) +} +``` + +#### Instead, do this: + +```jsx +export default function Sidebar({ items }) { + return ( + + ) +} +``` + +It's a small change that makes a huge difference. In the first example, we won't be able to reuse the component to render other set of items. In the second one, it's as easy as passing a separate `items` array as a prop. + +Whenever you need to add some Studio-specific business logic or data, use Containers. + +### Containers + +A container is a React component that handles some business logic and data. It **must** never render its own UI but instead, it **must** render existing components. They live in the `src/containers` directory. + +You can use containers to logically group parts or sections of the UI. + +#### Don't do this: + +```jsx +export default function SidebarContainer() { + const items = [ + { icon: ..., title: ..., onClick: ... }, + ... + ] + + return ( + + ) +} +``` + +#### Not even this, if possible: + +```jsx +import Sidebar from '../components/Sidebar' + +export default function SidebarContainer() { + const items = [ + { icon: ..., title: ..., onClick: ... }, + ... + ] + + return ( +