Skip to content

Commit 82b56fe

Browse files
feat: update boilerplate skill for per-DB architecture
- Update environment config: single NEXT_PUBLIC_DB_NAME instead of three endpoints - Update SDK structure: @sdk/admin, @sdk/auth, @sdk/app - Update project structure: hooks/admin/, hooks/auth/ - Add SDK usage examples and import patterns - Add 'Building Your App' section - Update troubleshooting table
1 parent ac1b7fc commit 82b56fe

1 file changed

Lines changed: 145 additions & 56 deletions

File tree

.agents/skills/constructive-starter-kits/references/nextjs-app.md

Lines changed: 145 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ Use this skill when:
1717

1818
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.
1919

20+
**Per-DB Architecture**: The boilerplate uses three separate SDK contexts, each pointing to a different API endpoint:
21+
22+
| SDK | Endpoint | Purpose |
23+
|-----|----------|---------|
24+
| `@sdk/admin` | `admin-{db}.localhost:3000` | Organizations, members, permissions, invites |
25+
| `@sdk/auth` | `auth-{db}.localhost:3000` | Users, emails, authentication |
26+
| `@sdk/app` | `app-public-{db}.localhost:3000` | Your business data (tables you created) |
27+
2028
## Setup
2129

2230
### 1. Clone the Boilerplate
2331

24-
Use `pgpm init` with the `-w` flag to scaffold a workspace from the template. All required arguments must be provided to avoid interactive prompts:
32+
Use `pgpm init` with the `-w` flag to scaffold a workspace from the template:
2533

2634
```bash
2735
pgpm init -w \
@@ -36,7 +44,7 @@ pgpm init -w \
3644
--moduleName <module-name>
3745
```
3846

39-
**Required arguments for non-interactive mode (avoid asking for user input):**
47+
**Required arguments for non-interactive mode:**
4048

4149
| Argument | Description |
4250
|----------|-------------|
@@ -50,14 +58,9 @@ pgpm init -w \
5058

5159
The boilerplate is created at `<workspace-name>/packages/<module-name>/`.
5260

53-
> **Interactive mode (for humans):** Prompt will be asking for the arguments missing from the required arguments list:
54-
> ```bash
55-
> pgpm init -w --repo constructive-io/sandbox-templates --template nextjs/constructive-app
56-
> ```
57-
5861
#### Adding to an Existing Workspace
5962

60-
If you already have a pnpm workspace (a directory with `pnpm-workspace.yaml`), use `pgpm init` **without** the `-w` flag to clone the boilerplate as a new module inside it. Run this from the **workspace root**:
63+
If you already have a pnpm workspace, use `pgpm init` **without** the `-w` flag:
6164

6265
```bash
6366
pgpm init \
@@ -66,21 +69,6 @@ pgpm init \
6669
--moduleName <module-name>
6770
```
6871

69-
**Required arguments for existing workspace :**
70-
71-
| Argument | Description |
72-
|----------|-------------|
73-
| `--moduleName` | Module/package name for the new boilerplate |
74-
75-
This creates the module at `packages/<module-name>/` within your existing workspace. The workspace-level arguments (`--name`, `--fullName`, `--email`, etc.) are **not needed** since the workspace already exists.
76-
77-
> **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.
78-
79-
> **Interactive mode (for humans):** :
80-
> ```bash
81-
> pgpm init --repo constructive-io/sandbox-templates --template nextjs/constructive-app
82-
> ```
83-
8472
### 2. Install Dependencies
8573

8674
```bash
@@ -90,11 +78,24 @@ pnpm install
9078

9179
### 3. Configure Environment
9280

93-
Create or verify `.env.local`:
81+
Create `.env.local` with your database name:
9482

9583
```bash
96-
# GraphQL endpoint (must point to a running Constructive backend)
97-
NEXT_PUBLIC_SCHEMA_BUILDER_GRAPHQL_ENDPOINT=http://api.localhost:3000/graphql
84+
# Required: Your provisioned database name
85+
NEXT_PUBLIC_DB_NAME=your-db-name
86+
```
87+
88+
This single variable derives all three API endpoints:
89+
- `admin-{db}.localhost:3000/graphql`
90+
- `auth-{db}.localhost:3000/graphql`
91+
- `app-public-{db}.localhost:3000/graphql`
92+
93+
**Optional endpoint overrides** (only if your setup differs from standard):
94+
95+
```bash
96+
# NEXT_PUBLIC_ADMIN_ENDPOINT=http://admin-mydb.localhost:3000/graphql
97+
# NEXT_PUBLIC_AUTH_ENDPOINT=http://auth-mydb.localhost:3000/graphql
98+
# NEXT_PUBLIC_APP_ENDPOINT=http://app-public-mydb.localhost:3000/graphql
9899
```
99100

100101
### 4. Generate GraphQL SDK
@@ -105,7 +106,10 @@ The SDK must be generated against a running backend:
105106
pnpm codegen
106107
```
107108

108-
This runs `@constructive-io/graphql-codegen` using `graphql-codegen.config.ts` and outputs the SDK to `src/graphql/schema-builder-sdk/api`.
109+
This generates three SDK targets:
110+
- `src/graphql/sdk/admin/` — Admin operations
111+
- `src/graphql/sdk/auth/` — Auth operations
112+
- `src/graphql/sdk/app/` — Your business data
109113

110114
### 5. Start Development
111115

@@ -115,6 +119,8 @@ pnpm dev
115119

116120
Opens at [http://localhost:3001](http://localhost:3001).
117121

122+
After login, you'll see the **"Start Building Here"** page with instructions for adding your business logic.
123+
118124
## Backend Requirements
119125

120126
This boilerplate requires a running Constructive backend. The easiest way is via **Constructive Hub**:
@@ -134,8 +140,7 @@ Required backend services:
134140
| Service | Port | Purpose |
135141
|---------|------|---------|
136142
| PostgreSQL | 5432 | Database with Constructive schema |
137-
| GraphQL Server (Public) | 3000 | API endpoint for app operations |
138-
| GraphQL Server (Private) | 3002 | Admin operations |
143+
| GraphQL Server | 3000 | API endpoints (admin, auth, app-public) |
139144
| Job Service | 8080 | Background job processing |
140145
| Email Function | 8082 | Email sending via SMTP |
141146
| Mailpit SMTP | 1025 | Email server (development) |
@@ -147,7 +152,9 @@ Required backend services:
147152
src/
148153
├── app/ # Next.js App Router pages
149154
│ ├── layout.tsx # Root layout with providers
150-
│ ├── page.tsx # Home / org listing page
155+
│ ├── page.tsx # Home page (Start Building Here)
156+
│ ├── (authenticated)/ # Protected pages
157+
│ │ └── organizations/ # Organizations list
151158
│ ├── login/ # Login page
152159
│ ├── register/ # Registration page
153160
│ ├── forgot-password/ # Password reset request
@@ -167,7 +174,7 @@ src/
167174
│ ├── members/ # Org members management
168175
│ └── settings/ # Org settings
169176
├── components/
170-
│ ├── ui/ # shadcn/ui components (43 components)
177+
│ ├── ui/ # shadcn/ui components
171178
│ ├── auth/ # Auth forms (login, register, reset, etc.)
172179
│ ├── organizations/ # Org CRUD components
173180
│ ├── invites/ # Invite management components
@@ -183,24 +190,116 @@ src/
183190
├── graphql/
184191
│ ├── execute.ts # GraphQL execution layer
185192
│ ├── index.ts # GraphQL exports
186-
│ ├── typed-document.ts # Typed document utilities
187-
│ └── schema-builder-sdk/ # Generated SDK (via codegen)
193+
│ └── sdk/ # Generated SDKs
194+
│ ├── admin/ # Admin SDK (orgs, members, permissions)
195+
│ ├── auth/ # Auth SDK (users, authentication)
196+
│ └── app/ # App SDK (your business data)
188197
├── hooks/ # Shared React hooks
189198
├── lib/
190199
│ ├── auth/ # Auth utilities and context
191-
│ ├── gql/ # GraphQL hooks and query factories
200+
│ ├── gql/
201+
│ │ └── hooks/
202+
│ │ ├── admin/ # Admin-related hooks (orgs, members)
203+
│ │ │ ├── account/ # Account management hooks
204+
│ │ │ ├── app/ # App-level hooks
205+
│ │ │ ├── organizations/ # Organization hooks
206+
│ │ │ └── policies/ # Permission hooks
207+
│ │ └── auth/ # Auth hooks (login, register, logout)
192208
│ ├── navigation/ # Route and navigation helpers
193209
│ ├── permissions/ # Permission checking utilities
194-
│ ├── constants/ # App constants
195-
│ ├── logger/ # Logging utilities
196-
│ ├── runtime/ # Runtime helpers
197-
│ ├── utils/ # General utilities
198-
│ └── validation/ # Zod schemas and validation
210+
│ ├── runtime/ # Runtime configuration
211+
│ └── utils/ # General utilities
199212
├── store/ # Client state management
200213
├── app-config.ts # App-wide configuration
201214
└── app-routes.ts # Route definitions
202215
```
203216

217+
## SDK Usage
218+
219+
### Import Examples
220+
221+
```typescript
222+
// Your business data (from your provisioned tables)
223+
import {
224+
useYourTableQuery,
225+
useCreateYourTableMutation,
226+
useUpdateYourTableMutation,
227+
useDeleteYourTableMutation
228+
} from '@sdk/app';
229+
230+
// Current user & authentication
231+
import { useCurrentUserQuery, useSignInMutation } from '@sdk/auth';
232+
233+
// Organizations & permissions
234+
import { useOrgMembershipsQuery, useAppMembershipsQuery } from '@sdk/admin';
235+
```
236+
237+
### SDK Structure
238+
239+
| SDK | Import | Use For |
240+
|-----|--------|---------|
241+
| `@sdk/admin` | `import { ... } from '@sdk/admin'` | Organizations, members, permissions, invites |
242+
| `@sdk/auth` | `import { ... } from '@sdk/auth'` | Users, emails, signIn, signUp, currentUser |
243+
| `@sdk/app` | `import { ... } from '@sdk/app'` | Your business tables |
244+
245+
## Building Your App
246+
247+
After login, the home page (`src/app/page.tsx`) shows a guide. To add your business logic:
248+
249+
### 1. Edit the Home Page
250+
251+
Replace the guide content in `src/app/page.tsx` with your main feature:
252+
253+
```typescript
254+
'use client';
255+
256+
import { useYourTableQuery, useCreateYourTableMutation } from '@sdk/app';
257+
258+
export default function HomePage() {
259+
const { data, isLoading } = useYourTableQuery({});
260+
const createMutation = useCreateYourTableMutation();
261+
262+
if (isLoading) return <div>Loading...</div>;
263+
264+
return (
265+
<div className="p-8">
266+
<h1 className="text-2xl font-bold mb-4">Your Feature</h1>
267+
268+
<ul className="space-y-2">
269+
{data?.yourTable?.nodes?.map((item) => (
270+
<li key={item.id}>{item.name}</li>
271+
))}
272+
</ul>
273+
274+
<button
275+
onClick={() => createMutation.mutate({ input: { name: 'New Item' } })}
276+
className="mt-4 px-4 py-2 bg-primary text-white rounded"
277+
>
278+
Create New
279+
</button>
280+
</div>
281+
);
282+
}
283+
```
284+
285+
### 2. Add New Pages
286+
287+
Create pages in `src/app/(authenticated)/`:
288+
289+
```
290+
src/app/(authenticated)/your-feature/page.tsx
291+
```
292+
293+
### 3. Update Sidebar
294+
295+
Edit `src/lib/navigation/sidebar-config.ts` to add navigation items.
296+
297+
### 4. Regenerate SDK After Schema Changes
298+
299+
```bash
300+
pnpm codegen
301+
```
302+
204303
## Customization
205304

206305
### Branding
@@ -210,7 +309,6 @@ Edit `src/config/branding.ts` to customize:
210309
- Logo and wordmark paths (relative to `/public`)
211310
- Company name for legal footer
212311
- Legal links (disclaimer, privacy policy, etc.)
213-
- Home path for logo links
214312

215313
### Adding UI Components
216314

@@ -220,18 +318,6 @@ Components use the Constructive shadcn registry:
220318
npx shadcn@latest add @constructive/<component>
221319
```
222320

223-
Registry URL is configured in `components.json`. Components use Base UI primitives, Tailwind CSS 4, and cva for variants.
224-
225-
### GraphQL SDK
226-
227-
The SDK is generated from the running backend schema. After backend schema changes:
228-
229-
```bash
230-
pnpm codegen
231-
```
232-
233-
Config in `graphql-codegen.config.ts` points to `http://api.localhost:3000/graphql` by default.
234-
235321
## Features
236322

237323
- **Authentication** — Login, register, logout, password reset, email verification
@@ -244,7 +330,10 @@ Config in `graphql-codegen.config.ts` points to `http://api.localhost:3000/graph
244330

245331
## Troubleshooting
246332

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
249-
- **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
333+
| Issue | Solution |
334+
|-------|----------|
335+
| GraphQL errors on startup | Ensure backend is running and `NEXT_PUBLIC_DB_NAME` is set |
336+
| Empty SDK directory | Run `pnpm codegen` with backend running |
337+
| `useXxx` not found | Check if importing from correct SDK (`@sdk/admin`, `@sdk/auth`, or `@sdk/app`) |
338+
| Password reset emails not arriving | Check Mailpit UI at `http://localhost:8025` |
339+
| Port conflicts | Frontend: 3001, Backend GraphQL: 3000 |

0 commit comments

Comments
 (0)