How hql287/manta works
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