# paulinetaillemite/my-own-unsplash architecture

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

- Interactive diagram: https://gitdiagram.com/paulinetaillemite/my-own-unsplash
- Repository: https://github.com/paulinetaillemite/my-own-unsplash

## Overview

##### Project type and purpose
- This is a minimalist single-page front-end application.
- Its only responsibility is to load static assets (HTML, CSS, JS) in the browser, take user input, fetch random images from the Unsplash API, loop over the results, and render them on the page.

##### File structure
- index.html: entry point and container for the UI.
- style.css: styling rules and layout definitions.
- script.js: contains the business logic—listens for user input, issues fetch requests to the Unsplash API, processes the JSON, and dynamically injects image elements into the DOM.
- No backend code or databases are present—everything runs in the browser.

##### Key architectural insights from the README
- Technologies: plain HTML, CSS, and JavaScript.
- Core feature: fetch images by theme (user input) using the Unsplash API.
- Challenge: managing asynchronous data and looping through results to render them efficiently.

##### Main components
a. Client / Browser
– Renders index.html, applies styles from style.css, runs script.js.
– Holds the UI form/input, image gallery container.
b. Static Asset Server (or CDN)
– Hosts and serves index.html, script.js, style.css to the client.
c. Unsplash External API
– Receives HTTP GET requests from script.js including query parameters (search term, API key).
– Returns JSON payload with image URLs and metadata.
d. DOM & Rendering Engine
– The browser’s internal component that takes the JSON from script.js, loops through it, and injects <img> elements into the page.

##### Relationships and interactions
- User types a theme and submits the form in the browser.
- script.js captures the event, calls fetch() to Unsplash API via the network.
- Unsplash API processes the request and returns a JSON response.
- script.js receives the JSON Promise, loops through the results, builds HTML snippets, and appends them to the DOM.
- The browser’s rendering engine paints the new images on screen.

##### Architectural patterns and principles
- Separation of concerns: HTML for structure, CSS for style, JS for behavior.
- Event-driven flow: user events trigger asynchronous fetch operations.
- External API integration: clear boundary between client code and third-party service.
- Stateless interactions: each fetch is independent; no client-side persistence beyond the DOM.

##### Technologies to call out
- HTML5 and DOM APIs
- CSS3 (hover effects, hidden/display logic)
- JavaScript fetch API and Promise chaining
- Unsplash REST API (authentication via API key in request headers or query string)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Components
    subgraph "Browser (Client)" 
        direction TB
        IndexHTML["index.html"]:::client
        StyleCSS["style.css"]:::client
        subgraph "script.js"
            direction TB
            EventListener["Event Listener\n(user submits form)"]:::client
            FetchLogic["fetch() & JSON Loop"]:::client
            DomInject["DOM Injection\n(create <img> elements)"]:::client
        end
        DOM["DOM & Rendering Engine"]:::client
    end

    StaticServer["Static Asset Server"]:::external
    UnsplashAPI["Unsplash API"]:::external

    %% Data Flows
    StaticServer -->|"HTTP GET index.html, CSS, JS"| IndexHTML
    IndexHTML -->|loads| Browser
    StyleCSS -->|applies styles to| Browser
    IndexHTML -->|includes script.js| EventListener

    EventListener -->|"calls fetch()"| FetchLogic
    FetchLogic -->|"HTTP GET /search/photos?q={theme}&client_id=…"| UnsplashAPI
    UnsplashAPI -->|"JSON payload"| FetchLogic
    FetchLogic -->|passes results| DomInject
    DomInject -->|injects elements into| DOM
    DOM -->|renders images on screen| Browser

    %% Click Events
    click IndexHTML "https://github.com/paulinetaillemite/my-own-unsplash/blob/main/index.html"
    click StyleCSS "https://github.com/paulinetaillemite/my-own-unsplash/blob/main/style.css"
    click FetchLogic "https://github.com/paulinetaillemite/my-own-unsplash/blob/main/script.js"
    click DomInject "https://github.com/paulinetaillemite/my-own-unsplash/blob/main/script.js"

    %% Styles
    classDef client fill:#b4f2b2,stroke:#2d8f2d,stroke-width:2px
    classDef external fill:#b2dffc,stroke:#1f4e7a,stroke-width:2px
```
