= ({...}) => {...}
```
---
## 2. UI/UX规范
### 2.1 设计系统
- **组件库:** Material-UI v6 + 自定义金融主题
- **设计Token:**
```ts
export const FINANCE_THEME = {
riskHigh: '#ff4757',
dataVizPalette: ['#1e88e5', '#43a047', ...]
}
```
### 2.2 响应式设计
- **断点策略:**
| 设备 | 断点 | 布局示例 |
|------------|---------|-------------------|
| 移动端 | <768px | 单列卡片堆叠 |
| 桌面端 | ≥1200px | 多面板仪表盘 |
### 2.3 无障碍标准
- **WCAG 2.1 AA合规:**
- 所有交互元素`aria-*`属性完整
- 金融图表提供``替代描述
- 颜色对比度 ≥ 4.5:1
### 2.4 交互模式
- **数据加载:** Skeleton占位 + 渐进式加载
- **交易操作:** 二次确认 + 动画反馈
---
## 3. 组件架构
### 3.1 设计模式
| 模式 | 使用场景 | 示例 |
|---------------|------------------------|--------------------|
| 容器/展示组件 | 数据逻辑分离 | DashboardContainer|
| 复合组件 | 表单组合 | TradeForm |
### 3.2 状态管理
```mermaid
graph LR
A[API Service] -->|Fetch| B(Redux Store)
B -->|Selector| C[UI Components]
D[用户交互] -->|Dispatch| B
```
### 3.3 组件规范
- **Props设计:**
```tsx
interface TChartProps {
data: TFinancialData[]; // 强制类型校验
onDataPointClick?: (event: ChartEvent) => void; // 可选事件
}
```
- **复用原则:** 通过`props.children`实现插槽组件
---
## 4. 性能优化
### 4.1 加载优化
- **代码分割:**
```tsx
const RiskReport = React.lazy(() => import('./views/RiskReport'));
```
- **图片加载:** WebP格式 + CDN动态缩放
### 4.2 渲染优化
- **记忆化策略:**
```tsx
const memoizedChart = React.memo(FinancialChart, (prev, next) =>
prev.data === next.data
);
```
### 4.3 包体积控制
- **Bundle分析:** `webpack-bundle-analyzer`
- **关键优化:**
- 第三方库按需引入(如`lodash-es`)
- Gzip + Brotli压缩
---
## 5. 测试标准
### 5.1 测试金字塔
```mermaid
pie
title 测试覆盖率目标
“单元测试” : 70%
“集成测试” : 20%
“E2E测试” : 10%
```
### 5.2 工具链
| 测试类型 | 工具 | 示例 |
|----------------|-----------------------|-----------------------|
| 单元测试 | Jest + React Testing Library | `render()` |
| E2E测试 | Cypress | 交易全流程验证 |
### 5.3 核心用例
```ts
// 金融计算函数测试
test('calculateCompoundInterest returns correct value', () => {
expect(calculateCompoundInterest(1000, 0.05, 12)).toBeCloseTo(1647.01);
});
```
---
## 6. 构建与部署
### 6.1 开发工作流
```mermaid
graph TB
A[Feature Branch] --> B(CI Pipeline)
B -->|Lint/Test| C[Preview Deployment]
C --> D[Code Review]
D -->|Approved| E[Merge to Main]
```
### 6.2 环境配置
| 环境变量 | 开发环境 | 生产环境 |
|----------------|-------------|---------------|
| `API_ENDPOINT` | api-dev.elq | api.prod.elq |
| `SENTRY_DSN` | - | 启用 |
### 6.3 部署策略
- **零停机部署:** AWS ECS蓝绿部署
- **回滚机制:** 自动保留最近3个版本镜像
---
**文档维护说明:**
1. 所有组件需在Storybook中提供可视化用例
2. 重大变更需通过RFC流程审批
3. 每季度进行指南合规性审计
> 本指南符合金融级应用开发标准,兼顾高性能与合规性要求。
> Eloquent Architecture Team © 2025
--- AI Generated Technical Documentation (Frontend Guideline Document) ---
### **Frontend Development Guideline Document**
**Project: Eloquent AI**
**Version: 1.0**
**Date: 6/20/2025**
---
### **1. Development Standards**
#### **Code Style & Formatting**
- **Tools**: ESLint (Airbnb config) + Prettier.
- **Rules**:
- 2-space indentation, semicolons required.
- Max line length: 120 characters.
- Arrow functions for functional components.
- **Automation**: Pre-commit hooks (Husky + lint-staged) enforce checks.
#### **Naming Conventions**
- **Files**: `PascalCase` for components (e.g., `DashboardCard.tsx`), `camelCase` for utilities (e.g., `dataFormatter.ts`).
- **Variables**: `camelCase` (e.g., `userProfile`), `SCREAMING_SNAKE_CASE` for constants.
- **Components**: Prefix context-specific names (e.g., `FinancialReportTable`).
#### **File & Folder Organization**
```
src/
├── components/ # Reusable UI components
│ ├── common/ # Button, Input
│ └── modules/ # FinanceChart, RiskAssessmentPanel
├── hooks/ # Custom hooks (e.g., useMarketData)
├── services/ # API clients (Axios wrappers)
├── styles/ # Global CSS, themes
├── utils/ # Helper functions
└── pages/ # Route-based page components
```
#### **Documentation**
- **Components**: JSDoc for props, interfaces, and complex logic.
- **READMEs**: Per folder for architectural context.
- **Changelog**: ADR (Architecture Decision Records) for major updates.
---
### **2. UI/UX Guidelines**
#### **Design System**
- **Library**: Storybook-driven component library with Figma integration.
- **Tokens**: Centralized variables (colors, typography) via CSS-in-JS (Emotion).
- **Theming**: Dark/light mode support via React Context.
#### **Responsive Design**
- **Breakpoints**: Mobile-first approach (320px, 768px, 1024px).
- **Grid**: Flexbox/CSS Grid; avoid fixed widths.
- **Testing**: Chrome DevTools + BrowserStack for cross-device validation.
#### **Accessibility (WCAG 2.1 AA)**
- **Semantic HTML**: Proper ARIA roles (e.g., `aria-label` for icons).
- **Keyboard Navigation**: Focus management via `react-focus-lock`.
- **Tools**: Axe-core integration in CI pipeline.
#### **Interaction Patterns**
- **Feedback**: Skeleton loaders for async data, toast notifications for actions.
- **Animations**: Framer Motion for micro-interactions (max 300ms duration).
---
### **3. Component Architecture**
#### **Design Patterns**
- **Atomic Design**: Atoms (buttons), Molecules (search bars), Organisms (data grids).
- **Container/Component**: Separation of logic (containers) and UI (components).
#### **State Management**
- **Local State**: `useState`/`useReducer` for component-specific state.
- **Global State**: Context API for app-wide themes; Redux Toolkit for complex data flows (e.g., real-time financial data).
#### **Props & Events**
- **Props**: Strict TypeScript interfaces (`interface CardProps { title: string; }`).
- **Events**: Custom event handlers (e.g., `onRiskAssessmentComplete`).
#### **Reusable Components**
- **Props Design**: Minimize required props; use default values.
- **Composition**: Slots pattern via `children` prop.
- **Testing**: Unit tests mandatory before PR merge.
---
### **4. Performance Guidelines**
#### **Code Splitting & Lazy Loading**
- **Routes**: React.lazy + Suspense for route-based splitting.
- **Components**: Dynamic imports for heavy modules (e.g., data visualization libraries).
#### **Bundle Optimization**
- **Tree Shaking**: ES6 modules + Webpack 5.
- **Dependencies**: Audit bundle size via `source-map-explorer`; limit third-party libraries.
#### **Rendering Performance**
- **Memoization**: `React.memo` for expensive components; `useMemo`/`useCallback` to prevent re-renders.
- **Virtualization**: `react-window` for large lists/tables.
#### **Memory Management**
- **Leaks**: Cleanup effects (e.g., `clearInterval` in `useEffect` return).
- **Monitoring**: Chrome Memory Profiler in QA cycles.
---
### **5. Testing Standards**
#### **Unit Testing**
- **Tools**: Jest + React Testing Library.
- **Coverage**: 85%+ for core components; snapshot testing for UI consistency.
#### **Integration Testing**
- **Scope**: Component interactions (e.g., form submissions).
- **Mocking**: MSW (Mock Service Worker) for API responses.
#### **E2E Testing**
- **Framework**: Cypress (prioritize critical user journeys: login, data export).
- **Run Frequency**: Nightly in CI/CD pipeline.
#### **Tools**
- **Reporters**: Allure for test reporting.
- **Parallelization**: CI jobs split by test type.
---
### **6. Build & Deployment**
#### **Development Workflow**
- **Git**: Feature branches → PR → Code Review (2 approvals) → Merge to `main`.
- **Environments**:
- `dev`: Vercel previews per PR.
- `staging`: AWS S3 bucket.
- `prod`: AWS CloudFront CDN.
#### **Build Optimization**
- **CI**: GitHub Actions; build time ≤ 5 minutes.
- **Artifacts**: Dockerized builds for environment consistency.
#### **Environment Configuration**
- **Variables**: `.env` files (prefix: `REACT_APP_`); secrets via AWS Parameter Store.
#### **Deployment Strategies**
- **Blue/Green**: Traffic shifting via AWS Route53.
- **Rollbacks**: Automated if error rate > 1% (CloudWatch alarms).
---
**Maintainability Note**: Review guidelines quarterly; automate enforcement via tooling.
**Generated**: 6/20/2025, 10:15:30 AM
--- 生成时间: 6/19/2025, 9:08:43 PM ---">
= ({...}) => {...}
```
---
## 2. UI/UX规范
### 2.1 设计系统
- **组件库:** Material-UI v6 + 自定义金融主题
- **设计Token:**
```ts
export const FINANCE_THEME = {
riskHigh: '#ff4757',
dataVizPalette: ['#1e88e5', '#43a047', ...]
}
```
### 2.2 响应式设计
- **断点策略:**
| 设备 | 断点 | 布局示例 |
|------------|---------|-------------------|
| 移动端 | <768px | 单列卡片堆叠 |
| 桌面端 | ≥1200px | 多面板仪表盘 |
### 2.3 无障碍标准
- **WCAG 2.1 AA合规:**
- 所有交互元素`aria-*`属性完整
- 金融图表提供``替代描述
- 颜色对比度 ≥ 4.5:1
### 2.4 交互模式
- **数据加载:** Skeleton占位 + 渐进式加载
- **交易操作:** 二次确认 + 动画反馈
---
## 3. 组件架构
### 3.1 设计模式
| 模式 | 使用场景 | 示例 |
|---------------|------------------------|--------------------|
| 容器/展示组件 | 数据逻辑分离 | DashboardContainer|
| 复合组件 | 表单组合 | TradeForm |
### 3.2 状态管理
```mermaid
graph LR
A[API Service] -->|Fetch| B(Redux Store)
B -->|Selector| C[UI Components]
D[用户交互] -->|Dispatch| B
```
### 3.3 组件规范
- **Props设计:**
```tsx
interface TChartProps {
data: TFinancialData[]; // 强制类型校验
onDataPointClick?: (event: ChartEvent) => void; // 可选事件
}
```
- **复用原则:** 通过`props.children`实现插槽组件
---
## 4. 性能优化
### 4.1 加载优化
- **代码分割:**
```tsx
const RiskReport = React.lazy(() => import('./views/RiskReport'));
```
- **图片加载:** WebP格式 + CDN动态缩放
### 4.2 渲染优化
- **记忆化策略:**
```tsx
const memoizedChart = React.memo(FinancialChart, (prev, next) =>
prev.data === next.data
);
```
### 4.3 包体积控制
- **Bundle分析:** `webpack-bundle-analyzer`
- **关键优化:**
- 第三方库按需引入(如`lodash-es`)
- Gzip + Brotli压缩
---
## 5. 测试标准
### 5.1 测试金字塔
```mermaid
pie
title 测试覆盖率目标
“单元测试” : 70%
“集成测试” : 20%
“E2E测试” : 10%
```
### 5.2 工具链
| 测试类型 | 工具 | 示例 |
|----------------|-----------------------|-----------------------|
| 单元测试 | Jest + React Testing Library | `render()` |
| E2E测试 | Cypress | 交易全流程验证 |
### 5.3 核心用例
```ts
// 金融计算函数测试
test('calculateCompoundInterest returns correct value', () => {
expect(calculateCompoundInterest(1000, 0.05, 12)).toBeCloseTo(1647.01);
});
```
---
## 6. 构建与部署
### 6.1 开发工作流
```mermaid
graph TB
A[Feature Branch] --> B(CI Pipeline)
B -->|Lint/Test| C[Preview Deployment]
C --> D[Code Review]
D -->|Approved| E[Merge to Main]
```
### 6.2 环境配置
| 环境变量 | 开发环境 | 生产环境 |
|----------------|-------------|---------------|
| `API_ENDPOINT` | api-dev.elq | api.prod.elq |
| `SENTRY_DSN` | - | 启用 |
### 6.3 部署策略
- **零停机部署:** AWS ECS蓝绿部署
- **回滚机制:** 自动保留最近3个版本镜像
---
**文档维护说明:**
1. 所有组件需在Storybook中提供可视化用例
2. 重大变更需通过RFC流程审批
3. 每季度进行指南合规性审计
> 本指南符合金融级应用开发标准,兼顾高性能与合规性要求。
> Eloquent Architecture Team © 2025
--- AI Generated Technical Documentation (Frontend Guideline Document) ---
### **Frontend Development Guideline Document**
**Project: Eloquent AI**
**Version: 1.0**
**Date: 6/20/2025**
---
### **1. Development Standards**
#### **Code Style & Formatting**
- **Tools**: ESLint (Airbnb config) + Prettier.
- **Rules**:
- 2-space indentation, semicolons required.
- Max line length: 120 characters.
- Arrow functions for functional components.
- **Automation**: Pre-commit hooks (Husky + lint-staged) enforce checks.
#### **Naming Conventions**
- **Files**: `PascalCase` for components (e.g., `DashboardCard.tsx`), `camelCase` for utilities (e.g., `dataFormatter.ts`).
- **Variables**: `camelCase` (e.g., `userProfile`), `SCREAMING_SNAKE_CASE` for constants.
- **Components**: Prefix context-specific names (e.g., `FinancialReportTable`).
#### **File & Folder Organization**
```
src/
├── components/ # Reusable UI components
│ ├── common/ # Button, Input
│ └── modules/ # FinanceChart, RiskAssessmentPanel
├── hooks/ # Custom hooks (e.g., useMarketData)
├── services/ # API clients (Axios wrappers)
├── styles/ # Global CSS, themes
├── utils/ # Helper functions
└── pages/ # Route-based page components
```
#### **Documentation**
- **Components**: JSDoc for props, interfaces, and complex logic.
- **READMEs**: Per folder for architectural context.
- **Changelog**: ADR (Architecture Decision Records) for major updates.
---
### **2. UI/UX Guidelines**
#### **Design System**
- **Library**: Storybook-driven component library with Figma integration.
- **Tokens**: Centralized variables (colors, typography) via CSS-in-JS (Emotion).
- **Theming**: Dark/light mode support via React Context.
#### **Responsive Design**
- **Breakpoints**: Mobile-first approach (320px, 768px, 1024px).
- **Grid**: Flexbox/CSS Grid; avoid fixed widths.
- **Testing**: Chrome DevTools + BrowserStack for cross-device validation.
#### **Accessibility (WCAG 2.1 AA)**
- **Semantic HTML**: Proper ARIA roles (e.g., `aria-label` for icons).
- **Keyboard Navigation**: Focus management via `react-focus-lock`.
- **Tools**: Axe-core integration in CI pipeline.
#### **Interaction Patterns**
- **Feedback**: Skeleton loaders for async data, toast notifications for actions.
- **Animations**: Framer Motion for micro-interactions (max 300ms duration).
---
### **3. Component Architecture**
#### **Design Patterns**
- **Atomic Design**: Atoms (buttons), Molecules (search bars), Organisms (data grids).
- **Container/Component**: Separation of logic (containers) and UI (components).
#### **State Management**
- **Local State**: `useState`/`useReducer` for component-specific state.
- **Global State**: Context API for app-wide themes; Redux Toolkit for complex data flows (e.g., real-time financial data).
#### **Props & Events**
- **Props**: Strict TypeScript interfaces (`interface CardProps { title: string; }`).
- **Events**: Custom event handlers (e.g., `onRiskAssessmentComplete`).
#### **Reusable Components**
- **Props Design**: Minimize required props; use default values.
- **Composition**: Slots pattern via `children` prop.
- **Testing**: Unit tests mandatory before PR merge.
---
### **4. Performance Guidelines**
#### **Code Splitting & Lazy Loading**
- **Routes**: React.lazy + Suspense for route-based splitting.
- **Components**: Dynamic imports for heavy modules (e.g., data visualization libraries).
#### **Bundle Optimization**
- **Tree Shaking**: ES6 modules + Webpack 5.
- **Dependencies**: Audit bundle size via `source-map-explorer`; limit third-party libraries.
#### **Rendering Performance**
- **Memoization**: `React.memo` for expensive components; `useMemo`/`useCallback` to prevent re-renders.
- **Virtualization**: `react-window` for large lists/tables.
#### **Memory Management**
- **Leaks**: Cleanup effects (e.g., `clearInterval` in `useEffect` return).
- **Monitoring**: Chrome Memory Profiler in QA cycles.
---
### **5. Testing Standards**
#### **Unit Testing**
- **Tools**: Jest + React Testing Library.
- **Coverage**: 85%+ for core components; snapshot testing for UI consistency.
#### **Integration Testing**
- **Scope**: Component interactions (e.g., form submissions).
- **Mocking**: MSW (Mock Service Worker) for API responses.
#### **E2E Testing**
- **Framework**: Cypress (prioritize critical user journeys: login, data export).
- **Run Frequency**: Nightly in CI/CD pipeline.
#### **Tools**
- **Reporters**: Allure for test reporting.
- **Parallelization**: CI jobs split by test type.
---
### **6. Build & Deployment**
#### **Development Workflow**
- **Git**: Feature branches → PR → Code Review (2 approvals) → Merge to `main`.
- **Environments**:
- `dev`: Vercel previews per PR.
- `staging`: AWS S3 bucket.
- `prod`: AWS CloudFront CDN.
#### **Build Optimization**
- **CI**: GitHub Actions; build time ≤ 5 minutes.
- **Artifacts**: Dockerized builds for environment consistency.
#### **Environment Configuration**
- **Variables**: `.env` files (prefix: `REACT_APP_`); secrets via AWS Parameter Store.
#### **Deployment Strategies**
- **Blue/Green**: Traffic shifting via AWS Route53.
- **Rollbacks**: Automated if error rate > 1% (CloudWatch alarms).
---
**Maintainability Note**: Review guidelines quarterly; automate enforcement via tooling.
**Generated**: 6/20/2025, 10:15:30 AM
--- 生成时间: 6/19/2025, 9:08:43 PM ---">
Mermaid流程图\数据流转说明\接口定义...