create-next-imagicma 0.1.13 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template-hono/.env.example +16 -3
- package/template-hono/AGENTS.md +91 -16
- package/template-hono/README.md +89 -3
- package/template-hono/client/src/components/HelloClient.tsx +1 -1
- package/template-hono/client/src/globals.css +1 -417
- package/template-hono/client/src/lib/ai-ui-stream.ts +64 -0
- package/template-hono/client/src/providers.tsx +1 -1
- package/template-hono/client/src/theme/default-theme.css +482 -0
- package/template-hono/drizzle.config.ts +3 -36
- package/template-hono/package.json +5 -1
- package/template-hono/pnpm-lock.yaml +186 -54
- package/template-hono/server/app.ts +2 -0
- package/template-hono/server/controllers/ai-chat-controller.ts +49 -0
- package/template-hono/server/controllers/greeting-controller.ts +25 -0
- package/template-hono/server/db/client.ts +25 -0
- package/template-hono/server/env.ts +89 -0
- package/template-hono/server/index.ts +1 -1
- package/template-hono/server/lib/ai-provider.ts +74 -0
- package/template-hono/server/lib/ai.ts +205 -0
- package/template-hono/server/middlewares/auth.ts +69 -0
- package/template-hono/server/middlewares/index.ts +12 -0
- package/template-hono/server/repositories/message-repository.ts +13 -0
- package/template-hono/server/routes/ai-chat.ts +9 -0
- package/template-hono/server/routes/greeting.ts +2 -18
- package/template-hono/shared/routes.ts +55 -0
- package/template-hono/shared/schema/greeting.ts +17 -0
- package/template-hono/shared/schema.ts +8 -16
- package/template-hono/tailwind.config.mjs +111 -62
- package/template-hono/vite.config.ts +1 -1
- package/template-hono/server/database-path.ts +0 -35
- package/template-hono/server/db.ts +0 -20
- package/template-hono/server/storage.ts +0 -30
package/package.json
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# 复制为 .env.local 后按需覆盖(.env.local 不会被提交)
|
|
2
2
|
#
|
|
3
|
-
#
|
|
4
|
-
#
|
|
5
|
-
|
|
3
|
+
# 必填:PostgreSQL 连接串
|
|
4
|
+
# DATABASE_URL="postgresql://postgres:password@127.0.0.1:5432/hono_app"
|
|
5
|
+
#
|
|
6
|
+
# AI 网关配置
|
|
7
|
+
# 可选:提供商,支持 openai / openai-compatible / minimax / kimi
|
|
8
|
+
# AI_PROVIDER="minimax"
|
|
9
|
+
# 必填:模型访问密钥
|
|
10
|
+
# AI_API_KEY="<your-api-key>"
|
|
11
|
+
# 可选:自定义网关地址;minimax / kimi 留空时会自动使用官方兼容地址
|
|
12
|
+
# AI_BASE_URL="https://api.minimaxi.com/v1"
|
|
13
|
+
# 可选:模型 ID;未设置时默认 gpt-4o-mini
|
|
14
|
+
# AI_MODEL="MiniMax-M2.7"
|
|
15
|
+
#
|
|
16
|
+
# 兼容旧变量名:
|
|
17
|
+
# OPENAI_API_KEY="<your-api-key>"
|
|
18
|
+
# OPENAI_BASE_URL="https://api.openai.com/v1"
|
package/template-hono/AGENTS.md
CHANGED
|
@@ -2,17 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
## Project Structure & Module Organization
|
|
4
4
|
|
|
5
|
-
This is a `Hono + Vite + React` app. Keep browser code in `client/src`, server entrypoints in `server/`, and shared contracts in `shared/`.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
- `
|
|
5
|
+
This is a `Hono + Vite + React` app designed for enterprise-level product development. Keep browser code in `client/src`, server entrypoints in `server/`, and shared contracts in `shared/`.
|
|
6
|
+
|
|
7
|
+
### Documentation Structure (Design Phase)
|
|
8
|
+
All design artifacts are stored under `docs/designer/`:
|
|
9
|
+
|
|
10
|
+
- `docs/designer/project_state.json`: project state and version tracking
|
|
11
|
+
- `docs/designer/prd/prd.md`: Product Requirements Document
|
|
12
|
+
- `docs/designer/persona/persona_*.md`: user personas (one file per persona)
|
|
13
|
+
- `docs/designer/feature_plan/`: feature module planning
|
|
14
|
+
- `feature_modules.md`: module list, relationship diagrams, and shared/common components (may contain full details if ≤4 modules)
|
|
15
|
+
- `feature_module_[name].md`: detailed module specifications for large apps (pages, layouts, components, business rules, and navigation)
|
|
16
|
+
- `docs/designer/style_guide/*.style-guide.md`: visual design guidelines
|
|
17
|
+
- `docs/designer/db/`: database schema documentation
|
|
18
|
+
- `db_schema.md`: global ER diagram and module index
|
|
19
|
+
- `db_schema_[module].md`: per-module database schemas
|
|
20
|
+
|
|
21
|
+
### Application Code Structure
|
|
22
|
+
- `client/src/pages/`: route-level pages (e.g., `home.tsx`)
|
|
23
|
+
- `client/src/components/`: reusable UI components, with shadcn/ui primitives under `components/ui/`
|
|
24
|
+
- `client/src/lib/` and `client/src/hooks/`: client utilities and custom hooks
|
|
25
|
+
- `client/src/main.tsx`: frontend entry point
|
|
26
|
+
- `client/src/App.tsx`: React Router configuration
|
|
27
|
+
- `client/src/globals.css`: global styles
|
|
28
|
+
- `client/public/`: static assets
|
|
29
|
+
- `server/app.ts`: Hono application entry point
|
|
30
|
+
- `server/routes/`: route registration only; bind paths and hand off to controllers
|
|
31
|
+
- `server/middlewares/`: cross-cutting HTTP middleware such as auth, request-id, logging, and rate-limit
|
|
32
|
+
- `server/controllers/`: HTTP layer; parse requests, call repositories/lib, and map errors to responses
|
|
33
|
+
- `server/repositories/`: data access only; wrap Drizzle/SQL queries
|
|
34
|
+
- `server/db/`: database client and database-level infrastructure
|
|
35
|
+
- `server/lib/`: external integrations and reusable backend helpers
|
|
36
|
+
- `server/env.ts`: environment loading and config validation
|
|
11
37
|
- `shared/routes.ts` and `shared/schema.ts`: Zod-backed API contracts and shared schema
|
|
12
38
|
- `scripts/`: guarded dev/start scripts; do not bypass them
|
|
13
|
-
- `.
|
|
39
|
+
- `.env.local`: local runtime secrets such as `DATABASE_URL`; do not commit it
|
|
40
|
+
|
|
41
|
+
**Critical**: The homepage must never ship blank. `client/src/pages/home.tsx` should render visible, meaningful content on first load, not hidden placeholders or empty shells.
|
|
42
|
+
|
|
43
|
+
## Development Preparation
|
|
44
|
+
|
|
45
|
+
Before starting development, agents must confirm the database connection with the user by using `question`. Ask for the PostgreSQL connection string that should be used locally, for example:
|
|
14
46
|
|
|
15
|
-
|
|
47
|
+
- `DATABASE_URL="postgresql://postgres:password@127.0.0.1:5432/hono_app"`
|
|
48
|
+
|
|
49
|
+
Do not assume the database host, port, username, password, or database name. After the user confirms the value, place it in `.env.local` (or ensure it is already available in the environment) before running database-related work such as `pnpm db:push`, server development, or any feature that depends on persistence.
|
|
16
50
|
|
|
17
51
|
## Build, Test, and Development Commands
|
|
18
52
|
|
|
@@ -21,24 +55,65 @@ The homepage must never ship blank. `client/src/pages/home.tsx` should render vi
|
|
|
21
55
|
- `pnpm start`: runs the production server through the guarded startup script
|
|
22
56
|
- `pnpm check`: TypeScript type-check for both client and server configs
|
|
23
57
|
- `pnpm lint`: runs ESLint across the repository
|
|
24
|
-
- `pnpm db:push`: applies Drizzle schema changes to the
|
|
58
|
+
- `pnpm db:push`: applies Drizzle schema changes to the PostgreSQL database from `DATABASE_URL`
|
|
59
|
+
|
|
60
|
+
### AI Feature Rule
|
|
61
|
+
- If you are developing AI-related features in this template, you must use the `ai-feature` skill before implementation.
|
|
25
62
|
|
|
26
63
|
## Coding Style & Naming Conventions
|
|
27
64
|
|
|
28
65
|
Use TypeScript and ESM throughout. Follow the existing style: 2-space indentation, double quotes, semicolons, and trailing commas. Prefer:
|
|
29
66
|
|
|
30
|
-
- PascalCase for React components
|
|
31
|
-
- kebab-case for route/page files
|
|
32
|
-
-
|
|
67
|
+
- PascalCase for React components (e.g., `HelloClient.tsx`)
|
|
68
|
+
- kebab-case for route/page files (e.g., `not-found.tsx`)
|
|
69
|
+
- snake_case for database schema files (e.g., `db_schema_user.md`)
|
|
70
|
+
- Colocate logic in `hooks/`, `lib/`, and `routes/` before creating new top-level folders
|
|
33
71
|
|
|
34
72
|
Reuse the `@/` import alias for client code where it improves readability.
|
|
35
73
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
74
|
+
### Backend Layering Rules
|
|
75
|
+
- Backend request flow must follow `routes -> middlewares -> controllers -> repositories -> db`.
|
|
76
|
+
- `routes/` may define paths and middleware, but must not contain business logic or direct database access.
|
|
77
|
+
- `middlewares/` are for cross-cutting concerns such as auth, request-id, logging, and rate-limit; they may read/write Hono Context and short-circuit requests when needed.
|
|
78
|
+
- Auth-related checks should be implemented as middleware and mounted in `routes/`, not reimplemented inside controllers.
|
|
79
|
+
- `controllers/` may read/write HTTP details, call repositories or `lib/`, and map errors, but must not contain SQL.
|
|
80
|
+
- `repositories/` own database reads/writes only and must not shape HTTP responses.
|
|
81
|
+
- `db/` is limited to connection setup, schema wiring, and database infrastructure helpers.
|
|
82
|
+
- `lib/` is for external providers or shared backend utilities; routes should reach it through middleware or controllers, not directly.
|
|
83
|
+
- Controllers should consume auth context that middleware has already prepared instead of parsing tokens again.
|
|
84
|
+
- New backend features should default to adding files along the same chain: route, middleware when needed, controller, repository.
|
|
85
|
+
- Do not mock backend data for feature development. Implement against real backend flows, real repositories, and real interfaces unless the user explicitly asks for a temporary test double.
|
|
86
|
+
|
|
87
|
+
### Shared Schema Rules
|
|
88
|
+
- Always split shared schema by business module in `shared/schema/*.ts`, not by individual table.
|
|
89
|
+
- `shared/schema.ts` must remain the unified export entry so existing imports and Drizzle config stay stable.
|
|
90
|
+
- Each schema module should contain the tables, Zod schema exports, and inferred TS types for that module.
|
|
91
|
+
- Avoid one-file-per-table unless the user explicitly asks for it or a single module is exceptionally large.
|
|
92
|
+
|
|
93
|
+
### Design Documentation Standards
|
|
94
|
+
- All Mermaid diagrams must NOT include styling elements (no style definitions, classDef, linkStyle or fill colors)
|
|
95
|
+
- Use basic graph syntax only: `graph TD`/`graph TB` for architecture, and `erDiagram` for schemas
|
|
96
|
+
- File naming must strictly follow the patterns defined in File Structure section
|
|
97
|
+
|
|
98
|
+
### Technical Selection Policy
|
|
99
|
+
Technical selection is strictly an engineering responsibility, governed globally:
|
|
100
|
+
- When evaluating complex system requirements (e.g., OCR, Payments, AI integrations, Auth), propose solutions contrasting self-built vs. commercial options.
|
|
101
|
+
- Strip away meaningless basic scaffolding choices; focus squarely on domain-specific system blockers.
|
|
102
|
+
- When human input is mandatory to finalize a route, translate technical jargon into business dimensions for the stakeholders: "Development Time, Cost, and Product Experience".
|
|
103
|
+
- Final architectural decisions must be persisted into `docs/designer/tech_design/tech_design.md`.
|
|
104
|
+
|
|
105
|
+
## Testing & Quality Assurance
|
|
106
|
+
|
|
107
|
+
Before opening a PR, complete manual verification to ensure the application is usable end to end.
|
|
39
108
|
|
|
40
109
|
If you add tests, keep them as `*.test.ts` or `*.test.tsx`, or add a `tests/` folder and document the new command in `package.json`.
|
|
41
110
|
|
|
111
|
+
### Manual Verification Checklist
|
|
112
|
+
- All API endpoints work correctly
|
|
113
|
+
- All pages are accessible without 404 errors
|
|
114
|
+
- All buttons are clickable and trigger the expected behavior
|
|
115
|
+
- All links navigate to the correct destination
|
|
116
|
+
|
|
42
117
|
## Commit & Pull Request Guidelines
|
|
43
118
|
|
|
44
119
|
Recent history uses Conventional Commit prefixes such as `feat:`, `fix:`, and `chore:`; keep that format and write concise subjects. PRs should include:
|
|
@@ -50,4 +125,4 @@ Recent history uses Conventional Commit prefixes such as `feat:`, `fix:`, and `c
|
|
|
50
125
|
|
|
51
126
|
## Runtime & Configuration Notes
|
|
52
127
|
|
|
53
|
-
Agents must use `restart_workflow` instead of invoking `pnpm dev` manually. Do not pass a port on the command line or by prefixing `pnpm dev` with `PORT=...`; keep runtime port configuration in `.imagicma/runtime.env`. Database
|
|
128
|
+
Agents must use `restart_workflow` instead of invoking `pnpm dev` manually. Do not pass a port on the command line or by prefixing `pnpm dev` with `PORT=...`; keep runtime port configuration in `.imagicma/runtime.env`. Database access must come from `DATABASE_URL` in `.env.local` (or process env), and secrets must never be committed.
|
package/template-hono/README.md
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
- 前端:React 19、React Router、Tailwind CSS v4、shadcn/ui、React Query
|
|
8
8
|
- 后端:Hono(Node runtime)
|
|
9
|
-
- 数据层:Drizzle ORM +
|
|
9
|
+
- 数据层:Drizzle ORM + PostgreSQL(默认通过 `DATABASE_URL` 连接)
|
|
10
|
+
- AI 网关:Vercel AI SDK 5(`ai` + `@ai-sdk/openai` + `@ai-sdk/openai-compatible`)
|
|
10
11
|
- 校验契约:Zod(`shared/routes.ts`)
|
|
11
12
|
|
|
12
13
|
## 目录结构(重点)
|
|
@@ -19,6 +20,24 @@
|
|
|
19
20
|
- `server/`:Hono 后端入口与路由
|
|
20
21
|
- `shared/`:前后端共享契约与 schema
|
|
21
22
|
|
|
23
|
+
## AI 网关基础设施
|
|
24
|
+
|
|
25
|
+
模板已内置最薄的 AI 基础设施,不带默认业务页面:
|
|
26
|
+
|
|
27
|
+
- 服务端统一入口:`POST /api/ai/chat`
|
|
28
|
+
- 服务端默认架构:Hono API -> Vercel AI SDK -> OpenAI / OpenAI 兼容模型
|
|
29
|
+
- 当前默认支持的小文件附件类型:`image/*`、`text/*`、`application/pdf`
|
|
30
|
+
- 附件限制:最多 3 个文件,总大小不超过 5MB,且必须以内联 data URL 提交
|
|
31
|
+
|
|
32
|
+
推荐做法:
|
|
33
|
+
|
|
34
|
+
- 前端页面调用项目内 `/api/ai/chat`
|
|
35
|
+
- 不要把模型密钥暴露到浏览器
|
|
36
|
+
- 需要聊天 UI 时,优先使用 `@ai-sdk/react` 的 `useChat` / `DefaultChatTransport` 对接服务端 UI message stream
|
|
37
|
+
- 如果暂时不引入 `@ai-sdk/react`,请复用 `client/src/lib/ai-ui-stream.ts`,不要手写 SSE 解析器
|
|
38
|
+
- OpenAI 官方走 `AI_PROVIDER=openai`
|
|
39
|
+
- MiniMax / Kimi 这类 OpenAI 兼容供应商,优先走 `AI_PROVIDER=minimax|kimi` 或 `openai-compatible`
|
|
40
|
+
|
|
22
41
|
## 开发
|
|
23
42
|
|
|
24
43
|
```bash
|
|
@@ -54,8 +73,74 @@ PORT=6424
|
|
|
54
73
|
pnpm db:push
|
|
55
74
|
```
|
|
56
75
|
|
|
57
|
-
-
|
|
58
|
-
-
|
|
76
|
+
- 请先复制 `.env.example` 为 `.env.local`
|
|
77
|
+
- 在 `.env.local` 中设置 `DATABASE_URL`
|
|
78
|
+
- `pnpm db:push` 会将 schema 推送到该 PostgreSQL 数据库
|
|
79
|
+
|
|
80
|
+
## AI 配置
|
|
81
|
+
|
|
82
|
+
请在 `.env.local` 中配置:
|
|
83
|
+
|
|
84
|
+
- `AI_PROVIDER`:可选;支持 `openai`、`openai-compatible`、`minimax`、`kimi`
|
|
85
|
+
- `AI_API_KEY`:必填
|
|
86
|
+
- `AI_BASE_URL`:可选;接 OpenAI 兼容网关时填写。`minimax` / `kimi` 留空时自动走官方默认地址
|
|
87
|
+
- `AI_MODEL`:可选;默认 `gpt-4o-mini`
|
|
88
|
+
|
|
89
|
+
兼容说明:
|
|
90
|
+
|
|
91
|
+
- 旧变量 `OPENAI_API_KEY` / `OPENAI_BASE_URL` 仍然可用,但新项目建议改用通用命名的 `AI_*`
|
|
92
|
+
- `minimax` 与 `kimi` 默认都走 OpenAI 兼容模式,不需要额外改代码
|
|
93
|
+
- 如果接其它兼容供应商,使用 `AI_PROVIDER=openai-compatible` 并填写 `AI_BASE_URL`
|
|
94
|
+
|
|
95
|
+
模板内置的 AI 路由会优先读取这些环境变量,再由服务端统一调用模型供应商。
|
|
96
|
+
|
|
97
|
+
补充说明:
|
|
98
|
+
|
|
99
|
+
- `/api/ai/chat` 返回的是 AI SDK 5 的 UI message stream(SSE `data:` 事件,不是旧的 `0:"..."` 文本流)
|
|
100
|
+
- 如果模型网关不可达,优先检查 `AI_BASE_URL`、网络连通性与服务商侧配置
|
|
101
|
+
|
|
102
|
+
最小请求示例:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
curl -N \
|
|
106
|
+
-X POST http://127.0.0.1:6424/api/ai/chat \
|
|
107
|
+
-H 'Content-Type: application/json' \
|
|
108
|
+
-d '{
|
|
109
|
+
"messages": [
|
|
110
|
+
{
|
|
111
|
+
"role": "user",
|
|
112
|
+
"parts": [
|
|
113
|
+
{ "type": "text", "text": "请用一句话介绍这个项目的 AI 网关职责。" }
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
}'
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
常见配置示例:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# OpenAI 官方
|
|
124
|
+
AI_PROVIDER=openai
|
|
125
|
+
AI_API_KEY=<your-openai-key>
|
|
126
|
+
AI_MODEL=gpt-4o-mini
|
|
127
|
+
|
|
128
|
+
# MiniMax
|
|
129
|
+
AI_PROVIDER=minimax
|
|
130
|
+
AI_API_KEY=<your-minimax-key>
|
|
131
|
+
AI_MODEL=MiniMax-M2.7
|
|
132
|
+
|
|
133
|
+
# Kimi
|
|
134
|
+
AI_PROVIDER=kimi
|
|
135
|
+
AI_API_KEY=<your-kimi-key>
|
|
136
|
+
AI_MODEL=kimi-k2.5
|
|
137
|
+
|
|
138
|
+
# 其它 OpenAI 兼容供应商
|
|
139
|
+
AI_PROVIDER=openai-compatible
|
|
140
|
+
AI_API_KEY=<your-provider-key>
|
|
141
|
+
AI_BASE_URL=https://api.provider.com/v1
|
|
142
|
+
AI_MODEL=<provider-model-id>
|
|
143
|
+
```
|
|
59
144
|
|
|
60
145
|
## 运行时文件
|
|
61
146
|
|
|
@@ -64,4 +149,5 @@ pnpm db:push
|
|
|
64
149
|
## 验证路径
|
|
65
150
|
|
|
66
151
|
- API:`GET /api/greeting`
|
|
152
|
+
- AI:`POST /api/ai/chat`
|
|
67
153
|
- 页面:`/hello`
|
|
@@ -62,7 +62,7 @@ function EnvHint() {
|
|
|
62
62
|
return (
|
|
63
63
|
<div className="text-sm text-muted-foreground">
|
|
64
64
|
<p>
|
|
65
|
-
默认使用
|
|
65
|
+
默认使用 PostgreSQL。若 API 报错,请先在 <code>.env.local</code> 设置 <code>DATABASE_URL</code>,再执行 <code>pnpm db:push</code> 初始化数据库。
|
|
66
66
|
</p>
|
|
67
67
|
</div>
|
|
68
68
|
);
|