Organize coding standards and team conventions so Droid follows them consistently across all work.
Rules are codified standards that Droid follows every time. Unlike memories (which capture decisions and context), rules define how code should be written. This guide shows you how to organize rules effectively for individuals and teams.
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// ✅ Correctinterface User { id: string; name: string;}type Status = 'active' | 'inactive';type UserWithStatus = User & { status: Status };// ❌ Avoidtype 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.
Copy
// ✅ 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.
Workarounds:
Organize by file type: Create separate rules files and reference them contextually
Copy
# In AGENTS.mdWhen working on React components (*.tsx), follow `.factory/rules/react.md`When working on API routes, follow `.factory/rules/api.md`
Use clear scoping in rules: State applicability clearly
Copy
## This rule applies to: React component files (*.tsx)
Use skills for complex workflows: Skills can encode file-type-specific instructions
## ~~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