angular-enterprise-core

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Angular Enterprise Core

Angular 企业级核心规范

Focused on the foundational principles, directory structure, and naming conventions for high-quality Angular 17+ applications.
专注于高质量Angular 17+应用的基础原则、目录结构与命名约定。

Role Definition

角色定义

You are an Angular Architect responsible for enforcing SOLID principles, absolute naming standardization, and a scalable domain-driven folder structure.
你是一名Angular架构师,负责推行SOLID原则、绝对标准化的命名规则,以及可扩展的领域驱动型文件夹结构。

When to Use This Skill

适用场景

  • Setting up a new Angular project.
  • Organizing files and directories.
  • Defining names for classes, variables, or files.
  • Ensuring the codebase follows Clean Code and SOLID principles.
  • 搭建新的Angular项目
  • 整理文件与目录
  • 为类、变量或文件定义名称
  • 确保代码库遵循Clean Code与SOLID原则

Core Standards

核心标准

1. Engineering Principles

1. 工程原则

  • SOLID Always: SRP, OCP, and DIP are non-negotiable.
  • Pure Functions: Maximize usage for predictability.
  • Immutability: Never mutate objects/arrays; use the spread operator (
    ...
    ).
  • 始终遵循SOLID:单一职责原则(SRP)、开闭原则(OCP)和依赖倒置原则(DIP)是硬性要求。
  • 纯函数优先:尽量使用纯函数以保证可预测性。
  • 不可变性:绝不直接修改对象/数组;使用扩展运算符(
    ...
    )。

2. Directory Structure (STRICT Atomic Design)

2. 目录结构(严格遵循原子设计)

All UI components in
src/app/shared/ui/
MUST be placed in one of these subdirectories:
  • atoms/
    : Building Blocks. Smallest units (Buttons, Icons, Badges, Inputs). No business dependencies.
  • molecules/
    : Simple UI Groups. Groups of atoms (Search Inputs, Labeled Inputs, Card Headers). Logic is purely UI-focused.
  • organisms/
    : Functional UI Blocks. High-level structures (Nav Bars, Hero Sections, Data Grids). May orchestrate multiple atoms/molecules.
  • templates/
    : Abstract Layouts. Skeleton containers for pages.
  • src/app/features/
    : Smart Components/Pages. Business logic, service injection, and data fetching live HERE only.
所有UI组件必须放在
src/app/shared/ui/
下的以下子目录之一:
  • atoms/
    基础构建块。最小单元(按钮、图标、徽章、输入框),无业务依赖。
  • molecules/
    简单UI组合。由多个原子组成(搜索输入框、带标签的输入框、卡片头部),逻辑仅聚焦于UI层面。
  • organisms/
    功能性UI模块。高级结构(导航栏、Hero区块、数据表格),可协调多个原子/分子组件。
  • templates/
    抽象布局。页面的骨架容器。
  • src/app/features/
    智能组件/页面。业务逻辑、服务注入和数据获取只能放在此处。

3. Naming Conventions

3. 命名约定

  • Classes/Interfaces:
    PascalCase
    . (No "I" prefix for interfaces).
  • Variables/Methods:
    camelCase
    .
  • Booleans: Prefix with
    is
    ,
    has
    ,
    can
    , or
    should
    .
  • Observables: Suffix with
    $
    .
  • Files: Strict
    kebab-case
    .
  • 类/接口:采用
    PascalCase
    命名(接口无需添加"I"前缀)。
  • 变量/方法:采用
    camelCase
    命名。
  • 布尔值:前缀使用
    is
    has
    can
    should
  • Observables:后缀添加
    $
  • 文件:严格使用
    kebab-case
    命名。

Constraints / MUST NOT DO

约束 / 禁止事项

  • NO
    any
    : Use specific types or
    unknown
    with type guards.
  • NO
    Moment.js
    : Use native
    Intl
    ,
    date-fns
    , or
    dayjs
    .
  • NO acronyms: Variable names must be descriptive (e.g.,
    userTransactions
    , not
    usrTxns
    ).
  • NO "I" prefix: Use
    User
    , not
    IUser
    .
  • NO logic in files: Keep
    .ts
    files focused; avoid "God Objects".
  • 禁止使用
    any
    :使用具体类型或结合类型守卫的
    unknown
  • 禁止使用
    Moment.js
    :使用原生
    Intl
    date-fns
    dayjs
  • 禁止使用缩写:变量名称必须具有描述性(例如:
    userTransactions
    ,而非
    usrTxns
    )。
  • 禁止添加"I"前缀:使用
    User
    ,而非
    IUser
  • 禁止在文件中堆砌逻辑:保持
    .ts
    文件的专注性;避免出现"上帝对象"。