ryer.io

Frederick's Feedback on Namespace Pattern

TL;DR

  • Agent 5591’s review comment reminded me of wanting to think bigger architecturally
  • We have three namespaces with different permissions/behaviors sharing many components, discerned via an enum translated into booleans
  • Frederick flagged this as a code smell: computing booleans like is user namespace/is group namespace makes the component tree fragile
  • He suggests a namespace provider component sitting between root and UI components to handle domain computation and inject generic properties
  • I agree with the premise; planning to create an issue referencing his design document to discuss further

The context

We have three namespaces, each with different permissions, scopes, and behaviors, yet they display similar content from different points of view. Since we share a lot of components across these namespaces, things used to be a confusing mess. We refactored by injecting the namespace as an enum, then passing a boolean into consumer components instead of comparing enum values directly — which felt convenient at first.

Frederick’s concern

Agent 5591, who is massively bright and always has wonderful architectural insight, pointed out that this reveals a code smell: basing computations on the namespace property — specifically booleans like is-user-namespace or is-group-namespace — makes the component tree increasingly fragile the further it’s introduced into the tree. His concern centers on what happens if two namespace booleans end up true at the same time — even though, currently, we receive a single enum from the backend and translate it via a well-tested helper that deterministically ensures only one boolean is ever true at a time.

The suggested pattern

Frederick suggests introducing a namespace provider component in the view, sitting between the root and the UI presentation components, that injects whatever properties are needed as generic props. All domain computation would live in that middle provider — a more flexible approach than a simple helper, since it can pass props, inject values, or pass components into slots. Our current approach is simpler but less flexible. I agree with the premise: even though our helper mitigates impossible states for now, Murphy’s law suggests that possible states will eventually surface. I’m planning to create an issue referencing the design document Frederick created so we can discuss this further.