# pelayochristian/my-weather-app architecture

> Architecture diagram of the GitHub repository pelayochristian/my-weather-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pelayochristian/my-weather-app
- Repository: https://github.com/pelayochristian/my-weather-app

## Overview

To accurately represent the architecture of the “Weather Dashboard on SF Experience Cloud” project, follow these guidelines. The goal is to break the system into its core components, show how data flows between them, and highlight the Salesforce-specific integration points.

##### Project Type and Purpose
- This is a full-stack, Salesforce Experience Cloud (LWR) application that surfaces weather data.
- Frontend: Lightning Web Components (LWC) running in an Experience Cloud site.
- Backend: Apex classes handling controller, service, and model logic.
- Integration: External OpenWeather REST API via Salesforce Named Credentials and Custom Metadata.

##### Main Components
a. User & Browser
b. Experience Cloud (LWR) Site
c. Lightning Web Components
- mwBaseTemplate, mwDashboardWrapper, mwDayForecastCard, etc.
- PubSub module for inter-component messaging
d. Apex Layer
- Controller: MW_OpenWeatherOneCallController
- Service: MW_OpenWeatherOneCallService
- Models: MW_OpenWeatherOneCall, MW_OpenWeatherGeoLocation
- Utility: MW_UtilHelper, MockCalloutService (for testing)
e. Configuration & Security
- Custom Metadata: My_Weather_Config__mdt (stores API key)
- Named Credential: Open_Weather_Service (endpoint abstraction)
- CSP Trusted Sites & Remote Site Settings (allow callouts)
f. Static Resources
g. External Service
- OpenWeather REST API

##### Relationships & Data Flow
1. User loads the Experience Cloud site in browser.
2. LWR template serves LWC components.
3. LWC invokes @AuraEnabled Apex controller methods (MW_OpenWeatherOneCallController).
4. Controller delegates to service layer (MW_OpenWeatherOneCallService).
5. Service constructs a callout using Named Credential + endpoint path from MW_UtilHelper (retrieves API key from Custom Metadata).
6. External HTTP request to OpenWeather API returns JSON.
7. JSON parsed into Apex model objects (MW_OpenWeatherOneCall, MW_OpenWeatherGeoLocation).
8. Controller returns structured data to LWC.
9. LWC populates UI elements (cards, panels) and uses PubSub to communicate between components.

##### Architectural Patterns & Principles
- MVC Separation:
- Model classes encapsulate JSON schema and parsing
- Service layer handles integration concerns
- Controller layer exposes Apex methods to LWC
- Service Abstraction: Named Credentials + Utility class for API key management
- Event-Bus (PubSub) for decoupled component communication
- Test-Driven Structure: Separate test classes alongside each Apex class

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    Browser["User Browser"]:::frontend
    Browser -->|"1. Load site"| ExpCloud

    subgraph "Salesforce Experience Cloud (LWR Template)" 
        direction TB
        ExpCloud["Experience Cloud Site"]:::frontend

        subgraph "LWC Components"
            direction TB
            BaseTemplate["mwBaseTemplate"]:::frontend
            DashboardWrapper["mwDashboardWrapper"]:::frontend
            DayCard["mwDayForecastCard"]:::frontend
            TodayPanel["mwTodaysHighlightPanel"]:::frontend
            WeekPanel["mwWeekForecastPanel"]:::frontend
            MainPanel["mwMainPanel"]:::frontend
            SidePanel["mwSidePanel"]:::frontend
            HighlightSlot["mwHighlightSlot"]:::frontend
            Footer["mwFooter"]:::frontend
            PubSub["pubsub.js"]:::frontend
        end

        ExpCloud -->|"2. Render LWC"| BaseTemplate
        BaseTemplate --> DashboardWrapper
        DashboardWrapper --> DayCard
        DashboardWrapper --> TodayPanel
        DashboardWrapper --> WeekPanel
        DashboardWrapper --> MainPanel
        DashboardWrapper --> SidePanel
        DashboardWrapper --> HighlightSlot
        DashboardWrapper --> Footer
        DashboardWrapper --> PubSub
    end

    %% Backend Layer
    subgraph "Salesforce Apex Layer"
        direction TB
        Controller["MW_OpenWeatherOneCallController"]:::backend
        Service["MW_OpenWeatherOneCallService"]:::backend
        Models["Apex Models"]:::backend
        UtilHelper["MW_UtilHelper"]:::backend
        MockService["MockCalloutService"]:::backend

        Controller -->|"3. @AuraEnabled calls"| Service
        Service -->|"4. Construct callout"| UtilHelper
        UtilHelper -->|"lookup API key"| ConfigMeta
        Service -->|"5. HTTP GET via Named Credential"| NamedCred
        Service -->|"6. JSON → Apex model"| Models
        Controller -->|"7. Return data"| DashboardWrapper
    end

    %% Configuration & Security
    subgraph "Configuration & Security" 
        direction TB
        ConfigMeta["Custom Metadata\nMy_Weather_Config__mdt"]:::config
        NamedCred["Named Credential\nOpen_Weather_Service"]:::config
        CSP1["CSP Trusted Site\nopenweathermap"]:::config
        CSP2["CSP Trusted Site\nshieldsio"]:::config
        RemoteSite["Remote Site Setting\nshieldsio"]:::config
    end

    %% Static Resources
    subgraph "Static Resources" 
        direction TB
        Assets["MWAssets"]:::config
        Icons["MWMeteocons"]:::config
    end

    %% External API
    OpenWeather["OpenWeather REST API"]:::external

    NamedCred -->|"External call"| OpenWeather
    OpenWeather -->|"JSON response"| Service

    %% Click Events - LWC
    click ExpCloud "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/experiences/myWeather1.site-meta.xml"
    click BaseTemplate "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/lwc/mwBaseTemplate/"
    click DashboardWrapper "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/lwc/mwDashboardWrapper/"
    click DayCard "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/lwc/mwDayForecastCard/"
    click TodayPanel "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/lwc/mwTodaysHighlightPanel/"
    click WeekPanel "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/lwc/mwWeekForecastPanel/"
    click MainPanel "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/lwc/mwMainPanel/"
    click SidePanel "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/lwc/mwSidePanel/"
    click HighlightSlot "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/lwc/mwHighlightSlot/"
    click Footer "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/lwc/mwFooter/"
    click PubSub "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/lwc/pubsub/pubsub.js"

    %% Click Events - Apex
    click Controller "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/classes/controller/MW_OpenWeatherOneCallController.cls"
    click Service "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/classes/service/MW_OpenWeatherOneCallService.cls"
    click Models "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/classes/model/MW_OpenWeatherOneCall.cls"
    click UtilHelper "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/classes/common/MW_UtilHelper.cls"
    click MockService "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/classes/common/MockCalloutService.cls"

    %% Click Events - Configuration
    click NamedCred "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/namedCredentials/Open_Weather_Service.namedCredential-meta.xml"
    click ConfigMeta "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/customMetadata/My_Weather_Config.Open_Weather_API_Key.md-meta.xml"
    click CSP1 "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/cspTrustedSites/openweathermap.cspTrustedSite-meta.xml"
    click CSP2 "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/cspTrustedSites/shieldsio.cspTrustedSite-meta.xml"
    click RemoteSite "https://github.com/pelayochristian/my-weather-app/blob/main/force-app/main/default/remoteSiteSettings/shieldsio.remoteSite-meta.xml"

    %% Click Events - Static Resources
    click Assets "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/staticresources/MWAssets/"
    click Icons "https://github.com/pelayochristian/my-weather-app/tree/main/force-app/main/default/staticresources/MWMeteocons/"

    %% Styles
    classDef frontend fill:#E8F1FA,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#E0F8D0,stroke:#28a745,stroke-width:1px
    classDef config fill:#F0F0F0,stroke:#6a737d,stroke-width:1px
    classDef external fill:#FFE0B2,stroke:#d93f0b,stroke-width:1px
```
