# idootop/magicmirror architecture

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

- Interactive diagram: https://gitdiagram.com/idootop/magicmirror
- Repository: https://github.com/idootop/magicmirror

## Overview

##### Main Components

a) Frontend Layer:
- React-based UI (src/ directory) with key components:
- Main UI Views (pages/Launch.tsx, pages/Mirror.tsx)
- Component Library (components/)
- Hooks for Business Logic (hooks/)
- Services for Core Functions (services/)

b) Desktop Application Shell:
- Tauri framework (src-tauri/) which bridges web frontend and native backend:
- Main Process (src-tauri/src/main.rs)
- IPC Commands (src-tauri/src/commands.rs)
- Utility Functions (src-tauri/src/utils.rs)

c) Python Backend Server:
- AI processing server (src-python/):
- Main Server (server.py)
- Face Processing Module (magic/face.py)
- Application Logic (magic/app.py)

##### Interaction Flows

- Frontend → Tauri Bridge: IPC calls for native operations
- Tauri → Python Server: Local API communications
- Python Server → AI Models: Face processing operations
- Data flow for image processing pipeline

##### Architectural Patterns to Highlight

- Client-Server Architecture (Frontend ↔ Python Backend)
- Bridge Pattern (Tauri connecting Web UI and Native features)
- Service-based Architecture (Frontend services layer)
- Hook-based State Management (React hooks)

##### Technical Stack Indicators

- Frontend: React, TypeScript, Vite
- Desktop: Tauri (Rust)
- Backend: Python
- AI: InsightFace, FaceFusion

##### Additional Elements

- Configuration files (tauri.conf.json, pyproject.toml)
- Resource directories (assets, locales)
- Build/Deploy workflows (.github/workflows)

Remember to:
- Use consistent symbols and notation
- Brief annotations for key components
- Both synchronous and asynchronous flows
- Error handling paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        UI[UI Layer]
        UI --> Pages
        UI --> Components
        UI --> Hooks
        UI --> Services
        UI --> Styles["Styles & Assets"]:::styles

        subgraph Pages
            Launch["Launch Page"]:::frontend
            Mirror["Mirror Page"]:::frontend
        end

        subgraph Components
            Lang["Language Switcher"]:::frontend
            Progress["Progress Bar"]:::frontend
        end

        subgraph Hooks
            Download["Download Hook"]:::frontend
            DragDrop["Drag & Drop Hook"]:::frontend
            OS["OS Hook"]:::frontend
            Server["Server Hook"]:::frontend
            SwapFace["Face Swap Hook"]:::frontend
        end

        subgraph Services
            I18N["i18n Service"]:::frontend
            ServerSvc["Server Service"]:::frontend
            Utils["Utils Service"]:::frontend
        end
    end

    subgraph Desktop
        Tauri["Tauri Bridge"]:::desktop
        MainRS["Main Process"]:::desktop
        Commands["IPC Commands"]:::desktop
        TauriUtils["Utility Functions"]:::desktop
        Config["Tauri Config"]:::config
    end

    subgraph Backend
        PyServer["Python Server"]:::backend
        FaceProc["Face Processing"]:::backend
        AppLogic["Application Logic"]:::backend
        Models["AI Models"]:::ai
    end

    subgraph Resources
        Assets["Assets"]:::resource
        Locales["Locales"]:::resource
        Icons["Icons"]:::resource
    end

    subgraph Workflows
        BuildApp["Build App"]:::workflow
        BuildServer["Build Server"]:::workflow
    end

    UI --> Tauri
    Tauri --> PyServer
    PyServer --> Models
    Services --> Tauri
    Hooks --> Services

    %% Click Events
    click Launch "https://github.com/idootop/MagicMirror/blob/main/src/pages/Launch.tsx"
    click Mirror "https://github.com/idootop/MagicMirror/blob/main/src/pages/Mirror.tsx"
    click Lang "https://github.com/idootop/MagicMirror/blob/main/src/components/LanguageSwitcher.tsx"
    click Progress "https://github.com/idootop/MagicMirror/blob/main/src/components/ProgressBar.tsx"
    click Download "https://github.com/idootop/MagicMirror/blob/main/src/hooks/useDownload.ts"
    click DragDrop "https://github.com/idootop/MagicMirror/blob/main/src/hooks/useDragDrop.ts"
    click OS "https://github.com/idootop/MagicMirror/blob/main/src/hooks/useOS.ts"
    click Server "https://github.com/idootop/MagicMirror/blob/main/src/hooks/useServer.ts"
    click SwapFace "https://github.com/idootop/MagicMirror/blob/main/src/hooks/useSwapFace.ts"
    click I18N "https://github.com/idootop/MagicMirror/blob/main/src/services/i18n.ts"
    click ServerSvc "https://github.com/idootop/MagicMirror/blob/main/src/services/server.ts"
    click Utils "https://github.com/idootop/MagicMirror/blob/main/src/services/utils.ts"
    click MainRS "https://github.com/idootop/MagicMirror/blob/main/src-tauri/src/main.rs"
    click Commands "https://github.com/idootop/MagicMirror/blob/main/src-tauri/src/commands.rs"
    click TauriUtils "https://github.com/idootop/MagicMirror/blob/main/src-tauri/src/utils.rs"
    click PyServer "https://github.com/idootop/MagicMirror/blob/main/src-python/server.py"
    click FaceProc "https://github.com/idootop/MagicMirror/blob/main/src-python/magic/face.py"
    click AppLogic "https://github.com/idootop/MagicMirror/blob/main/src-python/magic/app.py"
    click Config "https://github.com/idootop/MagicMirror/blob/main/src-tauri/tauri.conf.json"
    click Assets "https://github.com/idootop/MagicMirror/tree/main/src/assets/locales"
    click Icons "https://github.com/idootop/MagicMirror/tree/main/src-tauri/icons"
    click BuildApp "https://github.com/idootop/MagicMirror/blob/main/.github/workflows/build-app.yaml"
    click BuildServer "https://github.com/idootop/MagicMirror/blob/main/.github/workflows/build-server.yaml"
    click Styles "https://github.com/idootop/MagicMirror/tree/main/src/styles"

    %% Styling
    classDef frontend fill:#3498db,color:#fff
    classDef desktop fill:#2ecc71,color:#fff
    classDef backend fill:#f1c40f,color:#000
    classDef ai fill:#9b59b6,color:#fff
    classDef resource fill:#95a5a6,color:#fff
    classDef workflow fill:#34495e,color:#fff
    classDef config fill:#e74c3c,color:#fff
    classDef styles fill:#1abc9c,color:#fff

    %% Legend
    subgraph Legend
        Frontend["Frontend"]:::frontend
        Desktop["Desktop"]:::desktop
        Backend["Backend"]:::backend
        AI["AI Components"]:::ai
        Resource["Resources"]:::resource
        Workflow["Workflows"]:::workflow
        Config["Configuration"]:::config
    end
```
