11---
22name : constructive-boilerplate-nextjs-app
3- description : Set up and develop with the Constructive App frontend boilerplate — a Next.js application with authentication, organization management, invites, members, and a GraphQL SDK. Use when scaffolding a new Constructive frontend application from the boilerplate.
3+ description : Set up and develop with the Constructive App frontend boilerplate — a Next.js application with authentication, organization management, invites, members, and a per-DB GraphQL SDK architecture . Use when scaffolding a new Constructive frontend application from the boilerplate.
44---
55
6- Set up and develop with the Constructive App frontend boilerplate — a Next.js application with authentication, organization management, invites, members, and a GraphQL SDK.
6+ Set up and develop with the Constructive App frontend boilerplate — a Next.js application with authentication, organization management, invites, members, and a per-DB GraphQL SDK architecture .
77
88## When to Apply
99
@@ -15,7 +15,7 @@ Use this skill when:
1515
1616## Overview
1717
18- The Constructive App boilerplate is a ** frontend-only** Next.js application that connects to a Constructive backend. It provides production-ready authentication flows, organization management, invite handling, member management, and account settings — all powered by a generated GraphQL SDK .
18+ The Constructive App boilerplate is a ** frontend-only** Next.js application that connects to a Constructive backend using a ** per-database architecture ** . It provides production-ready authentication flows, organization management, invite handling, member management, and account settings — all powered by three generated GraphQL SDKs (admin, auth, app) .
1919
2020## Setup
2121
@@ -66,7 +66,7 @@ pgpm init \
6666 --moduleName < module-name>
6767```
6868
69- ** Required arguments for existing workspace :**
69+ ** Required arguments for existing workspace:**
7070
7171| Argument | Description |
7272| ----------| -------------|
@@ -76,7 +76,7 @@ This creates the module at `packages/<module-name>/` within your existing worksp
7676
7777> ** Note:** You must run this from the workspace root or a valid ` packages/ ` subdirectory. If you are not inside a pnpm workspace, pgpm will error with "Not inside a PNPM workspace." Use the ` -w ` flag (see above) to create a new workspace and module together.
7878
79- > ** Interactive mode (for humans):** :
79+ > ** Interactive mode (for humans):**
8080> ``` bash
8181> pgpm init --repo constructive-io/sandbox-templates --template nextjs/constructive-app
8282> ` ` `
@@ -90,34 +90,52 @@ pnpm install
9090
9191### 3. Configure Environment
9292
93- Create or verify ` .env.local ` :
93+ Create ` .env.local ` from ` .env.example ` :
9494
9595``` bash
96- # GraphQL endpoint (must point to a running Constructive backend)
97- NEXT_PUBLIC_SCHEMA_BUILDER_GRAPHQL_ENDPOINT=http://api.localhost:3000/graphql
96+ # Database name — REQUIRED
97+ # This single value derives all GraphQL endpoints:
98+ # admin-{db}.localhost:3000 → organizations, members, permissions
99+ # auth-{db}.localhost:3000 → users, authentication
100+ # app-public-{db}.localhost:3000 → your business data
101+ NEXT_PUBLIC_DB_NAME=your-db-name
102+
103+ # Optional: Override the default API port (default: 3000)
104+ # NEXT_PUBLIC_API_PORT=3000
105+
106+ # Optional: Override individual endpoints (bypasses DB_NAME derivation)
107+ # NEXT_PUBLIC_ADMIN_ENDPOINT=http://admin-mydb.localhost:3000/graphql
108+ # NEXT_PUBLIC_AUTH_ENDPOINT=http://auth-mydb.localhost:3000/graphql
109+ # NEXT_PUBLIC_APP_ENDPOINT=http://app-public-mydb.localhost:3000/graphql
98110```
99111
100112### 4. Generate GraphQL SDK
101113
102- The SDK must be generated against a running backend:
114+ The SDK must be generated against a running backend with your per-DB endpoints :
103115
104116``` bash
105117pnpm codegen
106118```
107119
108- This runs ` @constructive-io/graphql-codegen ` using ` graphql-codegen.config.ts ` and outputs the SDK to ` src/graphql/schema-builder-sdk/api ` .
120+ This runs ` @constructive-io/graphql-codegen ` using ` graphql-codegen.config.ts ` and outputs ** three SDKs** :
121+
122+ | SDK | Output | Endpoint | Purpose |
123+ | -----| --------| ----------| ---------|
124+ | ` admin ` | ` src/graphql/sdk/admin/ ` | ` http://admin-{db}.localhost:3000/graphql ` | Organizations, members, permissions, invites (44 tables) |
125+ | ` auth ` | ` src/graphql/sdk/auth/ ` | ` http://auth-{db}.localhost:3000/graphql ` | Users, emails, authentication (6 tables) |
126+ | ` app ` | ` src/graphql/sdk/app/ ` | ` http://app-public-{db}.localhost:3000/graphql ` | Your business data |
109127
110128### 5. Start Development
111129
112130``` bash
113131pnpm dev
114132```
115133
116- Opens at [ http://localhost:3001 ] ( http://localhost:3001 ) .
134+ Opens at [ http://localhost:3011 ] ( http://localhost:3011 ) by default .
117135
118136## Backend Requirements
119137
120- This boilerplate requires a running Constructive backend. The easiest way is via ** Constructive Hub** :
138+ This boilerplate requires a running Constructive backend with per-DB endpoints . The easiest way is via ** Constructive Hub** :
121139
122140``` bash
123141# Terminal 1: Start backend infrastructure
@@ -134,7 +152,7 @@ Required backend services:
134152| Service | Port | Purpose |
135153| ---------| ------| ---------|
136154| PostgreSQL | 5432 | Database with Constructive schema |
137- | GraphQL Server (Public) | 3000 | API endpoint for app operations |
155+ | GraphQL Server | 3000 | Per-DB endpoints (admin- * , auth- * , app-public- * ) |
138156| GraphQL Server (Private) | 3002 | Admin operations |
139157| Job Service | 8080 | Background job processing |
140158| Email Function | 8082 | Email sending via SMTP |
@@ -157,8 +175,10 @@ src/
157175│ ├── invite/ # Accept invite flow
158176│ ├── invites/ # Pending invites list
159177│ ├── account/ # Account management
178+ │ │ └── settings/ # Account settings + theme
160179│ ├── settings/ # App settings
161180│ ├── users/ # User management
181+ │ ├── organizations/ # Organization listing page
162182│ └── orgs/
163183│ └── [orgId]/ # Org-scoped pages
164184│ ├── layout.tsx # Org layout with sidebar
@@ -167,7 +187,24 @@ src/
167187│ ├── members/ # Org members management
168188│ └── settings/ # Org settings
169189├── components/
170- │ ├── ui/ # shadcn/ui components (43 components)
190+ │ ├── ui/ # UI components (26 files)
191+ │ │ ├── stack/ # Stack card system (slide-in panels)
192+ │ │ │ ├── stack-card.tsx
193+ │ │ │ ├── stack-context.tsx
194+ │ │ │ ├── stack-viewport.tsx
195+ │ │ │ └── ...
196+ │ │ ├── toast/ # Toast notifications
197+ │ │ │ ├── toast-error.tsx
198+ │ │ │ ├── toast-success.tsx
199+ │ │ │ └── ...
200+ │ │ ├── alert-dialog.tsx
201+ │ │ ├── button.tsx
202+ │ │ ├── card.tsx
203+ │ │ ├── dropdown-menu.tsx
204+ │ │ ├── input.tsx
205+ │ │ ├── select.tsx
206+ │ │ ├── table.tsx
207+ │ │ └── ...
171208│ ├── auth/ # Auth forms (login, register, reset, etc.)
172209│ ├── organizations/ # Org CRUD components
173210│ ├── invites/ # Invite management components
@@ -179,38 +216,119 @@ src/
179216│ ├── shared/ # Shared/reusable components
180217│ └── skeletons/ # Loading skeleton components
181218├── config/
182- │ └── branding.ts # App name, logos, legal links
219+ │ └── branding.ts # App name, logos, tagline, legal links
183220├── graphql/
184221│ ├── execute.ts # GraphQL execution layer
185222│ ├── index.ts # GraphQL exports
186223│ ├── typed-document.ts # Typed document utilities
187- │ └── schema-builder-sdk/ # Generated SDK (via codegen)
224+ │ └── sdk/ # Generated SDKs (via codegen)
225+ │ ├── admin/ # Admin SDK (orgs, members, permissions)
226+ │ │ ├── hooks/ # React Query hooks
227+ │ │ ├── orm/ # ORM client
228+ │ │ └── README.md
229+ │ ├── auth/ # Auth SDK (users, emails)
230+ │ │ ├── hooks/
231+ │ │ ├── orm/
232+ │ │ └── README.md
233+ │ ├── app/ # App SDK (your business tables)
234+ │ │ ├── hooks/
235+ │ │ ├── orm/
236+ │ │ └── README.md
237+ │ └── README.md
188238├── hooks/ # Shared React hooks
239+ │ ├── use-character-limit.ts
240+ │ ├── use-debounce.ts
241+ │ ├── use-deferred-mutation.ts
242+ │ ├── use-edit-value.ts
243+ │ ├── use-file-upload.ts
244+ │ ├── use-health-check.ts
245+ │ ├── use-image-status.ts
246+ │ ├── use-in-view.ts
247+ │ ├── use-json-view-scroll.ts
248+ │ ├── use-measure.ts
249+ │ ├── use-mobile.ts
250+ │ ├── use-mounted.ts
251+ │ └── use-scroll-direction.ts
189252├── lib/
190253│ ├── auth/ # Auth utilities and context
254+ │ │ ├── auth-context.tsx
255+ │ │ ├── auth-errors.ts
256+ │ │ ├── route-guards.tsx
257+ │ │ ├── token-manager.ts
258+ │ │ └── ...
191259│ ├── gql/ # GraphQL hooks and query factories
260+ │ │ ├── hooks/
261+ │ │ │ ├── admin/ # Admin hooks (orgs, invites, members)
262+ │ │ │ └── auth/ # Auth hooks (login, register, etc.)
263+ │ │ ├── error-handler.ts
264+ │ │ └── query-error-boundary.tsx
192265│ ├── navigation/ # Route and navigation helpers
266+ │ │ ├── sidebar-config.ts
267+ │ │ ├── use-entity-params.ts
268+ │ │ └── use-sidebar-navigation.ts
193269│ ├── permissions/ # Permission checking utilities
194270│ ├── constants/ # App constants
195271│ ├── logger/ # Logging utilities
196- │ ├── runtime/ # Runtime helpers
272+ │ ├── runtime/ # Runtime configuration
273+ │ │ ├── config-core.ts
274+ │ │ ├── env-sync.ts
275+ │ │ ├── get-runtime-config.ts
276+ │ │ └── runtime-config.types.ts
277+ │ ├── motion/ # Animation configuration
197278│ ├── utils/ # General utilities
198- │ └── validation/ # Zod schemas and validation
199- ├── store/ # Client state management
279+ │ ├── validation/ # Zod schemas and validation
280+ │ ├── query-client.ts # React Query client
281+ │ ├── schema-context.tsx # Schema context provider
282+ │ └── slot.tsx # Slot utility
283+ ├── store/ # Client state management (Zustand)
284+ │ ├── app-store.ts # Main app store
285+ │ ├── auth-slice.ts # Auth state slice
286+ │ ├── env-slice.ts # Environment state slice
287+ │ └── preferences-slice.ts # User preferences slice
200288├── app-config.ts # App-wide configuration
201289└── app-routes.ts # Route definitions
202290```
203291
292+ ## SDK Imports
293+
294+ The template provides path aliases for the three SDKs:
295+
296+ ``` typescript
297+ // Your business data
298+ import { useBoardsQuery , useCreateBoardMutation } from ' @sdk/app' ;
299+
300+ // Users and authentication
301+ import { useCurrentUserQuery , useSignInMutation } from ' @sdk/auth' ;
302+
303+ // Organizations, members, permissions
304+ import { useOrganizationsQuery , useOrgMembersQuery } from ' @sdk/admin' ;
305+ ```
306+
204307## Customization
205308
206309### Branding
207310
208311Edit ` src/config/branding.ts ` to customize:
209- - App name and tagline
210- - Logo and wordmark paths (relative to ` /public ` )
211- - Company name for legal footer
212- - Legal links (disclaimer, privacy policy, etc.)
213- - Home path for logo links
312+
313+ ``` typescript
314+ export const branding: BrandingConfig = {
315+ name: ' airpage' , // App name
316+ tagline: ' powered by Constructive' , // Tagline below brand name
317+
318+ logo: ' /logo.svg' , // Logo mark (collapsed sidebar, auth)
319+ wordmark: ' /wordmark.svg' , // Full wordmark (expanded sidebar)
320+ logoDark: null , // Dark mode logo override
321+ wordmarkDark: null , // Dark mode wordmark override
322+
323+ companyName: ' Constructive' , // Legal footer company name
324+ legalLinks: [ // Auth footer links
325+ { label: ' Disclaimer' , href: ' ...' },
326+ { label: ' Privacy Policy' , href: ' ...' },
327+ ],
328+
329+ homePath: ' /' , // Logo link destination
330+ };
331+ ```
214332
215333### Adding UI Components
216334
@@ -222,15 +340,15 @@ npx shadcn@latest add @constructive/<component>
222340
223341Registry URL is configured in ` components.json ` . Components use Base UI primitives, Tailwind CSS 4, and cva for variants.
224342
225- ### GraphQL SDK
343+ ### GraphQL SDK Regeneration
226344
227- The SDK is generated from the running backend schema. After backend schema changes :
345+ After backend schema changes, regenerate the SDKs :
228346
229347``` bash
230348pnpm codegen
231349```
232350
233- Config in ` graphql-codegen.config.ts ` points to ` http://api.localhost:3000/graphql ` by default .
351+ Config in ` graphql-codegen.config.ts ` derives endpoints from ` NEXT_PUBLIC_DB_NAME ` .
234352
235353## Features
236354
@@ -240,11 +358,14 @@ Config in `graphql-codegen.config.ts` points to `http://api.localhost:3000/graph
240358- ** Members** — Manage organization members and roles
241359- ** Account Management** — Profile, email verification, account deletion
242360- ** App Shell** — Sidebar navigation, theme switching, responsive layout
361+ - ** Stack Cards** — Slide-in panel system for create/edit flows
243362- ** Permissions** — Role-based access control for org features
363+ - ** State Management** — Zustand store with auth, env, and preferences slices
244364
245365## Troubleshooting
246366
247- - ** GraphQL errors on startup** : Ensure the Constructive backend is running and the endpoint in ` .env.local ` is correct
248- - ** Empty SDK directory** : Run ` pnpm codegen ` with the backend running to generate the SDK
367+ - ** GraphQL errors on startup** : Ensure the Constructive backend is running and ` NEXT_PUBLIC_DB_NAME ` in ` .env.local ` is correct
368+ - ** Empty SDK directory** : Run ` pnpm codegen ` with the backend running to generate the SDKs
249369- ** Password reset emails not arriving** : Requires the full backend stack (job service + email function). Check Mailpit UI at ` http://localhost:8025 `
250- - ** Port conflicts** : The frontend runs on port 3001 by default. The backend GraphQL server uses port 3000
370+ - ** Port conflicts** : The frontend runs on port 3011 by default. The backend GraphQL server uses port 3000
371+ - ** SDK import errors** : Ensure path aliases (` @sdk/admin ` , ` @sdk/auth ` , ` @sdk/app ` ) are configured in ` tsconfig.json `
0 commit comments