# jpougano/challenge-charlie architecture

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

- Interactive diagram: https://gitdiagram.com/jpougano/challenge-charlie
- Repository: https://github.com/jpougano/challenge-charlie

## Overview

##### Project type and purpose
- This is a single-page application (SPA) built with Create-React-App that runs entirely in the browser.
- Its sole purpose is to fetch and display weather forecasts (current and future) and a dynamic background image based on the user’s location or a manually entered city.

##### File structure
- Top level:
- challenge/ – the React project root (contains package.json, public/, src/, .env template)
- README.md – explains use cases, APIs, and setup
- public/ – static assets (index.html)
- src/ – React source code
- components/
– Content/Content.js, Content/style.css
– Search/Search.js, Search/style.css
- helpers/WeatherTheme.js – logic to map weather to a theme
- style/style.css and font assets
- App.js, index.js

##### Key insights from the README
- External services used:
- Bing Image API (with AllOrigins CORS proxy)
- OpenWeather API
- OpenCage Geocoding API
- No backend or database—just public APIs and browser geolocation
- Styling and fonts are static CSS assets

##### Main components
a. Browser Client
- Geolocation API
- React SPA (static JS/CSS delivered from a CDN or host)
b. React Application internals
- UI Components
– Search component (user input, city lookup)
– Content component (renders weather data and theme)
- Helper modules
c. Build/Deployment
- Static hosting (e.g., S3/Netlify)
- Environment variables (.env) injected at build time for API keys
d. External Services
- AllOrigins CORS proxy (for Bing background)
- Bing Image API
- OpenCage Geocoding API
- OpenWeather Forecast API

##### Relationships and data flow
1. User opens the SPA in the Browser
2. Browser geolocation permission → returns coordinates
3. React App calls OpenCage API to reverse-geocode coordinates → city name
4. React App calls OpenWeather API with coordinates or city name → forecast data
5. React App calls AllOrigins → proxies Bing Image API → background image URL
6. Data flows back into UI components → Content renders forecast + dynamic CSS (via WeatherTheme)
7. On user-typed city search, steps (3)–(6) repeat with new input

##### Architectural patterns and principles
- Component-based modularity: separate Search vs. Content vs. helper logic
- Single data-flow direction: user action → API call → state update → UI render
- External dependency isolation: environment variables store API keys; CORS proxy isolates browser limitations
- Styling separation: CSS modules and global style sheet

- Break the system into as many meaningful components as possible
- External dependencies and where API keys come from (.env at build time)
- Data flow direction and sequence (geolocation → geocode → weather → image)
- Notes on hosting, build step, and environment variable injection

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Browser Client<br>(Geolocation API)"]:::browser

    subgraph "Static Hosting & Build"
        HostHTML["index.html (public/index.html)"]:::host
        Env[".env (challenge/.env)"]:::host
        Package["package.json"]:::host
    end

    Browser -->|"loads SPA"| HostHTML
    HostHTML --> ReactIndex["index.js (src/index.js)"]:::appEntry
    ReactIndex --> App["App.js (src/App.js)"]:::appEntry

    subgraph "React App Internals"
        Search["Search.js<br>(src/components/Search)"]:::ui
        SearchCSS["style.css<br>(src/components/Search)"]:::ui
        Content["Content.js<br>(src/components/Content)"]:::ui
        ContentCSS["style.css<br>(src/components/Content)"]:::ui
        WeatherTheme["WeatherTheme.js<br>(src/helpers)"]:::helper
        GlobalStyles["style.css & fonts<br>(src/style/)"]:::host
    end

    App --> Search
    App --> Content
    App --> WeatherTheme
    App --> GlobalStyles

    Browser -->|"getCoordinates"| Geocode["OpenCage Geocoding API"]:::external
    Search -->|"onSearch"| Geocode
    Geocode -->|"cityName"| App

    App -->|"fetchForecast"| WeatherAPI["OpenWeather Forecast API"]:::external
    App -->|"fetchImage"| BingProxy["AllOrigins CORS Proxy"]:::external
    BingProxy --> Bing["Bing Image API"]:::external
    WeatherAPI --> Content
    BingProxy --> Content

    click ReactIndex "https://github.com/jpougano/challenge-charlie/blob/master/challenge/src/index.js"
    click App "https://github.com/jpougano/challenge-charlie/blob/master/challenge/src/App.js"
    click HostHTML "https://github.com/jpougano/challenge-charlie/blob/master/challenge/public/index.html"
    click Search "https://github.com/jpougano/challenge-charlie/blob/master/challenge/src/components/Search/Search.js"
    click SearchCSS "https://github.com/jpougano/challenge-charlie/blob/master/challenge/src/components/Search/style.css"
    click Content "https://github.com/jpougano/challenge-charlie/blob/master/challenge/src/components/Content/Content.js"
    click ContentCSS "https://github.com/jpougano/challenge-charlie/blob/master/challenge/src/components/Content/style.css"
    click WeatherTheme "https://github.com/jpougano/challenge-charlie/blob/master/challenge/src/helpers/WeatherTheme.js"
    click GlobalStyles "https://github.com/jpougano/challenge-charlie/blob/master/challenge/src/style/style.css"
    click GlobalStyles "https://github.com/jpougano/challenge-charlie/blob/master/challenge/src/style/Font-face/meteocons-webfont.eot"
    click Env "https://github.com/jpougano/challenge-charlie/blob/master/challenge/.env"
    click Package "https://github.com/jpougano/challenge-charlie/blob/master/challenge/package.json"

    classDef ui fill:#ADD8E6,stroke:#000;
    classDef helper fill:#98FB98,stroke:#000;
    classDef external fill:#FFDEAD,stroke:#000;
    classDef host fill:#D3D3D3,stroke:#000;
    classDef browser fill:#DDA0DD,stroke:#000;
    classDef appEntry fill:#ADD8E6,stroke:#000;
```
