Works with Factory App: These conventions work identically in both CLI and Factory App—Droid reads the same .factory/rules/ files regardless of interface.
## Coding StandardsFollow the conventions documented in `.factory/rules/`:- **TypeScript**: `.factory/rules/typescript.md`- **React**: `.factory/rules/react.md`- **Testing**: `.factory/rules/testing.md`- **API Design**: `.factory/rules/api.md`- **Security**: `.factory/rules/security.md`When working on a file, check the relevant rules first.
# TypeScript Rules## Type Definitions### Use `interface` for object shapes**Applies to**: All type definitions for objects**Rule**: Use `interface` for object types, `type` for unions, intersections, and primitives.```typescript// ✅ 正しいinterface User { id: string; name: string;}type Status = 'active' | 'inactive';type UserWithStatus = User & { status: Status };// ❌ 避けるtype User = { id: string; name: string;};
### Testing RulesCreate `.factory/rules/testing.md`:```markdown# Testing Rules## File Organization### Colocate test files**Applies to**: All tests except E2E**Rule**: Place test files next to source files.
### E2E tests in dedicated directory**Applies to**: End-to-end tests**Rule**: Place E2E tests in `e2e/` at project root.## Test Structure### Descriptive test names**Applies to**: All test cases**Rule**: Format as "should [action] when [condition]".```typescript// ✅ Correctit('should display error message when login fails', () => {});it('should redirect to dashboard when login succeeds', () => {});// ❌ Avoidit('login error', () => {});it('works', () => {});
### Security RulesCreate `.factory/rules/security.md`:```markdown# Security Rules## Secrets Management### Never hardcode secrets**Applies to**: All code**Rule**: Use environment variables for all secrets. Never commit secrets.```typescript// ✅ Correctconst apiKey = process.env.API_KEY;// ❌ Never do thisconst apiKey = 'sk-1234567890abcdef';
Applies to: API routes, form handlers
Rule: Use Zod to validate all input from users or external sources.
// ✅ Correctimport { z } from 'zod';const CreateUserSchema = z.object({ email: z.string().email(), name: z.string().min(1).max(100),});export async function createUser(input: unknown) { const data = CreateUserSchema.parse(input); // data is now typed and validated}
Reference in AGENTS.md:```markdown## Rules- Base rules: `.factory/rules/_base/` - Apply to all code- Frontend rules: `.factory/rules/frontend/` - React components- Backend rules: `.factory/rules/backend/` - API and services- Testing rules: `.factory/rules/testing/` - All tests
Currently, Droid doesn’t support conditional rule application based on file patterns (e.g., “apply these rules only to *.tsx files”). This is on the roadmap.
回避策:
ファイルタイプごとに整理: 別々のルールファイルを作成し、コンテキストに応じて参照する
# In AGENTS.mdWhen working on React components (*.tsx), follow `.factory/rules/react.md`When working on API routes, follow `.factory/rules/api.md`
ルールで明確なスコープを使用: 適用可能性を明確に述べる
## This rule applies to: React component files (*.tsx)
## ~~Use PropTypes for type checking~~ (DEPRECATED)**Status**: Deprecated as of 2024-02**Reason**: We now use TypeScript for all type checking**Replacement**: See TypeScript rules for prop typing