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>
35 lines
1.9 KiB
Markdown
35 lines
1.9 KiB
Markdown
# 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 `Service` classes that do everything).
|
|
- Extract logic into dedicated handlers, managers, or utilities.
|
|
- **Example**: Instead of one `BotService` handling login, monitoring, and messaging, split into `AuthService`, `MonitorService`, and `MessagingService`.
|
|
|
|
### 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-queue` or `p-retry` for 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 `winston` for structured logging. Do not use `console.log` in production code.
|
|
|
|
## Workflow for Agents
|
|
1. **Analyze**: Before writing code, read the file and understand the context.
|
|
2. **Plan**: Identify what needs to change. Check if the change violates SRP.
|
|
3. **Refactor**: Create new files if necessary. Don't be afraid to create new small files.
|
|
4. **Verify**: Ensure types check out (`npm run build` or `tsc`).
|