How duxianwei520/react works
Key architectural components
a. Client/browser
• Loads index.html → pulls in a webpack-built JavaScript bundle
• Renders the React component tree, dispatches Redux actions, reacts to state changes
b. Bundler/Dev Server
• webpack-dev-server serves the app in development (scripts/webpack.dev.config.js)
• webpack.build produces production assets (scripts/webpack.prod.config.js)
c. API Layer
• configs/ajax.js wraps axios to call either the mock endpoints (app/mocks) or a real HTTP server
• app/apis/*.js define high-level API functions
d. Mock Server
• app/mocks provides JSON endpoints for login, menu, user/role/module management, etc.
• Triggered when you run npm run mock alongside npm start
e. Redux
• Actions (app/redux/actions) dispatch API calls
• Reducers (app/redux/reducers) update store
• Middleware (app/middleware) handles logging, history, router sync, async flows
f. UI Layer
• app/pages organizes top-level views (login, menu, settings, base shell)
• Styling: Less files under app/styles
• Third-party UI: Ant Design (antd)
g. Testing
• Unit tests (Jest/Enzyme) under test/
• End-to-end tests (Cypress) under cypress/
Interactions and data flow
• Browser requests index.html → webpack-dev-server responds
• Browser downloads JS/CSS bundles → React hydrates root component
• User action → React component dispatches Redux action → API call via axios → Mock or real server returns JSON → ajax.js middleware inspects status → actions resolve → reducers update store → React re-renders
• react-router maps URL → renders corresponding page/component
Architectural patterns and principles
• Flux pattern via Redux: clear separation of actions, reducers, store, and view
• Container vs. Presentational components: pages handle data, components focus on UI
• API abstraction: app/apis layer decouples UI from raw HTTP calls
• Mock injection: switchable mock server for offline development
• Webpack configuration layers: base, dev, prod, testing to keep builds DRY
• Use rectangles for major subsystems (Client, Bundler, Mock Server, Real API)
• Browser → Dev Server (initial load)
• UI → Redux actions → API → Mock/Real → Redux reducers → UI
• Blue for client-side components
• Green for servers (mock, real)
• Orange for build tools (webpack)