opencode-data-modelOpenCode plugin for generating data model documentation, database schemas, and TypeScript or JavaScript models
0
34
近 7 天 6
25.5
生态多维模型
2 个月前
2026-06-03
快速安装与配置
opencode.json写入当前项目的 opencode.json,只对这个仓库生效。
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-data-model@0.1.1"]
}写入 ~/.config/opencode/opencode.json,对所有项目生效。
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-data-model@0.1.1"]
}若你要在本地改造这个插件,先装到项目里再从本地路径引用。
shell
pnpm add -D opencode-data-modelopencode 启动时会通过内嵌运行时自动加载 npm 依赖并缓存至本地目录,无需手动在全局环境执行安装。
opencode-data-model
OpenCode plugin for generating normalized, high-performance schemas and compile-safe TypeScript or JavaScript data models.
Why
I asked LLMs to generate schemas a million times. Too often they looked right, then failed on relationships, constraints, nullability, indexes, SQL dialects, or TypeScript boundaries. This plugin adds a stronger prompt contract, forced validation, and optional AI double-checking to reduce those mistakes before the model reaches your codebase.
Install
OpenCode loads plugins from two sources.
From npm (recommended)
Add the package to the plugin array in your config file. OpenCode installs npm
plugins automatically with Bun at startup and caches them (and their
dependencies) under ~/.cache/opencode/node_modules/.
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-data-model"]
}
Both regular and scoped npm packages are supported. The same package works under
npm or Bun — bun add opencode-data-model resolves the identical artifact.
From local files
Drop the built JavaScript/TypeScript file into a plugin directory and OpenCode loads it automatically at startup:
.opencode/plugins/— project-level plugins~/.config/opencode/plugins/— global plugins
mise run build
mise run link # symlinks dist/index.js into ~/.config/opencode/plugins/
To use external packages from a local plugin, create a package.json inside your
config directory, or publish to npm and reference it from config instead.
Load order
Plugins load from all sources, and every hook runs in sequence:
- Global config (
~/.config/opencode/opencode.json) - Project config (
opencode.json) - Global plugin directory (
~/.config/opencode/plugins/) - Project plugin directory (
.opencode/plugins/)
Duplicate npm packages with the same name and version load once. A local plugin and an npm plugin with similar names load separately.
Objects
| Object | Command | Tool |
|---|---|---|
| Blueprint | /model |
model_doc |
| MySQL Forge | /schema-mysql |
schema_mysql |
| Postgres Forge | /schema-pg |
schema_pg |
| Type Loom | /types-ts |
types_ts |
| JSDoc Loom | /types-js |
types_js |
| Quality Map | /data-model-roadmap |
roadmap_model |
| Gatekeeper | /model-check |
audit_model |
Classic /data-model-* commands and generate_* tool names are still available
for compatibility.
Prompt Contract
- Act as a principal data architect.
- Normalize write models first; document read-model exceptions.
- Design for correctness, query performance, maintainability, and migrations.
- Add indexes for real access patterns without over-indexing.
- Make nullability, ownership, deletion behavior, and constraints explicit.
- Keep TypeScript and JavaScript models compile-safe and boundary-aware.
- Reject the draft if validation finds hallucinated fields, missing relations, weak indexes, dialect errors, or type/interface drift.
Development
mise trust
bun install
mise run build
mise run lint
mise run test
mise run typecheck
Validation uses Bun snapshots, Zod contract checks, SQL DDL parsing, and
TypeScript syntax checks. Update snapshots with mise run test_update.
Publishing
npm login
mise run publish --tag latest
# if your npm account enforces publish 2FA:
mise run publish --tag latest --otp <one-time-code>
License
MIT License. See LICENSE.