vroqjs.com

03-app-structure/05-shared-code.md

Shared code

Shared code

The shared/ directory contains code that is reused across multiple features.

Shared code should be minimal and clearly reusable. Avoid moving feature-specific logic into shared/ too early.

Typical shared structure

shared/
  store/
    configureStore.js
    initialState.js

  api/

  ui/

What belongs in shared

Good candidates for shared code:

  • store setup
  • helpers reused by multiple features
  • API helpers used by several features
  • small reusable UI helpers

What should NOT go in shared

Avoid placing these in shared:

  • feature-specific reducers
  • feature-specific API wrappers
  • UI sections tied to a single feature

If code clearly belongs to one feature, keep it in that feature folder.

When to promote code to shared

Code should move to shared/ when:

  • it is used by two or more features
  • it represents a generic concept across the app
  • duplication would otherwise appear

Final rule

Use shared/ only for truly reusable logic. Feature-specific logic should remain inside feature folders.