xiaohongshu
xiaohongshu
feature-generator
React Native Feature 模块生成指南。当用户提到"创建 feature"、"新建模块"、"生成功能"、"添加功能模块"、"feature 模板"时使用此 skill。
Full skill instructions
在 comet CLI 落地前,本指南提供手动创建符合设计规范的 feature 模块的完整流程。
# 创建目录结构
mkdir -p src/features/<feature-name>/{presentation/{screens,components,stores},domain/{entities,repositories},data/{datasources,repositories}}
# 创建测试目录
mkdir -p __tests__/features/<feature-name>/{presentation,domain,data}
mkdir -p src/features/<feature-name>/presentation/{screens,components,stores}
mkdir -p __tests__/features/<feature-name>/presentation
src/features/<feature-name>/
presentation/
screens/
<FeatureName>Screen.tsx # 页面组件
components/
<FeatureName>View.tsx # 纯展示组件
<OtherComponent>.tsx # 其他 UI 组件
stores/
use<FeatureName>Store.ts # Zustand Store
hooks/
use<FeatureName>Query.ts # TanStack Query(可选)
domain/
entities/
<featureName>.ts # 实体类型定义
repositories/
<featureName>Repository.ts # 仓库接口
data/
datasources/
<FeatureName>RemoteDataSource.ts # 远程数据源
<FeatureName>LocalDataSource.ts # 本地数据源(可选)
repositories/
<FeatureName>RepositoryImpl.ts # 仓库实现
presentation/screens/<FeatureName>Screen.tsx
import React from 'react';
import {View, Text} from 'react-native';
// import {use<FeatureName>Store} from '../stores/use<FeatureName>Store';
type Props = {
// navigation props if needed
};
export function <FeatureName>Screen({}: Props) {
// const {state, action} = use<FeatureName>Store();
return (
<View className="flex-1 items-center justify-center">
<Text><FeatureName> Screen</Text>
</View>
);
}
presentation/components/<FeatureName>View.tsx
import React from 'react';
import {View, Text} from 'react-native';
type Props = {
// view props
};
export function <FeatureName>View({}: Props) {
return (
<View>
<Text><FeatureName> View</Text>
</View>
);
}
presentation/stores/use<FeatureName>Store.ts
import {create} from 'zustand';
type <FeatureName>State = {
// state
isLoading: boolean;
error: string | null;
// actions
setLoading: (loading: boolean) => void;
setError: (error: string | null) => void;
reset: () => void;
};
const initialState = {
isLoading: false,
error: null,
};
export const use<FeatureName>Store = create<<FeatureName>State>((set) => ({
...initialState,
setLoading: (isLoading) => set({isLoading}),
setError: (error) => set({error}),
reset: () => set(initialState),
}));
presentation/hooks/use<FeatureName>Query.ts
import {useQuery, useMutation, useQueryClient} from '@tanstack/react-query';
// import {<featureName>Repository} from '../../domain/repositories/<featureName>Repository';
export const <featureName>Keys = {
all: ['<featureName>'] as const,
lists: () => [...<featureName>Keys.all, 'list'] as const,
list: (filters: string) => [...<featureName>Keys.lists(), {filters}] as const,
details: () => [...<featureName>Keys.all, 'detail'] as const,
detail: (id: string) => [...<featureName>Keys.details(), id] as const,
};
export function use<FeatureName>ListQuery() {
return useQuery({
queryKey: <featureName>Keys.lists(),
queryFn: async () => {
// return <featureName>Repository.getList();
return [];
},
});
}
export function use<FeatureName>DetailQuery(id: string) {
return useQuery({
queryKey: <featureName>Keys.detail(id),
queryFn: async () => {
// return <featureName>Repository.getById(id);
return null;
},
enabled: !!id,
});
}
domain/entities/<featureName>.ts
// Domain entity - pure TypeScript, no RN dependencies
export type <FeatureName> = {
id: string;
// other properties
createdAt: Date;
updatedAt: Date;
};
export type Create<FeatureName>Input = Omit<<FeatureName>, 'id' | 'createdAt' | 'updatedAt'>;
export type Update<FeatureName>Input = Partial<Create<FeatureName>Input>;
domain/repositories/<featureName>Repository.ts
import type {<FeatureName>, Create<FeatureName>Input, Update<FeatureName>Input} from '../entities/<featureName>';
export type <FeatureName>Repository = {
getAll(): Promise<<FeatureName>[]>;
getById(id: string): Promise<<FeatureName> | null>;
create(input: Create<FeatureName>Input): Promise<<FeatureName>>;
update(id: string, input: Update<FeatureName>Input): Promise<<FeatureName>>;
delete(id: string): Promise<void>;
};
data/datasources/<FeatureName>RemoteDataSource.ts
import type {<FeatureName>, Create<FeatureName>Input, Update<FeatureName>Input} from '../../domain/entities/<featureName>';
// import {httpClient} from '@/core/network/httpClient';
export type <FeatureName>RemoteDataSource = {
fetchAll(): Promise<<FeatureName>[]>;
fetchById(id: string): Promise<<FeatureName> | null>;
create(input: Create<FeatureName>Input): Promise<<FeatureName>>;
update(id: string, input: Update<FeatureName>Input): Promise<<FeatureName>>;
delete(id: string): Promise<void>;
};
export function create<FeatureName>RemoteDataSource(): <FeatureName>RemoteDataSource {
const BASE_PATH = '/<feature-name>s';
return {
async fetchAll() {
// const response = await httpClient.get<{data: <FeatureName>[]}>(BASE_PATH);
// return response.data.data;
return [];
},
async fetchById(id) {
// const response = await httpClient.get<{data: <FeatureName>}>(`${BASE_PATH}/${id}`);
// return response.data.data;
return null;
},
async create(input) {
// const response = await httpClient.post<{data: <FeatureName>}>(BASE_PATH, input);
// return response.data.data;
throw new Error('Not implemented');
},
async update(id, input) {
// const response = await httpClient.patch<{data: <FeatureName>}>(`${BASE_PATH}/${id}`, input);
// return response.data.data;
throw new Error('Not implemented');
},
async delete(id) {
// await httpClient.delete(`${BASE_PATH}/${id}`);
},
};
}
data/repositories/<FeatureName>RepositoryImpl.ts
import type {<FeatureName>Repository} from '../../domain/repositories/<featureName>Repository';
import type {<FeatureName>RemoteDataSource} from '../datasources/<FeatureName>RemoteDataSource';
export function create<FeatureName>Repository(
remoteDataSource: <FeatureName>RemoteDataSource
): <FeatureName>Repository {
return {
async getAll() {
return remoteDataSource.fetchAll();
},
async getById(id) {
return remoteDataSource.fetchById(id);
},
async create(input) {
return remoteDataSource.create(input);
},
async update(id, input) {
return remoteDataSource.update(id, input);
},
async delete(id) {
return remoteDataSource.delete(id);
},
};
}
app/navigation/routes.ts
export const AppRoutes = {
// ... existing routes
<FeatureName>: '<FeatureName>',
} as const;
export type RootStackParamList = {
// ... existing params
<FeatureName>: undefined; // 或 { id: string } 等参数
};
app/navigation/RootNavigator.tsx
import {<FeatureName>Screen} from '@/features/<feature-name>/presentation/screens/<FeatureName>Screen';
// 在 Stack.Navigator 中添加
<Stack.Screen name="<FeatureName>" component={<FeatureName>Screen} />
__tests__/features/<feature-name>/presentation/use<FeatureName>Store.test.ts
import {use<FeatureName>Store} from '@/features/<feature-name>/presentation/stores/use<FeatureName>Store';
describe('use<FeatureName>Store', () => {
beforeEach(() => {
use<FeatureName>Store.getState().reset();
});
it('should initialize with default state', () => {
const state = use<FeatureName>Store.getState();
expect(state.isLoading).toBe(false);
expect(state.error).toBeNull();
});
it('should update loading state', () => {
use<FeatureName>Store.getState().setLoading(true);
expect(use<FeatureName>Store.getState().isLoading).toBe(true);
});
it('should reset to initial state', () => {
use<FeatureName>Store.getState().setLoading(true);
use<FeatureName>Store.getState().setError('test error');
use<FeatureName>Store.getState().reset();
const state = use<FeatureName>Store.getState();
expect(state.isLoading).toBe(false);
expect(state.error).toBeNull();
});
});
__tests__/features/<feature-name>/presentation/<FeatureName>Screen.test.tsx
import React from 'react';
import {render, screen} from '@testing-library/react-native';
import {<FeatureName>Screen} from '@/features/<feature-name>/presentation/screens/<FeatureName>Screen';
describe('<FeatureName>Screen', () => {
it('should render correctly', () => {
render(<<FeatureName>Screen />);
expect(screen.getByText(/<FeatureName>/i)).toBeTruthy();
});
});
| 类型 | 命名格式 | 文件名 | 示例 |
|---|---|---|---|
| Feature 目录 | kebab-case | - | user-profile/ |
| Screen | <FeatureName>Screen | <FeatureName>Screen.tsx | UserProfileScreen.tsx |
| View | <FeatureName>View | <FeatureName>View.tsx | UserProfileView.tsx |
| Store | use<FeatureName>Store | use<FeatureName>Store.ts | useUserProfileStore.ts |
| Query Hook | use<FeatureName>Query | use<FeatureName>Query.ts | useUserProfileQuery.ts |
| Entity | <FeatureName> | <featureName>.ts | userProfile.ts |
| Repository | <FeatureName>Repository | <featureName>Repository.ts | userProfileRepository.ts |
| DataSource | <FeatureName>RemoteDataSource | <FeatureName>RemoteDataSource.ts | UserProfileRemoteDataSource.ts |
| RepositoryImpl | <FeatureName>RepositoryImpl | <FeatureName>RepositoryImpl.ts | UserProfileRepositoryImpl.ts |
presentation ──► domain ◄── data
│ │ │
│ │ │
▼ │ ▼
core/* │ core/network
(UI, theme) │ core/storage
│
纯 TypeScript
(无 RN 依赖)
| 层级 | 可依赖 | 禁止依赖 |
|---|---|---|
presentation/ | domain/、core/、React/RN | 其他 feature 的 store/组件 |
domain/ | 纯 TypeScript 类型 | react-native、UI 包、data/ |
data/ | domain/ 接口、core/network | presentation/ |
创建 feature 时,建议通过子代理执行以确保一致性:
Task({
subagent_type: 'general-purpose',
description: '创建 user-profile feature',
prompt: `按照 .claude/skills/feature-generator/SKILL.md 创建完整的 user-profile feature,包含三层架构`,
});
创建 Feature 时的检查清单:
presentation/domain/data)xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience