@claude-code-mastery/starter-kit 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -59,4 +59,7 @@ Non-negotiable for this codebase. From production, not preference.
|
|
|
59
59
|
|
|
60
60
|
## Schema
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
Collections enforce no structure by default, so validate in two layers.
|
|
63
|
+
|
|
64
|
+
- **Parse before every write.** Validate each document against its Zod schema right before it hits the database, so a malformed shape never lands. The schema itself isn't Mongo-specific, it's the same contract the API and frontend use, see the `schema-source-of-truth` skill for defining it once and deriving every layer from one base.
|
|
65
|
+
- **Keep a `$jsonSchema` collection validator as the floor.** Zod only guards writes that go through your app, so the DB validator is the last line that also catches mongosh, scripts, and other services. Add it as a collection stabilizes and more code depends on its shape. Roll out safely: `validationAction: "warn"` to observe first, then `error`; `validationLevel: "moderate"` to spare existing nonconforming documents.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: schema-source-of-truth
|
|
3
|
+
description: One canonical Zod schema per entity, reused across the stack instead of redeclared at each layer. Use whenever defining or changing a data shape, a TypeScript type or interface for an entity, an API request/response validator, an Express body/query/params check, a frontend form validator, or a DB document shape. Catches the same-entity-defined-four-times drift. TypeScript-first, derive types and per-layer variants from one base instead of hand-writing parallel copies.
|
|
4
|
+
when_to_use: |
|
|
5
|
+
- Defining or editing an entity's shape (a User, Order, etc.) in types, an API, a form, or the DB
|
|
6
|
+
- Writing API request/response validation or Express middleware that checks req.body / query / params
|
|
7
|
+
- Writing a frontend form validator, or a TypeScript interface/type for data that also lives on the backend
|
|
8
|
+
- Any moment you're about to write a second definition of a shape that already exists somewhere
|
|
9
|
+
- Do NOT use for one-off internal types with no cross-layer counterpart
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Schema as a Single Source of Truth
|
|
13
|
+
|
|
14
|
+
A data entity should be defined once, as a Zod schema, and everything else derived from it. The failure pattern to kill: declaring the same entity separately at each layer, a frontend `interface User`, a backend `interface User`, a hand-written API validator, and a manual Mongo `$jsonSchema`. Four shapes for one entity, kept in sync by hand, guaranteed to drift the first time a field is added or renamed.
|
|
15
|
+
|
|
16
|
+
## One schema per entity, derive the rest
|
|
17
|
+
|
|
18
|
+
Define the canonical schema once and generate every other representation from it:
|
|
19
|
+
|
|
20
|
+
- **TypeScript type:** `type User = z.infer<typeof UserSchema>`. Never hand-write an `interface` that parallels a schema, infer it so it can't fall out of sync.
|
|
21
|
+
- **API validation:** parse `req.body` / `req.query` / `req.params` through the schema in middleware. `safeParse` and return 400 on failure, no field-by-field `if` checks.
|
|
22
|
+
- **Frontend forms:** the same schema drives form validation (`zodResolver` with react-hook-form), so client and server reject the same inputs by the same rules.
|
|
23
|
+
- **Pre-write guard:** parse before writing to the DB. See the `mongodb-rules` skill for the Mongo-specific parse-before-write and `$jsonSchema` floor.
|
|
24
|
+
- **OpenAPI and `$jsonSchema`:** generate them from the schema (`zod-to-openapi`, `zod-to-json-schema`) rather than maintaining them by hand.
|
|
25
|
+
|
|
26
|
+
Zod is TypeScript-first with zero runtime dependencies, so this costs one small library and removes every duplicated definition.
|
|
27
|
+
|
|
28
|
+
## One base, many variants (they are not identical)
|
|
29
|
+
|
|
30
|
+
"Same schema everywhere" is the goal, but a create payload is not the stored document and a response is not the request, so don't pretend they're one object. Model it honestly: one base schema, with per-layer variants derived from it, sharing a single origin while differing where they genuinely must.
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
const UserSchema = z.object({
|
|
34
|
+
_id: z.string(),
|
|
35
|
+
email: z.string().email(),
|
|
36
|
+
name: z.string().min(1),
|
|
37
|
+
createdAt: z.date(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const CreateUser = UserSchema.omit({ _id: true, createdAt: true }); // POST body
|
|
41
|
+
const UpdateUser = CreateUser.partial(); // PATCH body
|
|
42
|
+
const UserResponse = UserSchema.extend({ displayName: z.string() }); // adds computed field
|
|
43
|
+
type User = z.infer<typeof UserSchema>;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Derive variants with `.omit()`, `.partial()`, `.pick()`, `.extend()`. When the base gains a field, every variant inherits it automatically, which is the entire point. A hand-copied variant is just the drift problem at smaller scale.
|
|
47
|
+
|
|
48
|
+
## Make it physically shared
|
|
49
|
+
|
|
50
|
+
Single source of truth only holds if there is literally one file. Put entity schemas in a shared module both sides import, a `packages/schemas` workspace, or a shared `src/schemas/` reachable by frontend and backend. If each side keeps its own copy, they diverge no matter how disciplined the intent. The shared import is the enforcement, not the convention.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @claude-code-mastery/starter-kit
|
|
2
2
|
|
|
3
|
-
A Claude Code toolkit that installs 27 commands,
|
|
3
|
+
A Claude Code toolkit that installs 27 commands, 11 skills, 10 hooks, and scaffolding templates into Claude Code globally - so every project you open already has them available.
|
|
4
4
|
|
|
5
5
|
**Requires:** Node.js 20+ and [Claude Code](https://claude.ai/code)
|
|
6
6
|
|
|
@@ -25,7 +25,7 @@ After `init`, your `~/.claude/` directory looks like this:
|
|
|
25
25
|
├── starter-kit/ <- package files live here (single source of truth)
|
|
26
26
|
│ ├── commands/ <- 27 slash commands
|
|
27
27
|
│ ├── hooks/ <- 10 lifecycle hooks
|
|
28
|
-
│ ├── skills/ <-
|
|
28
|
+
│ ├── skills/ <- 11 skill files
|
|
29
29
|
│ └── .starter-kit/ <- scaffolding templates for /new-project
|
|
30
30
|
├── commands/
|
|
31
31
|
│ ├── new-project.md -> (symlink to starter-kit/commands/new-project.md)
|
|
@@ -84,6 +84,7 @@ Skills are expertise files Claude loads when relevant. These install automatical
|
|
|
84
84
|
- `create-service` - scaffolding patterns for new services
|
|
85
85
|
- `mcp-builder` - MCP server development patterns
|
|
86
86
|
- `terminal-tui` - Ink + React TUI patterns, resize handling
|
|
87
|
+
- `schema-source-of-truth` - one canonical Zod schema per entity, derived across all layers; catches the same shape defined four times drift
|
|
87
88
|
|
|
88
89
|
---
|
|
89
90
|
|
package/README.npm.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @claude-code-mastery/starter-kit
|
|
2
2
|
|
|
3
|
-
A Claude Code toolkit that installs 27 commands,
|
|
3
|
+
A Claude Code toolkit that installs 27 commands, 11 skills, 10 hooks, and scaffolding templates into Claude Code globally - so every project you open already has them available.
|
|
4
4
|
|
|
5
5
|
**Requires:** Node.js 20+ and [Claude Code](https://claude.ai/code)
|
|
6
6
|
|
|
@@ -25,7 +25,7 @@ After `init`, your `~/.claude/` directory looks like this:
|
|
|
25
25
|
├── starter-kit/ <- package files live here (single source of truth)
|
|
26
26
|
│ ├── commands/ <- 27 slash commands
|
|
27
27
|
│ ├── hooks/ <- 10 lifecycle hooks
|
|
28
|
-
│ ├── skills/ <-
|
|
28
|
+
│ ├── skills/ <- 11 skill files
|
|
29
29
|
│ └── .starter-kit/ <- scaffolding templates for /new-project
|
|
30
30
|
├── commands/
|
|
31
31
|
│ ├── new-project.md -> (symlink to starter-kit/commands/new-project.md)
|
|
@@ -84,6 +84,7 @@ Skills are expertise files Claude loads when relevant. These install automatical
|
|
|
84
84
|
- `create-service` - scaffolding patterns for new services
|
|
85
85
|
- `mcp-builder` - MCP server development patterns
|
|
86
86
|
- `terminal-tui` - Ink + React TUI patterns, resize handling
|
|
87
|
+
- `schema-source-of-truth` - one canonical Zod schema per entity, derived across all layers; catches the same shape defined four times drift
|
|
87
88
|
|
|
88
89
|
---
|
|
89
90
|
|
package/package.json
CHANGED