idanzam/Angular21-企业级无区域架构-Claude技能
生产级Angular 21 + PrimeNG 21企业架构和Claude Code技能系统,用于无区域、Signal优先的实时应用,具备可扩展前端模式、WebSocket架构、Tailwind集成和性能导向工程。
概述
该Claude技能专为开发使用Angular 21和PrimeNG 21的企业级、无区域(zoneless)实时应用程序而设计。它利用了Angular的最新功能,如Signal API和独立组件,构建高效、可维护的前端。技能集成了Claude Code,提供智能代码生成、架构建议和性能优化。
主要特性
- 无区域架构(Zoneless):利用Angular 21的Signal API,无需zone.js即可实现高效变更检测。
- Signal优先状态管理:使用
signal()、computed()和effect()进行响应式状态管理。 - PrimeNG 21集成:使用PrimeNG UI组件库构建美观的企业级界面。
- WebSocket架构:内置WebSocket支持,实现实时数据同步。
- Tailwind CSS:集成Tailwind CSS进行高效样式开发。
- 性能优化:通过延迟加载、虚拟滚动和变更检测策略提升性能。
- Claude Code辅助:利用Claude Code自动生成组件、服务、路由和测试代码。
入门指南
前提条件
- Node.js 18+ 和 npm 9+
- Angular CLI 21
- Claude Code (可选,但推荐)
安装
npx @angular/cli new my-app --standalone --no-zone
cd my-app
npm install primeng primeicons
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
配置Claude技能
在项目根目录创建或编辑.claude文件夹,并添加技能定义。
{
"skills": [
{
"id": "angular21-enterprise-architecture",
"path": "path/to/skill.md"
}
]
}
架构原则
模块化组件设计
- 每个特性模块对应一个功能域(如用户管理、仪表盘)。
- 组件遵循单一职责原则,可重用和可测试。
- 使用Angular独立组件(standalone components),减少NgModule依赖。
状态管理
使用Signal API进行本地和全局状态管理。
import { signal, computed, effect } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class AppStateService {
private count = signal(0);
readonly doubled = computed(() => this.count() * 2);
increment() {
this.count.update(c => c + 1);
}
}
WebSocket集成
@Injectable({ providedIn: 'root' })
export class WebSocketService {
private socket$!: WebSocketSubject<any>;
private messages$ = signal<any[]>([]);
constructor() {
this.socket$ = webSocket('ws://localhost:8080/ws');
this.socket$.subscribe(msg => {
this.messages$.update(msgs => [...msgs, msg]);
});
}
send(message: any) {
this.socket$.next(message);
}
}
Tailwind CSS样式
<div class="p-4 bg-white shadow-md rounded-lg">
<h2 class="text-xl font-bold text-gray-800">欢迎</h2>
<p class="text-gray-600 mt-2">这是一个使用Tailwind CSS样式的组件。</p>
</div>
性能优化
- 使用
OnPush变更检测策略。 - 组件和路由的延迟加载。
- 虚拟滚动用于大数据集。
- 使用
trackBy优化列表渲染。 - 利用Angular的
provideZoneChangeDetection({ eventCoalescing: true })配置。
测试
使用Jasmine和Karma进行单元测试,Cypress进行端到端测试。
describe('AppComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AppComponent]
}).compileComponents();
});
it('应该创建应用', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
});
与Claude Code配合使用
启动Claude Code并导航到项目目录。使用自然语言命令,例如:
- "为仪表盘创建一个Angular独立组件,使用PrimeNG卡片和表格"
- "生成一个WebSocket服务,处理实时消息"
- "添加Tailwind样式到登录页面组件"
- "优化此组件的性能,使用Signal和OnPush策略"
Claude将生成符合本技能架构指南的代码。
许可
MIT