code-documentation by skillcreatorai/ai-agent-skills
npx skills add https://github.com/skillcreatorai/ai-agent-skills --skill code-documentation# 项目名称
本项目功能的简要描述。
## 快速开始
\`\`\`bash
npm install
npm run dev
\`\`\`
## 安装
详细的安装说明...
## 使用
\`\`\`typescript
import { something } from 'project';
// 使用示例
const result = something.doThing();
\`\`\`
## API 参考
### `functionName(param: Type): ReturnType`
描述该函数的功能。
**参数:**
- `param` - 参数描述
**返回:** 返回值描述
**示例:**
\`\`\`typescript
const result = functionName('value');
\`\`\`
## 配置
| 选项 | 类型 | 默认值 | 描述 |
|--------|------|---------|-------------|
| `option1` | `string` | `'default'` | 功能说明 |
## 贡献
如何参与贡献...
## 许可证
MIT
/**
* 创建新用户账户。
*
* @param userData - 用于创建账户的用户数据
* @param options - 可选配置
* @returns 创建的用户对象
* @throws {ValidationError} 如果邮箱无效
* @example
* ```ts
* const user = await createUser({
* email: 'user@example.com',
* name: 'John'
* });
* ```
*/
async function createUser(
userData: UserInput,
options?: CreateOptions
): Promise<User> {
// 实现
}
/**
* API 客户端的配置选项。
*/
interface ClientConfig {
/** API 基础 URL */
baseUrl: string;
/** 请求超时时间(毫秒) @default 5000 */
timeout?: number;
/** 请求中包含的自定义头部 */
headers?: Record<string, string>;
}
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
openapi: 3.0.0
info:
title: My API
version: 1.0.0
paths:
/users:
post:
summary: 创建用户
description: 创建新用户账户
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserInput'
responses:
'201':
description: 用户创建成功
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: 无效输入
components:
schemas:
UserInput:
type: object
required:
- email
- name
properties:
email:
type: string
format: email
name:
type: string
User:
type: object
properties:
id:
type: string
email:
type: string
name:
type: string
createdAt:
type: string
format: date-time
// 良好:解释"为什么",而不是"是什么"
// 使用二分查找,因为列表始终有序且可能包含数百万项 - O(log n) 对比 O(n)
const index = binarySearch(items, target);
// 良好:解释复杂的业务逻辑
// 如果用户成为会员超过2年且购买次数超过10次,则享受20%折扣(根据营销团队2024年第四季度决定)
if (user.memberYears >= 2 && user.purchaseCount >= 10) {
applyDiscount(0.2);
}
// 良好:记录变通方案
// 注意:Safari 不支持此 API,回退到轮询方式
// 待办:Safari 添加支持后移除(跟踪:webkit.org/b/12345)
if (!window.IntersectionObserver) {
startPolling();
}
// 不佳:陈述显而易见的事实
// 计数器加1
counter++;
// 不佳:解释清晰的代码
// 检查用户是否为管理员
if (user.role === 'admin') { ... }
// 不佳:过时的注释(比没有注释更糟)
// 返回用户的全名 <-- 实际上现在返回邮箱!
function getUserIdentifier(user) {
return user.email;
}
# ADR-001:使用 PostgreSQL 作为主数据库
## 状态
已接受
## 背景
我们需要一个数据库来存储用户数据和交易。
考虑的选项:PostgreSQL、MySQL、MongoDB、DynamoDB。
## 决策
使用 PostgreSQL 并托管在 Supabase。
## 理由
- 金融数据需要强 ACID 合规性
- 团队有 PostgreSQL 经验
- Supabase 提供认证和实时功能
- pgvector 扩展支持未来 AI 功能
## 后果
- 需要管理模式迁移
- 可能需要读取副本以扩展规模
- 团队需要学习 Supabase 特定功能
## 认证模块
### 概述
使用 JWT 令牌和刷新轮换机制处理用户认证。
### 流程
1. 用户提交凭证到 `/auth/login`
2. 服务器验证并返回访问令牌和刷新令牌
3. 访问令牌用于 API 请求(15分钟过期)
4. 刷新令牌用于获取新的访问令牌(7天过期)
### 依赖项
- `jsonwebtoken` - 令牌生成/验证
- `bcrypt` - 密码哈希
- `redis` - 刷新令牌存储
### 配置
- `JWT_SECRET` - 令牌签名密钥
- `ACCESS_TOKEN_EXPIRY` - 访问令牌有效期
- `REFRESH_TOKEN_EXPIRY` - 刷新令牌有效期
每周安装量
199
代码仓库
GitHub 星标数
953
首次出现
2026年1月20日
安全审计
安装于
opencode162
codex159
gemini-cli157
github-copilot142
cursor140
claude-code129
# Project Name
Brief description of what this project does.
## Quick Start
\`\`\`bash
npm install
npm run dev
\`\`\`
## Installation
Detailed installation instructions...
## Usage
\`\`\`typescript
import { something } from 'project';
// Example usage
const result = something.doThing();
\`\`\`
## API Reference
### `functionName(param: Type): ReturnType`
Description of what the function does.
**Parameters:**
- `param` - Description of parameter
**Returns:** Description of return value
**Example:**
\`\`\`typescript
const result = functionName('value');
\`\`\`
## Configuration
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `option1` | `string` | `'default'` | What it does |
## Contributing
How to contribute...
## License
MIT
/**
* Creates a new user account.
*
* @param userData - The user data for account creation
* @param options - Optional configuration
* @returns The created user object
* @throws {ValidationError} If email is invalid
* @example
* ```ts
* const user = await createUser({
* email: 'user@example.com',
* name: 'John'
* });
* ```
*/
async function createUser(
userData: UserInput,
options?: CreateOptions
): Promise<User> {
// Implementation
}
/**
* Configuration options for the API client.
*/
interface ClientConfig {
/** The API base URL */
baseUrl: string;
/** Request timeout in milliseconds @default 5000 */
timeout?: number;
/** Custom headers to include in requests */
headers?: Record<string, string>;
}
openapi: 3.0.0
info:
title: My API
version: 1.0.0
paths:
/users:
post:
summary: Create a user
description: Creates a new user account
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/UserInput'
responses:
'201':
description: User created successfully
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: Invalid input
components:
schemas:
UserInput:
type: object
required:
- email
- name
properties:
email:
type: string
format: email
name:
type: string
User:
type: object
properties:
id:
type: string
email:
type: string
name:
type: string
createdAt:
type: string
format: date-time
// GOOD: Explain WHY, not WHAT
// Use binary search because the list is always sorted and
// can contain millions of items - O(log n) vs O(n)
const index = binarySearch(items, target);
// GOOD: Explain complex business logic
// Users get 20% discount if they've been members for 2+ years
// AND have made 10+ purchases (per marketing team decision Q4 2024)
if (user.memberYears >= 2 && user.purchaseCount >= 10) {
applyDiscount(0.2);
}
// GOOD: Document workarounds
// HACK: Safari doesn't support this API, fallback to polling
// TODO: Remove when Safari adds support (tracking: webkit.org/b/12345)
if (!window.IntersectionObserver) {
startPolling();
}
// BAD: Stating the obvious
// Increment counter by 1
counter++;
// BAD: Explaining clear code
// Check if user is admin
if (user.role === 'admin') { ... }
// BAD: Outdated comments (worse than no comment)
// Returns the user's full name <-- Actually returns email now!
function getUserIdentifier(user) {
return user.email;
}
# ADR-001: Use PostgreSQL for Primary Database
## Status
Accepted
## Context
We need a database for storing user data and transactions.
Options considered: PostgreSQL, MySQL, MongoDB, DynamoDB.
## Decision
Use PostgreSQL with Supabase hosting.
## Rationale
- Strong ACID compliance needed for financial data
- Team has PostgreSQL experience
- Supabase provides auth and realtime features
- pgvector extension for future AI features
## Consequences
- Need to manage schema migrations
- May need read replicas for scale
- Team needs to learn Supabase-specific features
## Authentication Module
### Overview
Handles user authentication using JWT tokens with refresh rotation.
### Flow
1. User submits credentials to `/auth/login`
2. Server validates and returns access + refresh tokens
3. Access token used for API requests (15min expiry)
4. Refresh token used to get new access token (7d expiry)
### Dependencies
- `jsonwebtoken` - Token generation/validation
- `bcrypt` - Password hashing
- `redis` - Refresh token storage
### Configuration
- `JWT_SECRET` - Secret for signing tokens
- `ACCESS_TOKEN_EXPIRY` - Access token lifetime
- `REFRESH_TOKEN_EXPIRY` - Refresh token lifetime
Weekly Installs
199
Repository
GitHub Stars
953
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode162
codex159
gemini-cli157
github-copilot142
cursor140
claude-code129
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
111,800 周安装