# wjq990112/holiday-avatar architecture

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

- Interactive diagram: https://gitdiagram.com/wjq990112/holiday-avatar
- Repository: https://github.com/wjq990112/holiday-avatar

## Overview

##### Project type and purpose
- This is a Vue-based frontend component library (an open-source “avatar generator” tool) that exports:
- A single `Avatar` component that dynamically composes dozens of subcomponents (hair, eyes, mouth, etc.)
- A `genConfig` function to produce random or customizable avatar configs
- A plugin installer (`withInstall`) for global registration
- It uses Rollup to build ES/CJS bundles, and includes a demo app to showcase integration and tree-shaking.

##### File structure
- Top level
- `src/` – all TSX code:
– `Avatar.tsx` – core composition component
– Subfolders (`Ear/`, `Hair/`, `Eyes/`, …) each exporting multiple variants + an index.tsx
– `utils/` – `createName.ts`, `withInstall.ts`
– `index.tsx` – entry, re-exports `Avatar`, `genConfig`, plugin
- `demo/` – a standalone Vue app (HTML+TSX) using its own Rollup config (`rollup.config.demo.ts`)
- `rollup.config.ts` – build script for the library
- `package.json`, `tsconfig.json`, lockfiles, READMEs, license, changelog
- Architectural patterns
- Component composition / factory pattern (avatar parts)
- Plugin pattern (`withInstall`)
- Build pipeline (Rollup) for tree-shaking and dual-module output

##### Extract insights from the README
- Emphasis on direct import vs. global installation
- Usage examples show passing props (config & individual overrides)
- Customizable options table defines public API surface
- Demo link for live preview
- No backend, purely client-side UI library

– Consumer Vue App(s) (downstream projects)
– Holiday-Avatar NPM package
– Core Composition Layer (`Avatar` component)
– Part modules (Hair, Face, Eyes, …)
– Config Generator (`genConfig`)
– Utils (`withInstall`, `createName`)
– Build Pipeline (Rollup)
– Demo Application (separate entrypoint)
b. Relationships and interactions
– Consumer app imports from `holiday-avatar` (either via plugin or direct import)
– `genConfig` generates a JSON config → passed into `Avatar` as props
– `Avatar` core reads config → delegates to individual part modules → renders SVG/JSX
– Build pipeline pulls only imported parts (tree-shaking) → outputs ES/CJS bundles
– Demo app depends on the same build output to render examples
c. Key architectural patterns
– Modular component composition (each avatar part is its own module)
– Factory pattern for config generation
– Plugin registration pattern via `withInstall`
– Tree-shaking optimization via Rollup & ESM
d. Relevant technologies/frameworks
– Vue 3 (JSX/TSX support)
– TypeScript & declaration files
– Rollup (library build + demo bundling)
– pnpm (lockfile, workspace management)

##### Detail without over-segmentation
- At the core, break down `Avatar` into at least these groups: Face, Hair, Eyes, Eyebrow, Ear, Nose, Mouth, Glasses, Shirt, Hat
- `genConfig` feeding into `Avatar` and also being a standalone export

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Consumers
    ConsumerApp["Consumer Vue App(s)"]:::external
    DemoApp["Demo Application"]:::external

    %% Library Package
    subgraph "Holiday-Avatar Package"
        direction TB
        Entry["src/index.tsx\n(Library Entry)"]:::core
        Avatar["Avatar\n(src/Avatar.tsx)"]:::core
        GenConfig["genConfig()\n(src/index.tsx)"]:::util
        WithInstall["withInstall\n(src/utils/withInstall.ts)"]:::util
        CreateName["createName\n(src/utils/createName.ts)"]:::util

        subgraph "Subcomponents"
            direction TB
            Face["Face\n(src/Face/index.tsx)"]:::sub
            Hair["Hair\n(src/Hair/index.tsx)"]:::sub
            Eyes["Eyes\n(src/Eyes/index.tsx)"]:::sub
            EyeBrow["EyeBrow\n(src/EyeBrow/index.tsx)"]:::sub
            Ear["Ear\n(src/Ear/index.tsx)"]:::sub
            Nose["Nose\n(src/Nose/index.tsx)"]:::sub
            Mouth["Mouth\n(src/Mouth/index.tsx)"]:::sub
            Glasses["Glasses\n(src/Glasses/index.tsx)"]:::sub
            Hat["Hat\n(src/Hat/index.tsx)"]:::sub
            Shirt["Shirt\n(src/Shirt/index.tsx)"]:::sub
        end
    end

    %% Build Pipeline
    Build["rollup.config.ts\n(Build Pipeline)"]:::build

    %% Demo Application Structure
    subgraph "Demo App"
        direction TB
        DemoConfig["rollup.config.demo.ts"]:::demo
        DemoHTML["index.html\n(demo/index.html)"]:::demo
        DemoMain["main.ts\n(demo/src/main.ts)"]:::demo
        DemoAppComp["App.tsx\n(demo/src/App.tsx)"]:::demo
    end

    %% Relationships
    ConsumerApp -->|"import package"| Entry
    ConsumerApp -->|"use plugin"| WithInstall
    Entry -->|"exports Avatar"| Avatar
    Entry -->|"exports genConfig"| GenConfig
    Entry -->|"exports withInstall"| WithInstall
    GenConfig -->|"produces config"| Avatar
    Avatar -->|"renders parts"| Face
    Avatar -->|"renders parts"| Hair
    Avatar -->|"renders parts"| Eyes
    Avatar -->|"renders parts"| EyeBrow
    Avatar -->|"renders parts"| Ear
    Avatar -->|"renders parts"| Nose
    Avatar -->|"renders parts"| Mouth
    Avatar -->|"renders parts"| Glasses
    Avatar -->|"renders parts"| Hat
    Avatar -->|"renders parts"| Shirt
    Build -->|"bundles src/*"| Entry
    Build -->|"tree-shaking"| Avatar
    DemoApp -->|"uses build"| DemoConfig
    DemoConfig -->|"bundles demo"| DemoMain
    DemoMain -->|"mounts App"| DemoAppComp
    DemoAppComp -->|"renders Avatar"| Avatar

    %% Click events
    click Avatar "https://github.com/wjq990112/holiday-avatar/blob/main/src/Avatar.tsx"
    click Face "https://github.com/wjq990112/holiday-avatar/blob/main/src/Face/index.tsx"
    click Hair "https://github.com/wjq990112/holiday-avatar/blob/main/src/Hair/index.tsx"
    click Eyes "https://github.com/wjq990112/holiday-avatar/blob/main/src/Eyes/index.tsx"
    click EyeBrow "https://github.com/wjq990112/holiday-avatar/blob/main/src/EyeBrow/index.tsx"
    click Ear "https://github.com/wjq990112/holiday-avatar/blob/main/src/Ear/index.tsx"
    click Nose "https://github.com/wjq990112/holiday-avatar/blob/main/src/Nose/index.tsx"
    click Mouth "https://github.com/wjq990112/holiday-avatar/blob/main/src/Mouth/index.tsx"
    click Glasses "https://github.com/wjq990112/holiday-avatar/blob/main/src/Glasses/index.tsx"
    click Hat "https://github.com/wjq990112/holiday-avatar/blob/main/src/Hat/index.tsx"
    click Shirt "https://github.com/wjq990112/holiday-avatar/blob/main/src/Shirt/index.tsx"
    click GenConfig "https://github.com/wjq990112/holiday-avatar/blob/main/src/index.tsx"
    click WithInstall "https://github.com/wjq990112/holiday-avatar/blob/main/src/utils/withInstall.ts"
    click CreateName "https://github.com/wjq990112/holiday-avatar/blob/main/src/utils/createName.ts"
    click Entry "https://github.com/wjq990112/holiday-avatar/blob/main/src/index.tsx"
    click Build "https://github.com/wjq990112/holiday-avatar/blob/main/rollup.config.ts"
    click DemoConfig "https://github.com/wjq990112/holiday-avatar/blob/main/rollup.config.demo.ts"
    click DemoHTML "https://github.com/wjq990112/holiday-avatar/blob/main/demo/index.html"
    click DemoMain "https://github.com/wjq990112/holiday-avatar/blob/main/demo/src/main.ts"
    click DemoAppComp "https://github.com/wjq990112/holiday-avatar/blob/main/demo/src/App.tsx"

    %% Styles
    classDef core fill:#D0E6FF,stroke:#339,stroke-width:1px
    classDef sub fill:#D4F7D4,stroke:#2A7,stroke-width:1px
    classDef util fill:#FFE6AD,stroke:#EA0,stroke-width:1px
    classDef build fill:#ECECEC,stroke:#999,stroke-width:1px
    classDef demo fill:#F0F0F8,stroke:#669,stroke-width:1px
    classDef external fill:#F5E1FF,stroke:#936,stroke-width:1pxendmodule
```
