Question presented to candidate: "Our Next.js app has grown to 200 routes and four teams. Files are everywhere. How would you structure the app directory so it stays navigable, and which Next.js conventions help?"
What a strong answer should cover:
- Only
pageandroutefiles make a URL public, so components, tests and helpers can be colocated insideapp/safely. - Private folders (
_components) opt a folder and everything under it out of routing;%5Fcreates a real URL segment that starts with an underscore. - Route groups (
(marketing),(shop)) organize by section or team and attach different layouts without changing the URL. - Multiple root layouts via groups cause a full page load when navigating between them; two groups resolving to the same path fail the build.
- A clear split between route code in
app/and shared domain code (lib/,features/, a server-only data layer), plus an import alias like@/.
Clarifying questions expected:
- "Do sections need different root layouts (different html, fonts, providers)?" β that decides between one root layout and several.
- "Are teams split by feature or by layer?" β it decides whether to group folders by feature or keep shared code outside
app/.
Code / implementation expected: Yes β a folder tree using route groups and private folders, and the layouts that go with them.