modern-admin-integration
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseModern Admin — Integration skill
Modern Admin — 集成技能
Modern Admin is a vendor framework. Treat as read-only;
only call its public exports. This skill encodes the project's non-obvious
rules so you don't re-discover them.
@modern-admin/*Modern Admin是一个供应商框架。请将视为只读;仅调用其公开导出的内容。本技能收录了项目中的非显性规则,帮你避免重复踩坑。
@modern-admin/*Ground rules (always apply)
基本规则(始终适用)
- bun only. Never /
npm/yarn.pnpm - UUID v7 for every generated id. . Never
import { uuidv7 } from '@modern-admin/core',crypto.randomUUID(),randomUUID(). Don't trustnanoid— generate in app code.@default(uuid(7)) - Latest stable versions. Adapt code to new APIs; never pin older to dodge breaking changes.
- i18n everywhere. No hardcoded user-visible strings. Add keys to
AND mirror to all 8 other locales (
packages/i18n/src/locales/en.ts/de/es/fr/it/ja/pl/pt-BR). UI components stay i18n-unaware (ruprop);labels?: {...}is the translation boundary. Seepackages/react.references/conventions.md - Mobile-first. Verify every new UI at ≤375px viewport.
- Auto-discovery beats config. Override only what diverges.
- 仅使用bun。绝不使用/
npm/yarn。pnpm - 所有生成的ID均使用UUID v7。导入。绝不使用
import { uuidv7 } from '@modern-admin/core'、crypto.randomUUID()、randomUUID()。不要信任nanoid——在应用代码中生成。@default(uuid(7)) - 始终使用最新稳定版本。适配新API;绝不通过锁定旧版本来规避破坏性变更。
- 全流程国际化。禁止硬编码用户可见字符串。将键添加至,并同步到其他8种语言(
packages/i18n/src/locales/en.ts/de/es/fr/it/ja/pl/pt-BR)。UI组件保持无感知国际化(通过ru属性传递);labels?: {...}是翻译边界。详见packages/react。references/conventions.md - 移动端优先。验证每个新UI在≤375px视口下的表现。
- 自动发现优于配置。仅覆盖与默认规则不符的部分。
When to use Modern Admin
Modern Admin的适用场景
Use it for CRUD-over-Postgres admin panels (Prisma 7 / Drizzle 0.45) with
role-gated actions, search, filters, uploads, audit log, revisions, webhooks,
AI assistant. Don't use it for public UI, non-relational stores, or
when admin shouldn't share a DB with main app (use it as a separate service
against a replica instead).
适用于基于Postgres的CRUD管理面板(Prisma 7 / Drizzle 0.45),支持角色权限控制、搜索、筛选、上传、审计日志、版本回溯、Webhook、AI助手。请勿将其用于公共UI、非关系型存储,或管理面板不应与主应用共享数据库的场景(此时应将其作为独立服务连接至副本数据库)。
Deployment model — default to standalone
部署模型——默认采用独立部署
Recommended layout: separate NestJS 11 service against the same Postgres.
Scaffold with .
Mount behind of the main domain via reverse proxy. See
for the existing-Prisma reuse rules (one schema,
one client; never add a second ) and the fourteen models
that must be copied verbatim — fails at boot if any are
missing.
MODERN_ADMIN_TOKEN=ghp_xxx bun create @modern-admin admin-service/adminreferences/deployment.mdgeneratorMa*setupPrismaSystem推荐架构:独立的NestJS 11服务连接至同一Postgres数据库。使用搭建项目。通过反向代理挂载至主域名的路径下。现有Prisma复用规则详见(单一schema、单一客户端;绝不添加第二个),必须完整复制的14个模型——若缺失任何一个,会在启动时失败。
MODERN_ADMIN_TOKEN=ghp_xxx bun create @modern-admin admin-service/adminreferences/deployment.mdgeneratorMa*setupPrismaSystemThe three pieces of every resource
每个资源的三个核心部分
- Source registry () — maps logical resource ids to adapter-specific raw source objects via
src/admin-sources.ts. Import as a side-effect beforeregisterAdminSources({...})inNestFactory.create.main.ts - Resource controller — (never body-less), carries
extends AdminController<Row>metadata +@AdminResource(...)/@Beforehooks +@Aftermethods.@Action - NestJS module — .
@Module({ controllers: [FooAdminController] })
See for the canonical Prisma source factory
(including the critical relation-field- rewrite for FK→reference
resolution), the resource-creation 8-step checklist, and the property-type
selection matrix.
references/resources.mdtype- 源注册表()——通过
src/admin-sources.ts将逻辑资源ID映射到适配器特定的原始源对象。在registerAdminSources({...})的main.ts之前作为副作用导入。NestFactory.create - 资源控制器——(绝不能为空实现),包含
extends AdminController<Row>元数据 +@AdminResource(...)/@Before钩子 +@After方法。@Action - NestJS模块——。
@Module({ controllers: [FooAdminController] })
标准Prisma源工厂(包括用于外键→引用解析的关键关联字段重写)、资源创建8步清单、属性类型选择矩阵详见。
typereferences/resources.mdNestJS-style permissions — actions:
key is FORBIDDEN
actions:NestJS风格权限——禁止使用actions:
字段
actions:The #1 mistake AI agents make.
AdminResourceMeta = Omit<ResourceOptions, 'actions'> & {source, ...}@AdminResource({ actions: {...} })TS2353@Action@Before@AfterMaRole.permissionsisAccessiblereferences/permissions.mdPromise<never>TS2416guard:isAccessible:AI助手最常犯的错误。
AdminResourceMeta = Omit<ResourceOptions, 'actions'> & {source, ...}@AdminResource({ actions: {...} })TS2353@Action@Before@AfterMaRole.permissionsisAccessiblePromise<never>TS2416guard:isAccessible:references/permissions.mdAuth wiring — the five must-knows
认证配置——必须掌握的五点
- plugin is MANDATORY when using
admin(). Without itrolesResourceIdissession.user.roleand every role-gated action returns 403 — even whenundefinedisma_user.rolein the database.'admin' - Mount Better Auth via , not bare
createBetterAuthMiddleware(toNodeHandler(auth)). The bare handler is greedy and shadowstoNodeHandler'sAuthController,/login,/mewith its own 404s./ui-props - is REQUIRED to serve the SPA + handle deep-link refreshes. Without it
ModernAdminStaticUiModule.forRoot({ path: '/admin', ... })and every refresh 404s./admin - — pass clients, not URLs. ioredis can't multiplex pub/sub on a command connection.
RedisCacheProvider({ client, subscriber }) - Keep ,
app.use(<basePath>, ...), andbetterAuth({ basePath })in lockstep. A mismatch surfaces asruntimeConfig.authBasePathon login.POST /api/auth/sign-in/email 404
Full details + code examples: .
references/auth-and-infra.md- 使用时,
rolesResourceId插件是强制要求。若无此插件,admin()会是session.user.role,所有角色权限控制的动作都会返回403——即使数据库中undefined为ma_user.role。'admin' - 通过挂载Better Auth,而非直接使用
createBetterAuthMiddleware(toNodeHandler(auth))。直接使用处理器会抢占toNodeHandler的AuthController、/login、/me路径,导致这些接口返回404。/ui-props - 必须配置,用于提供SPA服务并处理深度链接刷新。若无此配置,
ModernAdminStaticUiModule.forRoot({ path: '/admin', ... })路径及所有刷新操作都会返回404。/admin - ——传递客户端实例,而非URL。ioredis无法在命令连接上复用发布/订阅功能。
RedisCacheProvider({ client, subscriber }) - 保持、
app.use(<basePath>, ...)和betterAuth({ basePath })三者一致。不匹配会导致登录时出现runtimeConfig.authBasePath错误。POST /api/auth/sign-in/email 404
完整细节及代码示例:。
references/auth-and-infra.mdReferences
参考文档
- — §2 standalone deploy, §2.5 reusing existing Prisma schema, the 14
./references/deployment.mdmodels, anti-pattern of duplicated generators.Ma* - — §3 the three-pieces recipe, source registry, resource controller, 8-step per-resource checklist, §4 property-type matrix, §5 hide vs. expose (
./references/resources.mdvsisVisible).isAccessible - — §6 roles × actions, DB-driven vs code-pinned,
./references/permissions.mdforbidden, read-only via roles, base-class signature, true invariants, sealed-invariant propertyactions:,isAccessiblevs permissions.guard: - — §7 built-in actions and when to override, §8 plugin/feature selection guide, §10 hooks vs actions vs handlers.
./references/actions-and-plugins.md - — §9 when to write a custom component, the three-step workflow,
./references/custom-ui.mdprimitives, Tailwind 4@modern-admin/uirule.border - — §11 a–f:
./references/auth-and-infra.mdwiring,BetterAuthProvider,RedisCacheProvider,ModernAdminStaticUiModule,createBetterAuthMiddlewareplugin requirement,admin()serialisation.BigInt - — §12 i18n boundary, §13 UUID v7, §14 cache + realtime.
./references/conventions.md - — §15 full anti-pattern list, §16 verification checklist, §17 reference index of canonical files.
./references/anti-patterns.md
- — §2独立部署,§2.5复用现有Prisma schema,14个
./references/deployment.md模型,重复generator的反模式。Ma* - — §3三部分方案,源注册表,资源控制器,每个资源的8步清单,§4属性类型矩阵,§5隐藏与暴露(
./references/resources.mdvsisVisible)。isAccessible - — §6角色×动作,数据库驱动vs代码固定,禁止使用
./references/permissions.md,通过角色设置只读,基类签名,真正不变规则,密封不变属性actions:,isAccessiblevs 权限。guard: - — §7内置动作及重写时机,§8插件/功能选择指南,§10钩子vs动作vs处理器。
./references/actions-and-plugins.md - — §9自定义组件的编写时机,三步工作流,
./references/custom-ui.md基础组件,Tailwind 4@modern-admin/ui规则。border - — §11 a–f:
./references/auth-and-infra.md配置,BetterAuthProvider,RedisCacheProvider,ModernAdminStaticUiModule,createBetterAuthMiddleware插件要求,admin()序列化。BigInt - — §12国际化边界,§13 UUID v7,§14缓存+实时性。
./references/conventions.md - — §15完整反模式列表,§16验证清单,§17标准文件参考索引。
./references/anti-patterns.md
Verification checklist (always run before "done")
验证清单(完成前必须执行)
- (or
bun run dev) starts clean;scripts/dev.sh start api-prisma webshow no errors..dev-logs/ - Seed admin can log in at and sees every registered resource.
/admin - Sensitive columns (,
password, …) absent from both JSON and UI.apiKey - Every destructive action has confirm +
guard:role check.isAccessible - Every new visible string exists in all 9 locale files.
- is green workspace-wide.
bun run typecheck - Tests added for every custom hook, action handler, UI component.
- 375px viewport: list/show/edit pages have no horizontal page scroll.
- (或
bun run dev)启动无异常;scripts/dev.sh start api-prisma web中无错误日志。.dev-logs/ - 种子管理员可在登录,并能看到所有已注册资源。
/admin - 敏感列(、
password等)在JSON和UI中均不可见。apiKey - 所有破坏性动作均配置确认 +
guard:角色校验。isAccessible - 每个新增可见字符串均存在于所有9个语言文件中。
- 在整个工作区中执行通过。
bun run typecheck - 为每个自定义钩子、动作处理器、UI组件添加测试。
- 375px视口下:列表/详情/编辑页面无横向滚动条。
Canonical files to read before writing new code
编写新代码前必读的标准文件
- — hooks + record + bulk actions.
apps/_shared/src/admin/posts/posts.controller.ts - —
apps/_shared/src/admin/customers/customers.controller.ts+passwordsFeature+ custom action.aiFillFeature - — source registry.
apps/_shared/src/admin/source-registry.ts - — logical-id mapping + relation field rewriting.
apps/api-prisma/src/admin-sources.ts - — admin module wiring.
apps/api-prisma/src/admin.module.ts - — schemas.
packages/core/src/decorators/{resource,property,action}-options.ts - ,
packages/core/src/actions/action.ts—packages/core/src/ports/current-admin.ts,ActionContexttypes forCurrentAdmin/isAccessiblecallbacks.isVisible - —
packages/nest/src/admin/decorators.ts,AdminController,@Before,@After.@Action
When in doubt, read the source — every public export has JSDoc explaining
its contract.
- — 钩子 + 单条/批量动作。
apps/_shared/src/admin/posts/posts.controller.ts - —
apps/_shared/src/admin/customers/customers.controller.ts+passwordsFeature+ 自定义动作。aiFillFeature - — 源注册表。
apps/_shared/src/admin/source-registry.ts - — 逻辑ID映射 + 关联字段重写。
apps/api-prisma/src/admin-sources.ts - — 管理模块配置。
apps/api-prisma/src/admin.module.ts - — schema定义。
packages/core/src/decorators/{resource,property,action}-options.ts - 、
packages/core/src/actions/action.ts—packages/core/src/ports/current-admin.ts、ActionContext类型,用于CurrentAdmin/isAccessible回调。isVisible - —
packages/nest/src/admin/decorators.ts、AdminController、@Before、@After装饰器。@Action
如有疑问,阅读源码——每个公开导出的内容都有JSDoc说明其契约。