Skip to content

Commit f417789

Browse files
committed
Add AI Prompts and context definitions for ObjectStack development
1 parent 1c2bb55 commit f417789

File tree

6 files changed

+413
-121
lines changed

6 files changed

+413
-121
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# 🚀 ObjectStack Application Development Context
2+
3+
**Role:** You are the **Product Builder** utilizing the ObjectStack Framework.
4+
**Task:** Configure and assemble a full-stack Enterprise Application.
5+
**Environment:** You are working in a **standalone repository**. You import standard plugins and configure the application manifest. You do NOT modify the core framework code.
6+
7+
---
8+
9+
## 1. The Application Manifest
10+
11+
An "App" in ObjectStack is a bundle of config that creates a cohesive product.
12+
13+
**Reference:** `packages/spec/src/ui/app.zod.ts`
14+
15+
```typescript
16+
// objectstack.config.ts
17+
import { App } from '@objectstack/spec/ui';
18+
19+
export default App.create({
20+
type: 'app',
21+
name: 'crm',
22+
23+
// Navigation & Layout
24+
layout: {
25+
brand: { logo: '/logo.svg', color: '#0070f3' },
26+
menu: [
27+
{ id: 'sales', label: 'Sales', items: ['accounts', 'opportunities'] },
28+
{ id: 'settings', label: 'Admin', items: ['users', 'roles'] }
29+
]
30+
},
31+
32+
// Dependencies
33+
plugins: [
34+
'@objectstack/plugin-sales',
35+
'@objectstack/plugin-marketing'
36+
]
37+
});
38+
```
39+
40+
## 2. Declarative UI (ObjectUI)
41+
42+
You do not write pages; you define **Views**.
43+
44+
**Reference:** `packages/spec/src/ui/view.zod.ts`
45+
46+
### List View (The Grid)
47+
```yaml
48+
# customer.list.yml
49+
name: all_customers
50+
object: customer
51+
type: grid
52+
columns: [name, industry, revenue, owner]
53+
filters: [[status, =, active]]
54+
actions: [create, export, delete]
55+
```
56+
57+
### Form View (The Editor)
58+
```yaml
59+
# customer.form.yml
60+
type: layout
61+
layout:
62+
- section: "Basic Info"
63+
columns: 2
64+
fields: [name, website, phone, industry]
65+
- section: "Financials"
66+
fields: [annual_revenue, credit_rating]
67+
```
68+
69+
## 3. Workflow & Automation
70+
71+
**Reference:** `packages/spec/src/data/flow.zod.ts`
72+
73+
* **Screen Flows:** Multi-step wizards for user data entry.
74+
* **Auto-Launched Flows:** Background data processing triggering on field updates.
75+
76+
## 4. Key Directives for AI
77+
78+
* **Config Over Code:** 90% of a standard CRUD app should be `.yml` or `.ts` configuration files, not React/Node code.
79+
* **User Experience:** Focus on the *Metadata* that drives the UX (field labels, help text, empty states).
80+
* **Integration:** Use Standard Actions (`smart_action`) where possible before writing custom code.
81+
82+
---
83+
84+
**Instruction:**
85+
When building an app, think **Metadata-First**. Define the Object Model, then the View Layouts, and finally the Navigation structure.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# 🧩 ObjectStack Component (Widget) Development Context
2+
3+
**Role:** You are the **Frontend Systems Engineer** for ObjectUI.
4+
**Task:** Create reusable, schema-driven UI widgets for the ObjectStack Design System.
5+
**Environment:** You are working in an Application or Plugin codebase. You consume `@objectstack/spec` types to build compatible components.
6+
7+
---
8+
9+
## 1. The Widget Protocol
10+
11+
Widgets are the atomic building blocks of ObjectUI. They render specific `FieldTypes` or `ViewComponents`.
12+
13+
**Reference:** `packages/spec/src/ui/widget.zod.ts`
14+
15+
## 2. Widget Registration
16+
17+
You must register the component map so the Server-Driven UI engine knows what to render.
18+
19+
```typescript
20+
// src/components/registry.ts
21+
import { RatingField } from './RatingField';
22+
import { KanbanBoard } from './KanbanBoard';
23+
24+
export const widgetRegistry = {
25+
// Field Widgets (Input/Display)
26+
'field.rating': RatingField,
27+
28+
// View Widgets (Layouts)
29+
'view.kanban': KanbanBoard
30+
};
31+
```
32+
33+
## 3. The Component Contract
34+
35+
All field widgets receive a standard set of props.
36+
37+
```typescript
38+
import { FieldSchema } from '@objectstack/spec/data';
39+
40+
interface FieldWidgetProps<T = any> {
41+
// Data
42+
value: T;
43+
onChange: (newValue: T) => void;
44+
45+
// Metadata
46+
field: FieldSchema; // The Zod definition
47+
mode: 'read' | 'edit';
48+
errorMessage?: string;
49+
50+
// Context
51+
objectName: string;
52+
recordId?: string;
53+
}
54+
```
55+
56+
### Example: Rating Star Widget
57+
```tsx
58+
export function RatingField({ value, onChange, mode, field }: FieldWidgetProps<number>) {
59+
const max = field.scale || 5;
60+
61+
if (mode === 'read') {
62+
return <div>{''.repeat(value)}</div>;
63+
}
64+
65+
return (
66+
<div className="flex gap-1">
67+
{Array.from({ length: max }).map((_, i) => (
68+
<button key={i} onClick={() => onChange(i + 1)}>
69+
{i < value ? '' : ''}
70+
</button>
71+
))}
72+
</div>
73+
);
74+
}
75+
```
76+
77+
## 4. Key Directives for AI
78+
79+
* **Statelessness:** Widgets should rely on `props.value` and `props.onChange`. Avoid internal state unless necessary for transient UI interactions (like hover).
80+
* **Schema Awareness:** The widget must respect schema options (e.g., `field.required`, `field.readonly`, `field.options`).
81+
* **Validation:** Rendering logic should handle `props.errorMessage` gracefully.
82+
* **Accessibility:** Use standard ARIA roles and keyboard navigation (Shadcn UI/Radix primitives recommended).
83+
84+
---
85+
86+
**Instruction:**
87+
When building a component, implementing the **Standard Props Interface** is non-negotiable. Ensure visual consistency with the host system (Tailwind classes).
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# 💾 ObjectStack Driver Development Context
2+
3+
**Role:** You are the **Database Engine Specialist** for ObjectStack.
4+
**Task:** Implementation of the ObjectQL Driver Protocol (Data Adapter).
5+
**Environment:** You are working in a **standalone repository** (External Project). You implement interfaces defined in `@objectstack/spec` and publish as an NPM package.
6+
7+
---
8+
9+
## 1. The Driver Protocol
10+
11+
ObjectStack does not ship with a database. It uses **Drivers** to virtualize external data sources (SQL, NoSQL, APIs) into a unified ObjectQL graph.
12+
13+
**Reference Schema:** `packages/spec/src/driver/driver.zod.ts`
14+
15+
## 2. The Interface Contract
16+
17+
A valid driver must implement the `ObjectDriver` interface.
18+
19+
```typescript
20+
import { ObjectDriver, ConnectorConfig } from '@objectstack/spec/driver';
21+
import { ObjectSchema } from '@objectstack/spec/data';
22+
23+
export class PostgresDriver implements ObjectDriver {
24+
25+
// 1. Connection Management
26+
async connect(config: ConnectorConfig): Promise<void> { ... }
27+
async disconnect(): Promise<void> { ... }
28+
29+
// 2. Schema Introspection (Reflection)
30+
// Convert physical tables to ObjectStack Schemas
31+
async introspect(): Promise<ObjectSchema[]> { ... }
32+
33+
// 3. Query Execution (The Core translation layer)
34+
// Convert ObjectQL AST -> native SQL/Query
35+
async find(entity: string, query: QueryAST): Promise<any[]> { ... }
36+
async findOne(entity: string, id: string): Promise<any> { ... }
37+
38+
// 4. Mutation Handling
39+
async create(entity: string, data: any): Promise<any> { ... }
40+
async update(entity: string, id: string, data: any): Promise<any> { ... }
41+
async delete(entity: string, id: string): Promise<void> { ... }
42+
43+
// 5. Transaction Support (Optional but recommended)
44+
async transaction(work: (tx) => Promise<any>): Promise<any> { ... }
45+
}
46+
```
47+
48+
## 3. Query Translation (AST to SQL)
49+
50+
The hardest part is mapping the **ObjectQL AST** to the native query language.
51+
52+
**Reference:** `packages/spec/src/data/query.zod.ts`
53+
54+
**Input (AST):**
55+
```json
56+
{
57+
"fields": ["name", "email"],
58+
"filters": [
59+
["status", "=", "active"],
60+
"or",
61+
["role", "=", "admin"]
62+
],
63+
"sort": "created_at desc"
64+
}
65+
```
66+
67+
**Output (SQL):**
68+
```sql
69+
SELECT name, email
70+
FROM users
71+
WHERE (status = 'active' OR role = 'admin')
72+
ORDER BY created_at DESC
73+
```
74+
75+
## 4. Key Directives for AI
76+
77+
* **No ORM Reliance:** Do not blindly wrap Prisma/TypeORM. ObjectStack *is* the ORM. You are writing the low-level adapter.
78+
* **Type Fidelity:** Precision in mapping `FieldType` (e.g., `lookup`, `currency`) to physical column types is crucial.
79+
* **Performance:** Always implement `find` with efficient pagination (LIMIT/OFFSET or Cursor).
80+
* **Security:** ALL user input from the AST must be parameterized to prevent Injection Attacks.
81+
82+
---
83+
84+
**Instruction:**
85+
When building a driver, focus on the **mapping layer**: transforming the abstract AST into the concrete query language of the target datasource.

0 commit comments

Comments
 (0)