Skip to content

Commit a463b5c

Browse files
authored
docs: overhaul documentation and introduce .serverless-full-stack-webapp-starter-kit/ directory (#125)
## Issue close #109 close #111 ## Changes - **AGENTS.md**: New file. Development guide with irreducible knowledge only — authentication patterns, async job dispatch, DB migration, Lambda constraints, coding conventions, and guardrails. 80 lines, designed to work in copied projects. - **DESIGN_PRINCIPLES.md**: New file at `.serverless-full-stack-webapp-starter-kit/design/`. Kit maintainer context — quality standards, design decisions, technology choice rationale, ADR policy. - **README.md**: Rewritten with Getting started flow (copy → customize → deploy → add features), maintenance policy, updated image paths, contributor credits. - **CONTRIBUTING.md**: Added language policy and Conventional Commits (Angular style). - **webapp/README.md**: Simplified to local dev setup and env var notes, delegates to AGENTS.md. - **imgs/**: Moved to `.serverless-full-stack-webapp-starter-kit/docs/imgs/`. - **AmazonQ.md**, **webapp/AmazonQ.md**: Deleted (consolidated into AGENTS.md). ## Verification - README.md image paths resolve correctly - AGENTS.md is self-contained (no dependency on README.md or .serverless-full-stack-webapp-starter-kit/) - All links between documents are valid
1 parent e32dc7a commit a463b5c

File tree

10 files changed

+238
-442
lines changed

10 files changed

+238
-442
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Design Principles
2+
3+
This document is for kit maintainers. If you copied this kit to build your own app, you can safely delete the `.serverless-full-stack-webapp-starter-kit/` directory.
4+
5+
## What this kit is
6+
7+
A template you **copy** (not fork) and grow into your own app. It is not a framework — users are expected to read, understand, and modify every file.
8+
9+
## Quality standards
10+
11+
As an aws-samples project:
12+
13+
- Correctness is the top priority — users learn patterns from this code.
14+
- Reproducibility — following the README must produce a working deployment.
15+
- Readability — code should be understandable by developers new to serverless.
16+
- One-command deploy — `npx cdk deploy --all` must be the only deployment step.
17+
18+
The litmus test for any PR: "After this merges, will a developer who copies the kit build their app on a correct understanding?"
19+
20+
## Design decisions
21+
22+
### Template, not framework
23+
24+
- Breaking changes have low impact — users copy and diverge. Major versions can be bumped without a lengthy deprecation cycle.
25+
- The sample app exists solely to prove all kit components work together. Users will delete it. Do not expand sample app features beyond what is needed for this proof.
26+
- Avoid over-abstraction. Readability and modifiability matter more than DRY.
27+
28+
### What to include
29+
30+
- Patterns that every serverless full-stack webapp needs (auth, DB, async jobs, real-time).
31+
- Operational essentials (migration, logging, cost-optimized defaults).
32+
- Only what cannot be trivially added later.
33+
34+
### What to exclude
35+
36+
- App-specific business logic.
37+
- Dependencies on specific AI models or services.
38+
- Patterns needed by fewer than half of expected users.
39+
40+
### Technology choices
41+
42+
| Choice | Rationale |
43+
|--------|-----------|
44+
| `prisma db push` over `prisma migrate` | Simpler default for starter-kit scope. Users can switch to `prisma migrate` when they need migration history. |
45+
| NAT Instance over NAT Gateway | ~$30/month savings. Acceptable trade-off for a starter kit. |
46+
| Single Lambda for all async jobs | Reduces cold starts and simplifies deployment. `cmd` parameter selects the entry point. |
47+
| `proxy.ts` over Next.js middleware | Runs inside Lambda handler, avoiding cold-start CPU starvation from JWKS fetch in middleware. |
48+
| `output: 'standalone'` | Required for Lambda deployment via Docker image. |
49+
| Lambda Web Adapter | Enables response streaming with CloudFront + Lambda Function URL. |
50+
51+
### Architecture Decision Records (ADR)
52+
53+
ADRs are not used yet. Introduce `design/adr/` when a major technology decision is made (e.g., ORM migration, database engine change) that requires recording the context, alternatives considered, and rationale.

imgs/architecture.png renamed to .serverless-full-stack-webapp-starter-kit/docs/imgs/architecture.png

File renamed without changes.

imgs/signin.png renamed to .serverless-full-stack-webapp-starter-kit/docs/imgs/signin.png

File renamed without changes.

imgs/top.png renamed to .serverless-full-stack-webapp-starter-kit/docs/imgs/top.png

File renamed without changes.

AGENTS.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# AGENTS.md
2+
3+
## Commands
4+
5+
```bash
6+
# webapp
7+
cd webapp && npm ci
8+
cd webapp && npm run dev # starts on port 3010
9+
cd webapp && npm run build
10+
cd webapp && npm run lint
11+
cd webapp && npm run format
12+
13+
# cdk
14+
cd cdk && npm ci
15+
cd cdk && npm run build
16+
cd cdk && npm test
17+
cd cdk && npm run format
18+
cd cdk && npx cdk deploy --all
19+
cd cdk && npx cdk diff
20+
21+
# local development (requires Docker)
22+
docker compose up -d # PostgreSQL on port 5432
23+
cd webapp && npx prisma db push # sync schema to local DB
24+
cd webapp && npm run dev
25+
```
26+
27+
## Development guide
28+
29+
### Authentication
30+
31+
All server-side mutations must go through `authActionClient` (defined in `lib/safe-action.ts`). It validates the Cognito session via Amplify server-side auth and injects `ctx.userId`. Never call Prisma directly from a Server Action without this middleware.
32+
33+
`proxy.ts` handles route protection (redirect to `/sign-in` for unauthenticated users). It is NOT a Next.js middleware file — it runs inside the Lambda handler. There is no `middleware.ts` in this project.
34+
35+
### Async jobs
36+
37+
The dispatch flow is: Server Action → `runJob()` (Lambda async invoke) → `async-job-runner.ts` (discriminated union dispatch) → job handler → `sendEvent()` (AppSync Events) → client `useEventBus` hook.
38+
39+
To add a new job:
40+
1. Add a Zod schema with a `type` literal to the discriminated union in `async-job-runner.ts`
41+
2. Implement the handler in `src/jobs/async-job/`
42+
3. Add the case to the switch statement
43+
44+
All job types share a single Lambda function via `job.Dockerfile`. The CDK `cmd` parameter selects the entry point.
45+
46+
### Database migration
47+
48+
`prisma db push` is used for schema sync by default. The migration runner Lambda is invoked automatically during `cdk deploy` via CDK Trigger. For manual invocation, use the `MigrationCommand` from CDK outputs.
49+
50+
Schema changes: edit `prisma/schema.prisma` → run `npx prisma db push` locally → commit. The `zod-prisma-types` generator auto-generates Zod schemas from the Prisma schema. If you switch to `prisma migrate`, update the migration runner accordingly.
51+
52+
### Lambda environment
53+
54+
The webapp runs on Lambda behind CloudFront via Lambda Web Adapter (response streaming). `next.config.ts` uses `output: 'standalone'`. Build-time env vars (prefixed `NEXT_PUBLIC_`) are injected via CDK `ContainerImageBuild` build args — they cannot be changed at runtime.
55+
56+
### Real-time notifications
57+
58+
Server → client push uses AppSync Events. Server-side: `sendEvent(channelName, payload)` with IAM SigV4 signing. Client-side: `useEventBus` hook with Cognito user pool auth. The channel namespace is `event-bus/`.
59+
60+
## Documentation policy
61+
62+
- Do not document what can be derived from code. An agent can read the codebase.
63+
- Enforce verifiable constraints with tests and linters, not prose.
64+
- Code comments explain "why not" only — the non-obvious reason something was done a certain way.
65+
- Before adding a line to this file, ask: "If I remove this line, will an agent make a mistake?" If no, don't add it. If a root cause is fixed, remove the corresponding line.
66+
67+
## Conventions
68+
69+
- PR titles and code comments in English.
70+
- Issues and discussions in English or Japanese.
71+
- PR titles follow [Conventional Commits](https://www.conventionalcommits.org/) (`feat:`, `fix:`, `chore:`, etc.).
72+
- UI components: use [shadcn/ui](https://ui.shadcn.com/). Do not introduce alternative component libraries.
73+
- Logs: use JSON structured output.
74+
- Dependencies: esbuild and Next.js bundle everything, so only packages with native binaries needed at Lambda runtime belong in `dependencies`. Everything else goes in `devDependencies`.
75+
76+
## Do not
77+
78+
- Do not bypass `authActionClient` for any mutation. No raw Prisma calls from Server Actions.
79+
- Do not add `middleware.ts`. Route protection is handled by `proxy.ts` inside the Lambda runtime.
80+
- Do not use `prisma migrate` commands unless you have explicitly switched from `prisma db push`. The default setup uses `prisma db push`.
81+
- Do not hardcode AWS region or account IDs. Use CDK context or environment variables.
82+
- Do not add `NEXT_PUBLIC_` env vars to `.env.local` for deployed builds — they must be set as CDK build args in `webapp.ts`.

AmazonQ.md

Lines changed: 0 additions & 137 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ documentation, we greatly value feedback and contributions from our community.
66
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
77
information to effectively respond to your bug report or contribution.
88

9+
## Language policy
10+
11+
- PR titles and code comments: English
12+
- Issues and discussions: English or Japanese
13+
14+
## Commit and PR conventions
15+
16+
PR titles follow [Conventional Commits](https://www.conventionalcommits.org/) (Angular style). Enforced by CI. Releases are automated via [Release Please](https://github.com/googleapis/release-please).
917

1018
## Reporting Bugs/Feature Requests
1119

@@ -19,7 +27,6 @@ reported the issue. Please try to include as much information as you can. Detail
1927
* Any modifications you've made relevant to the bug
2028
* Anything unusual about your environment or deployment
2129

22-
2330
## Contributing via Pull Requests
2431
Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:
2532

0 commit comments

Comments
 (0)