# hql287/manta architecture

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

- Interactive diagram: https://gitdiagram.com/hql287/manta
- Repository: https://github.com/hql287/manta

## Overview

##### Project Type & Purpose
- Manta is an Electron‐based desktop application for creating beautiful, customizable invoices.
- It uses React + Redux for its UI, PouchDB (browser) for local storage, multiple renderer “sub‐apps” (main app, preview, modal, tour), and Electron’s main process to handle file I/O, PDF export, and auto‐updates.

##### High‐Level Architecture Analysis
- Top‐Level Folders & Files:
- main/ – Electron main process scripts (window creation, PDF save, directory selection, updater, tour logic)
- app/ – Primary renderer: React/Redux invoice creation UI
- preview/ – Secondary renderer: React/Redux invoice preview and template selection
- modal/ – Renderer for lightweight dialogs
- tour/ – Renderer for first‐run user tour
- static/ – CSS, fonts, images, sound assets
- store/, reducers/, actions/, components/, middlewares/ under app/ follow a classic Redux-based structure
- helpers/ – shared utilities (date, image, PouchDB wrapper)
- i18n/ – translation JSON per locale
- webpack.config.js – bundling entry points for each renderer + main

- Key Architectural Patterns:
- Electron’s multi‐process model (1 main process + multiple renderer windows)
- Frontend uses Redux for unidirectional data flow, React‐DnD/react‐motion for drag/drop and animations
- Local persistence via PouchDB/browser in the renderer—no external server
- IPC (Electron’s inter‐process communication) channels glue main & renderers

##### Core Components
A. Electron Main Process
- Creates & manages windows (App, Preview, Modal, Tour)
- Handles file dialogs, saves PDF (save-pdf.js), logo selection, export directory
- Auto‐update logic (updater.js)
- IPC Server endpoints for:
- “export:pdf”
- “select-logo”
- “select-dir”
- update checks

1. App Window (app/index.jsx)
- React UI components (form, contacts, invoices list, settings)
- Redux store (actions → middlewares → reducers → state → components)
- PouchDB/browser persistence via helpers/pouchDB.js
- i18n module injection
- Drag & Drop & animation HOCs

2. Preview Window (preview/index.jsx)
- Uses the same Redux pattern local to preview
- Renders templates (business, minimal) with dynamic data
- Exposes “print” & PDF preview

3. Modal Window (modal/index.jsx)
- Lightweight React dialog for confirmations, alerts

4. Tour Window (tour/index.jsx)
- Slider container for first‐run user walkthrough

C. Local Storage
- PouchDB (wrapped in helpers/pouchDB.js) persists invoices, settings, contacts
- Config files (electron-settings.js in mocks)

D. Assets & Static Hosting
- CSS/fonts/images under static/ served in each renderer
- Sound effects under libs/ and static/sounds with dynamic loading

##### Relationships & Data Flows
- User Input → App Renderer → Redux Action → Middleware → Reducer → State
- State Changes → PouchDB Persistence → State
- “Preview” Button → IPC call to Main Process (“open-preview”) → Main opens Preview Window → Pass invoice data via IPC or query params
- “Export PDF” → Preview Renderer triggers IPC (“export:pdf”) → Main creates PDF via save-pdf.js and returns status
- Settings changes → Persisted locally → Reflected across renderers via main‐to‐renderer IPC or shared PouchDB

##### Architectural Patterns & Principles
- Single‐Source‐of‐Truth: Redux store per renderer
- Separation of Concerns: UI (React components) vs side‐effects (middlewares) vs storage (PouchDB) vs Electron APIs (main)
- Polyglot Renderer Model: each feature (form, preview, modal, tour) isolated in its own window/process
- Clean IPC Layer: restrict main‐renderer messages to well‐defined channels

## Diagram (Mermaid)

```mermaid
graph TD
    User["User"]:::user

    subgraph "Electron Main Process"
        MP["Electron Main Process\n(window management,\nPDF export,\nupdater)"]:::main
    end

    subgraph "Renderers"
        direction TB
        AR["App Renderer"]:::renderer
        PR["Preview Renderer"]:::renderer
        MR["Modal Renderer"]:::renderer
        TR["Tour Renderer"]:::renderer
    end

    DB["PouchDB\n(Local Storage)"]:::db
    AS["Static Assets\n(CSS, Fonts,\nImages, Sounds)"]:::assets
    I18N["i18n Module"]:::i18n
    WP["Webpack Build"]:::build
    ARStore["Redux Store"]:::store

    User -->|"interacts with"| AR
    AR -->|"dispatch(action)"| ARStore
    ARStore -->|"persist"| DB
    AR -->|"load translations"| I18N
    AR -->|"open preview\n(IPC:'open-preview')"| MP
    MP -->|"creates Preview Window"| PR
    PR -->|"IPC:'export:pdf'"| MP
    MP -->|"returns status"| PR
    DB -->|"shared storage"| PR
    AS -->|"served by webpack"| AR
    AS -->|"served by webpack"| PR
    AS -->|"served by webpack"| MR
    AS -->|"served by webpack"| TR
    WP -->|"bundles entry points"| MP
    WP -->|"bundles entry points"| AR
    WP -->|"bundles entry points"| PR
    WP -->|"bundles entry points"| MR
    WP -->|"bundles entry points"| TR

    %% Click Events
    click MP "https://github.com/hql287/manta/tree/master/main/"
    click AR "https://github.com/hql287/manta/blob/master/app/index.jsx"
    click DB "https://github.com/hql287/manta/blob/master/app/helpers/pouchDB.js"
    click AS "https://github.com/hql287/manta/tree/master/static/"
    click I18N "https://github.com/hql287/manta/blob/master/i18n/i18n.js"
    click WP "https://github.com/hql287/manta/blob/master/webpack.config.js"

    classDef main fill:#f5a623,stroke:#000,color:#000;
    classDef renderer fill:#00aaff,stroke:#000,color:#000;
    classDef db fill:#7ed321,stroke:#000,color:#000;
    classDef assets fill:#9b9b9b,stroke:#000,color:#000;
    classDef i18n fill:#9013fe,stroke:#000,color:#fff;
    classDef build fill:#50e3c2,stroke:#000,color:#000;
    classDef store fill:#4a90e2,stroke:#000,color:#fff;
    classDef user fill:#ffffff,stroke:#000,color:#000;
```
