8.4 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
Ant Design Pro — an enterprise-class React UI solution built on Umi Max (v4), antd v6, and ProComponents v3. It serves as both a production boilerplate and a live demo of Ant Design's capabilities.
Commands
# Development
npm start # Dev server with mock (UMI_ENV=dev)
npm run dev # Dev server without mock
npm run start:no-mock # Start with MOCK=none, proxy to real backend
npm run start:pre # Pre-production environment
npm run start:test # Test environment
# Build & Preview
npm run build # Production build (utoopack, Turbopack-based)
npm run preview # Preview production build on port 8000
npm run preview:build # Build and preview on port 8000
npm run deploy # Build and deploy to GitHub Pages (gh-pages branch)
npm run analyze # Bundle size analysis
# Lint & Type Check
npm run lint # Biome lint + tsc --noEmit
npm run biome # Biome check --write (auto-fix)
npm run tsc # Type check only (tsc --noEmit)
# Test
npm run test # Run all Jest tests
npm run test:coverage # Jest with coverage
npm run test:update # Update test snapshots
# Run a single test: npx jest src/pages/user/login/login.test.tsx
# Code Generation
npm run openapi # Regenerate services from config/oneapi.json (overwrites src/services/)
# Other
npm run simple # Irreversible: removes most page blocks for minimal version
npm run i18n-remove # Remove i18n, replace with zh-CN
npm run record # Record request data for mock replay
Documentation
docs/cheatsheet.zh-CN.md/docs/cheatsheet.en-US.md— comprehensive cheatsheet covering routes, layout, data flow, requests, permissions, i18n, styling, and testing with code examples. Rendered in the Welcome page via@ant-design/x-markdown.
Architecture
Framework: Umi Max
Umi Max (@umijs/max) is the meta-framework. It wraps the build pipeline and provides conventions:
- Build tool: utoopack (Turbopack-based, Webpack-compatible). Configured via
utoopackfield inconfig/config.ts, supportsmodule.rulesfor custom loaders - Central config:
config/config.ts(defineConfig) controls all plugins, theme, proxy, and build settings - Routes: Defined declaratively in
config/routes.ts, not convention-based. Each route mapscomponentto a file undersrc/pages/. Routenameauto-maps tomenu.xxxi18n key. Routeaccessfield controls menu visibility (unauthorized routes hidden from menu) - Convention files in
src/:app.tsx(runtime config),access.ts(permissions),global.tsx(side effects),loading.tsx(route transitions),typings.d.ts(global types) - Umi plugins are enabled via config flags in
config/config.ts(e.g.,model,initialState,access,locale,qiankun)
Authentication Flow
app.tsxexportsgetInitialState()→ callsGET /api/currentUser- If 401 and not on login page → redirect to
/user/login?redirect=... access.tsdefines permissions:canAdmin=currentUser.access === 'admin'- Routes use
access: 'canAdmin'inconfig/routes.tsfor permission gating - Login mock credentials:
admin/ant.design(admin) oruser/ant.design(user)
API & Request Layer
- Auto-generated services in
src/services/ant-design-pro/— do NOT edit manually; regenerate withnpm run openapi - Per-page services: many pages have co-located
service.tsfiles - Request config: centralized in
src/requestErrorConfig.ts(error handler, interceptors, base URL). Therequestexport inapp.tsxsets globalRequestConfig - Built-in
requestfunction from@umijs/max— no manual axios wrapping needed - Production API:
https://pro-api.ant-design-demo.workers.dev - Dev proxy config:
config/proxy.ts(keyed byUMI_ENV)
Mock System
- Global mocks in
mock/(Express-style handlers matching URL patterns like'GET /api/currentUser') - Co-located page mocks:
src/pages/**/_mock.ts(Umi auto-discovers these) requestRecord.mock.jsis gitignored
State Management
- Umi model plugin (
useModel): files insrc/models/auto-register as global hooks. UseuseModel('filename')in any component useModel('@@initialState')for global state (currentUser, settings). Initialized bygetInitialState()inapp.tsxwhich runs once on app startupuseRequestfrom@umijs/maxfor simple data fetching- @tanstack/react-query for complex server state (e.g., table-list uses
useMutation+useQuery) - Most pages use ProTable's built-in
requestprop for data loading
Styling: Three Systems Coexist
- Tailwind CSS v4 — entry:
src/tailwind.css, PostCSS plugin inpostcss.config.js. Best for layout utilities - antd-style v4 (
createStyles) — CSS-in-JS with design token access ({ token }). Preferred when consuming theme tokens - CSS Modules (
*.module.less/*.module.css) — for component-scoped styles - Less (
global.less) — legacy, only for font-face declarations and base styles
New code should prefer Tailwind for layout, antd-style for theme-aware styles, CSS Modules for component styles. Less is only for legacy global styles.
Dynamic theme: configured in config/config.ts under antd.configProvider.theme.token. Dev mode SettingDrawer allows live theme switching.
Internationalization
8 locales in src/locales/ (zh-CN, en-US, zh-TW, ja-JP, pt-BR, id-ID, fa-IR, bn-BD). Pages use useIntl().formatMessage() with id and defaultMessage. Menu labels auto-resolve via route name key (e.g., name: 'login' → menu.login).
Layout
ProLayout is configured via the layout export in src/app.tsx (RunTimeLayoutConfig). Layout settings (theme, color, layout mode) in config/defaultSettings.ts. Layout modes: side (sidebar), top (top nav), mix (mixed). Routes with layout: false (e.g., /user/*) render without the ProLayout shell. Use <PageContainer> from @ant-design/pro-components for page-level headers and breadcrumbs.
Page Co-location Pattern
Each page directory contains its own index.tsx, optional service.ts, _mock.ts, data.d.ts (types), and style.ts or CSS files. This is the primary organizational pattern — keep page-specific code with the page.
Cloudflare Worker Backend
cloudflare-worker/ is a separate deployable (Hono framework, own package.json/tsconfig.json). Not an npm workspace — manage independently. Provides the production demo API.
Ant Design CLI
@ant-design/cli (antd) is installed as a dev dependency. It provides offline antd component metadata and project analysis. Run via npx antd.
- Always query before writing antd code — use
npx antd info <Component>to check props/APIs rather than guessing from memory npx antd demo <Component> <name>— get working demo codenpx antd token <Component>— check design tokensnpx antd semantic <Component>— check semantic classNamesnpx antd lint ./src— find deprecated or problematic antd usagenpx antd doctor— diagnose project configuration issuesnpx antd migrate <v1> <v2>— migration checklist between versions- Always use
--format jsonfor structured output
The CLI also supports MCP server mode: npx antd mcp (for IDE integrations).
Key Conventions
- Biome replaces ESLint + Prettier. Config in
biome.json. Pre-commit hook runslint-stagedwith Biome. - Commit messages: must follow conventional commits (
commitlintwith@commitlint/config-conventional). - TypeScript strict mode enabled. Path aliases:
@/*→./src/*,@@/*→./src/.umi/*. - Node >= 20 required.
- Markdown as raw strings:
config/md-raw-loader.cjslets.mdfiles be imported as strings (used in Welcome/cheatsheet pages with@ant-design/x-markdown). - Auto-generated code in
src/services/is excluded from Biome linting. Never edit manually — regenerate withnpm run openapi. - Adding a new page: 1) Create component in
src/pages/2) Add route inconfig/routes.ts3) Add menu translation insrc/locales/(routenamemaps tomenu.xxxi18n key) - Adding global state: Create a file in
src/models/exporting a custom Hook, useuseModel('filename')in components - Access control: Route-level via
accessfield in routes; component-level via<Access accessible={...}>oruseAccess()hook from@umijs/max