# josiahdahl/sar-alerts architecture

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

- Interactive diagram: https://gitdiagram.com/josiahdahl/sar-alerts
- Repository: https://github.com/josiahdahl/sar-alerts

## Overview

##### Main Components

a. Frontend Layer:
- Vue.js Components (found in backend/resources/assets/js/components)
- Widget System (Widget.vue as base component)
- Specialized Widgets (Weather, Tides, Time, Notice, Wind)
- Store Management (store.js)

b. Backend Layer (Laravel):
- API Controllers (in backend/app/Http/Controllers/Api)
- Authentication System
- Service Providers
- Data Models
- Integration Contracts

c. Data Services Layer (Python):
- Flask API (api/app.py)
- Job Workers
- Data Providers
- RabbitMQ Message Queue

d. External Services:
- Weather API (OpenWeatherMap)
- Tides Data (GC Tides)
- Time Services
- Notification Services

**[Client Layer] → [Backend Layer] → [Data Services Layer]**
- ↑               ↕                    ↕
- ┴────────────────────┘

##### Component Relationships

- Frontend widgets ↔ Laravel API Controllers
- Laravel Controllers ↔ Integration Contracts
- Integration Contracts ↔ Python Data Services
- Data Services ↔ External APIs
- RabbitMQ connecting Backend and Data Services

##### Key Elements to Highlight

a. Modular Widget System:
- How widgets connect to different data sources
- Component hierarchy

b. Data Flow:
- API request paths
- Job queue processing
- Data update cycles

c. Integration Points:
- External API connections
- Service contracts
- Database interactions

##### Additional Details

Specific components:
- Authentication flow
- Database tables (users, widgets, data_sources, etc.)
- Cache layer
- Job scheduling system

##### Architectural Patterns to Emphasize

- Service Provider Pattern (shown in backend/app/Providers)
- Repository Pattern (for data access)
- Contract-based Integration Pattern
- Event-driven architecture (with RabbitMQ)

- Component types (services, controllers, models)
- Integration points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        direction TB
        BaseWidget["Widget Base Component"]:::frontend
        Store["Store Management"]:::frontend
        
        subgraph Widgets["Widget Components"]
            direction TB
            Weather["Weather Widget"]:::frontend
            Tides["Tides Widget"]:::frontend
            Time["Time Widget"]:::frontend
            Notice["Notice Widget"]:::frontend
            Wind["Wind Widget"]:::frontend
        end
        
        BaseWidget --> Weather & Tides & Time & Notice & Wind
        Store --> BaseWidget
    end

    subgraph Backend["Backend Layer"]
        direction TB
        subgraph Controllers["API Controllers"]
            WeatherCtrl["Weather Controller"]:::backend
            TidesCtrl["Tides Controller"]:::backend
            TimeCtrl["Time Controller"]:::backend
            NoticesCtrl["Notices Controller"]:::backend
        end

        subgraph Auth["Authentication"]
            AuthSystem["Auth System"]:::backend
        end

        subgraph Providers["Service Providers"]
            WeatherSP["Weather Service Provider"]:::backend
            TideSP["Tide Service Provider"]:::backend
            TimeSP["Time Service Provider"]:::backend
            NoticeSP["Notice Service Provider"]:::backend
        end

        subgraph Contracts["Integration Contracts"]
            WeatherContract["Weather Contract"]:::backend
            TimeContract["Time Contract"]:::backend
            NoticeContract["Notice Contract"]:::backend
            DataContract["Data Services Contract"]:::backend
        end

        subgraph Jobs["Job System"]
            TidesJob["Get Tides Job"]:::backend
            WeatherJob["Get Weather Job"]:::backend
        end

        DB[(Database)]:::database
    end

    subgraph Services["Data Services Layer"]
        direction TB
        FlaskAPI["Flask API"]:::python
        JobWorker["Job Worker"]:::python
        DataProviders["Data Providers"]:::python
        MQ{"RabbitMQ"}:::queue
    end

    subgraph External["External Services"]
        direction TB
        OpenWeather["OpenWeatherMap API"]:::external
        GCTides["GC Tides API"]:::external
        TimeService["Time Service"]:::external
        NotifyService["Notification Service"]:::external
    end

    %% Connections
    Weather & Tides & Time & Notice & Wind --> Controllers
    Controllers --> Auth
    Controllers --> Providers
    Providers --> Contracts
    Contracts --> Jobs
    Jobs --> MQ
    MQ --> JobWorker
    JobWorker --> DataProviders
    DataProviders --> External
    FlaskAPI --> Controllers

    %% Click Events
    click BaseWidget "https://github.com/josiahdahl/sar-alerts/blob/master/backend/resources/assets/js/components/Widget.vue"
    click Store "https://github.com/josiahdahl/sar-alerts/blob/master/backend/resources/assets/js/store.js"
    click Weather "https://github.com/josiahdahl/sar-alerts/blob/master/backend/resources/assets/js/components/WidgetWeather.vue"
    click Tides "https://github.com/josiahdahl/sar-alerts/blob/master/backend/resources/assets/js/components/WidgetTides.vue"
    click Time "https://github.com/josiahdahl/sar-alerts/blob/master/backend/resources/assets/js/components/WidgetTime.vue"
    click Notice "https://github.com/josiahdahl/sar-alerts/blob/master/backend/resources/assets/js/components/WidgetNotice.vue"
    click Wind "https://github.com/josiahdahl/sar-alerts/blob/master/backend/resources/assets/js/components/WidgetWind.vue"
    click WeatherCtrl "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Http/Controllers/Api/WeatherController.php"
    click TidesCtrl "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Http/Controllers/Api/TidesController.php"
    click TimeCtrl "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Http/Controllers/Api/TimeController.php"
    click NoticesCtrl "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Http/Controllers/Api/NoticesController.php"
    click AuthSystem "https://github.com/josiahdahl/sar-alerts/tree/master/backend/app/Http/Controllers/Auth/"
    click WeatherSP "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Providers/WeatherServiceProvider.php"
    click TideSP "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Providers/TideProvider.php"
    click TimeSP "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Providers/TimeServiceProvider.php"
    click NoticeSP "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Providers/NoticeServiceProvider.php"
    click WeatherContract "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Contracts/Integrations/WeatherIntegrationContract.php"
    click TimeContract "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Contracts/Integrations/TimeIntegrationContract.php"
    click NoticeContract "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Contracts/Integrations/NotificationIntegrationContract.php"
    click DataContract "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Contracts/Integrations/DataServicesIntegrationContract.php"
    click FlaskAPI "https://github.com/josiahdahl/sar-alerts/blob/master/data-services/api/app.py"
    click JobWorker "https://github.com/josiahdahl/sar-alerts/blob/master/data-services/worker.py"
    click DataProviders "https://github.com/josiahdahl/sar-alerts/blob/master/data-services/providers/gc_tides_provider.py"
    click TidesJob "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Jobs/GetTides.php"
    click WeatherJob "https://github.com/josiahdahl/sar-alerts/blob/master/backend/app/Jobs/GetWeatherAndWind.php"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef python fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    classDef database fill:#9b59b6,stroke:#8e44ad,color:white
    classDef queue fill:#e67e22,stroke:#d35400,color:white

    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        BackendComp["Backend Component"]:::backend
        PythonComp["Python Service"]:::python
        ExternalComp["External Service"]:::external
        DatabaseComp["Database"]:::database
        QueueComp["Message Queue"]:::queue
    end
```
