# duxianwei520/react architecture

> Architecture diagram of the GitHub repository duxianwei520/react, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/duxianwei520/react
- Repository: https://github.com/duxianwei520/react

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Bundler/Dev Server"
        WBase["webpack.base.config.js"]:::tool
        WDev["webpack.dev.config.js"]:::tool
        WProd["webpack.prod.config.js"]:::tool
        WTest["webpack.testing.config.js"]:::tool
    end

    subgraph "Client/Browser"
        EntryHTML["index.html"]:::client
        ClientJS["client.js"]:::client

        subgraph "API Layer"
            Ajax["ajax.js"]:::client
            CommonAPI["common.js"]:::client
            ManageAPI["manage.js"]:::client
            MockImpl["__mocks__"]:::client
        end

        subgraph "State Management"
            ActionsCG["common.js"]:::client
            ActionsTab["tabList.js"]:::client
            ReducersIdx["index.js"]:::client
            ReducersCG["common.js"]:::client
            ReducersTab["tabList.js"]:::client
            MiddlewareIdx["index.js"]:::client
            MiddlewareLog["logger.js"]:::client
            MiddlewareHist["history.js"]:::client
            MiddlewareRouter["router.js"]:::client
            MiddlewareCS["configureStore.js"]:::client
        end

        subgraph "UI Layer"
            Components["Components (draw, logo, tableList)"]:::client
            Pages["Pages (base, menu, set)"]:::client
            Styles["Styles (.less)"]:::client
        end
    end

    subgraph "Mock Server"
        HttpMock["http.js"]:::server
        ImMap["interfaceMap.js"]:::server
        ImFilter["interfaceFilter.js"]:::server
        MockAPIs["apis/..."]:::server
    end

    RealAPI["Real Backend API"]:::server

    Jest["Jest/Enzyme Tests"]:::test
    Cypress["Cypress E2E Tests"]:::test

    Browser["Browser"]:::client

    Browser -->|GET /| WDev
    WDev -->|serves index.html & bundle| Browser
    Browser -->|loads bundle| EntryHTML
    EntryHTML -->|executes| ClientJS
    ClientJS -->|hydrate root component| Components
    Components -->|dispatch| ActionsCG
    Components -->|dispatch| ActionsTab
    ActionsCG -->|calls| Ajax
    ActionsTab -->|calls| Ajax
    Ajax -->|uses| CommonAPI
    Ajax -->|uses| ManageAPI
    Ajax -->|uses| MockImpl
    Ajax -->|HTTP request| MockAPIs
    Ajax -->|HTTP request| RealAPI
    MockAPIs -->|returns JSON| Ajax
    RealAPI -->|returns JSON| Ajax
    Ajax -->|response| ActionsCG
    Ajax -->|response| ActionsTab
    ActionsCG -->|dispatch| ReducersIdx
    ActionsCG -->|dispatch| ReducersCG
    ActionsTab -->|dispatch| ReducersTab
    ReducersIdx -->|update store| ClientJS
    ReducersCG -->|update store| ClientJS
    ReducersTab -->|update store| ClientJS
    ClientJS -->|re-render| Components
    ClientJS -->|route change| Pages
    Pages -->|styling| Styles

    Jest -->|tests| Components
    Jest -->|tests| ActionsCG
    Jest -->|tests| ReducersIdx
    Cypress -->|E2E flows| Browser

    classDef client fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef server fill:#d4edda,stroke:#333,stroke-width:1px
    classDef tool fill:#ffe5b4,stroke:#333,stroke-width:1px
    classDef test fill:#f2dede,stroke:#333,stroke-width:1px

    click EntryHTML "https://github.com/duxianwei520/react/blob/master/app/index.html"
    click ClientJS "https://github.com/duxianwei520/react/blob/master/app/client.js"
    click WBase "https://github.com/duxianwei520/react/blob/master/scripts/webpack.base.config.js"
    click WDev "https://github.com/duxianwei520/react/blob/master/scripts/webpack.dev.config.js"
    click WProd "https://github.com/duxianwei520/react/blob/master/scripts/webpack.prod.config.js"
    click WTest "https://github.com/duxianwei520/react/blob/master/scripts/webpack.testing.config.js"
    click Ajax "https://github.com/duxianwei520/react/blob/master/app/configs/ajax.js"
    click CommonAPI "https://github.com/duxianwei520/react/blob/master/app/apis/common.js"
    click ManageAPI "https://github.com/duxianwei520/react/blob/master/app/apis/manage.js"
    click MockImpl "https://github.com/duxianwei520/react/tree/master/app/apis/__mocks__"
    click HttpMock "https://github.com/duxianwei520/react/blob/master/app/mocks/http.js"
    click ImMap "https://github.com/duxianwei520/react/blob/master/app/mocks/interfaceMap.js"
    click ImFilter "https://github.com/duxianwei520/react/blob/master/app/mocks/interfaceFilter.js"
    click MockAPIs "https://github.com/duxianwei520/react/tree/master/app/mocks/apis"
    click ActionsCG "https://github.com/duxianwei520/react/blob/master/app/redux/actions/common.js"
    click ActionsTab "https://github.com/duxianwei520/react/blob/master/app/redux/actions/tabList.js"
    click ReducersIdx "https://github.com/duxianwei520/react/blob/master/app/redux/reducers/index.js"
    click ReducersCG "https://github.com/duxianwei520/react/blob/master/app/redux/reducers/common.js"
    click ReducersTab "https://github.com/duxianwei520/react/blob/master/app/redux/reducers/tabList.js"
    click MiddlewareIdx "https://github.com/duxianwei520/react/blob/master/app/middleware/index.js"
    click MiddlewareLog "https://github.com/duxianwei520/react/blob/master/app/middleware/logger.js"
    click MiddlewareHist "https://github.com/duxianwei520/react/blob/master/app/middleware/history.js"
    click MiddlewareRouter "https://github.com/duxianwei520/react/blob/master/app/middleware/router.js"
    click MiddlewareCS "https://github.com/duxianwei520/react/blob/master/app/middleware/configureStore.js"
    click Jest "https://github.com/duxianwei520/react/tree/master/test/"
    click Cypress "https://github.com/duxianwei520/react/tree/master/cypress/"
    click Components "https://github.com/duxianwei520/react/tree/master/app/components"
    click Pages "https://github.com/duxianwei520/react/tree/master/app/pages"
    click Styles "https://github.com/duxianwei520/react/tree/master/app/styles"
```
