cs-rag-architecture-guideline

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CS-RAG 架构总规范

CS-RAG Architecture General Specification

CS-RAG 项目专用架构总规范。已无损合并
architecture-cognition
architecture-design
的规则内容,可在原 skill 删除后独立使用。

General Architecture Specification for CS-RAG Project. The rules from
architecture-cognition
and
architecture-design
have been merged losslessly, and it can be used independently after deleting the original skills.

⚠️ 核心强制要求

⚠️ Core Mandatory Requirements

统一三层架构约束

Unified Three-Layer Architecture Constraints

  • 前端层 → 业务层 → 基础设施层(单向依赖)
  • 禁止反向依赖:基础设施层不能依赖业务层或前端层
  • 禁止跨层访问:前端层不能直接访问基础设施层
  • 基础设施层不得夹带业务逻辑
  • Frontend Layer → Business Layer → Infrastructure Layer (one-way dependency)
  • Prohibit reverse dependencies: Infrastructure Layer cannot depend on Business Layer or Frontend Layer
  • Prohibit cross-layer access: Frontend Layer cannot directly access Infrastructure Layer
  • Infrastructure Layer must not contain business logic

认知与设计的组合治理顺序

Combined Governance Sequence of Cognition and Design

  1. 先执行架构认知检查:层级位置、组件关系、数据流影响
  2. 再执行架构设计检查:接口契约、依赖注入、可插拔设计
  3. 最后执行合规复核:跨层、反向依赖、循环依赖、兼容性
  1. First perform architecture cognition inspection: layer position, component relationships, data flow impact
  2. Then perform architecture design inspection: interface contracts, dependency injection, pluggable design
  3. Finally perform compliance review: cross-layer, reverse dependencies, circular dependencies, compatibility

升级给用户决策的场景

Scenarios Requiring User Decision for Upgrade

  • 涉及跨层依赖修改
  • 涉及核心组件接口变更(尤其破坏性变更)
  • 涉及数据流向/主路径改变
  • 涉及全局策略、性能、资源消耗或数据一致性风险

  • Involving cross-layer dependency modifications
  • Involving core component interface changes (especially breaking changes)
  • Involving data flow/main path changes
  • Involving global strategy, performance, resource consumption or data consistency risks

AI Agent 行为要求

AI Agent Behavior Requirements

阶段 A:架构认知(原
architecture-cognition
全量迁入)

Phase A: Architecture Cognition (full migration from original
architecture-cognition
)

修改代码前必须回答:
  1. 位置识别:属于哪一层?影响哪些组件?有跨层依赖风险?
  2. 影响范围:影响哪些数据流?有组件依赖此接口?需更新测试?
  3. 架构约束:是否违反三层架构?是否引入循环依赖?
创建新组件时必须明确:
  1. 职责定位:属于哪一层?单一职责是什么?与现有组件关系?
  2. 接口设计:需要抽象基类/Protocol?需要工厂模式?
  3. 依赖管理:依赖哪些组件?是否可依赖注入?是否违反依赖方向?
快速参考(项目上下文):
核心组件职责
前端层
frontend/main.py
用户交互、UI 展示
业务层
RAGService
,
QueryEngine
业务逻辑、流程编排
基础设施层
IndexManager
,
Embedding
,
LLM
技术实现、无业务逻辑
Before modifying code, you must answer:
  1. Position Identification: Which layer does it belong to? Which components are affected? Is there a cross-layer dependency risk?
  2. Impact Scope: Which data flows are affected? Do any components depend on this interface? Do tests need to be updated?
  3. Architecture Constraints: Does it violate the three-layer architecture? Does it introduce circular dependencies?
When creating new components, you must clarify:
  1. Responsibility Positioning: Which layer does it belong to? What is the single responsibility? What is the relationship with existing components?
  2. Interface Design: Is an abstract base class/Protocol required? Is the factory pattern required?
  3. Dependency Management: Which components does it depend on? Can dependency injection be used? Does it violate the dependency direction?
Quick Reference (Project Context):
LayerCore ComponentsResponsibilities
Frontend Layer
frontend/main.py
User interaction, UI display
Business Layer
RAGService
,
QueryEngine
Business logic, process orchestration
Infrastructure Layer
IndexManager
,
Embedding
,
LLM
Technical implementation, no business logic

阶段 B:架构设计(原
architecture-design
全量迁入)

Phase B: Architecture Design (full migration from original
architecture-design
)

设计变更时检查项:
  • 标注影响到的层级与上下游模块
  • 确认无循环依赖
  • 确认无跨层访问
接口设计要求:
  • 以抽象基类或 Protocol 定义契约
  • 新接口默认向后兼容
  • 使用构造函数依赖注入,禁止静态单例
可插拔设计要求:
  • 使用工厂或注册表模式注册新实现
  • 所有可切换组件通过配置项启用
新模块规划时:
  • 每个模块/类仅负责单一领域
  • 命名遵循
    src/<layer>/<role>/module.py
    结构
Check items during design changes:
  • Mark the affected layers and upstream/downstream modules
  • Confirm no circular dependencies
  • Confirm no cross-layer access
Interface Design Requirements:
  • Define contracts with abstract base classes or Protocol
  • New interfaces are backward compatible by default
  • Use constructor-based dependency injection, prohibit static singletons
Pluggable Design Requirements:
  • Use factory or registry pattern to register new implementations
  • All switchable components are enabled via configuration items
When planning new modules:
  • Each module/class is responsible for only a single domain
  • Naming follows the
    src/<layer>/<role>/module.py
    structure

阶段 C:合规复核

Phase C: Compliance Review

  • 复核是否引入跨层访问或反向依赖
  • 复核接口变更是否具备兼容策略
  • 复核是否出现循环依赖

  • Review whether cross-layer access or reverse dependencies are introduced
  • Review whether interface changes have compatibility strategies
  • Review whether circular dependencies occur

判断标准

Judgment Criteria

  • 是否完成“认知 + 设计 + 复核”三阶段检查
  • 是否保持三层依赖方向正确且无循环依赖
  • 是否保留接口兼容性与实现可替换性

  • Whether the three-stage inspection of "cognition + design + review" is completed
  • Whether the three-layer dependency direction is correct and no circular dependencies exist
  • Whether interface compatibility and implementation replaceability are retained

无损合并声明

Lossless Merge Declaration

  • 本 skill 已承载两套原始规则的内容级迁移,不是仅链接跳转。
  • 原始
    SKILL.md
    文本已复制到:
    • references/architecture-cognition-skill.md
    • references/architecture-design-skill.md
  • 原始 references 文本已全量复制到本 skill 的
    references/
  • 详细映射见
    references/lossless-merge-routing.md
  • This skill has carried out content-level migration of two sets of original rules, not just link jumps.
  • The original
    SKILL.md
    text has been copied to:
    • references/architecture-cognition-skill.md
    • references/architecture-design-skill.md
  • The original reference texts have been fully copied to the
    references/
    directory of this skill.
  • For detailed mapping, see
    references/lossless-merge-routing.md
    .

删除源 skill 就绪说明

Readiness Instructions for Deleting Source Skills

  • 删除
    architecture-cognition
    architecture-design
    后,本 skill 仍可独立运行。
  • 删除前后仅路径变化,不会丢失规则内容。

  • After deleting
    architecture-cognition
    and
    architecture-design
    , this skill can still run independently.
  • Only the path changes before and after deletion, and no rule content will be lost.

参考资料

Reference Materials

  • references/lossless-merge-routing.md
    - 无损合并路由与原文映射
  • references/architecture-cognition-skill.md
    - 原
    architecture-cognition
    全文
  • references/architecture-cognition-system-overview.md
    - 原认知参考:系统定位
  • references/architecture-cognition-three-layer-architecture.md
    - 原认知参考:三层架构
  • references/architecture-cognition-component-map.md
    - 原认知参考:组件地图
  • references/architecture-cognition-data-flow.md
    - 原认知参考:数据流
  • references/architecture-design-skill.md
    - 原
    architecture-design
    全文
  • references/architecture-design-layer-guidelines.md
    - 原设计参考:分层指南
  • references/architecture-design-module-planning.md
    - 原设计参考:模块规划
  • references/architecture-design-interface-design.md
    - 原设计参考:接口设计
  • references/lossless-merge-routing.md
    - Lossless merge routing and original text mapping
  • references/architecture-cognition-skill.md
    - Full text of original
    architecture-cognition
  • references/architecture-cognition-system-overview.md
    - Original cognition reference: system positioning
  • references/architecture-cognition-three-layer-architecture.md
    - Original cognition reference: three-layer architecture
  • references/architecture-cognition-component-map.md
    - Original cognition reference: component map
  • references/architecture-cognition-data-flow.md
    - Original cognition reference: data flow
  • references/architecture-design-skill.md
    - Full text of original
    architecture-design
  • references/architecture-design-layer-guidelines.md
    - Original design reference: layered guidelines
  • references/architecture-design-module-planning.md
    - Original design reference: module planning
  • references/architecture-design-interface-design.md
    - Original design reference: interface design