|
| 1 | +--- |
| 2 | +title: Getting Started |
| 3 | +description: Build your first ObjectStack application in 5 minutes. |
| 4 | +--- |
| 5 | + |
| 6 | +import { Step, Steps } from 'fumadocs-ui/components/steps'; |
| 7 | + |
| 8 | +ObjectStack is a protocol, but `@objectstack/spec` is the reference implementation library that provides the Zod schemas and strict types to build valid metadata. |
| 9 | + |
| 10 | +<Steps> |
| 11 | + |
| 12 | +<Step> |
| 13 | +## Initialize your project |
| 14 | + |
| 15 | +You can start from scratch or add ObjectStack to an existing TypeScript project. |
| 16 | + |
| 17 | +```bash |
| 18 | +mkdir my-app |
| 19 | +cd my-app |
| 20 | +npm init -y |
| 21 | +npm install typescript zod @objectstack/spec |
| 22 | +npx tsc --init |
| 23 | +``` |
| 24 | +</Step> |
| 25 | + |
| 26 | +<Step> |
| 27 | +## Define your first Object |
| 28 | + |
| 29 | +Create a file named `src/objects/contact.schema.ts`. |
| 30 | +This is where the power of **Zod-First Definition** comes in. You get autocomplete and validation out of the box. |
| 31 | + |
| 32 | +```typescript |
| 33 | +import { ObjectSchema, Field } from '@objectstack/spec'; |
| 34 | + |
| 35 | +export const Contact = ObjectSchema.create({ |
| 36 | + name: 'contact', |
| 37 | + label: 'Contact', |
| 38 | + fields: { |
| 39 | + first_name: Field.text({ label: 'First Name', required: true }), |
| 40 | + last_name: Field.text({ label: 'Last Name', required: true }), |
| 41 | + email: Field.text({ format: 'email' }), |
| 42 | + type: Field.select(['Customer', 'Partner', 'Vendor']), |
| 43 | + }, |
| 44 | + enable: { |
| 45 | + api: true, |
| 46 | + audit: true |
| 47 | + } |
| 48 | +}); |
| 49 | +``` |
| 50 | +</Step> |
| 51 | + |
| 52 | +<Step> |
| 53 | +## Validate the Protocol |
| 54 | + |
| 55 | +Create a build script `src/build.ts` to verify your definitions comply with the ObjectStack Protocol. |
| 56 | + |
| 57 | +```typescript |
| 58 | +import { Contact } from './objects/contact.schema'; |
| 59 | + |
| 60 | +// This will throw a ZodError if your schema is invalid |
| 61 | +const protocol = Contact.parse(Contact); |
| 62 | + |
| 63 | +console.log(`✅ Object '${protocol.name}' is valid ObjectStack Metadata!`); |
| 64 | +console.log(JSON.stringify(protocol, null, 2)); |
| 65 | +``` |
| 66 | +</Step> |
| 67 | + |
| 68 | +<Step> |
| 69 | +## Next Steps |
| 70 | + |
| 71 | +Now that you have valid metadata, you can: |
| 72 | + |
| 73 | +1. **Generate SQL**: Use the Protocol Compiler (Coming Soon) to generate `CREATE TABLE` statements. |
| 74 | +2. **Generate UI**: Feed the JSON into the `<ObjectForm />` React component. |
| 75 | +3. **Deploy**: Push the JSON to an ObjectOS Kernel. |
| 76 | + |
| 77 | +</Step> |
| 78 | + |
| 79 | +</Steps> |
0 commit comments