# iview/iview-admin architecture

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

- Interactive diagram: https://gitdiagram.com/iview/iview-admin
- Repository: https://github.com/iview/iview-admin

## Overview

##### Main Components
- UI Components & Views: Show a clear separation between reusable components (found in src/components) and the larger views/pages (found in src/view). These include charts, tables, login forms, drag-and-drop elements, editors, and more.
- Routing: The src/router directory, including routers.js and before-close.js, handles the dynamic routing capabilities. This module is central to navigating between views.
- API Services & Data Handling: The src/api folder collects various modules (data.js, routers.js, user.js) that abstract backend interactions (or provide mock endpoints in src/mock). These form the service layer for communication.
- Global Config & Plugins: Directories such as src/config, src/plugin (e.g., error-store), and src/directive represent the configuration settings, custom directives, and global plugins enhancing functionality.
- Utilities & Libraries: The src/libs directory holds helper functions (axios wrappers, API request handlers, Excel utilities, etc.) that support business logic throughout the application.
- Internationalization (i18n): The src/locale directory maintains language files and locale setup important for supporting multiple languages.
- Testing: The tests directory (with e2e and unit tests) should be represented as a supporting component for quality assurance.

##### Component Interactions and Relationships
- User Interaction Flow: Start with the entry point (public/index.html and src/main.js) which loads the Vue instance. From here, display the App.vue component that sets up the root view.
- State Management: Indicate how actions initiated within UI components dispatch changes to the Vuex Store (src/store), which in turn updates UI components.
- Plugin & Directive Influence: Emphasize how custom plugins (error-store, etc.) and directives (in src/directive) enhance component behavior. They might be “attached” to the central Vue instance or directly to components.
- Assets & Static Files: Represent asset files and public resources as foundational layers used throughout the UI components.

##### Architectural Patterns & Design Principles
- Component-Based Design: The project leverages a modular component structure (Vue components divided by feature, like charts, forms, tables, etc.). Emphasize reuse and separation of concerns.
- MVC (or MVVM) Principles: Although it is a client-side application, there is a clear separation between the view (templates/components), state (Vuex store), and logic (API calls, utilities).
- Routing and State Synchronization: Highlight how dynamic routing combined with Vuex store management allows for reactive UI updates based on user authentication and navigation.
- Testing and Quality Assurance: Include a note on end-to-end (cypress) and unit tests to ensure reliability.

##### Relevant Technologies, Frameworks, and Libraries
- Vue.js (core framework for building the UI)
- iView (UI toolkit for styling and pre-built components)
- Vuex (state management)
- Vue Router (navigation/routing)
- ESLint, Babel, and other configuration tools (for code quality and compatibility)
- Cypress and unit testing frameworks (for testing)

##### Elements
- Annotation of external dependencies like Vue.js, iView UI, and any build tools.
- Testing layers can be represented as peripheral support ensuring the quality and reliability of components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Bootstrap Layer
    subgraph "Bootstrap"
        M1("Public Index"):::entry
        M2("Main Entry"):::entry
        M3("App Root"):::entry
        M1 --> M2
        M2 --> M3
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        N1("UI Components"):::ui
        N2("Page Views"):::ui
    end

    %% Navigation & Routing Layer
    subgraph "Navigation & Routing"
        N3("Vue Router"):::routing
    end

    %% Application Logic Layer
    subgraph "Application Logic Layer"
        N4("Vuex Store"):::store
        N5("API Services"):::api
        N6("Mock Endpoints"):::api
        N7("Global Config"):::plugin
        N8("Global Plugins"):::plugin
        N9("Custom Directives"):::plugin
        N10("Utilities & Libs"):::util
        N11("Internationalization"):::i18n
    end

    %% Infrastructure & Support Layer
    subgraph "Infrastructure & Support"
        N12("Static Assets"):::infra
        N13("Public Resources"):::infra
        N14("Build & Config Files"):::infra
        N15("Testing Suites"):::infra
    end

    %% Connections from Bootstrap to Application Logic
    M3 -->|"initializes"| N3
    M3 -->|"loadsConfig"| N7
    M3 -->|"attachesPlugins"| N8
    M3 -->|"appliesDirectives"| N9
    M3 -->|"usesLibs"| N10
    M3 -->|"setsLocale"| N11

    %% Connections between Navigation & Presentation
    N3 -->|"routesTo"| N2

    %% Within Presentation Layer
    N2 -->|"composes"| N1

    %% UI interactions and state management
    N2 -->|"dispatchesState"| N4
    N4 -->|"updatesView"| N2

    %% API interactions
    N2 -->|"triggersAPI"| N5
    N5 -->|"fetchesMock"| N6

    %% Infrastructure Supports
    N12 -->|"suppliesAssets"| N1
    N13 -->|"supportsInitialization"| M1
    N14 -->|"buildSupport"| M3
    N15 ---|"qualityAssurance"| M3

    %% Classes
    classDef entry fill:#F7E5FF,stroke:#8A2BE2,stroke-width:2px;
    classDef ui fill:#D0E8FF,stroke:#1E90FF,stroke-width:2px;
    classDef routing fill:#E0FFE0,stroke:#32CD32,stroke-width:2px;
    classDef store fill:#FFFACD,stroke:#DAA520,stroke-width:2px;
    classDef api fill:#FFE4E1,stroke:#FF6347,stroke-width:2px;
    classDef plugin fill:#E6E6FA,stroke:#9370DB,stroke-width:2px;
    classDef util fill:#F0FFF0,stroke:#3CB371,stroke-width:2px;
    classDef i18n fill:#FFF0F5,stroke:#FF69B4,stroke-width:2px;
    classDef infra fill:#FFFAF0,stroke:#CD853F,stroke-width:2px;

    %% Click Events
    click N1 "https://github.com/iview/iview-admin/tree/master/src/components"
    click N2 "https://github.com/iview/iview-admin/tree/master/src/view"
    click N3 "https://github.com/iview/iview-admin/tree/master/src/router"
    click N4 "https://github.com/iview/iview-admin/tree/master/src/store"
    click N5 "https://github.com/iview/iview-admin/tree/master/src/api"
    click N6 "https://github.com/iview/iview-admin/tree/master/src/mock"
    click N7 "https://github.com/iview/iview-admin/tree/master/src/config"
    click N8 "https://github.com/iview/iview-admin/tree/master/src/plugin"
    click N9 "https://github.com/iview/iview-admin/tree/master/src/directive"
    click N10 "https://github.com/iview/iview-admin/tree/master/src/libs"
    click N11 "https://github.com/iview/iview-admin/tree/master/src/locale"
    click N12 "https://github.com/iview/iview-admin/tree/master/src/assets"
    click N13 "https://github.com/iview/iview-admin/tree/master/public"
    click N15 "https://github.com/iview/iview-admin/tree/master/tests"
    click N14 "https://github.com/iview/iview-admin/blob/master/vue.config.js"
```
