Getting Started
Installation
npm install next-modularInitialize your project
Run the init command in your Next.js App Router project:
npx next-modular initThis creates the following files:
app/[...module]/page.tsxCatch-all route that delegates to module page components viahandleRoute()app/api/[...module]/route.tsCatch-all API route that delegates to module handlers viahandleApiRoute()proxy.tsMiddleware file that runs module middleware viahandleMiddleware()modules.config.tsWhere you list your active modulesnext-modular.runtime.tsCallsconfigureModules()to register modules at runtimemodules/Directory for local modules
Add a module from the registry
npx next-modular addThis shows available modules from the registry and installs the selected one.
Create a local module
npx next-modular create my-moduleThis scaffolds a new module in modules/my-module/ with routes, API handlers, and middleware boilerplate.
Register your module
Add it to modules.config.ts:
import { myModule } from './modules/my-module/src';
export const modules = [
myModule,
];The runtime file imports this config and registers all modules. The catch-all routes then resolve incoming requests to the correct module based on the URL path and the module’s basePath.
Last updated on