skills/aif-best-practices/SKILL.md
Code quality guidelines and best practices for writing clean, maintainable code. Covers naming, structure, error handling, testing, and code review standards. Use when writing code, reviewing, refactoring, or asking "how should I name this", "best practice for", "clean code".
npx skillsauth add lee-to/ai-factory aif-best-practicesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Universal code quality guidelines applicable to any language or framework.
Context: If .ai-factory/ARCHITECTURE.md exists, follow its folder structure, dependency rules, and module boundaries alongside these guidelines.
Read .ai-factory/skill-context/aif-best-practices/SKILL.md — MANDATORY if the file exists.
This file contains project-specific rules accumulated by /aif-evolve from patches,
codebase conventions, and tech-stack analysis. These rules are tailored to the current project.
How to apply skill-context rules:
Enforcement: After generating any output artifact, verify it against all skill-context rules. If any rule is violated — fix the output before presenting it to the user.
/aif-best-practices — Full overview/aif-best-practices naming — Naming conventions/aif-best-practices structure — Code organization/aif-best-practices errors — Error handling/aif-best-practices testing — Testing practices/aif-best-practices review — Code review checklist✅ Good ❌ Bad
─────────────────────────────────────────────
getUserById(id) getUser(i)
isValidEmail checkEmail
maxRetryCount max
calculateTotalPrice calc
handleSubmit submit
Rules:
id, url, api)is, has, can, should prefixfetchUser, validateInput)✅ Good ❌ Bad
─────────────────────────────────────────────
user-service.ts userService.ts (inconsistent)
UserRepository.ts user_repository.ts (mixed)
/components/Button/ /Components/button/
/services/auth/ /Services/Auth/
Rules:
*.test.ts or *.spec.ts (consistent)// ✅ Good: Single responsibility, clear inputs/outputs
function calculateDiscount(price: number, discountPercent: number): number {
if (discountPercent < 0 || discountPercent > 100) {
throw new Error('Discount must be between 0 and 100');
}
return price * (1 - discountPercent / 100);
}
// ❌ Bad: Multiple responsibilities, side effects
function processOrder(order) {
validateOrder(order); // validation
order.discount = getDiscount(); // mutation
saveToDatabase(order); // persistence
sendEmail(order.user); // notification
return order;
}
// ✅ Good: PHP with type declarations
function calculateDiscount(float $price, float $discountPercent): float
{
if ($discountPercent < 0 || $discountPercent > 100) {
throw new InvalidArgumentException('Discount must be between 0 and 100');
}
return $price * (1 - $discountPercent / 100);
}
Rules:
feature/
├── index.ts # Public exports only
├── types.ts # Types and interfaces
├── constants.ts # Constants
├── utils.ts # Pure utility functions
├── hooks.ts # React hooks (if applicable)
├── service.ts # Business logic
└── repository.ts # Data access
Rules:
_ or in internal/// ✅ Good: Specific errors, meaningful messages
class UserNotFoundError extends Error {
constructor(userId: string) {
super(`User not found: ${userId}`);
this.name = 'UserNotFoundError';
}
}
async function getUser(id: string): Promise<User> {
const user = await db.users.find(id);
if (!user) {
throw new UserNotFoundError(id);
}
return user;
}
// ❌ Bad: Generic errors, swallowed exceptions
async function getUser(id) {
try {
return await db.users.find(id);
} catch (e) {
console.log(e); // Swallowed!
return null; // Hides the problem
}
}
Rules:
✅ Good: "Failed to create user: email '[email protected]' already exists"
❌ Bad: "Error occurred"
❌ Bad: "Something went wrong"
describe('calculateDiscount', () => {
it('should apply percentage discount to price', () => {
// Arrange
const price = 100;
const discount = 20;
// Act
const result = calculateDiscount(price, discount);
// Assert
expect(result).toBe(80);
});
it('should throw for invalid discount percentage', () => {
expect(() => calculateDiscount(100, -10)).toThrow();
expect(() => calculateDiscount(100, 150)).toThrow();
});
});
Rules:
1. Critical business logic ████████████ Must have
2. Edge cases and boundaries ████████░░░░ Important
3. Integration points ██████░░░░░░ Important
4. Happy paths ████░░░░░░░░ Basic
5. UI components ██░░░░░░░░░░ Optional
/aif-security-checklist)✅ Good feedback:
"This could throw if `user` is null. Consider adding a null check
or using optional chaining: `user?.profile?.name`"
❌ Bad feedback:
"This is wrong"
"I don't like this"
"Why did you do it this way?"
| Area | Rule | |------|------| | Naming | Descriptive, consistent, reveals intent | | Functions | Small, single purpose, no side effects | | Errors | Specific types, never swallow, log context | | Tests | AAA pattern, test behavior, descriptive names | | Reviews | Be specific, suggest solutions, be kind |
.ai-factory/ARCHITECTURE.md, and skill-context overrides instead of reading config.yaml.data-ai
Archive completed plans and roadmap milestones. Moves finished plans to the archive directory and optionally trims closed milestones from ROADMAP.md. Use when user says "archive plans", "clean up plans", "archive completed", or "trim roadmap".
tools
Set up agent context for a project. Analyzes tech stack, installs relevant skills from skills.sh, generates custom skills, and configures MCP servers. Use when starting new project, setting up AI context, or asking "set up project", "configure AI", "what skills do I need".
development
Verify completed implementation against the plan. Checks that all tasks were fully implemented, nothing was forgotten, code compiles, tests pass, and quality standards are met. Use after "/aif-implement" completes, or when user says "verify", "check work", "did we miss anything".
data-ai
Plan implementation for a feature or task. Two modes — fast (single quick plan) or full (richer plan with optional git branch/worktree flow). Use when user says "plan", "new feature", "start feature", "create tasks".