|
| 1 | +--- |
| 2 | +applyTo: '**' |
| 3 | +--- |
| 4 | + |
| 5 | +This repository ("on-the-edge") is a Deno TypeScript service implementing API routes and application logic for AniTrend. The codebase is organized under `src/` and contains core infrastructure (logging, OTEL), middleware, feature experiments, and domain modules such as `news` and `series` with sources, repositories, services, transformers, and tests. |
| 6 | + |
| 7 | +When creating, editing, or reviewing code, follow these rules strictly: |
| 8 | + |
| 9 | + |
| 10 | +## 1. Project Overview |
| 11 | +This repository, "on-the-edge", is a Deno TypeScript service for AniTrend. It implements API routes, application logic, and domain features in a modular structure, leveraging core infrastructure like logging and distributed tracing. |
| 12 | + |
| 13 | +## 2. Repository Structure |
| 14 | +Key files and folders: |
| 15 | +- `deno.json`, `deno.lock` |
| 16 | + - Deno configurations and lockfile. Use Deno CLI for execution, tests, and formatting by default. |
| 17 | +- `src/server.ts`, `src/routes.ts` |
| 18 | + - Entry points for server bootstrap and route definitions. |
| 19 | +- `src/common/` |
| 20 | + - Shared core: environment loading, logging, OTEL tracing, middleware, MongoDB factory. |
| 21 | +- `src/config/` |
| 22 | + - Configuration sources, repository, and transformers for environment-based settings. |
| 23 | +- `src/news/`, `src/series/` |
| 24 | + - Domain feature modules organized into controller, service, repository, transformer, and local source. |
| 25 | + |
| 26 | +Prompting and code generation conventions |
| 27 | +- When the user asks for changes, produce a short checklist of requirements derived from the request and proceed only after creating a todo list entry. |
| 28 | +- Make one logical change per patch. If multiple files must be changed, group them into a single pull request with a descriptive title and a short summary. |
| 29 | + |
| 30 | +## 3. AI Coding Guidelines |
| 31 | +When creating, editing, or reviewing code, follow these rules strictly: |
| 32 | +1. Use Deno and TypeScript best practices: |
| 33 | + - `async/await`, explicit public API types, single-purpose functions. |
| 34 | +2. Maintain project structure and naming: |
| 35 | + - Follow existing patterns (`*.service.ts`, `*.repository.ts`, etc.). |
| 36 | +3. Keep patches minimal: |
| 37 | + - Focus on requested changes; avoid unrelated refactors. |
| 38 | +4. Add dependencies sparingly: |
| 39 | + - Use URL-based imports, document additions in `deno.json`. |
| 40 | +5. Write tests alongside logic: |
| 41 | + - Deno test utilities; small, fast, deterministic. |
| 42 | +6. Follow error-handling and logging patterns: |
| 43 | + - Use `error.ts` middleware, structured logs via `logger.ts`. |
| 44 | +7. Handle configuration securely: |
| 45 | + - Load via `env.ts`, use factories, never hard-code secrets. |
| 46 | + |
| 47 | +- For any code edits, run quick validation steps: `deno fmt`, `deno lint` and `deno test` (targeted to changed files when possible). Report pass/fail. |
| 48 | + |
| 49 | +## 4. Prompting Conventions |
| 50 | +1. Derive a checklist of requirements from user requests; log tasks via todo lists. |
| 51 | +2. Apply one logical change per patch; group multi-file updates in a single PR with summary. |
| 52 | +3. Validate edits with `deno fmt`, `deno lint`, `deno test --filter` and report outcomes. |
| 53 | +4. Include unit tests (happy path + edge case) for new behaviors. |
| 54 | + |
| 55 | + |
| 56 | +## 5. Quality Gates |
| 57 | +- **Build**: run `deno cache` after adding dependencies. |
| 58 | +- **Lint/Format**: run `deno fmt` and `deno lint`. |
| 59 | +- **Tests**: run `deno test --filter <module>`; ensure coverage for changes. |
| 60 | + |
| 61 | +------------ |
| 62 | +## 6. Assumptions |
| 63 | +- Default to Deno CLI (`deno run --allow-net ...`) if runtime unspecified. |
| 64 | +- Assume environment vars are managed externally (Docker, Compose, CI). |
| 65 | +- For new config, prefer `src/config` and `deno.json` updates. |
| 66 | + |
| 67 | +- Lint/Format: run `deno fmt` and `deno lint`. |
| 68 | + |
| 69 | +## 7. Security & Safety |
| 70 | +- Never read or write into `env` instead use `.env.defaults` |
| 71 | +- Do not commit secrets; use `env.ts` and document required variables. |
| 72 | +- Avoid outbound network calls in tests; use fakes or injected clients. |
| 73 | + |
| 74 | + |
| 75 | +## 8. Developer Communication |
| 76 | +- Update `README.md` or add docs for public API changes. |
| 77 | +- For refactors, open a draft PR with motivation and risk analysis. |
| 78 | + |
| 79 | +------------------------------------------------ |
| 80 | +## 9. Example Workflows |
| 81 | +- **Add a new domain service**: |
| 82 | + 1. Create `src/<domain>/service/<name>.service.ts` and test file. |
| 83 | + 2. Export in module `index.ts` and update mappings. |
| 84 | + 3. Implement repository/transformer as needed. |
| 85 | + 4. Run `deno test` for new files. |
| 86 | +- **Fix a failing test**: |
| 87 | + 1. Run `deno test --filter <name>`. |
| 88 | + 2. Apply minimal code change and update tests. |
| 89 | + 3. Run `deno fmt` & `deno lint` before commit. |
| 90 | + |
| 91 | +- If adding configuration, prefer adding to `src/config` and `deno.json` rather than top-level changes. |
| 92 | + |
| 93 | +## 10. References |
| 94 | +- OTEL & tracing: `src/common/core/otel.ts`. |
| 95 | +- Logging: `src/common/core/logger.ts`. |
| 96 | +- Domain examples: `src/news`, `src/series`. |
| 97 | +- Error Handling: A centralized error middleware in `src/common/middleware/error.ts` handles exceptions. |
| 98 | + |
| 99 | +Security and safety |
| 100 | +------------------- |
| 101 | +- Do not include secrets or credentials in repo changes. Use `env.ts` and document required env variables. |
| 102 | +- Avoid outbound network calls in unit tests. Use small, deterministic fakes or inject remote clients. |
| 103 | + |
| 104 | +Developer communication |
| 105 | +----------------------- |
| 106 | +- When changes touch behavior or public APIs, update `README.md` or add a short `docs/` note explaining the change and how to test locally. |
| 107 | +- For larger refactors, create a draft PR with a clear summary, motivation, and risk assessment. |
| 108 | + |
| 109 | +Example workflows for common tasks |
| 110 | +--------------------------------- |
| 111 | +- Add a new domain service: |
| 112 | + 1. Create `src/<domain>/service/<name>.service.ts` alongside tests in the same folder. |
| 113 | + 2. Wire it into the domain `index.ts` and export from the module. |
| 114 | + 3. Add or update any repository/transformer files as needed. |
| 115 | + 4. Write tests and run `deno test` for the new files. |
| 116 | + |
| 117 | +- Fix a failing test: |
| 118 | + 1. Run `deno test --filter <test-name>` and inspect failure. |
| 119 | + 2. Make minimal code change with accompanying unit test update. |
| 120 | + 3. Run `deno fmt` and `deno lint` before committing. |
| 121 | + |
| 122 | +Contact and context references |
| 123 | +------------------------------ |
| 124 | +- The codebase uses OTEL and structured logging — consult `src/common/core/otel.ts` and `src/common/core/logger.ts` for tracing and logging patterns. |
| 125 | +- Look at existing domain implementations (e.g., `src/news`, `src/series`) as reference for new modules. |
0 commit comments