# sprang/inkpad architecture

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

- Interactive diagram: https://gitdiagram.com/sprang/inkpad
- Repository: https://github.com/sprang/inkpad

## Overview

##### Project Type and Purpose
- Inkpad is a native iPad vector‐illustration application written in Objective-C/Cocoa Touch.
- It follows an MVC paradigm, with a rich UI layer built in XIBs/Storyboard, a domain-specific “Core” library for drawing and data modeling, and integrations for export and cloud services (Dropbox, OpenClipArt).

##### File Structure Analysis
- Base.lproj & *.lproj folders → UI resources (XIB files, Storyboard, localized strings).
- Classes/ → AppDelegate, UIView subclasses, UIViewControllers, managers, and controllers that glue UI to core logic.
- Inkpad-Core/ → The heart of the drawing engine:
- Tools (pen, eraser, zoom, rotate, boolean ops)
- SVG parser & exporter
- Curve fitting, utilities, math libs (livarot)
- DropboxSDK.framework → Third-party SDK for Dropbox integration.
- Openclipart/ → Custom client for downloading and caching OpenClipArt assets.
- PLists/ → Configuration and defaults (blend modes, page sizes, import formats).
- CrashReports/ → Collected crash logs for debugging.
- Help/, Samples/, Images/ → Static assets.
- Inkpad.xcodeproj, *.plist → Build and entitlements.

##### Insights from README
- High-performance vector operations, SVG/PDF/PNG/JPEG export, Dropbox direct export.
- Emphasis on handling thousands of objects without lag.
- Modular design to allow future feature contributions.

##### Diagramming the System Architecture
a. Main Components
- UI Layer:
– Storyboard & XIBs (layout definitions)
– Views (custom UIView subclasses)
– Controllers (UIViewController subclasses in Classes/)
- Domain/Core Engine (Inkpad-Core):
– Model objects (WDPath, WDGroup, WDText, etc.)
– Tool modules (WD*Tool classes)
– SVG Parser/Serializer
– CurveFit & livarot math library
– Utilities (WDUtilities, WDGLUtilities)
- Services & Integrations:
– DropboxSDK (DBRestClient, DBSession)
– OpenClipArt downloader & cache
- Export & Persistence:
– ExportController (generates SVG, PDF, images)
– Email integration (WDEmail)
– Local file I/O (document management via WDDocument)
- Configuration & Assets:

b. Relationships & Data Flows
1. User interacts with UI → Controller (e.g., WDCanvasController)
2. Controller invokes Core Engine APIs (e.g., ToolManager selects a tool, DrawingManager applies changes to the Model)
3. Model emits change notifications → Controller updates Views
4. ExportController requests Model serialization → SVG/PDF generated
5. For Dropbox export: ExportController hands off serialized data to DropboxSDK REST client
6. OpenClipArtController requests assets → Downloader fetches via network → updates Model and View

c. Architectural Patterns
- MVC: clear separation of Views, Controllers, and Model
- Delegation & Observer: Core engine notifies controllers of model changes
- Plugin-style Tools: each drawing tool implements a common interface (WDTool)
- Layered design: UI → Domain → Service

d. Key Technologies & Frameworks
- Objective-C, Cocoa Touch, Xcode project
- Interface Builder (XIB, Storyboard)
- Property lists for configuration
- DropboxSDK for cloud integration
- NSURLSession/Network code in OpenClipArt client
- Custom math & graphics libs (livarot, GL utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        AppDelegate["WDAppDelegate"]:::frontend
        CanvasController["WDCanvasController"]:::frontend
        ColorController["WDColorController"]:::frontend
        LayerController["WDLayerController"]:::frontend
        ImportController["WDImportController"]:::frontend
        SettingsController["WDSettingsController"]:::frontend
        BrowserController["WDBrowserController"]:::frontend
        CanvasView["WDCanvas"]:::frontend
        BlockingView["WDBlockingView"]:::frontend
        ImageView["WDImageView"]:::frontend
        SelectionView["WDSelectionView"]:::frontend
        Storyboard["XIBs & Storyboard"]:::frontend
    end

    %% Core Engine
    subgraph "Domain/Core Engine" 
        direction TB
        subgraph "Controllers" 
            DrawingController["WDDrawingController"]:::core
            GuideController["WDDynamicGuideController"]:::core
            PropertyManager["WDPropertyManager"]:::core
            ToolManager["WDToolManager"]:::core
        end
        subgraph "Model" 
            WDPath["WDPath"]:::core
            WDGroup["WDGroup"]:::core
            WDText["WDText"]:::core
            WDImage["WDImage"]:::core
            WDDrawing["WDDrawing"]:::core
            WDLayer["WDLayer"]:::core
            WDShadow["WDShadow"]:::core
            WDGradient["WDGradient"]:::core
        end
        subgraph "Tools" 
            SelectionTool["WDSelectionTool"]:::core
            PenTool["WDPenTool"]:::core
            EraserTool["WDEraserTool"]:::core
            ZoomTool["WDZoomTool"]:::core
            TransformTool["WDTransformTool"]:::core
            TextTool["WDTextTool"]:::core
        end
        subgraph "SVG Parser & Serializer" 
            SVGParser["WDSVGParser"]:::core
            SVGHelper["WDSVGHelper"]:::core
        end
        subgraph "Curve Fitting" 
            CurveFit["FitCurves"]:::core
        end
        subgraph "Math Library" 
            Liva["livarot"]:::core
        end
        subgraph "Utilities" 
            Utilities["WDUtilities"]:::core
            GLUtilities["WDGLUtilities"]:::core
        end
    end

    %% Export & Persistence
    subgraph "Export & Persistence"
        direction TB
        ExportController["WDExportController"]:::core
        Email["WDEmail"]:::core
        Document["WDDocument"]:::core
    end

    %% External Services
    subgraph "External Services" 
        direction TB
        Dropbox["DropboxSDK"]:::service
        OpenClipArt["OpenClipArt Client"]:::service
    end

    %% Configuration & Assets
    subgraph "Configuration & Assets"
        direction TB
        PLists["PLists"]:::config
        Samples["Samples & Static Assets"]:::config
        Localization["Localization Resources"]:::config
    end

    %% Relationships
    AppDelegate -->|initializes| CanvasController
    AppDelegate --> ColorController
    AppDelegate --> LayerController
    AppDelegate --> ImportController
    AppDelegate --> SettingsController
    AppDelegate --> BrowserController
    CanvasController -->|manages| CanvasView
    CanvasController -->|uses| BlockingView
    CanvasController -->|updates| SelectionView
    CanvasController -->|renders| ImageView
    CanvasController -->|invokes| ToolManager
    ToolManager -->|selects| PenTool
    ToolManager -->|selects| EraserTool
    ToolManager -->|selects| ZoomTool
    ToolManager -->|selects| TransformTool
    ToolManager -->|selects| TextTool
    ToolManager -->|communicates| DrawingController
    DrawingController -->|modifies| WDDrawing
    WDDrawing -->|contains| WDPath
    WDDrawing -->|contains| WDGroup
    WDDrawing -->|contains| WDText
    WDDrawing -->|contains| WDImage
    WDDrawing -->|contains| WDLayer
    WDDrawing -->|contains| WDShadow
    WDDrawing -->|contains| WDGradient
    DrawingController -->|observes| PropertyManager
    DrawingController -->|uses| GuideController
    CanvasController -->|observes| DrawingController
    ExportController -->|serializes via| SVGParser
    ExportController -->|uses| SVGHelper
    ExportController -->|fits curves using| CurveFit
    ExportController -->|calculates via| Liva
    ExportController -->|exports to| Dropbox
    ExportController -->|writes file via| Document
    ExportController -->|emails via| Email
    OpenClipArt -->|provides assets to| CanvasController
    OpenClipArt -->|caches assets| Samples
    PLists -->|configure| CanvasController
    PLists -->|configure| DrawingController
    Localization -->|localizes| Storyboard
    Storyboard -->|used by| CanvasController

    %% Click Events
    click AppDelegate "https://github.com/sprang/inkpad/blob/develop/Classes/WDAppDelegate.h"
    click CanvasController "https://github.com/sprang/inkpad/blob/develop/Classes/WDCanvasController.h"
    click ColorController "https://github.com/sprang/inkpad/blob/develop/Classes/WDColorController.h"
    click LayerController "https://github.com/sprang/inkpad/blob/develop/Classes/WDLayerController.h"
    click ImportController "https://github.com/sprang/inkpad/blob/develop/Classes/WDImportController.h"
    click SettingsController "https://github.com/sprang/inkpad/blob/develop/Classes/WDSettingsController.h"
    click BrowserController "https://github.com/sprang/inkpad/blob/develop/Classes/WDBrowserController.h"
    click CanvasView "https://github.com/sprang/inkpad/blob/develop/Classes/WDCanvas.h"
    click BlockingView "https://github.com/sprang/inkpad/blob/develop/Classes/WDBlockingView.h"
    click ImageView "https://github.com/sprang/inkpad/blob/develop/Classes/WDImageView.h"
    click SelectionView "https://github.com/sprang/inkpad/blob/develop/Classes/WDSelectionView.h"
    click Storyboard "https://github.com/sprang/inkpad/tree/develop/Base.lproj/"
    click DrawingController "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Controllers/WDDrawingController.h"
    click GuideController "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Controllers/WDDynamicGuideController.h"
    click PropertyManager "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Controllers/WDPropertyManager.h"
    click ToolManager "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Controllers/WDToolManager.h"
    click WDPath "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Model/WDPath.h"
    click WDGroup "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Model/WDGroup.h"
    click WDText "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Model/WDText.h"
    click WDImage "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Model/WDImage.h"
    click WDDrawing "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Model/WDDrawing.h"
    click WDLayer "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Model/WDLayer.h"
    click WDShadow "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Model/WDShadow.h"
    click WDGradient "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Model/WDGradient.h"
    click SelectionTool "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Tools/WDSelectionTool.h"
    click PenTool "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Tools/WDPenTool.h"
    click EraserTool "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Tools/WDEraserTool.h"
    click ZoomTool "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Tools/WDZoomTool.h"
    click TransformTool "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Tools/WDTransformTool.h"
    click TextTool "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Tools/WDTextTool.h"
    click SVGParser "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/SVG/WDSVGParser.h"
    click SVGHelper "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/SVG/WDSVGHelper.h"
    click CurveFit "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/CurveFit/FitCurves.h"
    click Liva "https://github.com/sprang/inkpad/tree/develop/Inkpad-Core/livarot/"
    click Utilities "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Utilities/WDUtilities.h"
    click GLUtilities "https://github.com/sprang/inkpad/blob/develop/Inkpad-Core/Utilities/WDGLUtilities.h"
    click Dropbox "https://github.com/sprang/inkpad/tree/develop/DropboxSDK.framework/"
    click OpenClipArt "https://github.com/sprang/inkpad/tree/develop/Openclipart/"
    click ExportController "https://github.com/sprang/inkpad/blob/develop/Classes/WDExportController.h"
    click Email "https://github.com/sprang/inkpad/blob/develop/Classes/WDEmail.h"
    click Document "https://github.com/sprang/inkpad/blob/develop/Classes/WDDocument.h"
    click PLists "https://github.com/sprang/inkpad/tree/develop/PLists/"
    click Samples "https://github.com/sprang/inkpad/tree/develop/Samples/"
    click Localization "https://github.com/sprang/inkpad/tree/develop/Base.lproj/"

    %% Styles
    classDef frontend fill:#C3DFFF,stroke:#0366d6,color:#000
    classDef core fill:#DFFFD8,stroke:#28a745,color:#000
    classDef service fill:#FFE4B5,stroke:#d73a49,color:#000
    classDef config fill:#E2E2E2,stroke:#6a737d,color:#000
```
