# vinhnx/clendar architecture

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

- Interactive diagram: https://gitdiagram.com/vinhnx/clendar
- Repository: https://github.com/vinhnx/clendar

## Overview

##### Project Type & Purpose
- Clendar is a mobile calendar application that has evolved from a UIKit-based project to a modern SwiftUI implementation. It is designed to be minimal yet feature-rich, including event management, natural language input parsing, Siri shortcuts, keyboard shortcuts, different themes, and even Apple Watch complications and Widget support.
- The README clearly shows that it is an iOS (and iPadOS, watchOS) app with auxiliary extensions (Watch App, Widget) that leverage modern Apple frameworks such as SwiftUI, WidgetKit, and WatchKit.

##### File Structure
- The top-level directories indicate separate concerns:
- "Clendar" contains the main application code, including various modules (Calendar View, Event Editor, Event Viewer, Settings, etc.) and base components.
- "ClendarTests" and "ClendarUITests" provide the testing layers.
- "ClendarWatchApp Extension" and "ClendarWidget" represent the watch extension and widget targets respectively.
- "Dependencies" and "Packages" house external dependencies and Swift Packages (e.g., ClendarTheme, a calendar view package) that support core functionality.
- Various configuration files (.swiftlint.yml, .swiftformat, Podfile, etc.) and CI workflows (GitHub Actions in the .github folder) indicate strong automated build and linting practices.
- The modular organization (Modules, Components, Helper, Models) suggests the source code is partitioned into distinct domains following separation-of-concerns principles.

a. Main Components of the System:
- App Layer: The main Clendar application (ClendarApp.swift) that initializes the app and sets up the SwiftUI view hierarchy.
- Modules: Separate folders for Calendar, Event Editor, Event Viewer, Settings, Siri Shortcuts, Lunar, and Plus. These modules encapsulate features such as calendar view rendering, event management, and customization.
- Helper & Utilities: Includes logging, purchase handling (IAPHandler), natural language input parsing, and various extensions to simplify Swift types and UI components.
- External Dependencies and Swift Packages: For instance, the “Shift” package for EventKit wrapper functionality, and “Laden” for loading indicators.
- Platform-specific Extensions:
- Watch App: ClendarWatchApp and its associated extension for Apple Watch complications.
- Widget: ClendarWidget which provides the calendar widget views and timeline providers.
- Tests: Unit tests (ClendarTests) and UI tests (ClendarUITests).

b. Relationships and Data Flow:
- The central app component (ClendarApp.swift) serves as the entry point and ties together the various modules.
- Modules interact with the Helper classes for utilities (e.g., Logger, Date parsing, IAPHandler) and with Models that represent core data (CalendarEvent, CalendarIdentifier, etc.).
- The UI, primarily designed in SwiftUI, communicates with backend logic through Combine and property wrappers.
- There is integration with external services like EventKit for calendar data, StoreKit for in-app purchases, and SiriKit for establishing shortcuts.
- The watch and widget extensions communicate with the main application for shared data (possibly via the shared UserDefaults or directly using utility classes).

c. Architectural Patterns & Design Principles:
- The app uses a modular architecture with separation between UI components (Views/Modifiers) and business logic, and each module is isolated in its own folder.
- SwiftUI’s declarative UI paradigm is central, with significant use of property wrappers and reactive programming (using Combine).
- There is clear usage of dependency management through Swift Package Manager and CocoaPods.
- The overall structure supports multi-target build (iOS, watchOS, Widget) indicating adaptive modularity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build & CI
    subgraph "Build & CI"
      GitHubActions["GitHub Actions"]:::ci
      Fastlane["Fastlane"]:::ci
    end

    %% External Dependencies
    subgraph "External Dependencies"
      ClendarTheme["ClendarTheme"]:::external
      CalendarViewPkg["CalendarView"]:::external
      Dependencies["Dependencies Config"]:::external
    end

    %% Main App Layer
    subgraph "Main App Layer"
      MA["ClendarApp"]:::ui
    end

    %% Modules
    subgraph "Modules"
      CalChooser["Calendar Chooser"]:::module
      CalView["Calendar View"]:::module
      CalEventList["Calendar Event List"]:::module
      CalMain["Main Calendar"]:::module
      EventEditor["Event Editor"]:::module
      EventViewer["Event Viewer"]:::module
      Settings["Settings"]:::module
      SiriShortcuts["Siri Shortcuts"]:::module
      Lunar["Lunar"]:::module
      PlusModule["Plus"]:::module
    end

    %% Helpers & Utilities
    subgraph "Helpers & Utilities"
      GeneralHelper["Helpers & Extensions"]:::helper
      Logger["Logger"]:::helper
      Purchase["Purchase Handler"]:::helper
    end

    %% Platform-Specific Targets
    subgraph "Platform-Specific Targets"
      watchMain["Watch App Main"]:::platform
      watchExtension["Watch App Extension"]:::platform
      Widget["Widget"]:::platform
    end

    %% Testing
    subgraph "Testing"
      UnitTests["ClendarTests"]:::test
      UITests["ClendarUITests"]:::test
    end

    %% Relationships
    GitHubActions -->|"build"| MA
    Fastlane -->|"deploy"| MA

    ClendarTheme -->|"dependency"| MA
    CalendarViewPkg -->|"dependency"| MA
    Dependencies -->|"config"| MA

    MA -->|"initiates"| CalChooser
    MA -->|"initiates"| CalView
    MA -->|"initiates"| CalEventList
    MA -->|"initiates"| CalMain
    MA -->|"initiates"| EventEditor
    MA -->|"initiates"| EventViewer
    MA -->|"initiates"| Settings
    MA -->|"initiates"| SiriShortcuts
    MA -->|"initiates"| Lunar
    MA -->|"initiates"| PlusModule

    CalChooser -->|"uses"| GeneralHelper
    CalView -->|"uses"| GeneralHelper
    EventEditor -->|"utilizes"| Logger
    EventViewer -->|"utilizes"| Purchase
    Settings -->|"calls"| GeneralHelper
    SiriShortcuts -->|"calls"| GeneralHelper
    Lunar -->|"calls"| GeneralHelper
    PlusModule -->|"calls"| GeneralHelper

    EventEditor -->|"uses"| CalendarViewPkg

    MA -->|"sharesData"| watchMain
    MA -->|"sharesData"| watchExtension
    MA -->|"sharesData"| Widget

    UnitTests -->|"tests"| MA
    UITests -->|"tests"| CalView

    %% Click Events
    click MA "https://github.com/vinhnx/clendar/blob/main/Clendar/ClendarApp.swift"
    click CalChooser "https://github.com/vinhnx/clendar/tree/main/Clendar/Modules/Calendar Chooser"
    click CalView "https://github.com/vinhnx/clendar/tree/main/Clendar/Modules/Calendar View"
    click CalEventList "https://github.com/vinhnx/clendar/tree/main/Clendar/Modules/Calendar/Event List"
    click CalMain "https://github.com/vinhnx/clendar/tree/main/Clendar/Modules/Calendar/Main Calendar"
    click EventEditor "https://github.com/vinhnx/clendar/tree/main/Clendar/Modules/Event Editor"
    click EventViewer "https://github.com/vinhnx/clendar/tree/main/Clendar/Modules/Event Viewer"
    click Settings "https://github.com/vinhnx/clendar/tree/main/Clendar/Modules/Settings"
    click SiriShortcuts "https://github.com/vinhnx/clendar/tree/main/Clendar/Modules/Siri Shortcuts"
    click Lunar "https://github.com/vinhnx/clendar/tree/main/Clendar/Modules/Lunar"
    click PlusModule "https://github.com/vinhnx/clendar/tree/main/Clendar/Modules/Plus"
    click GeneralHelper "https://github.com/vinhnx/clendar/tree/main/Clendar/Helper"
    click Logger "https://github.com/vinhnx/clendar/tree/main/Clendar/Helper/Logger"
    click Purchase "https://github.com/vinhnx/clendar/tree/main/Clendar/Helper/Purchase"
    click ClendarTheme "https://github.com/vinhnx/clendar/tree/main/Packages/ClendarTheme"
    click CalendarViewPkg "https://github.com/vinhnx/clendar/tree/main/Packages/CalendarView"
    click Dependencies "https://github.com/vinhnx/clendar/tree/main/Dependencies"
    click watchMain "https://github.com/vinhnx/clendar/tree/main/ClendarWatchApp"
    click watchExtension "https://github.com/vinhnx/clendar/tree/main/ClendarWatchApp Extension"
    click Widget "https://github.com/vinhnx/clendar/tree/main/ClendarWidget"
    click UnitTests "https://github.com/vinhnx/clendar/tree/main/ClendarTests"
    click UITests "https://github.com/vinhnx/clendar/tree/main/ClendarUITests"
    click GitHubActions "https://github.com/vinhnx/clendar/tree/main/.github/workflows"
    click Fastlane "https://github.com/vinhnx/clendar/tree/main/fastlane"

    %% Styles
    classDef ui fill:#f9c,stroke:#333,stroke-width:2px;
    classDef module fill:#bbf,stroke:#333,stroke-width:2px;
    classDef helper fill:#bfb,stroke:#333,stroke-width:2px;
    classDef external fill:#ffb,stroke:#333,stroke-width:2px;
    classDef platform fill:#fbf,stroke:#333,stroke-width:2px;
    classDef test fill:#fed,stroke:#333,stroke-width:2px;
    classDef ci fill:#dff,stroke:#333,stroke-width:2px;
```
