Skip to content

docs(backend): translate AGENT.md to English and fix formatting#7870

Open
Amartuvshins0404 wants to merge 9 commits into
erxes:mainfrom
Amartuvshins0404:translate-backend-agent-doc
Open

docs(backend): translate AGENT.md to English and fix formatting#7870
Amartuvshins0404 wants to merge 9 commits into
erxes:mainfrom
Amartuvshins0404:translate-backend-agent-doc

Conversation

@Amartuvshins0404

@Amartuvshins0404 Amartuvshins0404 commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Translates the backend plugin AGENT.md documentation from Mongolian to English and addresses all AI reviewer feedback from PR #7857.

Changes

  • Translation: All Mongolian descriptions translated to English for international contributor accessibility
  • Import aliases: Fixed incorrect examples (, ) to valid forms (, )
  • Code formatting: Converted tRPC example from indented to fenced TypeScript code block
  • Missing contract: Added required startPlugin() bootstrap export documentation with expected return shape (graphql, expressRouter, trpcAppRouter, meta)

Related


Type: Documentation
Scope: backend/plugins/AGENT.md

Summary by Sourcery

Documentation:

  • Add English-language backend plugin guidelines covering project structure, imports, GraphQL/Apollo usage, tRPC, pagination, and plugin registration requirements.

Summary by CodeRabbit

  • Documentation
    • Added comprehensive backend plugin developer documentation and mandatory rules covering standardized plugin structure and entrypoints, networking and port allocation, model and database conventions, GraphQL/tRPC/API contracts (including pagination expectations), resolver and federation guidance, background-worker and migration practices, import/path conventions, middleware/router wiring, and a developer checklist with do/don’t rules.

- Translate all Mongolian descriptions to English
- Fix import alias examples (~/, @/)
- Convert tRPC example to fenced code block
- Add missing startPlugin() bootstrap contract documentation
- Address AI reviewer feedback from PR erxes#7857
@sourcery-ai

sourcery-ai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Reviewer's Guide

Documents backend plugin conventions in AGENT.md in English, clarifies import aliases and gateway registration, adds concrete tRPC usage and pagination rules, and documents the required startPlugin() bootstrap contract for backend plugins.

File-Level Changes

Change Details Files
Add English backend plugin rules and project structure documentation for AGENT plugins.
  • Introduce project directory layout with brief descriptions for db, graphql, @types, utils, trpc, and routes folders.
  • Describe routes aggregation role for module routes.
  • Explain how plugins register their name and port in Redis for gateway discovery.
backend/plugins/AGENT.md
Clarify backend import alias conventions and GraphQL usage rules.
  • Document meaning of the ~/ alias (src root) and @/ alias (current module).
  • Specify GraphQL schema requirements including keyfield declaration and list response shape.
  • Describe use of expressMiddleware to bind Apollo Server into Express.
backend/plugins/AGENT.md
Document backend data layer and tRPC usage patterns.
  • Describe Mongoose model conventions including timestamps and indexing IDs.
  • Provide a fenced TypeScript example for sendTRPCMessage usage with annotated fields.
  • Define pagination requirements using totalCount, pageInfo, and cursorPaginate for lists.
backend/plugins/AGENT.md
Specify plugin bootstrap contract and general development constraints.
  • State port uniqueness and .env plugin enablement requirements for new plugins.
  • Define required startPlugin() export and its expected return object with graphql, expressRouter, trpcAppRouter, and meta.
  • Capture general warnings about avoiding any, using absolute imports, and not modifying core directly.
backend/plugins/AGENT.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds comprehensive backend plugin development documentation: bootstrap/startPlugin contract, Mongoose/model rules, GraphQL schema/resolver and pagination conventions, tRPC/Express wiring, import/export and worker patterns, inter-plugin messaging, migration rules, import aliasing, and a mandatory RULES.md.

Changes

Backend Plugin Development Guidelines

Layer / File(s) Summary
Project layout and startPlugin bootstrap
backend/plugins/AGENT.md
Document header, TOC, plugin directory layout, and src/main.ts bootstrap contract via startPlugin() including GraphQL/Apollo injection, optional routers/hooks, import/export wiring, and plugin port allocation.
Mongoose schemas and model registration
backend/plugins/AGENT.md
Mongoose conventions: use timestamps: true, separate schema vs class with loadClass(), define domain types/interfaces, and register models via connectionResolvers with plugin-prefixed collection names and caching.
GraphQL schema, resolvers, and pagination
backend/plugins/AGENT.md
Per-module schema fragments aggregated into final typeDefs, resolver aggregation patterns, Apollo federation @key(fields: "_id") guidance, resolver _id usage, and cursor-based pagination returning { list, totalCount, pageInfo } via cursorPaginate.
tRPC, Express routes, and meta registration
backend/plugins/AGENT.md
tRPC context typing and appRouter merging/export, requirement for single exported Express router passed to startPlugin(), and meta registration shapes for permissions, notifications, tags, and properties.
Import/Export, workers, messaging
backend/plugins/AGENT.md
Import/export producer registration via createCoreModuleProducerHandler, BullMQ background worker and scheduler wiring examples, and inter-plugin tRPC messaging via sendTRPCMessage with Redis gateway lookup rules.
Migrations, import aliases, and rules document
backend/plugins/AGENT.md, backend/plugins/rules/RULES.md
Migration placement and idempotency rules under src/migrations/, import alias rules (~/, @/) and style constraints, plus a new RULES.md with must/do-not-do checklists, port allocation table, and package.json template snippet.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit pens rules by lantern's glow,
Plugins tidy, schemas row on row,
Routers, workers, messages take flight,
startPlugin() binds the day and night,
Hop in — the docs make landing light. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title describes translating and fixing formatting in AGENT.md, but the actual changes include translating AGENT.md to English AND extracting development rules into a new rules/RULES.md file. The title only mentions the formatting aspect, missing the significant addition of rules/RULES.md. Update the title to reflect both major changes, such as 'docs(backend): translate AGENT.md and extract rules to RULES.md' or similar.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="backend/plugins/AGENT.md" line_range="19" />
<code_context>
+
+## Join Gateway
+
+Provide the plugin name and the port it runs on. This information is stored from the plugin to Redis, and the gateway and other plugins retrieve it from Redis.
+
+## Imports
</code_context>
<issue_to_address>
**suggestion (typo):** Clarify the Redis sentence by fixing the preposition usage.

“Stored from the plugin to Redis” is awkward. Please rephrase, e.g.: “This information is stored by the plugin in Redis, and the gateway and other plugins retrieve it from Redis.”

```suggestion
Provide the plugin name and the port it runs on. This information is stored by the plugin in Redis, and the gateway and other plugins retrieve it from Redis.
```
</issue_to_address>

### Comment 2
<location path="backend/plugins/AGENT.md" line_range="60" />
<code_context>
+
+## Pagination
+
+When calling a list, you must always return `totalCount` and `pageInfo` in addition to the list data.
+Use the `cursorPaginate` function for all lists.
+
</code_context>
<issue_to_address>
**suggestion (typo):** Consider rephrasing "calling a list" for improved clarity.

You could use alternatives like “When returning a list” or “When fetching a list” to better reflect the behavior without changing the meaning.

```suggestion
When returning a list, you must always return `totalCount` and `pageInfo` in addition to the list data.
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread backend/plugins/AGENT.md Outdated
Comment thread backend/plugins/AGENT.md Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/plugins/AGENT.md`:
- Around line 70-75: The docs incorrectly state plugins should export a
startPlugin() function that returns { graphql, expressRouter, trpcAppRouter,
meta }; instead, update the wording to match actual wiring: plugins must call
startPlugin({ graphql, expressRouter, trpcAppRouter, meta }) from their
entrypoint (as used in main.ts) — mention the exact call signature
startPlugin({...}) and the required config fields graphql, expressRouter,
trpcAppRouter and meta so authors implement the correct entrypoint pattern.
- Line 30: Replace the invalid Apollo Federation snippet "(keyfield: \"_id\")"
with the proper `@key` directive syntax: instruct using `@key`(fields: "_id") on the
entity type (for example "type User `@key`(fields: \"_id\") { _id: ID! ... }") and
mention that for Federation 2+ the `@key` must be available via `@link`; update the
line that currently reads `When defining a schema, you must declare (keyfield:
"_id").` to reference the correct `@key`(fields: "_id") usage and the example
entity form.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0f24aa27-0fe5-4c38-83c8-eb7fda43e84a

📥 Commits

Reviewing files that changed from the base of the PR and between 06a764d and cc017ae.

📒 Files selected for processing (1)
  • backend/plugins/AGENT.md

Comment thread backend/plugins/AGENT.md Outdated
Comment thread backend/plugins/AGENT.md Outdated
Amartuvshins0404 and others added 4 commits June 4, 2026 06:31
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
- Replace invalid (keyfield: "_id") with proper @key(fields: "_id") directive
- Fix startPlugin() contract: plugins call startPlugin({...}) from entrypoint,
  not export a function that returns an object
- Address CodeRabbit feedback from PR erxes#7870
- Add detailed project structure with file-level explanations
- Document startPlugin() configuration with all optional fields
- Add complete Database layer guide: schemas, models, types, connectionResolvers
- Add GraphQL layer guide: schema definitions, aggregation, typeDefs, resolvers, pagination
- Add tRPC layer guide with router initialization pattern
- Add Express routes guide
- Add Meta system guide: permissions, notifications, tags, properties
- Add Import/Export system guide
- Add Background Workers guide with BullMQ patterns
- Add Inter-Plugin Communication guide
- Add Migrations guide
- Add Import aliases and development rules with checklists
- Include port allocation table for all existing plugins
- Include package.json template

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/plugins/AGENT.md`:
- Around line 810-835: The import rule forbids relative imports in the "Rules"
section but several examples in the same document use relative imports; fix by
making the document consistent: either relax the rule text ("Prefer absolute
imports; relative imports allowed in examples") or change all example import
statements to use absolute aliases (`~/`, `@/`) so they comply; update the
“Rules: - Always use absolute paths” line and the conflicting example import
blocks so the prohibition and examples (the example import lines earlier in the
doc) match exactly.
- Line 27: The fenced directory-tree block starting with "```" that contains
"plugin_name_api/" should include a language tag to satisfy markdownlint MD040
and improve rendering; update the opening fence from ``` to ```text (i.e.,
change the code fence that precedes the directory tree to ```text) so the block
becomes a text-fenced block and keep the closing fence as ``` unchanged.
- Around line 769-771: The migration example uses an empty string for
generateModels(''), which will fail in SaaS because generateModels requires a
valid non-empty subdomain; update the migrateTasks function to supply a real
subdomain (or accept one as a parameter) and document it: change migrateTasks to
call generateModels with a proper subdomain value (or add a function parameter
like subdomain and pass it through to generateModels) and ensure any calling
code or README explains the required subdomain format so the example works in
the SaaS flow.
- Around line 134-141: The example defines the onServerInit key twice which
causes the first definition to be overridden; merge the duplicate into a single
async onServerInit function that accepts the app parameter and performs both
initialization tasks (e.g. initialize external services/websockets using the app
arg and then call await initMQWorkers(redis)); update the example to show both
responsibilities in one onServerInit and keep the background worker comment so
plugin authors don’t accidentally drop initialization logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 343c1afc-ac58-4147-9aa3-38e84e0fb4ad

📥 Commits

Reviewing files that changed from the base of the PR and between 61d1615 and c9f9426.

📒 Files selected for processing (1)
  • backend/plugins/AGENT.md

Comment thread backend/plugins/AGENT.md Outdated
Comment thread backend/plugins/AGENT.md
Comment thread backend/plugins/AGENT.md Outdated
Comment thread backend/plugins/AGENT.md Outdated
- Move Must Do / Must Not Do rules, port table, and package.json template
  from AGENT.md into new rules/RULES.md file
- Update AGENT.md to reference rules/RULES.md instead of inline content
- Keep AGENT.md focused on architecture and patterns guidance

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/plugins/rules/RULES.md`:
- Line 11: Update the checklist item that currently reads "[ ] Index frequently
queried fields and all `_id` fields" by removing the "_id" portion so it reads
"[ ] Index frequently queried fields"; leave the rest of the checklist untouched
and ensure no other references to indexing `_id` remain in RULES.md to avoid
prompting redundant index creation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2c7d5c29-6f7d-40ab-a944-70f668feecee

📥 Commits

Reviewing files that changed from the base of the PR and between c9f9426 and 78d164e.

📒 Files selected for processing (2)
  • backend/plugins/AGENT.md
  • backend/plugins/rules/RULES.md

- [ ] Register plugin name in `.env` to enable it
- [ ] Prefix collection names with plugin name (e.g., `operation_tasks`, `frontline_conversations`)
- [ ] Set `timestamps: true` on all Mongoose schemas
- [ ] Index frequently queried fields and all `_id` fields

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Remove the _id indexing requirement from the checklist.

_id is already indexed by default in MongoDB collections, so this rule is misleading and may prompt redundant index definitions. Keep the “frequently queried fields” guidance, but drop “and all _id fields”.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/plugins/rules/RULES.md` at line 11, Update the checklist item that
currently reads "[ ] Index frequently queried fields and all `_id` fields" by
removing the "_id" portion so it reads "[ ] Index frequently queried fields";
leave the rest of the checklist untouched and ensure no other references to
indexing `_id` remain in RULES.md to avoid prompting redundant index creation.

- Add text language tag to directory tree code fence (MD040)
- Merge duplicate onServerInit keys into single hook in startPlugin example
- Fix migration example to accept subdomain parameter instead of empty string
Replace xiaoju111a/kimi-actions with howardpen9/kimi-code-reviewer which:
- Fixes checkout failures on fork PRs (no manual ref fetching needed)
- Uses TypeScript instead of Docker (faster startup)
- Provides inline annotations via GitHub Checks API
- Supports prefix caching for lower costs
- Adds configurable .kimi-review.yml support

Also update model to kimi-k2.6 and add checks:write permission.
This file was not part of the AGENT.md documentation changes and should
not be included in this PR.
@sonarqubecloud

sonarqubecloud Bot commented Jun 3, 2026

Copy link
Copy Markdown

@Amartuvshins0404

Copy link
Copy Markdown
Collaborator Author

@claude

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

Claude Code is working…

I'll analyze this and get back to you.

View job run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant