# barchart/barchart-ondemand-client-js architecture

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

- Interactive diagram: https://gitdiagram.com/barchart/barchart-ondemand-client-js
- Repository: https://github.com/barchart/barchart-ondemand-client-js

## Overview

##### Project type and purpose
- This is a zero-dependency JavaScript client library (“barchart-ondemand-client-js”) that wraps HTTP/JSONP calls to the Barchart OnDemand REST APIs.
- Its main use case is to be included in any web page or web app to fetch market data (quotes, history, news, etc.) via simple method calls.

##### File structure
- Top-level files:
- Gruntfile.js: build tasks (concatenation, minification, test runner).
- bower.json & package.json: metadata, dependency management.
- README.md: usage and API reference.
- dist/: prebuilt bundle (browser-ready JS).
- src/ondemand-client.js: the single source module implementing the client API.
- tests/: Jasmine/BrowseRunner specs (OnDemandClientSpec.js) plus an index.html to run them in a browser.

##### README for additional insights
- The README lists all supported API methods (getQuote, getHistory, getNews, etc.).
- Example shows how the client:
a. Loads the dist script in an HTML page.
b. Instantiates OnDemandClient.
c. Sets an API key and JSONP mode.
d. Calls a method, passes callback, receives data.

a. Main components
1. Developer Environment
- src/ondemand-client.js
- Grunt build process
- tests (Jasmine runner)
2. Distribution
- dist/barchart-ondemand-client-js.js (minified bundle)
3. Consumer Application
- HTML/JS that embeds the dist bundle
- Instantiates OnDemandClient API
4. External System
- Barchart OnDemand API servers (REST endpoints)
b. Relationships & Data Flow
1. Developer writes/edits src → triggers Grunt → produces dist.
2. Tests run against src or dist via tests/index.html → pass/fail feedback.
3. Consumer app includes dist → invokes OnDemandClient methods → HTTP/JSONP requests → OnDemand API → responses → callbacks in app.
c. Architectural patterns & principles
- Single-module UMD wrapper (works in browser/node).
- Build pipeline: concatenation, minification, test automation.
- Callback-oriented async design (JSONP or XHR).
d. Key technologies
- JavaScript (UMD)
- Grunt (task runner: build, test)
- Jasmine (testing)
- Bower/NPM (package management)
- HTTP/JSONP transport

##### Detail
- That tests can run directly against src or bundled code.
- Configuration files (package.json, bower.json) feeding into the Build step.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer Environment
    subgraph "Developer Environment"
        SRC["Source Code\n(src/ondemand-client.js)"]:::internal
        META_PKG["Package Metadata\n(package.json)"]:::internal
        META_BOWER["Package Metadata\n(bower.json)"]:::internal
        GITIGNORE["Version Control Ignore\n(.gitignore)"]:::internal
        README["Documentation & API Reference\n(README.md)"]:::internal
    end

    %% Build & Test
    subgraph "Build & Test"
        GRUNT["Build Configuration\n(Gruntfile.js)"]:::internal
        subgraph "Tests"
            SPEC["Test Suite\n(tests/OnDemandClientSpec.js)"]:::internal
            RUNNER["Test Runner\n(tests/index.html)"]:::internal
        end
    end

    %% Distribution
    subgraph "Distribution"
        BUNDLE["Bundle\n(dist/barchart-ondemand-client-js.js)"]:::internal
    end

    %% Consumer Application
    CLIENT["Client App\n(HTML/JS)"]:::consumer

    %% External API
    API["Barchart OnDemand API"]:::external

    %% Connections
    SRC -->|"edits & extends"| GRUNT
    META_PKG -->|feeds into| GRUNT
    META_BOWER -->|feeds into| GRUNT
    GITIGNORE -->|feeds into| GRUNT
    README -.->|reference for dev| SRC

    GRUNT -->|"concat, uglify, jasmine"| SPEC
    GRUNT -->|runs| RUNNER
    SPEC -->|pass/fail| GRUNT

    GRUNT -->|"build outputs"| BUNDLE
    RUNNER -->|tests bundled or src| BUNDLE

    BUNDLE -->|"include script"| CLIENT
    CLIENT -->|"HTTP/JSONP request"| API
    API -->|"response callback"| CLIENT

    %% Click Events
    click SRC "https://github.com/barchart/barchart-ondemand-client-js/blob/master/src/ondemand-client.js"
    click GRUNT "https://github.com/barchart/barchart-ondemand-client-js/blob/master/Gruntfile.js"
    click META_PKG "https://github.com/barchart/barchart-ondemand-client-js/blob/master/package.json"
    click META_BOWER "https://github.com/barchart/barchart-ondemand-client-js/blob/master/bower.json"
    click BUNDLE "https://github.com/barchart/barchart-ondemand-client-js/blob/master/dist/barchart-ondemand-client-js.js"
    click SPEC "https://github.com/barchart/barchart-ondemand-client-js/blob/master/tests/OnDemandClientSpec.js"
    click RUNNER "https://github.com/barchart/barchart-ondemand-client-js/blob/master/tests/index.html"
    click README "https://github.com/barchart/barchart-ondemand-client-js/blob/master/README.md"
    click GITIGNORE "https://github.com/barchart/barchart-ondemand-client-js/blob/master/.gitignore"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#004085,color:#004085;
    classDef consumer fill:#d4edda,stroke:#155724,color:#155724;
    classDef external fill:#fff3cd,stroke:#856404,color:#856404;
```
