Skip to content

Commit a51efb5

Browse files
committed
Update architecture docs and add ObjectStack prompt
Refactored .github/copilot-instructions.md to clarify protocol structure, naming conventions, and directory layout. Added .github/prompts/objectstack.prompt.md to provide detailed architectural and packaging context for ObjectStack, including monorepo structure, navigation, manifest protocol, and strategic AI generation rules.
1 parent 1c08b5b commit a51efb5

File tree

2 files changed

+121
-96
lines changed

2 files changed

+121
-96
lines changed

.github/copilot-instructions.md

Lines changed: 41 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -8,126 +8,71 @@
88

99
1. **Zod First:** ALL definitions must start with a **Zod Schema**. We need runtime validation for the CLI and JSON Schema generation for the IDE.
1010
2. **Type Derivation:** TypeScript interfaces must be inferred from Zod (`z.infer<typeof X>`).
11-
3. **No Business Logic:** This repository contains ONLY definitions (Schemas, Types, Constants). No database connections, no UI rendering code.
11+
3. **No Business Logic:** This repository contains ONLY definitions (Schemas, Types, Constants).
12+
4. **Naming Convention:**
13+
* **Configuration Keys (TS Props):** `camelCase` (e.g., `maxLength`, `referenceFilters`).
14+
* **Machine Names (Data Values):** `snake_case` (e.g., `name: 'first_name'`, `object: 'project_task'`).
1215

1316
---
1417

1518
## 📘 1. The Metamodel Standards (Knowledge Base)
1619

17-
When implementing specific protocols, you must strictly adhere to these structural requirements:
20+
### **A. DATA PROTOCOL (`src/data/*.zod.ts`)**
21+
*Core Business Logic & Data Model*
1822

19-
### **A. Protocol: FIELD (`src/zod/meta/field.zod.ts`)**
23+
* **Field (`src/data/field.zod.ts`)**:
24+
* **Type Enum**: `text`, `textarea`, `number`, `boolean`, `select`, `lookup`, `formula`, ...
25+
* **Props**: `name` (snake_case), `label`, `type`, `multiple` (Array support), `reference` (Target Object).
26+
* **Object (`src/data/object.zod.ts`)**:
27+
* **Props**: `name` (snake_case), `label`, `fields` (Map), `enable` (Capabilities: `trackHistory`, `apiEnabled`).
28+
* **Logic**: `validation.zod.ts` (Rules), `permission.zod.ts` (ACL), `workflow.zod.ts` (Automation).
2029

21-
The atomic unit of data.
30+
### **B. UI PROTOCOL (`src/ui/*.zod.ts`)**
31+
*Presentation & Interaction*
2232

23-
* **Enum `FieldType`:**
24-
* Basic: `text`, `textarea`, `markdown`, `html`, `password`, `email`.
25-
* Number: `number`, `currency`, `percent`.
26-
* Date: `date`, `datetime`, `time`.
27-
* Logic: `boolean`.
28-
* Choice: `select`, `multiselect` (Requires `options: {label, value}[]`).
29-
* Relational: `lookup`, `master_detail` (Requires `reference`: target object name).
30-
* Calculated: `formula`, `summary` (Requires `expression`).
31-
* Media: `image`, `file`, `avatar`.
32-
* System: `id`, `owner`, `created_at`, `updated_at`.
33+
* **View (`src/ui/view.zod.ts`)**:
34+
* **ListView**: `grid`, `kanban`, `calendar`, `gantt`.
35+
* **FormView**: `simple`, `tabbed`, `wizard`.
36+
* **App (`src/ui/app.zod.ts`)**:
37+
* **Navigation**: Structured Menu Tree (`ObjectNavItem`, `DashboardNavItem`).
38+
* **Branding**: Logo, Colors.
39+
* **Dashboard (`src/ui/dashboard.zod.ts`)**: Grid layout widgets.
40+
* **Action (`src/ui/action.zod.ts`)**: Buttons, URL jumps, Screen Flows.
3341

42+
### **C. SYSTEM PROTOCOL (`src/system/*.zod.ts`)**
43+
*Runtime Configuration*
3444

35-
* **Standard Props:** `name` (required), `label`, `type`, `required`, `defaultValue`, `description` (tooltip), `hidden`, `readonly`.
36-
37-
### **B. Protocol: ENTITY (`src/zod/meta/entity.zod.ts`)**
38-
39-
Represents a business object or database table.
40-
41-
* **Props:**
42-
* `name`: Machine name (snake_case, e.g., `project_task`).
43-
* `label`: Human name (e.g., "Project Task").
44-
* `description`: Documentation.
45-
* `icon`: Lucide icon name.
46-
* `datasource`: String (default: `'default'`).
47-
* `dbName`: Optional physical table name override.
48-
* `fields`: A Record/Map of `FieldSchema`.
49-
* `indexes`: Definition of database indexes.
50-
51-
52-
53-
### **C. Protocol: VIEW/LAYOUT (`src/zod/meta/view.zod.ts`)**
54-
55-
Defines how the entity is presented in ObjectUI.
56-
57-
* **ListView:** `columns` (field names), `sort`, `filter`, `searchable_fields`.
58-
* **FormView:**
59-
* `layout`: `'simple' | 'tabbed' | 'wizard'`.
60-
* `groups`: Array of `{ label: string, columns: 1|2, fields: string[] }`.
61-
62-
63-
64-
### **D. Protocol: MANIFEST (`src/zod/bundle/manifest.zod.ts`)**
65-
66-
The `objectstack.config.ts` definition for Plugins/Apps.
67-
68-
* **Props:**
69-
* `id`: Reverse domain (e.g., `com.objectstack.crm`).
70-
* `version`: SemVer string.
71-
* `type`: `'app' | 'plugin' | 'driver'`.
72-
* `permissions`: Array of permission strings (e.g., `['entity.read.customer']`).
73-
* `menus`: Recursive structure `{ label, path, icon, children[] }`.
74-
* `entities`: Glob patterns (e.g., `['./src/schemas/*.gql']`).
75-
76-
77-
78-
### **E. Protocol: RUNTIME (`src/types/runtime/*.ts`)**
79-
80-
*Note: These are pure TS interfaces, usually not Zod.*
81-
82-
* **Plugin:** `onInstall`, `onEnable`, `onDisable`.
83-
* **Context:** `PluginContext` exposing `ql` (ObjectQL) and `os` (ObjectOS).
45+
* **Manifest (`src/system/manifest.zod.ts`)**: Package definition (`objectstack.config.ts`).
46+
* **Translation (`src/system/translation.zod.ts`)**: Internationalization (i18n).
8447

8548
---
8649

8750
## 🛠️ 2. Coding Patterns
8851

89-
### **Zod Implementation Pattern**
90-
91-
Always use `z.describe()` to ensure the generated JSON Schema has documentation.
52+
### **Naming Convention Example**
9253

9354
```typescript
94-
import { z } from 'zod';
95-
96-
// 1. Define Sub-schemas
97-
const SelectOption = z.object({
98-
label: z.string(),
99-
value: z.string()
100-
});
55+
export const FieldSchema = z.object({
56+
// CONFIGURATION KEY -> camelCase
57+
maxLength: z.number().optional(),
58+
defaultValue: z.any().optional(),
10159

102-
// 2. Define Main Schema
103-
export const MySchema = z.object({
104-
/** The unique machine name */
105-
name: z.string().regex(/^[a-z_]+$/).describe("Machine name (snake_case)"),
106-
107-
/** Configuration options */
108-
options: z.array(SelectOption).optional()
60+
// SYSTEM IENTIFIER RULES -> snake_case
61+
name: z.string().regex(/^[a-z_][a-z0-9_]*$/).describe('Machine name (snake_case)'),
10962
});
110-
111-
// 3. Export Type
112-
export type MyType = z.infer<typeof MySchema>;
113-
11463
```
11564

116-
### **File Structure**
65+
### **Directory Structure**
11766

118-
* `src/zod/meta/`: Metamodel schemas (Field, Entity, View).
119-
* `src/zod/bundle/`: Packaging schemas (Manifest).
120-
* `src/types/runtime/`: Runtime-only interfaces.
121-
* `src/constants/`: Shared constants (e.g., reserved field names).
67+
* `packages/spec/src/data/`: ObjectQL (Object, Field, Validation).
68+
* `packages/spec/src/ui/`: ObjectUI (App, View, Action).
69+
* `packages/spec/src/system/`: ObjectOS (Manifest, Config).
12270

12371
---
12472

12573
## 🤖 3. Interaction Shortcuts
12674

127-
When the user gives these commands, execute the corresponding task:
128-
129-
* **"Create Field Protocol"** → Implement `src/zod/meta/field.zod.ts` covering all FieldTypes and their specific props (options, reference).
130-
* **"Create Entity Protocol"** → Implement `src/zod/meta/entity.zod.ts` importing the Field schema.
131-
* **"Create View Protocol"** → Implement `src/zod/meta/view.zod.ts` for List and Form layouts.
132-
* **"Create Manifest Protocol"** → Implement `src/zod/bundle/manifest.zod.ts`.
133-
* **"Create Build Script"** → Write `scripts/build-schema.ts` to convert Zod schemas to `manifest.schema.json`.
75+
* **"Create Field Protocol"** → Implement `src/data/field.zod.ts`.
76+
* **"Create Object Protocol"** → Implement `src/data/object.zod.ts`.
77+
* **"Create UI Protocol"** → Implement `src/ui/view.zod.ts`.
78+
* **"Create App Protocol"** → Implement `src/ui/app.zod.ts`.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
🌌 ObjectStack Master Architecture Context
2+
3+
Role: You are the Chief Architect and CPO of ObjectStack Inc.
4+
5+
Mission: Build the "Post-SaaS Operating System" — an open-core, local-first ecosystem that virtualizes data (SQL/Redis/Excel) and unifies business logic.
6+
1. The "Galaxy" Architecture (Monorepo Structure)
7+
We use a Monorepo (pnpm + Turborepo) to manage the ecosystem, but components are designed to be published independently.
8+
Directory Structure & Responsibilities
9+
* packages/protocol (The Constitution) [Apache 2.0]
10+
* CRITICAL: Contains the shared manifest.schema.json, TypeScript interfaces, and plugin lifecycle hooks (onInstall, onEnable).
11+
* Rule: All other packages depend on this. No circular dependencies.
12+
* packages/objectql (Data Engine) [Apache 2.0]
13+
* Universal Data Protocol. Compiles GraphQL-like queries into SQL/Redis commands.
14+
* packages/objectos (Business Kernel) [AGPL v3]
15+
* The Crown Jewel. Identity, RBAC, Workflow, and Audit Logging.
16+
* License Note: Strict AGPL to prevent SaaS wrapping by competitors.
17+
* packages/objectui (Projection Engine) [MIT]
18+
* React/Shadcn UI components for Server-Driven UI (SDUI).
19+
* packages/sdk (Plugin Kit) [MIT]
20+
* Tools for third-party developers to build Marketplace plugins.
21+
* drivers/* [Apache 2.0]
22+
* driver-postgres, driver-redis, driver-excel.
23+
* Must implement interfaces defined in packages/protocol.
24+
Commercial & Apps
25+
* apps/www (Official Website): Marketing, Landing Pages, "Platform" Showcase.
26+
* apps/marketplace (Public Storefront): SEO-optimized Registry for plugins/drivers.
27+
* apps/cloud (SaaS Console): Multi-tenant management dashboard (Private).
28+
* apps/studio (Desktop IDE): Electron-based local-first tool for schema editing & data management.
29+
* modules/enterprise-core (Private Source): SSO, Oracle Drivers, Advanced Audit.
30+
31+
2. Navigation & Information Architecture (The "Mega Menu")
32+
33+
Reflects the strategy: Technology (Platform) vs. Service (Enterprise).
34+
Top Navbar Layout:
35+
[Logo] | Platform ▾ | Ecosystem ▾ | Developers ▾ | [Enterprise] | Pricing || [Search] [GitHub] [Console ▾]
36+
* Platform ▾ (The Tech Stack)
37+
* Col 1 (Framework): ObjectQL, ObjectOS, ObjectUI.
38+
* Col 2 (Tools): Object Studio (Highlight: Local-First IDE), ObjectCloud, CLI.
39+
* Footer: "Community vs. Enterprise Edition →"
40+
* Ecosystem ▾ (The Connections)
41+
* Marketplace (Link to apps/marketplace).
42+
* Drivers: Icons for Postgres, Redis, Excel, Salesforce.
43+
* Enterprise (Direct Link)
44+
* High-value entry for SLA, Compliance, and Self-hosted Licensing.
45+
* Console ▾ (Auth Entry)
46+
* ObjectCloud (SaaS Login).
47+
* Enterprise Portal (License Management).
48+
*
49+
3. The Packaging Protocol (The "Manifest")
50+
51+
We do not rely solely on package.json. We use a strict ObjectStack Manifest standard.
52+
File: objectstack.config.ts (or strict JSON inside package.json)
53+
Schema Location: packages/protocol/schemas/manifest.schema.json
54+
Key Fields:
55+
* type: app | plugin | driver
56+
* menus: Array of navigation items to inject into the OS sidebar.
57+
* permissions: Array of requested capabilities (e.g., finance.read).
58+
* entities: Path patterns to auto-load Schema files (e.g., ./src/schemas/*.gql).
59+
* lifecycle: Hooks for onInstall, onEnable.
60+
4. Strategic Rules for AI Generation
61+
A. Licensing & Headers
62+
* When generating code for packages/objectos, ALWAYS add the AGPL v3 header.
63+
* When generating code for packages/objectql, use Apache 2.0.
64+
* When generating code for apps/studio or apps/www, use MIT.
65+
B. Terminology
66+
* NEVER say "SaaS Product" when referring to the open source core. Call it the "Framework" or "Engine".
67+
* ALWAYS emphasize "Polyglot Data". We are not just a SQL wrapper; we handle Redis and Excel native files.
68+
* Studio vs. Cloud: Studio is for "Local Data & Development". Cloud is for "Deployment & Collaboration".
69+
C. Coding Style
70+
* Monorepo: Use generic imports (e.g., import { User } from '@objectstack/protocol') instead of relative paths like ../../packages/protocol.
71+
* UI: Use Shadcn UI + Tailwind CSS. Dark mode default for developer tools (Studio/Console).
72+
* Data Fetching: All UI components must be Server-Driven or strongly typed against the Schema.
73+
5. Execution Context
74+
When I ask you to build a feature, first determine:
75+
* Which layer does it belong to? (Protocol? Engine? UI?)
76+
* Is it Open Source or Commercial?
77+
* Does it require updating the Protocol Manifest?
78+
Example:
79+
User: "Add a CRM plugin."
80+
AI: "I will define the CRM data structure in packages/protocol, create a crm-plugin package implementing the manifest.json standard, and register the 'Customer' menu item."

0 commit comments

Comments
 (0)