# opficdev/swiftui_snapplan architecture

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

- Interactive diagram: https://gitdiagram.com/opficdev/swiftui_snapplan
- Repository: https://github.com/opficdev/swiftui_snapplan

## Overview

The SnapPlan project is an iOS application that extends the functionality of a standard calendar by incorporating photos, location information, and voice memos. It uses the MVVM (Model-View-ViewModel) design pattern to separate presentation, data, and business logic. In addition, it leverages several Firebase services—including FirebaseAuth for user authentication, Firestore for user and schedule data, and Firebase Storage for handling photos and voice memos.

##### Main Components
- Frontend (iOS App): Represent the app’s visual elements and user interface.
- Views: This layer includes various SwiftUI views like LoginView, CalendarView, PlannerView, ScheduleView, and others found in the SnapPlan/View folder.
- UI Components: Elements such as CalendarCell, DateTimePicker, LinearAudioPlayer, and various custom controls in the SnapPlan/Component directory.
- ViewModels: Found in SnapPlan/ViewModel, these components mediate between the UI (View) and the data/business logic layers. Notable ones include FirebaseViewModel, MapViewModel, and ScheduleViewModel.
- Model Layer: Located in SnapPlan/Model, this contains data structures such as ScheduleData, UserData, and others that define the core data of the application.
- App Lifecycle: The entry points like SnapPlanApp.swift and AppDelegate.swift serve as the application’s launch and lifecycle management.
- Firebase Backend:
- Authentication: FirebaseAuth to handle user sign-in.
- Firestore: For storing user information (Users Collection) and schedule/calendar data (Schedules Collection).
- Firebase Storage: For storing photos and voice memos.
- External Libraries/Technologies:
- Combine for reactive programming (e.g., updating the current time every 0.1 seconds).
- SwiftUI for UI development.

##### Relationships and Interactions
- That the Model layer represents both local data structures and contracts that come from the Firebase backend (e.g., schedule and user details).
- Separate and connect Firebase services:

##### Architectural Patterns and Design Principles
- MVVM as the core design pattern. Denote separate layers for Views (UI), ViewModels (Business Logic/State Management), and Models (Data Structures).
- Use of Combine for reactive data flow and asynchronous updates.
- That the Firebase service integration is abstracted through ViewModels, which manage all API calls and data synchronization with the backend.

##### Important Notes
- Be as detailed as possible: Include every main component and its interaction. For example, include even the FirebaseViewModel that handles authentication and data fetching.
- Don’t hesitate to break down further: Split larger components like the UI layer into separate modules (login, calendar view, schedule creation, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% App Lifecycle
    subgraph "App Lifecycle"
        AP1["SnapPlanApp"]:::lifecycle
        AP2["AppDelegate"]:::lifecycle
    end

    %% UI Layer
    subgraph "UI Layer"
        subgraph "Views"
            V1["LoginView"]:::ui
            V2["CalendarView"]:::ui
            V3["PlannerView"]:::ui
            V4["ScheduleView"]:::ui
            V5["ScheduleCycleView"]:::ui
        end
        subgraph "UI Components"
            UC1["CalendarCell"]:::ui
            UC2["DateTimePicker"]:::ui
            UC3["LinearAudioPlayer"]:::ui
            UC4["ScheduleBox"]:::ui
        end
    end

    %% Business Logic Layer (ViewModels)
    subgraph "Business Logic (ViewModels)"
        VM1["FirebaseViewModel"]:::vm
        VM2["MapViewModel"]:::vm
        VM3["PlannerViewModel"]:::vm
        VM4["ScheduleViewModel"]:::vm
        VM5["SearchLocationViewModel"]:::vm
        VM6["UIViewModel"]:::vm
    end

    %% Data Layer
    subgraph "Data Layer"
        subgraph "Models"
            M1["ScheduleData"]:::model
            M2["UserData"]:::model
        end
    end

    %% Firebase Services
    subgraph "Firebase Services"
        FB1["Firebase Auth"]:::fb
        FB2["Firestore - Users"]:::fb
        FB3["Firestore - Schedules"]:::fb
        FB4["Firebase Storage - Media"]:::fb
    end

    %% Connections from App Lifecycle to UI Layer
    AP1 -->|"launches"| V1
    AP2 -->|"initializes"| V1

    %% View to ViewModel bindings
    V1 -->|"binds_to"| VM1
    V2 -->|"binds_to"| VM4
    V3 -->|"binds_to"| VM3
    V4 -->|"binds_to"| VM4
    V5 -->|"binds_to"| VM4

    %% UI Components contribute to Views (UI interaction)
    UC1 -.->|"embedded_in"| V2
    UC2 -.->|"embedded_in"| V3
    UC3 -.->|"embedded_in"| V4
    UC4 -.->|"embedded_in"| V5

    %% ViewModels to Data Layer interactions
    VM1 -->|"data_binding"| M2
    VM4 -->|"data_updates"| M1

    %% ViewModels to Firebase Services interactions
    VM1 -->|"UserAuth"| FB1
    VM1 -->|"UserDataCRUD"| FB2
    VM4 -->|"ScheduleDataCRUD"| FB3
    VM1 -->|"MediaUploads"| FB4

    %% Additional connections within Business Logic (for reactive flows)
    VM1 ---|"Combine_reactive"| VM6

    %% Click Events for Component Mapping
    click V1 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/View/LoginView.swift"
    click V2 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/View/CalendarView.swift"
    click V3 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/View/PlannerView.swift"
    click V4 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/View/ScheduleView.swift"
    click V5 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/View/ScheduleCycleView.swift"
    
    click UC1 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/Component/CalendarCell.swift"
    click UC2 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/Component/DateTimePicker.swift"
    click UC3 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/Component/LinearAudioPlayer.swift"
    click UC4 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/Component/ScheduleBox.swift"
    
    click VM1 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/ViewModel/FirebaseViewModel.swift"
    click VM2 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/ViewModel/MapViewModel.swift"
    click VM3 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/ViewModel/PlannerViewModel.swift"
    click VM4 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/ViewModel/ScheduleViewModel.swift"
    click VM5 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/ViewModel/SearchLocationViewModel.swift"
    click VM6 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/ViewModel/UIViewModel.swift"
    
    click M1 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/Model/ScheduleData.swift"
    click M2 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/Model/UserData.swift"
    
    click AP1 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/SnapPlanApp.swift"
    click AP2 "https://github.com/opficdev/swiftui_snapplan/blob/main/SnapPlan/Delegate/AppDelegate.swift"

    %% Styles
    classDef ui fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef vm fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef model fill:#ABEBC6,stroke:#27AE60,stroke-width:2px;
    classDef lifecycle fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef fb fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
```
