api-custom-repositories

api-custom-repositories is a cursor rule for Cursor from bayesimpact/bayes-platform. It costs 0 tokens per session (686 once invoked), scanned A, original, MIT.

A NestJS code rule requiring services to use custom repository classes for database access instead of depending directly on TypeORM. TypeORM is a library that maps application code to database records.

In plain words
What is it for?
Use it when adding or reviewing NestJS services, repositories, modules, and transaction-scoped database access. It enforces a pattern for creating repository methods and registering them with NestJS.
Why use it?
It keeps database details out of service code and limits each service to named operations designed for the application. This makes the boundary between business logic and persistence clearer.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/. Also seen: reads .claude/ paths.

Good fit Use it when adding or reviewing NestJS services, repositories, modules, and transaction-scoped database access. It enforces a pattern for creating repository methods and registering them with NestJS.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/bayesimpact/bayes-platform/api-custom-repositories
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/bayesimpact/bayes-platform

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for api-custom-repositories

README.md
[![agentmods](https://agentmods.dev/badge/rules/bayesimpact/bayes-platform/api-custom-repositories/github.svg)](https://agentmods.dev/rules/bayesimpact/bayes-platform/api-custom-repositories)
Your own site
<a href="https://agentmods.dev/rules/bayesimpact/bayes-platform/api-custom-repositories"><img src="https://agentmods.dev/badge/rules/bayesimpact/bayes-platform/api-custom-repositories/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for api-custom-repositories

Your own site · 80×15
<a href="https://agentmods.dev/rules/bayesimpact/bayes-platform/api-custom-repositories"><img src="https://agentmods.dev/badge/rules/bayesimpact/bayes-platform/api-custom-repositories.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 686 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.00686
Opus 5.5 $0.00000 $0.00274
Sonnet 5.5 $0.00000 $0.00137
Haiku 4.5 $0.00000 $0.00069

Measured 1mo ago against content hash 9e8ad2a9f385, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

api-custom-repositories scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/api-custom-repositories.mdc · 65 lines

How it starts

The opening of the file, as written. The whole thing — 65 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Custom Repositories — No TypeORM in Services

How to add a repository: .claude/skills/custom-repository/SKILL.md and ADR 0020.

Rule: Services MUST NOT depend on TypeORM. All persistence goes through a custom {Entity}Repository that exposes only the methods the service needs.

Forbidden in services

  • import ... from "typeorm" or @nestjs/typeorm
  • @InjectRepository(...) / Repository<T>
  • TypeORM query APIs (find, findOne, save, create, In(), query builders)
  • Constructing ConnectRepository (it wraps TypeORM Repository<T>)

Required pattern

  1. Add {entity}.repository.ts as an @Injectable() Nest provider.
  2. Inject TransactionService and get the TypeORM repo inside the custom repository (getManager().getRepository(Entity)).
  3. Expose named methods only (createProject, findAllByIds, softDelete). Do not leak TypeORM types in the public API.
  4. Inject the custom repository into the service. Register it in the module providers (and exports if other modules need it).
  5. For connect-scoped entities, keep ConnectRepository inside the custom repository. The service passes connectScope into named methods.
  6. A caller-supplied id of a connect-scoped row (parentId, tagsToAdd, a target, a link) is loaded with that connectScope. findOneBy({ id }) or findBy({ id: In(ids) }) is not an existence check, including when the caller is another service. Every requested id must be in that organization and project. Missing, another project, and another organization are the same 404. A parent id cannot be the row itself or a descendant.
// ✅ Service — no TypeORM
@Injectable()
export class PlatformRoleService {
  constructor(private readonly platformRoleRepository: PlatformRoleRepository) {}

  grantGlobalRole(userId: string, roleKey: PlatformRoleKey): Promise<boolean> {
    return this.platformRoleRepository.grantGlobalRole(userId, roleKey)
  }
}

// ✅ Custom repository — TypeORM stays here
@Injectable()
export class ProjectRepository {
  constructor(private readonly transactionService: TransactionService) {}

  async createProject(params: { organizationId: string; name: string }): Promise<ProjectRecord> {
    const saved = await this.repo().save(this.repo().create(params))
    return this.toRecord(saved)
  }

  private repo(): Repository<Project> {
    return this.transactionService.getManager().getRepository(Project)
  }
}

Read the full file on GitHub · 65 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago Changed · +1 lines 9e8ad2a9f385
  2. 1mo ago Changed · +2 lines 5c56ef77f01b
  3. 1mo ago First seen · 62 lines · 0 tokens per session scan A 6e5ec3bd1f68

Subscribe to this mod's changes

api-custom-repositories is a cursor rule published in the GitHub repository bayesimpact/bayes-platform (23 stars, last pushed yesterday), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 686 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-24.

Related

api-custom-repositories compared with cursor rules from other repositories

api-custom-repositories next to 6 cursor rules from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
api-custom-repositoriesbayesimpact/bayes-platformCursor rule23yesterdayMITA0Cursor
vibes-plug-backendroedyrustam/vibes-plugCursor rule121yesterdayMITA0Cursor
ehs-ims-conventionsSafetyMP/Autonomous-EHS-ManagementCursor rule96d agoApache-2.0A722Cursor
rulesforconvexwaynesutton/markdown-siteCursor rule6275mo agoMITA514Cursor
startup-migration-bounded-workTACC/HPCPerfStatsCursor rule60yesterdayLGPL-2.1A0Cursor
convex-development---generalWebDevPeterGriffin/The-VibeCode-BibleCursor rule422d agononeA84Cursor
redis_rate_limitingjondoescoding/jondoescoding-coding-rulesCursor rule23mo agoMITA15Cursor