Guidance for AI coding agents working in this repository.
This project is a NestJS + Fastify API that normalizes responses across multiple Booru providers using @alejandroakbal/universal-booru-wrapper.
For product/context details, read:
Prerequisites:
- Node 24 (see
package.jsonengines) - Access to GitHub Packages for private dependency installation (see DOCUMENTATION.md)
Install and run:
corepack enablepnpm installpnpm dev(watch mode)pnpm buildpnpm start(runs compileddist/main)
Quality checks:
pnpm lintpnpm formatpnpm test
Key files:
- App bootstrap: src/main.ts
- Root module/providers: src/app.module.ts
- API root controller: src/app.controller.ts
- Booru module wiring: src/booru/booru.module.ts
- Booru endpoints: src/booru/booru.controller.ts
- Booru API construction: src/booru/booru.service.ts
- Error mapping/sanitization: src/booru/interceptors/booru-exception.interceptor.ts
- Auth credential management: src/booru/services/booru-auth-manager.service.ts
- Response envelope and links: src/lib/dto/response.dto.ts
- Validation pipe defaults: src/common/validation.ts
High-level flow:
- Controller validates params/query DTOs and builds a provider API instance via
BooruService. - Service maps endpoint/query/auth options into the wrapper API constructor.
- Controller calls wrapper methods (
getPosts,getRandomPosts,getSinglePost,getTags). - Interceptor converts wrapper errors into Nest HTTP exceptions and sanitizes sensitive URL params.
ResponseDtoshapes payload, pagination metadata, and navigation links.
- Keep request contracts in DTO classes under
src/booru/dto/withclass-validator+class-transformer. - Respect global validation behavior from
createAppValidationPipe():transform: truewhitelist: trueforbidNonWhitelisted: true
- Prefer adding behavior in services/interceptors over bloating controllers.
- Preserve response shape generated by
ResponseDtounless API contract changes are explicitly requested. - For booru auth data, keep sanitization behavior aligned with:
SENSITIVE_AUTH_PARAMS- URL/key-value redaction in auth/interceptor services.
- Unit tests use Jest +
@nestjs/testing. - Keep test files as
*.spec.tsnear the implementation (existing repo pattern). - Update/add tests when modifying:
- DTO validation behavior
- Error mapping/sanitization
- Response structure (
meta,links)
Reference tests:
- src/booru/booru.service.spec.ts
- src/booru/dto/booru-queries.dto.spec.ts
- src/booru/interceptors/booru-exception.interceptor.spec.ts
- src/booru/services/booru-auth-manager.service.spec.ts
- src/lib/dto/response.dto.spec.ts
- Do not assume private package install works without GitHub Packages login.
- Do not leak
auth_user,auth_pass, API keys, or equivalent credentials in errors/logs. - Be careful when refactoring
pageIDhandling inbooru.controller.tsandResponseDto; existing code uses@ts-ignorein several places. - Keep Fastify/Nest bootstrap behavior intact unless requested (Sentry init, CORS policy, static serving, global validation pipe, clustering).
Before finishing a change:
- Run
pnpm lintandpnpm testif dependencies are installed. - If DTOs changed, verify validation and query transforms with tests.
- If error/auth logic changed, verify sanitization and auth failure handling paths.
- If response generation changed, validate
metaandlinksoutputs.