Pattern to split Next.js app into modules/domain contexts #33877
Replies: 4 comments 2 replies
-
Yes its can be done its the new meta verse coming .. anything is possible |
Beta Was this translation helpful? Give feedback.
-
|
Hey we are interested in a similar solution, actually we've find the same dead end, multizones and turborepo. |
Beta Was this translation helpful? Give feedback.
-
|
For anyone still looking for a solution to this, I've been using this project structure with a lot of success for a ~50k LOC project:
|
Beta Was this translation helpful? Give feedback.
-
|
Any new progress? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Hello, I'd like to be able to split my source code into modules/domain contexts, like so:
Is there any known pattern for accomplishing something like this?
This is purely an organizational change; the application would still be built as one cohesive unit. In my experience, this kind of organization is necessary once your codebase grows above ~50k lines of code.
The Next.js automatic file-based routing would still work as expected, combining
pages/andapi/for all modules, and it would be up to the user to ensure that there are no conflicts (i.e. two different modules defining the same page route).Examples
Blitz.js (pre framework-agnostic pivot) supports this by default.
Existing issues/discussions
I couldn't find much in Next.js issues or discussions that addresses this. #6040 is related, but focuses on complete build separation rather than simple organizational changes:
Explored Solutions
The article Dividing Your App Into Modules describes the issue well, and explores a few options:
This works, but it's very tedious to maintain the original structure in
pages/andapi/for the importing.Much like Feasibility of micro frontends #6040, this treats each module as a separate build context.
I also considered using Turborepo, but this also treats each module as a separate Next.js application.
Beta Was this translation helpful? Give feedback.
All reactions