Skip to content

Commit ef0a0d6

Browse files
committed
feat: add documentation for application configuration, CLI commands, controller patterns, middleware patterns, and project structure
- Introduced new markdown files detailing application setup, CLI command usage, controller conventions, middleware patterns, and overall project structure for the koapp framework. - Enhanced developer experience by providing clear guidelines and examples for each aspect of the framework.
1 parent 1362a16 commit ef0a0d6

11 files changed

Lines changed: 113 additions & 0 deletions

‎.agents/rules/git-commit.mdc.tmpl‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
description: 起草或生成 git commit message 时使用(Conventional Commits + TaskID)
3+
alwaysApply: false
4+
---
5+
6+
# Git Commit Message 规范
7+
8+
对齐 `@commitlint/config-conventional` 与 Conventional Commits 1.0.0。起草 / 执行 `git commit` 时必须遵循本规范。
9+
10+
## 格式
11+
12+
```text
13+
<type>(<scope>): <subject> <TaskID>
14+
15+
<body>
16+
17+
<footer>
18+
```
19+
20+
- header / body / footer 之间空一行
21+
- `scope`、`TaskID`、`body`、`footer` 均可省略;有关联工单时必须带 `TaskID`
22+
- `subject` ≤ 50 字符,祈使语气,首字母小写、句末不加句号
23+
- `body` 每行尽量 ≤ 72 字符,可多段、可用列表
24+
25+
## type
26+
27+
| type | 含义 |
28+
|------|------|
29+
| `feat` | 新功能 |
30+
| `fix` | 修 bug |
31+
| `perf` | 性能优化(仅限性能,不含一般改进) |
32+
| `docs` | 文档 |
33+
| `style` | 代码格式(不影响运行的变动) |
34+
| `refactor` | 重构(非新功能、非修 bug),运维部署变更(端口号、环境变量、配置文件等) |
35+
| `test` | 增加或修正测试 |
36+
| `build` | 构建系统或外部依赖变更(pnpm、tsconfig、依赖升级等) |
37+
| `ci` | CI 配置与脚本变更(GitHub Actions 等) |
38+
| `chore` | 其他杂项(不改动源码与测试的维护性变动) |
39+
| `revert` | 撤销变更(header 复述被撤销 commit 的 header,body 注明 `This reverts commit <hash>.`) |
40+
41+
依赖变更写成 `build(deps): ...`,不要用独立的 `deps` type。
42+
43+
## scope(本仓库推荐)
44+
45+
- `services` — `apps/services`
46+
- `commands` — `packages/commands`
47+
- `cli` — `bin/`
48+
- `agents` — `.agents/`
49+
- `deps` — 依赖升降级(配合 `build`)
50+
- `root` — 根配置(`package.json`、pnpm workspace 等)
51+
52+
跨包改动可省略 scope,或用最主要影响面。
53+
54+
## footer
55+
56+
仅两种用途:
57+
58+
1. 不兼容变动:以 `BREAKING CHANGE: ` 开头,说明变动、理由与迁移方法;也可在 type/scope 后加 `!`(如 `feat(services)!: ...`)并配合 footer
59+
2. 关闭缺陷:`Closes #123` / `Fixes #123`
60+
61+
## 正反例
62+
63+
```text
64+
# 好
65+
feat(services): add health check endpoint T123
66+
67+
Expose GET /api/health without auth so deploy probes
68+
can verify the process is up.
69+
70+
# 好(无工单、无 body)
71+
fix(commands): handle missing app id in apikey create
72+
73+
# 好(依赖变更)
74+
build(deps): bump @axiosleo/koapp from 1.2.0 to 1.3.1
75+
76+
# 好(破坏性)
77+
feat(services): require bearer prefix on openapi keys
78+
79+
BREAKING CHANGE: Api-Key must start with sk2a_. Old keys
80+
need to be recreated via ${name} apikey create.
81+
82+
# 差
83+
Update stuff.
84+
fix: Fixed the bug.
85+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
description: apps/services 后端(koapp)模块结构与编码约定
3+
globs: apps/services/**
4+
alwaysApply: false
5+
---
6+
7+
# services 后端约定
8+
9+
## 模块结构
10+
11+
- 业务模块三件套:`src/modules/<name>/<name>.router.ts`(路由)+ `<name>.controller.ts`(处理器)+ `<name>.model.ts`(validatorjs 校验规则与类型)
12+
- 路由统一在 `src/modules/index.ts` 挂载,分两套 API 面:
13+
- `/openapi`:`authMiddleware`(Bearer Api-Key,按 app_id 限定作用域);模板为空壳,业务路由在此挂载
14+
- `/api`:admin 模块(登录/登出/资料)公开挂载,其余模块挂在 `adminAuthMiddleware`(Session)之后(当前为 app)
15+
- `GET /api/health`:无鉴权健康检查
16+
- 路由参数写法 `/{:id}`,校验规则挂路由第三参:`{ params/query/body: { rules } }`
17+
18+
## Controller
19+
20+
- 继承 `src/modules/controller.ts` 的 `BaseController`:
21+
- `this.appId(ctx)` 解析应用作用域(Api-Key 强制取 key 的 app_id;admin 会话可选过滤,null = 不过滤)
22+
- 响应用 `this.success(...)` / `this.error(status, msg)`
23+
24+
## 共享服务与测试
25+
26+
- 共享服务放 `src/services/`:`sqlite.ts`(元数据库:apps / api_keys)
27+
- 测试与源码同目录,命名 `*.test.ts`,mocha 运行:`pnpm test`;单跑一个文件用 `pnpm test-one <路径>`
28+
- koapp 框架 API 细节(Router / Controller / Model / 响应)见 `.cursor/skills/koapp*` 技能

0 commit comments

Comments
 (0)