🔥 目标一句话:能讲清楚 CICI 的架构 + 部署流水线
一、CICI 项目是什么?
大厂的企业级前端项目,绝不是简单的“表格 + 表单 + CRUD”。
CICI(Corporate Integrated Control Interface)是一个典型的企业级前端中后台系统,具备:
- 多租户(不同业务方独立使用同一系统)
- 复杂审批流(驳回、加签、分支条件)
- 自动化部署 & 多环境切换(开发、测试、灰度、生产)
- 监控 + 可观测性(前后端全链路埋点)
一句话:这是大厂前端晋升架构师必讲的项目!
二、整体架构
技术选型
- 前端:React + TypeScript + Redux Toolkit + React Query
- 后端:Node.js (NestJS) + GraphQL + Prisma
- 数据库:PostgreSQL
- 部署:Docker + K8s + GitHub Actions(CI/CD)
- 监控:Sentry + Prometheus
系统架构图
三、核心流程与关键代码
1. 登录与权限(前端动态路由)
// src/router/ProtectedRoute.tsx
import { Navigate } from "react-router-dom";
import { useAuth } from "@/hooks/useAuth";
export function ProtectedRoute({ roles, children }) {
const { user } = useAuth();
if (!user) return <Navigate to="/login" />;
if (roles && !roles.includes(user.role)) {
return <Navigate to="/403" />;
}
return children;
}
2. 动态 CRUD 页面
// src/components/DynamicForm.tsx
export const DynamicForm = ({ schema }) => (
<Form>
{schema.fields.map((f) => (
<Form.Item key={f.name} name={f.name}>
{f.type === "input" ? <Input /> : <Select options={f.options} />}
</Form.Item>
))}
</Form>
);
业务只要写 JSON 配置:
{
"fields": [
{ "name": "username", "type": "input", "label": "用户名" },
{ "name": "role", "type": "select", "options": ["Admin", "User"] }
]
}
即可生成表单。
3. 审批流引擎
// backend/services/approval.ts
export function runApprovalFlow(flowConfig, context) {
for (const step of flowConfig.steps) {
if (!step.condition(context)) {
return { status: "REJECTED", step };
}
}
return { status: "APPROVED" };
}
四、自动化部署流程
企业级前端,部署比写代码更重要。
1. Dockerfile(前端)
# 构建阶段
FROM node:18 AS builder
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
# 生产阶段
FROM nginx:1.25
COPY --from=builder /app/dist /usr/share/nginx/html
2. GitHub Actions CI
# .github/workflows/ci.yml
name: CI/CD Pipeline
on:
push:
branches: [ "main" ]
jobs:
build-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install deps
run: npm install
- name: Run Tests
run: npm run test
- name: Build App
run: npm run build
- name: Build Docker Image
run: docker build -t registry.company.com/cici-frontend:${{ github.sha }} .
- name: Push to Registry
run: docker push registry.company.com/cici-frontend:${{ github.sha }}
3. K8s 部署文件
# k8s/deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: cici-frontend
spec:
replicas: 3
selector:
matchLabels:
app: cici-frontend
template:
metadata:
labels:
app: cici-frontend
spec:
containers:
- name: cici-frontend
image: registry.company.com/cici-frontend:latest
ports:
- containerPort: 80
五、质量保障
-
自动化测试
- 单元测试:Jest + RTL(前端)
- 集成测试:Cypress(E2E)
-
代码检查
- ESLint + Prettier + Husky(pre-commit hook)
-
灰度发布
- 利用 K8s
canary deployment,逐步放量
- 利用 K8s
六、总结
CICI 项目展现了 企业级前端的三个必杀技:
- 架构清晰(React+Node+GraphQL+K8s)
- 核心功能健全(动态 CRUD、审批流、权限体系)
- 自动化全流程(GitHub Actions + Docker + K8s + 灰度发布)