Skip to content

Commit 4c3f761

Browse files
Copilothotlong
andcommitted
Complete comprehensive revision of .github/copilot-instructions.md
- Updated architecture tables with actual package structure - Added all missing packages (platform-node, sdk, starters) - Expanded dependency graph with platform and SDK layers - Added comprehensive metadata types section (12 types) - Added documentation references for specs, guides, and API - Added build & test command section - Added examples & starters information - Added common patterns & best practices with code examples - Expanded package descriptions to match actual implementations Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 877cb29 commit 4c3f761

1 file changed

Lines changed: 308 additions & 24 deletions

File tree

.github/copilot-instructions.md

Lines changed: 308 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,53 +50,337 @@ You must strictly enforce the following dependency rules:
5050

5151
1. **The Base:** `@objectql/types` is the bottom layer. It relies on NOTHING.
5252
2. **The Facade:** `@objectql/core` depends on `types`.
53-
3. **The Drivers:** `@objectql/driver-*` depends on `types` (to implement interfaces) and external libs (knex, mongodb).
54-
4. **The Server:** `@objectql/server` depends on `core` and `types`.
53+
3. **Platform Layer:** `@objectql/platform-node` depends on `types` and `core` for Node.js-specific features.
54+
4. **The Drivers:** `@objectql/driver-*` depends on `types` (to implement interfaces) and external libs (knex, mongodb).
55+
5. **The SDK:** `@objectql/sdk` (remote driver) depends on `types` only.
56+
6. **The Server:** `@objectql/server` depends on `core` and `types`.
57+
7. **The Tools:** `@objectql/cli` and `@objectql/studio` depend on `core`, `types`, and may use platform-specific packages.
58+
59+
**Critical Rules:**
5560
* 🔴 **FORBIDDEN:** Drivers must **NOT** depend on `core`. This prevents circular dependencies.
5661
* 🔴 **FORBIDDEN:** `types` and `core` must **NOT** import Node.js native modules (`fs`, `net`, `crypto`) to ensure browser compatibility (except where polyfilled or ignored in browser builds).
62+
* 🔴 **FORBIDDEN:** Universal packages (`types`, `core`, `sdk`) must work in both Node.js and browser environments.
5763

5864
## 4. Specific Package Instructions
5965

60-
### 📦 `packages/types`
66+
### 📦 `packages/foundation/types`
6167

6268
* **Content:**
63-
* `interface ObjectConfig`: The shape of the JSON schema.
64-
* `interface ObjectQLDriver`: The interface that all drivers must implement.
65-
* `interface IObjectRegistry`: The interface for registry behavior.
66-
* `enum FieldType`: `'text' | 'select' | 'lookup' ...`
67-
* `class ObjectQLError`: Shared error types.
69+
* `interface ObjectConfig`: The shape of object metadata schema.
70+
* `interface FieldConfig`: Field definition and validation configuration.
71+
* `interface Driver`: The interface that all drivers must implement.
72+
* `interface MetadataRegistry`: The interface for registry behavior.
73+
* `interface ValidationConfig`: Validation rules configuration.
74+
* `interface HookConfig`: Hook/trigger definitions.
75+
* `interface ActionConfig`: Custom RPC action definitions.
76+
* `interface PageConfig`: UI page metadata.
77+
* `interface PermissionConfig`: Access control rules.
78+
* `interface MenuConfig`: Navigation menu definitions.
79+
* `interface AppConfig`: Application container metadata.
6880

69-
* **Rule:** Keep it extremely lightweight. No business logic.
81+
* **Rule:** Keep it extremely lightweight. No business logic. Pure types only.
7082

71-
### 📦 `packages/core` (The User Entry Point)
83+
### 📦 `packages/foundation/core` (The User Entry Point)
7284

7385
* **Content:**
7486
* `class ObjectQL`: The main class (similar to TypeORM `DataSource`).
75-
* Methods: `connect()`, `register()`, `find()`, `create()`.
87+
* Methods: `init()`, `createContext()`, `getObject()`.
88+
* `class ObjectRepository`: Repository pattern for CRUD operations.
89+
* Methods: `find()`, `findOne()`, `create()`, `update()`, `delete()`.
90+
* `class Validator`: Metadata-driven validation engine.
91+
* Supports field-level, cross-field, and state machine validation.
92+
93+
* **Role:** It orchestrates the flow. It validates requests and delegates execution to the injected `driver`.
94+
95+
### 📦 `packages/foundation/platform-node`
96+
97+
* **Content:**
98+
* `class ObjectLoader`: File-based metadata loader using glob patterns.
99+
* Supports `*.object.yml`, `*.validation.yml`, `*.permission.yml`, etc.
100+
* `class PluginManager`: Plugin system for extending functionality.
101+
102+
* **Role:** Provides Node.js-specific utilities for loading metadata from the filesystem.
76103

77-
* `class SimpleRegistry`: A default in-memory implementation of `IObjectRegistry`.
104+
### 📦 `packages/drivers/sql` (SQL Driver)
105+
106+
* **Content:** Implementation of `Driver` interface using Knex.js.
107+
* **Role:**
108+
* Translate ObjectQL queries → SQL queries.
109+
* Support for PostgreSQL, MySQL, SQLite.
110+
* Hybrid storage strategy: Core columns + JSONB for dynamic fields.
111+
* Execute queries via Knex and map results back to ObjectQL format.
78112

79-
* **Role:** It orchestrates the flow. It validates the request using `SimpleRegistry` and delegates execution to the injected `driver`.
113+
* **Note:** Drivers maintain their own minimal mapping of "Object Name → Table Name".
80114

81-
### 📦 `packages/driver-*` (SQL / Mongo)
115+
### 📦 `packages/drivers/mongo` (MongoDB Driver)
82116

83-
* **Content:** Implementation of `ObjectQLDriver`.
117+
* **Content:** Implementation of `Driver` interface using MongoDB Node.js driver.
84118
* **Role:**
85-
* Translate ObjectQL AST -> SQL / MongoDB Query.
86-
* Execute query via underlying lib (e.g., `knex`, `mongodb`).
87-
* Map DB results back to ObjectQL format.
119+
* Translate ObjectQL queries → MongoDB aggregation pipelines.
120+
* Support for schema-less data and rapid prototyping.
121+
* Native MongoDB performance with full CRUD and filtering support.
122+
123+
### 📦 `packages/drivers/sdk` (Remote/HTTP Driver)
124+
125+
* **Content:** Implementation of `Driver` interface for remote ObjectQL servers.
126+
* **Role:**
127+
* Connect to ObjectQL servers via HTTP/REST.
128+
* Useful for client-side applications (browser, mobile).
129+
* Translates local API calls to HTTP requests.
130+
131+
* **Environment:** Universal (works in Node.js and browsers).
132+
133+
### 📦 `packages/runtime/server`
134+
135+
* **Content:** HTTP server adapter with Express middleware.
136+
* **Role:**
137+
* Exposes ObjectQL operations via REST and JSON-RPC APIs.
138+
* Handlers: `createNodeHandler()`, `createMetadataHandler()`, `createStudioHandler()`.
139+
* Provides endpoints for CRUD operations, metadata introspection, and admin UI.
140+
141+
### 📦 `packages/tools/cli`
88142

89-
* **Note:** Drivers should maintain their own minimal mapping of "Object Name -> Table Name".
143+
* **Content:** Command-line interface for ObjectQL projects.
144+
* **Commands:**
145+
* `init`: Initialize new project from templates.
146+
* `validate`: Validate metadata files.
147+
* `migrate`: Database migration tools.
148+
* `studio`: Launch web-based admin console.
90149

91-
### 📦 `packages/server`
150+
### 📦 `packages/tools/studio`
92151

93-
* **Content:** HTTP adapter.
94-
* **Role:** Exposes ObjectQL operations via REST/GraphQL-like API.
152+
* **Content:** Web-based admin UI (React application).
153+
* **Features:**
154+
* Object browser and schema inspector.
155+
* Data grid with CRUD operations.
156+
* Search and filtering capabilities.
157+
* Modern, responsive design.
95158

96-
## 5. Development Standards
159+
### 📦 `packages/starters/*` (Templates)
160+
161+
* **basic**: Minimal Node.js script example.
162+
* **enterprise**: Enterprise-scale metadata organization pattern with domain-driven structure.
163+
* **express-api**: Express.js server integration example.
164+
165+
## 5. Metadata Types & Organization
166+
167+
ObjectQL uses a **metadata-driven architecture**. All application logic, data models, and UI are defined in YAML/JSON files.
168+
169+
### Core Metadata Types
170+
171+
1. **Objects (`*.object.yml`)**: Data model definitions with fields, relationships, and indexes.
172+
2. **Validation (`*.validation.yml`)**: Field-level, cross-field, and state machine validation rules.
173+
3. **Permissions (`*.permission.yml`)**: Role-based access control and field-level security.
174+
4. **Hooks (`*.hook.ts`)**: Event-driven logic (beforeCreate, afterUpdate, etc.).
175+
5. **Actions (`*.action.ts`)**: Custom RPC methods and server-side functions.
176+
6. **Pages (`*.page.yml`)**: UI page layouts and components.
177+
7. **Views (`*.view.yml`)**: Data presentation configurations (list, grid, kanban).
178+
8. **Forms (`*.form.yml`)**: Data entry and editing interfaces.
179+
9. **Reports (`*.report.yml`)**: Analytics and BI configurations.
180+
10. **Menus (`*.menu.yml`)**: Navigation hierarchy and structure.
181+
11. **Applications (`*.app.yml`)**: Application container and configuration.
182+
12. **Workflows (`*.workflow.yml`)**: Business process automation.
183+
184+
### Metadata File Naming Convention
185+
186+
ObjectQL uses **filename-based identification**:
187+
- `project.object.yml` → Object name is `project`
188+
- `user.validation.yml` → Validation for `user` object
189+
- No need for redundant `name` property in most cases
190+
191+
### Recommended Directory Structure
192+
193+
```
194+
src/
195+
objects/ # Core data models
196+
*.object.yml # Object definitions
197+
*.validation.yml # Validation rules
198+
*.permission.yml # Permission rules
199+
*.hook.ts # Hook implementations
200+
*.action.ts # Action implementations
201+
202+
pages/ # UI pages
203+
*.page.yml # Page definitions
204+
205+
views/ # Data presentation
206+
*.view.yml # View configurations
207+
*.form.yml # Form layouts
208+
209+
reports/ # Analytics
210+
*.report.yml # Report definitions
211+
212+
workflows/ # Business processes
213+
*.workflow.yml # Workflow definitions
214+
215+
navigation/ # App structure
216+
*.menu.yml # Menu definitions
217+
*.app.yml # Application configs
218+
```
219+
220+
## 6. Development Standards
97221

98222
1. **Strict Typing:** `strict: true` in `tsconfig.json`. No `any` allowed unless absolutely necessary for low-level reflection.
99223
2. **Error Handling:** Throw `ObjectQLError` (from `types`) instead of generic `Error`.
100-
3. **Config Format:** The primary input format is `.object.yml`.
224+
3. **Config Format:** The primary input format is `.object.yml` (YAML) or `.object.json` (JSON).
101225
4. **NPM Scopes:** All internal imports must use the `@objectql/` scope (e.g., `import ... from '@objectql/types'`).
102226
5. **Language Requirement:** Always use English when generating code, comments, or documentation, even if the user prompts in another language.
227+
6. **Metadata Loading:** Use `@objectql/platform-node` for file-based metadata loading in Node.js environments.
228+
7. **Validation:** Always validate metadata using the `Validator` class before executing operations.
229+
8. **Testing:** Write tests for drivers, validation rules, and business logic. Use Jest as the testing framework.
230+
231+
## 7. Key Documentation References
232+
233+
### Specifications
234+
- **[Metadata Standard](../docs/spec/metadata-standard.md)**: Complete overview of the metadata system.
235+
- **[Object Schema](../docs/spec/object.md)**: Object and field definitions.
236+
- **[Query Language](../docs/spec/query-language.md)**: JSON-DSL query protocol.
237+
- **[Validation Rules](../docs/spec/validation.md)**: Validation rule types and syntax.
238+
- **[Hooks](../docs/spec/hook.md)**: Event-driven triggers.
239+
- **[Actions](../docs/spec/action.md)**: Custom RPC methods.
240+
- **[Permissions](../docs/spec/permission.md)**: Access control system.
241+
- **[Pages](../docs/spec/page.md)**: UI page metadata.
242+
243+
### Guides
244+
- **[Getting Started](../docs/guide/getting-started.md)**: Quick start guide.
245+
- **[Architecture](../docs/guide/architecture.md)**: System architecture and design.
246+
- **[Data Modeling](../docs/guide/data-modeling.md)**: Best practices for defining objects.
247+
- **[Querying](../docs/guide/querying.md)**: How to query data.
248+
- **[Formulas & Rules](../docs/guide/formulas-and-rules.md)**: Validation and calculation syntax.
249+
- **[Metadata Organization](../docs/guide/metadata-organization.md)**: Organizing large projects.
250+
- **[Server Integration](../docs/guide/server-integration.md)**: Running ObjectQL as an HTTP server.
251+
252+
### API Reference
253+
- **[API Overview](../docs/api/README.md)**: Complete API documentation.
254+
- **[Authentication](../docs/api/authentication.md)**: Security and authentication.
255+
256+
## 8. Build & Test Commands
257+
258+
### Building the Project
259+
260+
```bash
261+
# Install dependencies
262+
pnpm install
263+
264+
# Build all packages (TypeScript compilation)
265+
pnpm run build
266+
267+
# Build specific package
268+
cd packages/foundation/core && pnpm run build
269+
```
270+
271+
### Testing
272+
273+
```bash
274+
# Run all tests
275+
pnpm test
276+
277+
# Test specific package
278+
cd packages/foundation/core && pnpm test
279+
```
280+
281+
### Development Tools
282+
283+
```bash
284+
# Launch admin studio
285+
pnpm run studio
286+
287+
# Generate documentation
288+
pnpm run docs:dev
289+
```
290+
291+
## 9. Examples & Starters
292+
293+
### Available Examples
294+
295+
1. **`packages/starters/basic`**: Minimal Node.js script showing ObjectQL basics.
296+
2. **`packages/starters/express-api`**: Express.js server with ObjectQL REST API.
297+
3. **`packages/starters/enterprise`**: Enterprise-scale project structure with domain-driven organization.
298+
4. **`examples/tutorials/tutorial-task-manager`**: Task management application example.
299+
5. **`examples/tutorials/tutorial-crm-system`**: CRM system with accounts, contacts, and opportunities.
300+
6. **`examples/tutorials/tutorial-federation`**: Multi-database federation example.
301+
7. **`examples/plugins/audit-log`**: Plugin example for audit logging.
302+
303+
### Using Starters
304+
305+
Starters demonstrate best practices and provide templates for new projects:
306+
- **Basic**: Learn the fundamentals with a simple script.
307+
- **Express API**: See how to integrate ObjectQL into an Express server.
308+
- **Enterprise**: Understand how to organize metadata in large-scale applications with multiple modules.
309+
310+
## 10. Common Patterns & Best Practices
311+
312+
### Object Definition Pattern
313+
314+
```yaml
315+
# File: project.object.yml
316+
# Name is inferred from filename
317+
318+
label: Project
319+
fields:
320+
name:
321+
type: text
322+
required: true
323+
label: Project Name
324+
325+
status:
326+
type: select
327+
options:
328+
- { label: Planning, value: planning }
329+
- { label: Active, value: active }
330+
- { label: Completed, value: completed }
331+
332+
owner:
333+
type: lookup
334+
reference_to: users
335+
label: Project Owner
336+
```
337+
338+
### Validation Pattern
339+
340+
```yaml
341+
# File: project.validation.yml
342+
343+
rules:
344+
- name: valid_date_range
345+
type: cross_field
346+
rule:
347+
field: end_date
348+
operator: '>='
349+
compare_to: start_date
350+
message: End date must be after start date
351+
severity: error
352+
```
353+
354+
### Hook Pattern
355+
356+
```typescript
357+
// File: project.hook.ts
358+
import { HookDefinition } from '@objectql/types';
359+
360+
export const beforeCreate: HookDefinition = {
361+
when: 'before.create',
362+
async handler(ctx) {
363+
// Auto-set created date
364+
ctx.record.created_at = new Date();
365+
}
366+
};
367+
```
368+
369+
### Action Pattern
370+
371+
```typescript
372+
// File: project.action.ts
373+
import { ActionDefinition } from '@objectql/types';
374+
375+
export const completeProject: ActionDefinition = {
376+
label: 'Complete Project',
377+
async handler(ctx) {
378+
const { id } = ctx.input;
379+
await ctx.object('project').update(id, {
380+
status: 'completed',
381+
completed_at: new Date()
382+
});
383+
return { success: true };
384+
}
385+
};
386+
```

0 commit comments

Comments
 (0)