|
| 1 | +--- |
| 2 | +description: |
| 3 | +globs: packages/forge-models/src/**/*.ts,apps/docs/src/content/docs/models/**/* |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | +# Rule: Create Model |
| 7 | + |
| 8 | +This rule outlines the process for defining new data models and ensuring their corresponding documentation is comprehensive and up-to-date. Adherence to this rule maintains clarity and consistency across the DH Forge System. |
| 9 | + |
| 10 | +## Core Principle |
| 11 | + |
| 12 | +Model definitions and their documentation are inextricably linked. **Whenever a model is created or modified, its documentation must be created or updated accordingly.** |
| 13 | + |
| 14 | +## Model Definition |
| 15 | + |
| 16 | +1. **Location:** All core data models are defined as Zod schemas within the `/packages/forge-models/src/` directory. |
| 17 | +2. - Models are stored within versioned folders (e.g., `/src/version-0.2`. `/src/version-1.0`) |
| 18 | + - Organize models logically, potentially by category (e.g., `character/`, `item/`, `ability/`). |
| 19 | + - Follow existing patterns or create new categorized subdirectories if appropriate. |
| 20 | +3. **Technology:** Use @Zod schema definition and validation. |
| 21 | +4. **Naming Conventions:** |
| 22 | + - **Zod Schema Variable:** `camelCase` (e.g., `characterSchema`). |
| 23 | + - **Exported Type:** `PascalCase` (e.g., `Character`), typically inferred from the Zod schema using `z.infer<typeof yourSchemaName>`. |
| 24 | + - **File Names (for Zod schemas):** `kebab-case.ts` (e.g., `character.ts` or `item-schemas.ts`). |
| 25 | + |
| 26 | +## Documentation |
| 27 | + |
| 28 | +Each distinct model type _must_ have its own documentation page. |
| 29 | + |
| 30 | +1. **Location:** `apps/docs/src/content/docs/models/` |
| 31 | +2. **File Creation:** |
| 32 | + - Create a new `.mdx` file for the model (e.g., `character.mdx` or `primary-class.mdx`). |
| 33 | + - Use `kebab-case` for documentation filenames. |
| 34 | +3. **Content Requirements:** |
| 35 | + The `.mdx` file for each model must include: |
| 36 | + |
| 37 | + - **Frontmatter:** |
| 38 | + - `title`: A clear, descriptive title for the model (e.g., `Character Model`). |
| 39 | + - `description`: A brief overview of what this model represents. |
| 40 | + - **Main Content:** |
| 41 | + - **Description Section:** |
| 42 | + - A concise explanation of what the model represents and its purpose within the DH Forge System. |
| 43 | + - Clarify any potential ambiguities. |
| 44 | + - **Schema and Expected Values Section:** |
| 45 | + - Detail all fields, their expected data types (e.g., string, number, boolean, array, nested object). |
| 46 | + - Specify if fields are required or optional. |
| 47 | + - Describe any constraints, enumerations (e.g., "must be one of 'VALUE_A', 'VALUE_B'"), or formatting rules. |
| 48 | + - This section should accurately reflect the Zod schema. Including a relevant snippet of the Zod schema definition or a simplified representation is highly encouraged. |
| 49 | + - **Examples Section:** |
| 50 | + - Provide at least one, preferably multiple, clear JSON or TypeScript object examples illustrating valid instances of the model. |
| 51 | + - Include examples that cover common use cases and demonstrate the use of optional fields. |
| 52 | + |
| 53 | + **Example `.mdx` Structure:** |
| 54 | + |
| 55 | + ````mdx |
| 56 | + --- |
| 57 | + title: Example Model Name |
| 58 | + description: A brief overview of what this Example Model represents and its role in the system. |
| 59 | + --- |
| 60 | + |
| 61 | + ## Description |
| 62 | + |
| 63 | + The `ExampleModel` is used to structure data related to [...]. Its primary purpose is to ensure consistency and provide a clear definition for [...]. |
| 64 | + |
| 65 | + ## Schema and Expected Values |
| 66 | + |
| 67 | + The `ExampleModel` has the following structure: |
| 68 | + |
| 69 | + | key | type | required | note | |
| 70 | + |--------------------|---------------------|----------|--------------------------------------------------------------------------------------| |
| 71 | + | id | string | yes | Unique identifier for the instance. Must follow UUID v4 format. | |
| 72 | + | name | string | yes | Human-readable name for the instance. | |
| 73 | + | status | string | yes | Current status. Must be one of `ACTIVE`, `INACTIVE`, `PENDING`. | |
| 74 | + | configuration | object | no | Optional object containing further configuration details. | |
| 75 | + | configuration.retries | number | no | Number of retries, defaults to 3. | |
| 76 | + | configuration.isEnabled | boolean | yes | Flag to enable or disable. | |
| 77 | + | tags | array of strings | no | List of associated tags. | |
| 78 | + |
| 79 | + ## Examples |
| 80 | + |
| 81 | + ### Basic Example |
| 82 | + |
| 83 | + ```json |
| 84 | + { |
| 85 | + "id": "123e4567-e89b-12d3-a456-426614174000", |
| 86 | + "name": "My First Example Instance", |
| 87 | + "status": "ACTIVE" |
| 88 | + } |
| 89 | + ``` |
| 90 | + ```` |
| 91 | + |
| 92 | + ### Example with Optional Fields |
| 93 | + |
| 94 | + ```json |
| 95 | + { |
| 96 | + "id": "987e6543-e21b-32d1-b432-872251234011", |
| 97 | + "name": "Another Example Instance", |
| 98 | + "status": "PENDING", |
| 99 | + "configuration": { |
| 100 | + "retries": 5, |
| 101 | + "isEnabled": true |
| 102 | + }, |
| 103 | + "tags": ["important", "needs-review"] |
| 104 | + } |
| 105 | + ``` |
| 106 | + |
| 107 | + ``` |
| 108 | + |
| 109 | + ``` |
| 110 | + |
| 111 | +4. **Referencing Other Models:** |
| 112 | + - If the model references other models (e.g., using an ID that corresponds to another model, or the `category/type:id` convention if applicable), clearly explain these relationships. |
| 113 | + - Where appropriate, link to the documentation pages for any referenced models. |
| 114 | + |
| 115 | +## Process Summary |
| 116 | + |
| 117 | +1. **Define/Update Schema:** Create or modify the Zod schema in the relevant file within `/packages/forge-models/src/`. |
| 118 | +2. **Create/Update Documentation:** |
| 119 | + - Create a new `.mdx` file in `apps/docs/src/content/docs/models/` for a new model, or open the existing one for an update. |
| 120 | + - Ensure the filename is `kebab-case`. |
| 121 | +3. **Write Documentation Content:** Populate the `.mdx` file with the title, description, schema details, and examples as outlined above. |
| 122 | +4. **Verify Accuracy:** Double-check that the documentation accurately reflects the current model schema. |
| 123 | +5. **Commit Changes:** Commit both the schema changes (in `/packages/forge-models/`) and the documentation changes (in `apps/docs/src/content/docs/models/`) together in the same commit to ensure atomicity. |
0 commit comments