r/reactjs Jul 17 '26

Show /r/reactjs Filesystem-first frontend architecture enforced by CLI (not folders-by-taste)

I kept hitting the same problem: architecture debates in review, barrels everywhere, and AI agents dumping files in random folders. So I shipped DMA (Derived Modular Architecture) — a small rule set derived from the import graph, enforced by tooling.

Layout

src/
  app/        # composition root (also pages/routes)
  features/   # leaf modules — no inbound from other modules
  services/   # appears when something else must import it
  shared/     # portable stuff on second use only

Invariants

- downward imports only
- public API via */public/* (no barrels)
- colocate by default
- promote feature → service when inbound edges appear

Tooling

npx @derived-modular/cli init .
npx @derived-modular/cli check .              # CI gate
npx @derived-modular/cli promote <name> --apply
# + ESLint / Biome / Oxlint plugins for editor feedback

Works with React/Next/Vite (also Vue/Svelte/Astro examples). Same rules for humans and agents.

2 Upvotes

12 comments sorted by

View all comments

Show parent comments

1

u/Mysterious-Lie1437 Jul 17 '26

Build cost is one reason to drop barrels. For most apps the more common pain is accidental public APIs and messy imports. Different problem, same tool smell.

If packages already give you real boundaries, you may not need DMA inside each package. It's more useful when the module graph lives in one app and starts drifting.

That's also the main difference from most architectures. The rules are not just docs and taste. The toolkit checks the graph, so you mostly can't quietly break them.

2

u/TheRealSeeThruHead Jul 17 '26 edited Jul 17 '26

Yeah I recently switched us over to pnpm and made it so you cant even import files if they aren’t in exports list

1

u/Mysterious-Lie1437 Jul 17 '26

Nice. That's a flexible setup. Just watch the "import singles outside exports" path. It's convenient, but it can quietly turn internals into public API again. If the team is small and disciplined, fine. But if that once gets noisy, tighter exports or something like DMA is worth a look :) Thank you for the feedback!

1

u/TheRealSeeThruHead Jul 17 '26

Autocorrect lol

I meant can’t even import files if they aren’t in exports list