# forifor/scoutingapp architecture

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

- Interactive diagram: https://gitdiagram.com/forifor/scoutingapp
- Repository: https://github.com/forifor/scoutingapp

## Overview

##### Main Components
- User Interface (Frontend): Represented by the Prototype layer (AppDelegate, SceneDelegate, PrototypeViews) and utilizing SwiftUI and UIKit. This layer is where users interact with the app.
- Business Logic / Core Modules (Backend within the iOS app): Under the “code/ScoutingApp/Core” directory you have distinct modules:
- Authentication (AuthenticationService.swift): Manages user login and account management.
- Database (FirebaseManager.swift & SyncManager.swift): Handles offline/online data synchronization and general database connections via Firebase.
- Models (Models.swift): Defines the data structures used throughout the application.
- Report (AnalyticsService.swift, ReportService.swift, RewardService.swift): Handles report generation, evaluation, statistics analysis, and rewards.
- Schedule (ScheduleService.swift): Manages game schedules and event details.
- Security (SecurityManager.swift): Provides encryption using AES-GCM and manages Firebase security rules.
- External Services:
- Firebase: Underpins authentication, Firestore/Storage, Functions, and security; it is a critical external infrastructure component.
- Testing and Documentation:
- Tests directory covers unit, integration, and UI tests ensuring multiple quality gates.
- The Docs and Design directories (including architecture.md, wireframes.md, etc.) provide supporting documentation and design guidelines that can be referenced to further detail component interactions.

##### Relationships and Interactions
- The UI/Presentation layer (Prototype) invokes ViewModels that interact with the Core services.
- Core service modules (e.g., Authentication, Database, Report, Schedule, and Security) encapsulate business logic and are interconnected. For instance, when a user creates a scouting report via the UI, the Report module validates input and interacts with the Database module (FirebaseManager/SyncManager) to store and sync data.
- The Authentication module interfaces directly with Firebase for user verification, while Security follows both encryption protocols and Firebase Security Rules.
- All modules use Combine or similar reactive approaches (as indicated by the tech stack) to handle data synchronization and asynchronous flows.

##### Architectural Patterns & Technologies
- MVVM separation: Clearly separate the Presentation (views) from the business logic (core modules) using ViewModels.
- Combine Framework: Represent asynchronous data flows and real-time sync between the app and Firebase.
- Firebase Integration: Show data and authentication flows between the mobile application’s core services and external Firebase services.
- SwiftUI/ UIKit usage in UI layer to demonstrate the modern UI components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer (UI/Prototype)"
        P1["AppDelegate (Prototype)"]:::presentation
        P2["SceneDelegate (Prototype)"]:::presentation
        P3["PrototypeViews (Prototype)"]:::presentation
    end

    subgraph "Core Modules"
        subgraph "Authentication"
            A["AuthenticationService.swift"]:::core
        end
        subgraph "Database"
            D1["FirebaseManager.swift"]:::core
            D2["SyncManager.swift"]:::core
        end
        subgraph "Models"
            M["Models.swift"]:::core
        end
        subgraph "Report"
            R1["AnalyticsService.swift"]:::core
            R2["ReportService.swift"]:::core
            R3["RewardService.swift"]:::core
        end
        subgraph "Schedule"
            S["ScheduleService.swift"]:::core
        end
        subgraph "Security"
            Sec["SecurityManager.swift"]:::core
        end
    end

    subgraph "External Services"
        F["Firebase"]:::external
    end

    subgraph "Supporting"
        T["Tests"]:::testing
        DDocs["Docs & Design"]:::documentation
    end

    %% Data Flows and Interactions
    P3 -->|"login"| A
    P3 -->|"reportSubmission"| R2
    P3 -->|"scheduleUpdate"| S

    A -->|"auth"| F
    A -->|"secure"| Sec

    R2 -->|"store"| D1
    R2 -->|"sync"| D2

    R1 -->|"uses"| M
    R2 -->|"uses"| M
    R3 -->|"uses"| M

    D1 -->|"update"| F
    F -->|"notify"| D1
    D2 -->|"sync"| F

    %% Supporting Relationships
    T -->|"tests"| A
    T -->|"tests"| R2
    DDocs -->|"design"| P3

    %% Styling Classes
    class P1,P2,P3 presentation
    class A,D1,D2,M,R1,R2,R3,S,Sec core
    class F external
    class T testing
    class DDocs documentation

    %% Click Events for Component Mapping
    click P1 "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Prototype/AppDelegate.swift"
    click P2 "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Prototype/SceneDelegate.swift"
    click P3 "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Prototype/PrototypeViews.swift"
    click A "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Core/Authentication/AuthenticationService.swift"
    click D1 "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Core/Database/FirebaseManager.swift"
    click D2 "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Core/Database/SyncManager.swift"
    click M "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Core/Models/Models.swift"
    click R1 "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Core/Report/AnalyticsService.swift"
    click R2 "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Core/Report/ReportService.swift"
    click R3 "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Core/Report/RewardService.swift"
    click S "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Core/Schedule/ScheduleService.swift"
    click Sec "https://github.com/forifor/scoutingapp/blob/main/code/ScoutingApp/Core/Security/SecurityManager.swift"
    click T "https://github.com/forifor/scoutingapp/tree/main/code/ScoutingApp/Tests"
    click DDocs "https://github.com/forifor/scoutingapp/tree/main/docs"

    %% Class Definitions for Colors
    classDef presentation fill:#f9c,stroke:#333,stroke-width:2px;
    classDef core fill:#ccf,stroke:#333,stroke-width:2px;
    classDef external fill:#cfc,stroke:#333,stroke-width:2px;
    classDef testing fill:#ff9,stroke:#333,stroke-width:2px;
    classDef documentation fill:#fc9,stroke:#333,stroke-width:2px;
```
