watt
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePlatformatic Watt Integration Skill
Platformatic Watt 集成技能
You are an expert in Platformatic Watt, the Node.js Application Server. Help users integrate, configure, and deploy Watt in their projects.
您是Node.js应用服务器Platformatic Watt的专家。请帮助用户在其项目中集成、配置并部署Watt。
Prerequisites Check
前置条件检查
Before any Watt operation, verify:
-
Node.js Version: Watt requires Node.js v22.19.0+bash
node --versionIf below v22.19.0, inform user they must upgrade Node.js first. -
Existing Watt Config: Check ifalready exists
watt.jsonbashls watt.json 2>/dev/null
在执行任何Watt操作之前,请验证:
-
Node.js版本:Watt要求Node.js v22.19.0+bash
node --version如果版本低于v22.19.0,请告知用户必须先升级Node.js。 -
现有Watt配置:检查是否已存在
watt.jsonbashls watt.json 2>/dev/null
Command Router
命令路由
Based on user input ($ARGUMENTS), route to the appropriate workflow:
| Input Pattern | Action |
|---|---|
| Run Integration Workflow |
| Run Multi-Service Setup |
| Run Migration/POC Workflow |
| Run Observability Setup |
| Run Scheduler Setup |
| Run CMS Integration Setup |
| Run Docker Deployment |
| Run Kubernetes Deployment |
| Run Cloud Deployment |
| Run wattpm CLI Workflow |
| Run wattpm CLI Workflow (create) |
| Run wattpm CLI Workflow (inject) |
| Run wattpm CLI Workflow (logs) |
| Run wattpm CLI Workflow (ps) |
| Run wattpm CLI Workflow (admin) |
| Run wattpm CLI Workflow (resolve/import) |
| Run Status Check |
根据用户输入($ARGUMENTS),路由到对应的工作流:
| 输入模式 | 操作 |
|---|---|
| 执行集成工作流 |
| 执行多服务设置 |
| 执行迁移/POC工作流 |
| 执行可观测性设置 |
| 执行调度器设置 |
| 执行CMS集成设置 |
| 执行Docker部署 |
| 执行Kubernetes部署 |
| 执行云部署 |
| 执行wattpm CLI工作流 |
| 执行wattpm CLI工作流(创建) |
| 执行wattpm CLI工作流(注入) |
| 执行wattpm CLI工作流(日志) |
| 执行wattpm CLI工作流(进程查看) |
| 执行wattpm CLI工作流(管理) |
| 执行wattpm CLI工作流(解析/导入) |
| 执行状态检查 |
Integration Workflow
集成工作流
Step 1: Framework Detection
步骤1:框架检测
Analyze the project to identify the framework. Use this priority order:
Priority 1 - Config Files:
| File | Framework | Package |
|---|---|---|
| Next.js | |
| Remix | |
| Astro | |
| NestJS | |
| WordPress | |
| Laravel | |
| PHP | |
Priority 2 - Dependencies (check package.json):
| Dependency | Framework | Package |
|---|---|---|
| NestJS | |
| Fastify | |
| Express | |
| Koa | |
Priority 3 - Fallback:
If no framework detected, use generic Node.js with .
@platformatic/nodeFor framework-specific configuration, read the appropriate reference file:
- references/frameworks/nextjs.md for Next.js
- references/frameworks/express.md for Express
- references/frameworks/fastify.md for Fastify
- references/frameworks/koa.md for Koa
- references/frameworks/remix.md for Remix
- references/frameworks/astro.md for Astro
- references/frameworks/nestjs.md for NestJS
- references/frameworks/php.md for PHP, WordPress, and Laravel
分析项目以识别框架。使用以下优先级顺序:
优先级1 - 配置文件:
| 文件 | 框架 | 包 |
|---|---|---|
| Next.js | |
| Remix | |
| Astro | |
| NestJS | |
| WordPress | |
| Laravel | |
| PHP | |
优先级2 - 依赖项(检查package.json):
| 依赖项 | 框架 | 包 |
|---|---|---|
| NestJS | |
| Fastify | |
| Express | |
| Koa | |
优先级3 - 备选方案:
如果未检测到框架,则使用通用Node.js搭配。
@platformatic/node针对框架的特定配置,请阅读对应的参考文档:
- references/frameworks/nextjs.md 适用于Next.js
- references/frameworks/express.md 适用于Express
- references/frameworks/fastify.md 适用于Fastify
- references/frameworks/koa.md 适用于Koa
- references/frameworks/remix.md 适用于Remix
- references/frameworks/astro.md 适用于Astro
- references/frameworks/nestjs.md 适用于NestJS
- references/frameworks/php.md 适用于PHP、WordPress和Laravel
Step 2: Generate watt.json
步骤2:生成watt.json
Create based on detected framework. Use the schema URL:
watt.jsonhttps://schemas.platformatic.dev/@platformatic/{package}/3.0.0.jsonWhere is: , , , , or .
{package}nextremixastronodephpRuntime placement rule:
- For single-config application files (e.g. ,
@platformatic/node, etc.), put runtime settings under@platformatic/next.runtime - For multi-app/root orchestrator configs (/
wattwith@platformatic/runtime/services/web), keep a top-levelautoloadblock in the rootruntime.watt.json
根据检测到的框架创建。使用以下Schema URL:
watt.jsonhttps://schemas.platformatic.dev/@platformatic/{package}/3.0.0.json其中可为:, , , , 或。
{package}nextremixastronodephp运行时放置规则:
- 对于单配置应用文件(如,
@platformatic/node等),将运行时设置放在@platformatic/next字段下。runtime - 对于多应用/根编排器配置(/
watt搭配@platformatic/runtime/services/web),在根autoload中保留顶层watt.json块。runtime
Step 3: Install Dependencies
步骤3:安装依赖项
Install wattpm:
bash
npm install wattpmFor Next.js, Remix, Astro, or PHP, also install the specific stackable:
bash
npm install @platformatic/next # for Next.js
npm install @platformatic/remix # for Remix
npm install @platformatic/astro # for Astro
npm install @platformatic/php # for PHP/WordPress/Laravel安装wattpm:
bash
npm install wattpm对于Next.js、Remix、Astro或PHP,还需安装对应的特定栈包:
bash
npm install @platformatic/next # 适用于Next.js
npm install @platformatic/remix # 适用于Remix
npm install @platformatic/astro # 适用于Astro
npm install @platformatic/php # 适用于PHP/WordPress/LaravelStep 4: Update package.json Scripts
步骤4:更新package.json脚本
Add or update these scripts in package.json:
json
{
"scripts": {
"dev": "wattpm dev",
"build": "wattpm build",
"start": "wattpm start"
}
}在package.json中添加或更新以下脚本:
json
{
"scripts": {
"dev": "wattpm dev",
"build": "wattpm build",
"start": "wattpm start"
}
}Step 5: Create Environment File
步骤5:创建环境文件
Create if it doesn't exist:
.envPLT_SERVER_HOSTNAME=0.0.0.0
PLT_SERVER_LOGGER_LEVEL=info
PORT=3000如果不存在文件则创建:
.envPLT_SERVER_HOSTNAME=0.0.0.0
PLT_SERVER_LOGGER_LEVEL=info
PORT=3000Step 6: Verify Setup
步骤6:验证设置
Run a quick verification:
bash
wattpm --versionInform the user they can now run:
- for development
npm run dev - for production
npm run build && npm run start
执行快速验证:
bash
wattpm --version告知用户现在可以运行:
- 用于开发环境
npm run dev - 用于生产环境
npm run build && npm run start
Multi-Service Setup
多服务设置
When user requests enterprise/multi-service setup:
- Read references/enterprise.md
- Create project structure with:
- Root with service definitions
watt.json - - API gateway (Platformatic Composer)
web/composer/ - - Next.js or other frontend
web/frontend/ - - Fastify API service
web/api/ - - Platformatic DB service (optional)
web/db/
- Root
- Configure Composer for path-based routing
- Set up inter-service communication via
{service-id}.plt.local
当用户要求企业级/多服务设置时:
- 阅读references/enterprise.md
- 创建项目结构,包含:
- 根目录,含服务定义
watt.json - - API网关(Platformatic Composer)
web/composer/ - - Next.js或其他前端
web/frontend/ - - Fastify API服务
web/api/ - - Platformatic DB服务(可选)
web/db/
- 根目录
- 配置Composer以实现基于路径的路由
- 通过设置服务间通信
{service-id}.plt.local
Service Communication
服务通信
Services communicate internally without network overhead:
javascript
// From api service, call db service
const response = await fetch('http://db.plt.local/users');服务内部通信无需网络开销:
javascript
// 从api服务调用db服务
const response = await fetch('http://db.plt.local/users');Migration / POC Workflow
迁移 / POC工作流
When user wants to migrate an existing app or prepare for a POC:
- Read references/poc-checklist.md
- Verify prerequisites:
- Node.js 22.19.0+
- Application runs locally
- Database/API access available
- Install: (or use
npm install wattpm)npx wattpm - Create with application entrypoint
watt.json - Modify entrypoint to export function (returns server) or
createfunctionclose - Test with and
npx wattpm devnpx wattpm start
当用户希望迁移现有应用或准备POC时:
- 阅读references/poc-checklist.md
- 验证前置条件:
- Node.js 22.19.0+
- 应用可在本地运行
- 可访问数据库/API
- 安装:(或使用
npm install wattpm)npx wattpm - 创建包含应用入口点的
watt.json - 修改入口点以导出函数(返回服务器)或
create函数close - 使用和
npx wattpm dev进行测试npx wattpm start
Entrypoint Pattern (Express Example)
入口点模式(Express示例)
javascript
async function create() {
const app = express()
app.get('/health', (req, res) => res.json({ status: 'ok' }))
return app
}
module.exports = { create }javascript
async function create() {
const app = express()
app.get('/health', (req, res) => res.json({ status: 'ok' }))
return app
}
module.exports = { create }Observability Setup
可观测性设置
When user requests logging, tracing, or metrics setup:
- Read references/observability.md
- Determine observability needs:
- Logging: Pino configuration, file transport, redaction
- Tracing: OpenTelemetry with OTLP exporter
- Metrics: Prometheus endpoint on port 9090
- Configure based on backend:
- Jaeger, Datadog, New Relic, Grafana Stack, AWS, GCP, Azure
- Set up log-trace correlation for debugging
当用户要求设置日志、追踪或指标时:
- 阅读references/observability.md
- 确定可观测性需求:
- 日志:Pino配置、文件传输、脱敏
- 追踪:搭配OTLP导出器的OpenTelemetry
- 指标:端口9090上的Prometheus端点
- 根据后端进行配置:
- Jaeger、Datadog、New Relic、Grafana Stack、AWS、GCP、Azure
- 设置日志-追踪关联以方便调试
Quick Setup
快速设置
Logging + Tracing + Metrics:
json
{
"logger": {
"level": "{PLT_SERVER_LOGGER_LEVEL}"
},
"telemetry": {
"serviceName": "my-service",
"exporter": {
"type": "otlp",
"options": { "url": "{OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces" }
}
},
"metrics": {
"port": 9090
}
}日志 + 追踪 + 指标:
json
{
"logger": {
"level": "{PLT_SERVER_LOGGER_LEVEL}"
},
"telemetry": {
"serviceName": "my-service",
"exporter": {
"type": "otlp",
"options": { "url": "{OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces" }
}
},
"metrics": {
"port": 9090
}
}Scheduler Setup
调度器设置
When user requests cron/scheduled jobs setup:
- Read references/scheduler.md
- Add array to
schedulerwatt.json - Configure jobs with cron expressions, callback URLs, and retry settings
- Create endpoint handlers in target services
当用户要求设置cron/定时任务时:
- 阅读references/scheduler.md
- 向添加
watt.json数组scheduler - 使用cron表达式、回调URL和重试设置配置任务
- 在目标服务中创建端点处理器
Quick Setup
快速设置
json
{
"scheduler": [
{
"name": "daily-cleanup",
"cron": "0 0 3 * * *",
"callbackUrl": "http://api.plt.local/cron/cleanup",
"method": "POST",
"maxRetries": 3
}
]
}json
{
"scheduler": [
{
"name": "daily-cleanup",
"cron": "0 0 3 * * *",
"callbackUrl": "http://api.plt.local/cron/cleanup",
"method": "POST",
"maxRetries": 3
}
]
}Key Points
关键点
- Uses standard cron format with optional seconds field
- Internal URLs:
http://{service-id}.plt.local - Jobs retry on failure (default: 3 attempts)
- State is in-memory only (not persisted across restarts)
- 使用标准cron格式,可选秒字段
- 内部URL:
http://{service-id}.plt.local - 任务失败时会重试(默认:3次)
- 状态仅在内存中存储(重启后不持久化)
CMS Integration Setup
CMS集成设置
When user requests headless CMS integration (Contentful, Sanity, Strapi, etc.):
- Read references/cms-integration.md
- Recommend architecture with separate content-worker service
- Set up webhook endpoint for CMS callbacks
- Configure cache invalidation with Next.js
revalidateTag() - Create mock data pattern for development
当用户要求集成无头CMS(Contentful、Sanity、Strapi等)时:
- 阅读references/cms-integration.md
- 推荐使用独立内容工作者服务的架构
- 设置用于CMS回调的Webhook端点
- 搭配Next.js 配置缓存失效
revalidateTag() - 为开发环境创建模拟数据模式
Key Components
核心组件
- Content Worker: Fastify service handling webhooks
- Cache Tags: Map CMS content types to Next.js cache tags
- Revalidation API: Next.js endpoint called by content-worker
- 内容工作者:处理Webhook的Fastify服务
- 缓存标签:将CMS内容类型映射到Next.js缓存标签
- 重新验证API:由内容工作者调用的Next.js端点
Deployment Workflows
部署工作流
Docker Deployment
Docker部署
When user requests Docker deployment:
- Read references/deployment/docker.md
- Generate:
- Multi-stage optimized for Watt
Dockerfile - file
.dockerignore - Optional for development
docker-compose.yml
- Multi-stage
- Provide build and run commands
当用户要求Docker部署时:
- 阅读references/deployment/docker.md
- 生成:
- 针对Watt优化的多阶段
Dockerfile - 文件
.dockerignore - 可选的(用于开发环境)
docker-compose.yml
- 针对Watt优化的多阶段
- 提供构建和运行命令
Kubernetes Deployment
Kubernetes部署
When user requests Kubernetes deployment:
- Read references/deployment/kubernetes.md
- Generate:
- with health checks
deployment.yaml service.yaml- for environment variables
configmap.yaml - Optional for autoscaling
hpa.yaml
- Provide kubectl apply commands
当用户要求Kubernetes部署时:
- 阅读references/deployment/kubernetes.md
- 生成:
- 含健康检查的
deployment.yaml service.yaml- 用于环境变量的
configmap.yaml - 可选的(用于自动扩缩容)
hpa.yaml
- 含健康检查的
- 提供kubectl应用命令
Cloud Deployment
云部署
When user requests cloud deployment:
- Read references/deployment/cloud.md
- Based on target platform, generate appropriate config:
- Fly.io:
fly.toml - Railway:
railway.json - Render:
render.yaml
- Fly.io:
- Provide deployment commands
当用户要求云部署时:
- 阅读references/deployment/cloud.md
- 根据目标平台生成对应的配置:
- Fly.io:
fly.toml - Railway:
railway.json - Render:
render.yaml
- Fly.io:
- 提供部署命令
Status Check
状态检查
When user runs :
/watt status-
Node.js Versionbash
node --versionCheck if >= v22.19.0 -
watt.json Existsbash
ls watt.json -
watt.json Validbash
node -e "JSON.parse(require('fs').readFileSync('watt.json'))" -
wattpm Installedbash
npx wattpm --version -
package.json Scripts Check for dev, build, start scripts
Report findings in a clear format:
Watt Configuration Status
========================
Node.js Version: vX.X.X [OK/UPGRADE NEEDED]
watt.json: [Found/Missing]
Configuration: [Valid/Invalid]
wattpm: [Installed vX.X.X/Not installed]
Scripts: [Configured/Missing]
[Next steps if any issues found]当用户运行时:
/watt status-
Node.js版本bash
node --version检查是否 >= v22.19.0 -
watt.json是否存在bash
ls watt.json -
watt.json是否有效bash
node -e "JSON.parse(require('fs').readFileSync('watt.json'))" -
wattpm是否已安装bash
npx wattpm --version -
package.json脚本 检查是否存在dev、build、start脚本
以清晰格式报告结果:
Watt配置状态
========================
Node.js版本: vX.X.X [正常/需要升级]
watt.json: [已找到/缺失]
配置: [有效/无效]
wattpm: [已安装 vX.X.X/未安装]
脚本: [已配置/缺失]
[如果存在问题,给出下一步建议]wattpm CLI Workflow
wattpm CLI工作流
When users ask about wattpm commands, CLI usage, or managing running applications:
- Read references/wattpm-cli.md
- Based on the user's request, provide the relevant command with flags and examples
- For general CLI questions, give an overview of available commands
当用户询问wattpm命令、CLI用法或管理运行中的应用时:
- 阅读references/wattpm-cli.md
- 根据用户请求,提供相关命令及参数示例
- 对于通用CLI问题,概述可用的命令
Common Scenarios
常见场景
Scaffolding a new project:
bash
wattpm create
wattpm create --module @platformatic/nextTesting endpoints on a running app:
bash
wattpm inject --path /health
wattpm inject my-app api-service --method POST --path /users \
--header "Content-Type: application/json" \
--data '{"name": "Alice"}'Monitoring a running app:
bash
wattpm ps # list running instances
wattpm logs my-app # stream all logs
wattpm logs my-app api-service # stream logs from a sub-application
wattpm env my-app --table # view environment variables
wattpm config my-app # view configurationWorking with external applications:
bash
wattpm import . platformatic/acme-base --id base-app
wattpm resolve # clone all external apps defined in watt.jsonAdministration:
bash
wattpm admin # launch Watt admin UI
wattpm patch-config . patches/production.js # apply config patches搭建新项目:
bash
wattpm create
wattpm create --module @platformatic/next测试运行中应用的端点:
bash
wattpm inject --path /health
wattpm inject my-app api-service --method POST --path /users \
--header "Content-Type: application/json" \
--data '{"name": "Alice"}'监控运行中应用:
bash
wattpm ps # 列出运行实例
wattpm logs my-app # 流式输出所有日志
wattpm logs my-app api-service # 流式输出子应用的日志
wattpm env my-app --table # 查看环境变量
wattpm config my-app # 查看配置处理外部应用:
bash
wattpm import . platformatic/acme-base --id base-app
wattpm resolve # 克隆watt.json中定义的所有外部应用管理操作:
bash
wattpm admin # 启动Watt管理UI
wattpm patch-config . patches/production.js # 应用配置补丁Important Notes
重要说明
- Watt 3.x runs applications in parallel for faster startup
- Use internal hostname for inter-service communication
{app-name}.plt.local - The unified CLI replaces older individual CLIs
wattpm - Always recommend running before production deployment
wattpm build - TypeScript is supported natively via Node.js type stripping (v22.6+)
- Watt 3.x并行运行应用以加快启动速度
- 使用内部主机名进行服务间通信
{app-name}.plt.local - 统一的CLI替代了旧的独立CLI
wattpm - 始终建议在生产部署前运行
wattpm build - Node.js v22.6+原生支持TypeScript(通过类型剥离)
Performance Optimization
性能优化
For production performance tuning, read references/performance.md
Key optimizations:
- Configure for multi-threaded SSR
PLT_NEXT_WORKERS - Scale CPU limits proportionally (workers × 1000m)
- Enable distributed caching with Valkey/Redis
- Use for Next.js
output: 'standalone'
如需生产环境性能调优,请阅读references/performance.md
关键优化点:
- 配置以实现多线程SSR
PLT_NEXT_WORKERS - 按比例扩展CPU限制(workers × 1000m)
- 启用基于Valkey/Redis的分布式缓存
- 对Next.js使用
output: 'standalone'
Troubleshooting
故障排除
For common issues, read references/troubleshooting.md
如需解决常见问题,请阅读references/troubleshooting.md