Add gitignore rules for browser session data, SQLite databases, media downloads, and build artifacts. Remove previously tracked runtime files from the repository. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1.9 KiB
1.9 KiB
Agent Guidelines & Code Standards
Refactoring Goal
Refactor code to improve maintainability, testability, and clarity. Break down large components into smaller, single-purpose classes/modules.
Engineering Standards
1. Single Responsibility Principle (SRP)
- Avoid "God Classes" (e.g., massive
Serviceclasses that do everything). - Extract logic into dedicated handlers, managers, or utilities.
- Example: Instead of one
BotServicehandling login, monitoring, and messaging, split intoAuthService,MonitorService, andMessagingService.
2. Design Patterns
- Dependency Injection: Pass dependencies via constructors. This makes swapping implementations (e.g., for testing) easier.
- Factory Pattern: Use factories for creating complex objects (e.g., configuring different AI models).
- Strategy Pattern: Good for interchangeable algorithms (e.g., differentsubreddit selection strategies).
3. TypeScript Best Practices
- Strict Typing: No
any. Define interfaces/types for all data structures (especially API/Reddit responses). - Zod Validation: Use
zod(already in deps) to validate external data (config files, API responses). - Async/Await: properly handle promises. Use
p-queueorp-retryfor rate-limited operations.
4. Project Specifics
- Tech Stack: Node.js, TypeScript, Playwright, Express, SQLite.
- Directories:
src/services/for business logic.src/web/for Express server and UI.src/browser/for Playwright interactions.
- Logging: Use
winstonfor structured logging. Do not useconsole.login production code.
Workflow for Agents
- Analyze: Before writing code, read the file and understand the context.
- Plan: Identify what needs to change. Check if the change violates SRP.
- Refactor: Create new files if necessary. Don't be afraid to create new small files.
- Verify: Ensure types check out (
npm run buildortsc).