|
| 1 | +# @objectstack/spec Context for AI Agents |
| 2 | + |
| 3 | +> **SYSTEM NOTE**: This file provides a high-level summary of the ObjectStack Protocol to help LLMs understand the codebase structure and intent. |
| 4 | + |
| 5 | +## 1. Architecture Overview (The "Three-Layer Model") |
| 6 | + |
| 7 | +ObjectStack is a metadata-driven "Post-SaaS Operating System". |
| 8 | +It is divided into three layers, reflected in the import paths: |
| 9 | + |
| 10 | +### Layer 1: ObjectQL (`@objectstack/spec/data`) |
| 11 | +**The Business Kernel**. Defines "What Data Exists". |
| 12 | +- **`ObjectSchema`**: Defines database tables (postgres/mongo agnostic). |
| 13 | +- **`FieldSchema`**: Defines columns with types (`text`, `number`, `lookup`, `formula`). |
| 14 | +- **`QuerySchema`**: A JSON-based AST for querying data (replaces SQL). |
| 15 | +- **`DriverInterface`**: The contract for database adapters. |
| 16 | + |
| 17 | +### Layer 2: ObjectOS (`@objectstack/spec/system` & `@objectstack/spec/api`) |
| 18 | +**The Runtime Kernel**. Defines "How System Operates". |
| 19 | +- **`ManifestSchema`**: `objectstack.config.ts` configuration. |
| 20 | +- **`IdentitySchema`**: Users, Roles, and Authentication. |
| 21 | +- **`EventSchema`**: System bus and Webhooks. |
| 22 | +- **`EndpointSchema`**: API Gateway configuration. |
| 23 | + |
| 24 | +### Layer 3: ObjectUI (`@objectstack/spec/ui`) |
| 25 | +**The Presentation Layer**. Defines "How Users Interact". |
| 26 | +- **`AppSchema`**: Navigation menus and branding. |
| 27 | +- **`ViewSchema`**: Layouts for data (Grid, Kanban, Calendar). |
| 28 | +- **`ActionSchema`**: Buttons and triggers. |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## 2. Coding Patterns (Zod First) |
| 33 | + |
| 34 | +All definitions are virtually **Zod Schemas**. |
| 35 | +- **Configuration Keys**: `camelCase` (e.g., `maxLength`, `referenceFilters`). |
| 36 | +- **Data Values**: `snake_case` (e.g., `object: 'project_task'`, `type: 'lookup'`). |
| 37 | + |
| 38 | +### Example: Defining an Object |
| 39 | +```typescript |
| 40 | +import { ObjectSchema } from '@objectstack/spec/data'; |
| 41 | + |
| 42 | +// Describes a "Task" object |
| 43 | +const taskObject = { |
| 44 | + name: 'project_task', // snake_case table name |
| 45 | + label: 'Project Task', |
| 46 | + fields: { |
| 47 | + status: { type: 'select', options: ['todo', 'done'] }, |
| 48 | + priority: { type: 'number', defaultValue: 0 } |
| 49 | + } |
| 50 | +}; |
| 51 | +``` |
| 52 | + |
| 53 | +### Example: Building a Query |
| 54 | +```typescript |
| 55 | +import { QuerySchema } from '@objectstack/spec/data'; |
| 56 | + |
| 57 | +// JSON-based SQL alternative |
| 58 | +const query = { |
| 59 | + object: 'project_task', |
| 60 | + filters: [ |
| 61 | + ['status', '=', 'todo'], |
| 62 | + 'and', |
| 63 | + ['priority', '>', 1] |
| 64 | + ], |
| 65 | + sort: [{ field: 'created_at', order: 'desc' }], |
| 66 | + top: 10 |
| 67 | +}; |
| 68 | +``` |
| 69 | + |
| 70 | +--- |
| 71 | + |
| 72 | +## 3. Key exports by Namespace |
| 73 | + |
| 74 | +### `import * as Data from '@objectstack/spec/data'` |
| 75 | +- `ObjectSchema`, `FieldSchema`: Logic & Storage definition. |
| 76 | +- `QuerySchema`, `FilterSchema`: Data retrieval AST. |
| 77 | +- `DriverInterface`, `DatasourceSchema`: Database connectivity. |
| 78 | +- `WorkflowSchema`, `FlowSchema`: Automation logic. |
| 79 | + |
| 80 | +### `import * as UI from '@objectstack/spec/ui'` |
| 81 | +- `ViewSchema`: `type: 'grid' | 'kanban' | 'calendar'`. |
| 82 | +- `FormSchema`: `layout: 'simple' | 'tabbed'`. |
| 83 | +- `DashboardSchema`: Widget composition. |
| 84 | + |
| 85 | +### `import * as System from '@objectstack/spec/system'` |
| 86 | +- `PluginSchema`: Module lifecycle. |
| 87 | +- `EventSchema`: Pub/Sub definitions. |
| 88 | +- `PolicySchema`: Security rules. |
0 commit comments