# mysteryven/mini-vite architecture

> Architecture diagram of the GitHub repository mysteryven/mini-vite, 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/mysteryven/mini-vite
- Repository: https://github.com/mysteryven/mini-vite

## Overview

##### Main Components
- Core Build Tool (mini-vite):
- CLI Entry Point: Located in packages/mini-vite/bin (vite.js) which kicks off the tool.
- Node Layer: Under packages/mini-vite/src/node, this contains many of the internal modules. For instance:
▪ Configuration (config.ts & constant.ts) – for tool settings.
▪ HTTP & Server: Files like http.ts and the server directory (e.g., PluginContainer.ts, index.ts, middlewares, moduleGraph.ts, transformRequest.ts, ws.ts) that contribute to the dev server and hot module replacement aspects.
▪ Plugin System: Files such as plugin.ts and the plugins directory (assets.ts, css.ts, esbuild.ts, importAnalysis.ts, resolve.ts) emphasize extensibility and modular processing.
▪ Optimizer: The optimizer folder and its files (esbuildDepPlugin.ts, optimizer.ts, scan.ts) implement dependency pre-bundling – a key feature.
▪ Hot Module Replacement: Although noted as “work in progress,” files like hmr.ts indicate ongoing development.
- Utility Modules: Miscellaneous utilities like node/utils.ts.

- Demo Application (demo):
- Frontend Source: Located in packages/demo/src with components like App.tsx, main.tsx, styling (CSS) and asset management.
- Public Assets: The public directory serves static files.
- Essential configuration: index.html and various tsconfig files showing its integration with the mini-vite tool.

##### Relationships & Interactions
- The demo project is configured to work with mini-vite. When you run the demo (using “pnpm dev”), it invokes the CLI from the mini-vite package.
- The CLI initiates the dev server which employs the server, middleware, and plugin components for tasks like serving files, handling transforms, and managing HMR.
- The optimizer component engages in pre-bundling dependencies for faster builds.
- The plugin architecture allows different file types (JavaScript, TypeScript, JSX, TSX, CSS, etc.) and even static assets from the demo to be correctly processed, ensuring that the mini-vite environment mimics the full Vite experience.

##### Architectural Patterns & Design Principles
- Modularity: The clear division into CLI, server, plugins, and optimizer ensures that each feature can be developed and maintained in isolation.
- Plugin/Extension Pattern: The project’s design focus on a plugin system helps in cleanly separating processing logic for assets, CSS, and module imports.
- Client-Server Interaction: Although still evolving HMR and other functionalities, the system is laid out to handle dynamic server responses and client updates.
- Separation of concerns: The demo project and the core build tool are kept separate, reinforcing a clear interface between a development tool and the application it serves.

##### Relevant Technologies and Frameworks
- TypeScript is used extensively throughout both the demo and mini-vite packages.
- ESBuild integration through the optimizer for dependency handling.
- The usage of “pnpm” indicates package management, and file names like “vite.config.ts” and “tsconfig.json” show standardized configuration practices.
- Familiarity with Vite’s architecture is expected, as this project closely mirrors its structure.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Mini-vite Core Build Tool"
        CLI["\"CLI Entry Point\""]:::core
        CONFIG["\"Configuration Module\""]:::core
        HTTP_SERVER["\"HTTP & Dev Server\""]:::core
        PLUGIN["\"Plugin System\""]:::core
        OPTIMIZER["\"Dependency Optimizer\""]:::core
        HMR["\"Hot Module Replacement\""]:::core
        UTIL["\"Utility Modules\""]:::core
    end

    subgraph "Demo Application"
        DEMO_SRC["\"Demo Frontend Source\""]:::demo
        DEMO_PUBLIC["\"Demo Public Assets & Configuration\""]:::demo
    end

    CLI -->|"start-dev-server"| HTTP_SERVER
    CONFIG -->|"configure"| HTTP_SERVER
    UTIL -->|"support"| HTTP_SERVER

    HTTP_SERVER -->|"processes"| PLUGIN
    HTTP_SERVER -->|"pre-bundles"| OPTIMIZER
    HTTP_SERVER -->|"handles-HMR"| HMR

    DEMO_SRC -->|"send-requests"| HTTP_SERVER
    DEMO_PUBLIC -->|"serve-assets"| HTTP_SERVER

    click CLI "https://github.com/mysteryven/mini-vite/blob/main/packages/mini-vite/bin/vite.js"
    click CONFIG "https://github.com/mysteryven/mini-vite/blob/main/packages/mini-vite/src/node/config.ts"
    click HTTP_SERVER "https://github.com/mysteryven/mini-vite/blob/main/packages/mini-vite/src/node/http.ts"
    click PLUGIN "https://github.com/mysteryven/mini-vite/blob/main/packages/mini-vite/src/node/plugin.ts"
    click OPTIMIZER "https://github.com/mysteryven/mini-vite/tree/main/packages/mini-vite/src/node/optimizer"
    click HMR "https://github.com/mysteryven/mini-vite/blob/main/packages/mini-vite/src/node/hmr.ts"
    click UTIL "https://github.com/mysteryven/mini-vite/blob/main/packages/mini-vite/src/node/utils.ts"
    click DEMO_SRC "https://github.com/mysteryven/mini-vite/tree/main/packages/demo/src"
    click DEMO_PUBLIC "https://github.com/mysteryven/mini-vite/tree/main/packages/demo/public"

    classDef core fill:#AED6F1,stroke:#1F618D,stroke-width:2px
    classDef demo fill:#ABEBC6,stroke:#196F3D,stroke-width:2px
```
