Adding a Module¶
This guide outlines the steps to add a brand new business domain (module) to Atlas ERP.
1. Database Schema¶
Always start with the data.
- Open
packages/database/prisma/schema.prisma. - Define your new models. Remember to add the
workspaceIdfield and relation! - Run
pnpm prisma migrate dev --name init_new_module.
2. Backend Module Setup¶
Use the NestJS CLI to scaffold the backend structure.
| Bash | |
|---|---|
Move these files into a logically structured folder if the CLI didn't place them exactly where you want them.
3. Define DTOs¶
Create a dto/ folder inside your new module directory. Define your input validation classes using class-validator.
| TypeScript | |
|---|---|
4. Implement Logic¶
- Service: Inject the
PrismaServiceand write your CRUD operations, ensuring you pass theworkspaceIdto every query. - Controller: Map the HTTP verbs (
@Get(),@Post()) to the service methods. Apply@UseGuards(AuthGuard, WorkspaceGuard)to the controller class.
5. Frontend Types¶
Because we use a monorepo, you can export types from the backend, but typically it is better to define shared interfaces in packages/types/src/my-new-module.ts.
6. Frontend API Client¶
Create a new file in apps/web/src/lib/my-new-module.ts. Write functions that wrap apiClient.get and apiClient.post for your new endpoints.
7. Frontend UI¶
- Add the new route to the Next.js App Router (e.g.,
apps/web/src/app/dashboard/my-new-module/page.tsx). - Update the Sidebar (
apps/web/src/components/layout/Sidebar.tsx) to include a link to your new module. - Build the UI components using
shadcn/uiand React Query to fetch the data.