# threeplanetssoftware/apple_cloud_notes_parser architecture

> Architecture diagram of the GitHub repository threeplanetssoftware/apple_cloud_notes_parser, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/threeplanetssoftware/apple_cloud_notes_parser
- Repository: https://github.com/threeplanetssoftware/apple_cloud_notes_parser

## Overview

##### Project Type and Core Purpose
This is a specialized forensic analysis tool designed to parse and extract data from Apple Notes databases. The architecture should emphasize data processing pipelines and file handling capabilities.

##### Main Components

A. Input Layer:
- Multiple input sources (iTunes backup, physical backup, single file, Mac backup)
- Password handling component
- File validation and preprocessing

B. Core Processing Layer:
- Store Parser
- Decryption Engine
- Protobuf Processing
- Data Decompression
- Object Mapping System

C. Data Model Layer:
- Account Management
- Folder Structure
- Objects
- Embedded Objects Handler

D. Output Generation Layer:
- CSV Generator
- HTML Builder
- JSON Formatter
- File Export System

**[Input Sources] → [Processing Engine] → [Data Models] → [Output Generators]**

##### Specific Implementation Details to Highlight

a) Input Processing:
- Parallel paths for different input types (iTunes, physical, single file, Mac)
- Password validation flow connecting to decryption engine

b) Core Processing:
- SQLite database interactions
- Protobuf processing pipeline
- Gzip decompression flow

c) Object Model:
- Inheritance hierarchy of Apple Note classes
- Relationship between embedded objects and notes

d) Output Generation:
- Demonstrate parallel output formats (CSV, HTML, JSON)
- File organization structure

##### Technical Elements

- Ruby 3.0+ runtime environment
- SQLite3 database interactions
- Protobuf processing
- Zlib compression/decompression
- File system operations

##### Important Architectural Patterns

- Command pattern for different backup types
- Factory pattern for note and embedded object creation
- Strategy pattern for different output formats
- Observer pattern for logging and debugging

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        IT["iTunes Backup"]:::input
        PB["Physical Backup"]:::input
        MB["Mac Backup"]:::input
        SF["Single File"]:::input
        
        ITH["iTunes Handler"]:::handler
        PBH["Physical Handler"]:::handler
        MBH["Mac Handler"]:::handler
        HBH["Hashed Handler"]:::handler
        
        IT --> ITH
        PB --> PBH
        MB --> MBH
        SF --> HBH
    end

    subgraph Processing
        NSP["Note Store Parser"]:::core
        DE["Decryption Engine"]:::security
        PP["Protobuf Processing"]:::core
        PPA["Proto Patches"]:::core
        
        ITH & PBH & MBH & HBH --> NSP
        NSP --> DE
        DE --> PP
        PP --> PPA
    end

    subgraph "Data Model"
        AM["Account Management"]:::model
        FS["Folder Structure"]:::model
        NO["Note Objects"]:::model
        CK["CloudKit Integration"]:::model
        
        PPA --> AM
        AM --> FS
        FS --> NO
        NO --> CK
    end

    subgraph "Embedded Objects"
        EO["Base Embedded Object"]:::embedded
        DOC["Document Handler"]:::embedded
        PDF["PDF Handler"]:::embedded
        GAL["Gallery Handler"]:::embedded
        TAB["Table Handler"]:::embedded
        DRW["Drawing Handler"]:::embedded
        UTI["Uniform Type Identifier"]:::embedded
        
        EO --> DOC & PDF & GAL & TAB & DRW
        UTI --> EO
    end

    subgraph Output
        CSV["CSV Generator"]:::output
        HTML["HTML Builder"]:::output
        JSON["JSON Formatter"]:::output
        
        NO --> CSV & HTML & JSON
    end

    %% Click events for component mapping
    click ITH "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleBackup.rb"
    click PBH "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleBackupPhysical.rb"
    click MBH "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleBackupMac.rb"
    click HBH "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleBackupHashed.rb"
    click NSP "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNoteStore.rb"
    click DE "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleDecrypter.rb"
    click PP "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/notestore_pb.rb"
    click PPA "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/ProtoPatches.rb"
    click AM "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesAccount.rb"
    click FS "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesFolder.rb"
    click NO "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNote.rb"
    click CK "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleCloudKitRecord.rb"
    click EO "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedObject.rb"
    click DOC "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedDocument.rb"
    click PDF "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedPDF.rb"
    click GAL "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedGallery.rb"
    click TAB "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedTable.rb"
    click DRW "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleNotesEmbeddedDrawing.rb"
    click UTI "https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/master/lib/AppleUniformTypeIdentifier.rb"

    %% Styling
    classDef input fill:#a8d5ff
    classDef handler fill:#95b8ff
    classDef core fill:#95ff95
    classDef security fill:#ff9595
    classDef model fill:#ffffa8
    classDef embedded fill:#ffc8a8
    classDef output fill:#ffa8a8

    %% Legend
    subgraph Legend
        L1["Input Components"]:::input
        L2["Handler Components"]:::handler
        L3["Core Processing"]:::core
        L4["Security Components"]:::security
        L5["Data Models"]:::model
        L6["Embedded Objects"]:::embedded
        L7["Output Components"]:::output
    end
```
