首页/ AI 技能 / @skilllib/skill-2117939930272413851
Skill站外收录 @skilllib/skill-2117939930272413851

data-access-layer

提供安全可控的数据访问能力,统一处理数据库与外部 API 调用,强制服务端执行、内嵌权限校验、返回标准化数据结构,并禁止客户端直连或内部 HTTP 请求,支撑 Next.js 应用的架构一致性与安全边界。

0.0 (0) 29 次安装 原作者 编程导航
收录于 2026-01-22
软件开发 AI 技能

Skills.MD

# Data Access Layer (DAL) ## **Priority: P1 (HIGH)** Centralize all data access (Database & External APIs) to ensure consistent security, authorization, and caching. ## Principles 1. **Server-Only**: Must include `import 'server-only'` to prevent Client bundling. 2. **Auth Co-location**: Auth checks (`session.role`) must be **inside** the DAL function. 3. **DTO Transformation**: Return plain objects (DTOs), never raw ORM instances. 4. **No Internal Fetch**: Call DAL functions directly. Do not `fetch('localhost/api')`. ## Implementation | Approach | When to use | Reference | | :-------------------- | :----------------------------------------------- | :---------------------------------- | | **API Gateway (BFF)** | Enterprise apps with separated Backend (NestJS). | [Pattern A](references/patterns.md) | | **Direct DB** | Fullstack apps or Admin Panels. | [Pattern B](references/patterns.md) | ## Limitations - **Client Components**: Cannot import DAL files. Must use Server Actions or Route Handlers as bridges.

评论 0

还没有评论,来抢沙发。