English | 中文
# Clone the repository
git clone https://github.com/objectstack-ai/spec.git
cd spec
# Install dependencies and setup (one-time)
pnpm setup
# Run health check
pnpm doctor# Build CLI first (if not built)
pnpm --filter @objectstack/cli build
# Compile configuration to JSON
pnpm objectstack compile objectstack.config.ts dist/objectstack.json
# Start development mode (watch mode for packages)
pnpm objectstack dev [package-name]
# Check environment health
pnpm objectstack doctor
# Create new project
pnpm objectstack create plugin my-plugin
pnpm objectstack create example my-app# One-time setup
pnpm setup # Install dependencies and build core packages
# Development
pnpm dev # Start development mode (default: msw-react-crud example)
pnpm build # Build all packages
pnpm test # Run tests
# Diagnostics
pnpm doctor # Check environment health
# Cleanup
pnpm clean # Clean build artifacts# Watch mode (auto-rebuild on changes)
cd packages/spec
pnpm dev
# Run tests in watch mode
pnpm test:watch
# Generate schemas and docs
pnpm gen:schema
pnpm gen:docs# Using CLI
pnpm objectstack create plugin my-feature
# Then develop
cd packages/plugins/plugin-my-feature
pnpm install
pnpm dev# Using CLI
pnpm objectstack create example my-app
# Then develop
cd examples/my-app
pnpm install
pnpm build# Run all tests
pnpm test
# Run tests for specific package
pnpm --filter @objectstack/spec test
# Watch mode
pnpm --filter @objectstack/spec test:watch
# Coverage report
pnpm --filter @objectstack/spec test:coverage# Test CRM example
cd examples/crm
pnpm build
pnpm testPre-configured launch configurations are available in .vscode/launch.json:
- Debug Current TypeScript File - Debug any .ts file
- Debug @objectstack/spec Tests - Debug spec tests
- Debug CLI (compile) - Debug compile command
- Debug CLI (doctor) - Debug doctor command
- Debug Example (CRM) - Debug CRM example
To use:
- Open the file you want to debug
- Press
F5or go to Run & Debug panel - Select the appropriate configuration
- Set breakpoints and debug
# Debug with tsx
tsx --inspect packages/cli/src/bin.ts doctor
# Debug with node
node --inspect $(which tsx) packages/cli/src/bin.ts compile# Enable verbose logging
DEBUG=* pnpm build
# Package-specific logging
DEBUG=objectstack:* pnpm build// 1. Create schema file: packages/spec/src/data/my-schema.zod.ts
import { z } from 'zod';
/**
* My new schema
* @description Detailed description of the schema
*/
export const MySchema = z.object({
/** Field description */
name: z.string().describe('Machine name (snake_case)'),
/** Another field */
value: z.number().optional().describe('Optional value'),
});
export type MyType = z.infer<typeof MySchema>;
// 2. Export from index
// packages/spec/src/data/index.ts
export * from './my-schema.zod.js';
// 3. Build to generate JSON schema
pnpm --filter @objectstack/spec build# Filter by package name
pnpm --filter @objectstack/spec <command>
pnpm --filter @objectstack/cli <command>
# Filter pattern (all plugins)
pnpm --filter "@objectstack/plugin-*" build
# Run in all packages
pnpm -r <command>
# Run in parallel
pnpm -r --parallel <command>- Incremental Builds: Use watch mode (
pnpm dev) during development - Selective Testing: Test only changed packages
- Parallel Execution: Use
--parallelfor independent tasks - Filter Packages: Use
--filterto target specific packages
Dependencies not installed:
pnpm doctor
pnpm installBuild errors:
# Clean and rebuild
pnpm clean
pnpm buildType errors:
# Ensure spec is built first
pnpm --filter @objectstack/spec buildWatch mode not working:
# Kill existing processes
pkill -f "tsc --watch"
# Restart
pnpm dev# Check environment
pnpm doctor
# CLI help
pnpm objectstack --help
pnpm objectstack <command> --helpspec/
├── packages/ # Core packages
│ ├── spec/ # Protocol definitions (Zod schemas)
│ ├── cli/ # Command-line tools
│ ├── objectql/ # Query engine
│ ├── client/ # Client SDK
│ ├── client-react/ # React hooks
│ └── plugins/ # Plugin implementations
│ ├── driver-memory/
│ ├── plugin-hono-server/
│ └── plugin-msw/
├── examples/ # Example applications
│ ├── crm/ # Full CRM example
│ ├── todo/ # Simple todo example
│ └── ...
├── apps/ # Applications
│ └── docs/ # Documentation site
└── packages/cli/ # Command-line tools
├── src/commands/ # CLI commands (dev, doctor, create, compile, serve)
└── bin/ # Executable entry points
The serve command starts an ObjectStack server with plugins loaded from your configuration:
# Start server with default config
pnpm objectstack serve
# Start with custom config and port
pnpm objectstack serve objectstack.config.ts --port 8080
# Start without HTTP server plugin (headless mode)
pnpm objectstack serve --no-serverConfiguration Example:
// objectstack.config.ts
import { defineStack } from '@objectstack/spec';
import { HonoServerPlugin } from '@objectstack/plugin-hono-server';
export default defineStack({
metadata: {
name: 'my-app',
version: '1.0.0',
},
objects: {
// Your data objects
},
plugins: [
// Add plugins to load
new HonoServerPlugin({ port: 3000 }),
],
});The server will:
- Load your configuration file
- Register all plugins specified in
config.plugins - Start the HTTP server (unless
--no-serveris specified) - Listen on the specified port (default: 3000)
@objectstack/spec (Foundation - Zod schemas)
↓
@objectstack/cli (Uses spec for validation)
↓
@objectstack/objectql (Uses spec for types)
↓
@objectstack/client (Uses objectql)
↓
@objectstack/client-react (Uses client)
@objectstack/spec- Must build first (provides types)@objectstack/cli- Can build after spec- Other packages - Can build in parallel after spec
- Examples - Build last
- Zod First: Always define schemas with Zod first
- Type Derivation: Use
z.infer<typeof Schema>for types - Naming Conventions:
- Config keys:
camelCase(e.g.,maxLength) - Data values:
snake_case(e.g.,project_task)
- Config keys:
- Documentation: Add JSDoc comments with
@description
- Co-locate tests with source files (
*.test.ts) - Target 80%+ code coverage
- Use descriptive test names
- Test both success and error cases
- Use conventional commits format
- Reference issues in commit messages
- Keep changes focused and minimal
- Run
pnpm doctorbefore submitting - Ensure all tests pass
- Update documentation if needed
- Follow the PR template
- CONTRIBUTING.md - Detailed contribution guide
- ARCHITECTURE.md - Architecture documentation
- Package Dependencies - Dependency graph
- Quick Reference - API quick reference
Apache 2.0 © ObjectStack