Skip to content

docs: add repository method conventions to knowledge base#24443

Merged
eunjae-lee merged 3 commits into
mainfrom
devin/repository-conventions-1760429297
Oct 15, 2025
Merged

docs: add repository method conventions to knowledge base#24443
eunjae-lee merged 3 commits into
mainfrom
devin/repository-conventions-1760429297

Conversation

@hariombalhara
Copy link
Copy Markdown
Member

What does this PR do?

This PR adds a comprehensive "Repository Method Conventions" section to the .agents/knowledge-base.md file. The conventions provide guidance on:

  1. Concise method naming: Avoid redundancy by not repeating the entity name (e.g., findById instead of findBookingById)
  2. Explicit relation inclusion: Use keywords like include, with, or andRelations when fetching related data (e.g., findByIdIncludeHosts)
  3. Generic, reusable methods: Avoid use-case-specific names in favor of descriptive, general-purpose methods
  4. Separation of concerns: Keep business logic in Services, not Repositories

Each convention includes clear examples showing both good and bad patterns.

Context: These conventions were requested to establish consistency in repository patterns across the codebase.

Session URL: https://app.devin.ai/sessions/c3e3e2d687214883855cd44f4dd00953
Requested by: @hariombalhara (hariom@cal.com)

Visual Demo

N/A - Documentation only change.

Mandatory Tasks

  • I have self-reviewed the code
  • I have updated the developer docs - this PR updates the knowledge base documentation
  • N/A - No automated tests needed for documentation changes

How should this be tested?

No testing required - this is a documentation-only change. However, reviewers should:

  1. Verify these conventions align with the team's coding standards
  2. Check if existing repositories in the codebase follow these patterns
  3. Confirm the examples are accurate representations of desired patterns
  4. Consider if any additional repository conventions should be documented

Human Review Checklist

Important items to verify:

  • Do these conventions match the team's actual preferences and existing patterns?
  • Are there any repository patterns in the codebase that contradict these guidelines?
  • Are the code examples accurate and helpful?
  • Should any additional conventions be included (e.g., transaction handling, error handling)?
  • Is the placement in the knowledge base appropriate (added after "File Naming Conventions")?

Checklist

  • I have read the contributing guide
  • My changes follow the style guidelines of this project
  • Documentation is clear and includes helpful examples
  • Changes generate no new warnings

- Add comprehensive repository method naming conventions
- Include examples for method naming patterns
- Document separation of concerns between repositories and services
- Emphasize reusability and generic method naming

Co-Authored-By: hariom@cal.com <hariombalhara@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@keithwillcode keithwillcode added core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO labels Oct 14, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 14, 2025

Walkthrough

A new "Repository Method Conventions" documentation block was added to .agents/knowledge-base.md. It outlines naming rules, relation fetching semantics (including explicit include-like patterns), guidance on generic/reusable method design, and separation of concerns (repositories limited to data access, business logic in services). Concrete code examples are provided (e.g., findById, findByIdIncludeHosts, findByUserIdIncludeAttendees). The same section appears twice in the file, resulting in duplicated content. No changes to exported or public entities are present.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely describes the primary change by stating that repository method conventions are being added to the knowledge base documentation, accurately reflecting the content of the pull request.
Description Check ✅ Passed The description provides a detailed overview of the added documentation, explaining each convention, its rationale, and context, demonstrating that it is directly related to the changes in the knowledge base file.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/repository-conventions-1760429297

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hariombalhara hariombalhara marked this pull request as ready for review October 14, 2025 08:13
@graphite-app graphite-app Bot requested a review from a team October 14, 2025 08:13
@dosubot dosubot Bot added the docs area: docs, documentation, cal.com/docs label Oct 14, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a2bee76 and 897585b.

📒 Files selected for processing (1)
  • .agents/knowledge-base.md (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-07-28T11:50:23.946Z
Learnt from: CR
PR: calcom/cal.com#0
File: .cursor/rules/review.mdc:0-0
Timestamp: 2025-07-28T11:50:23.946Z
Learning: Applies to **/*Repository.ts : Repository files must include `Repository` suffix, prefix with technology if applicable (e.g., `PrismaAppRepository.ts`), and use PascalCase matching the exported class

Applied to files:

  • .agents/knowledge-base.md
🪛 markdownlint-cli2 (0.18.1)
.agents/knowledge-base.md

315-315: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


393-393: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


447-447: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

Comment thread .agents/knowledge-base.md
Comment on lines +315 to +447
**1. Don't include the repository's entity name in method names**

Method names should be concise and avoid redundancy since the repository class name already indicates the entity type.

```typescript
// ✅ Good - Concise method names
class BookingRepository {
findById(id: string) { ... }
findByUserId(userId: string) { ... }
create(data: BookingCreateInput) { ... }
delete(id: string) { ... }
}

// ❌ Bad - Redundant entity name in methods
class BookingRepository {
findBookingById(id: string) { ... }
findBookingByUserId(userId: string) { ... }
createBooking(data: BookingCreateInput) { ... }
deleteBooking(id: string) { ... }
}
```

**2. Use `include` or similar keywords for methods that fetch relational data**

When a method retrieves additional related entities, make this explicit in the method name using keywords like `include`, `with`, or `andRelations`.

```typescript
// ✅ Good - Clear indication of included relations
class EventTypeRepository {
findById(id: string) {
return prisma.eventType.findUnique({
where: { id },
});
}

findByIdIncludeHosts(id: string) {
return prisma.eventType.findUnique({
where: { id },
include: {
hosts: true,
},
});
}

findByIdIncludeHostsAndSchedule(id: string) {
return prisma.eventType.findUnique({
where: { id },
include: {
hosts: true,
schedule: true,
},
});
}
}

// ❌ Bad - Unclear what data is included
class EventTypeRepository {
findById(id: string) {
return prisma.eventType.findUnique({
where: { id },
include: {
hosts: true,
schedule: true,
},
});
}

findByIdForReporting(id: string) {
return prisma.eventType.findUnique({
where: { id },
include: {
hosts: true,
},
});
}
}
```

**3. Keep methods generic and reusable - avoid use-case-specific names**

Repository methods should be general-purpose and describe what data they return, not how or where it's used. This promotes code reuse across different features.

```typescript
// ✅ Good - Generic, reusable methods
class BookingRepository {
findByUserIdIncludeAttendees(userId: string) {
return prisma.booking.findMany({
where: { userId },
include: {
attendees: true,
},
});
}

findByDateRangeIncludeEventType(startDate: Date, endDate: Date) {
return prisma.booking.findMany({
where: {
startTime: { gte: startDate },
endTime: { lte: endDate },
},
include: {
eventType: true,
},
});
}
}

// ❌ Bad - Use-case-specific method names
class BookingRepository {
findBookingsForReporting(userId: string) {
return prisma.booking.findMany({
where: { userId },
include: {
attendees: true,
},
});
}

findBookingsForDashboard(startDate: Date, endDate: Date) {
return prisma.booking.findMany({
where: {
startTime: { gte: startDate },
endTime: { lte: endDate },
},
include: {
eventType: true,
},
});
}
}
```

**4. No business logic in repositories**
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix markdownlint MD036 violations in numbered rules.

markdownlint is flagging the bolded rule titles (**1. ...**, **2. ...**, etc.) as “emphasis used instead of a heading,” which will keep the PR failing lint. Please convert them into plain numbered list items (or actual subheadings) so the section passes MD036.

-**1. Don't include the repository's entity name in method names**
+1. Don't include the repository's entity name in method names-**2. Use `include` or similar keywords for methods that fetch relational data**
+2. Use `include` or similar keywords for methods that fetch relational data-**3. Keep methods generic and reusable - avoid use-case-specific names**
+3. Keep methods generic and reusable - avoid use-case-specific names-**4. No business logic in repositories**
+4. No business logic in repositories
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
**1. Don't include the repository's entity name in method names**
Method names should be concise and avoid redundancy since the repository class name already indicates the entity type.
```typescript
// ✅ Good - Concise method names
class BookingRepository {
findById(id: string) { ... }
findByUserId(userId: string) { ... }
create(data: BookingCreateInput) { ... }
delete(id: string) { ... }
}
// ❌ Bad - Redundant entity name in methods
class BookingRepository {
findBookingById(id: string) { ... }
findBookingByUserId(userId: string) { ... }
createBooking(data: BookingCreateInput) { ... }
deleteBooking(id: string) { ... }
}
```
**2. Use `include` or similar keywords for methods that fetch relational data**
When a method retrieves additional related entities, make this explicit in the method name using keywords like `include`, `with`, or `andRelations`.
```typescript
// ✅ Good - Clear indication of included relations
class EventTypeRepository {
findById(id: string) {
return prisma.eventType.findUnique({
where: { id },
});
}
findByIdIncludeHosts(id: string) {
return prisma.eventType.findUnique({
where: { id },
include: {
hosts: true,
},
});
}
findByIdIncludeHostsAndSchedule(id: string) {
return prisma.eventType.findUnique({
where: { id },
include: {
hosts: true,
schedule: true,
},
});
}
}
// ❌ Bad - Unclear what data is included
class EventTypeRepository {
findById(id: string) {
return prisma.eventType.findUnique({
where: { id },
include: {
hosts: true,
schedule: true,
},
});
}
findByIdForReporting(id: string) {
return prisma.eventType.findUnique({
where: { id },
include: {
hosts: true,
},
});
}
}
```
**3. Keep methods generic and reusable - avoid use-case-specific names**
Repository methods should be general-purpose and describe what data they return, not how or where it's used. This promotes code reuse across different features.
```typescript
// ✅ Good - Generic, reusable methods
class BookingRepository {
findByUserIdIncludeAttendees(userId: string) {
return prisma.booking.findMany({
where: { userId },
include: {
attendees: true,
},
});
}
findByDateRangeIncludeEventType(startDate: Date, endDate: Date) {
return prisma.booking.findMany({
where: {
startTime: { gte: startDate },
endTime: { lte: endDate },
},
include: {
eventType: true,
},
});
}
}
// ❌ Bad - Use-case-specific method names
class BookingRepository {
findBookingsForReporting(userId: string) {
return prisma.booking.findMany({
where: { userId },
include: {
attendees: true,
},
});
}
findBookingsForDashboard(startDate: Date, endDate: Date) {
return prisma.booking.findMany({
where: {
startTime: { gte: startDate },
endTime: { lte: endDate },
},
include: {
eventType: true,
},
});
}
}
```
**4. No business logic in repositories**
1. Don't include the repository's entity name in method names
Method names should be concise and avoid redundancy since the repository class name already indicates the entity type.
🧰 Tools
🪛 markdownlint-cli2 (0.18.1)

315-315: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


393-393: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)


447-447: Emphasis used instead of a heading

(MD036, no-emphasis-as-heading)

🤖 Prompt for AI Agents
In .agents/knowledge-base.md around lines 315 to 447 the numbered rule titles
are bolded (e.g. "**1. ...**") and trigger markdownlint MD036; remove the bold
emphasis from those numbered headings and convert them into either plain
numbered list items (e.g. "1. Don't include...") or proper Markdown subheadings
(e.g. "### Don't include...") consistently for all rules 1–4 so the emphasis is
not used in place of headings, then run markdownlint to verify the MD036
violation is resolved.

Copy link
Copy Markdown
Contributor

@eunjae-lee eunjae-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic !

@eunjae-lee eunjae-lee enabled auto-merge (squash) October 14, 2025 15:15
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 14, 2025

E2E results are ready!

@vercel
Copy link
Copy Markdown

vercel Bot commented Oct 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Oct 15, 2025 1:21pm
cal-eu Ignored Ignored Oct 15, 2025 1:21pm

@eunjae-lee eunjae-lee merged commit 7af46cc into main Oct 15, 2025
35 of 36 checks passed
@eunjae-lee eunjae-lee deleted the devin/repository-conventions-1760429297 branch October 15, 2025 13:44
akarsh-jain-790 pushed a commit to akarsh-jain-790/cal.com that referenced this pull request Mar 8, 2026
- Add comprehensive repository method naming conventions
- Include examples for method naming patterns
- Document separation of concerns between repositories and services
- Emphasize reusability and generic method naming

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core area: core, team members only docs area: docs, documentation, cal.com/docs enterprise area: enterprise, audit log, organisation, SAML, SSO ready-for-e2e size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants