# eventregistry/event-registry-node-js architecture

> Architecture diagram of the GitHub repository eventregistry/event-registry-node-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eventregistry/event-registry-node-js
- Repository: https://github.com/eventregistry/event-registry-node-js

## Overview

##### Project type and purpose
- This is a client‐side TypeScript/Node.js library (“eventregistry”) that wraps the Event Registry REST API.
- Its sole responsibility is to let users build queries (articles, events, trends, etc.), submit them to the external Event Registry service, and parse the JSON response into typed objects.

##### File structure
- Top‐level files: configuration (.eslintrc.js, tsconfig.json), metadata (package.json, README.md), tests, and examples.
- src/ directory: all core modules—each file corresponds to one piece of functionality (analytics.ts, query.ts, queryArticles.ts, etc.).
- tests/ directory: unit tests validating each query and helper.
- examples/ directory: usage scenarios demonstrating how clients import and call the library.

##### README for additional insights
- The README describes how to instantiate the core EventRegistry class, create Query and Request objects, and invoke async calls.
- It lists the main use cases (articles, events, trends, social shares, duplicates, etc.)—each maps to a module under src/.

a. Main components
- Client Application (user code or examples)
- EventRegistry Core (src/index.ts + src/eventRegistry.ts)
- Query Layer (classes under src/query*.ts and src/queryEvent.ts, src/queryArticles.ts, etc.)
- Request/Result Layer (classes under src/request* or “returnInfo.ts”)
- Data Models (src/types.ts, src/data.ts)
- Utility Modules (src/logger.ts, src/base.ts, src/eventRegistry.ts)
- HTTP Transport (the underlying HTTP client invoked by EventRegistry.execQuery)
- External System (Event Registry REST API)

b. Relationships and interactions
1. Client → EventRegistry constructor (inject API key, config)
2. Client → Instantiate Query object (e.g., new QueryArticles(er, params))
3. Client → Optionally attach a RequestInfo object (e.g., new RequestArticlesInfo)
4. Client → Call er.execQuery(query)
5. EventRegistry → Translates query into HTTP request via base.ts/http client
6. HTTP client → Sends request over TLS → Event Registry API
7. Event Registry API → Returns JSON payload
8. EventRegistry → Parses JSON into typed Data Models (types.ts)
9. EventRegistry → Returns Promise resolving to typed response to Client

c. Architectural patterns and design principles
- Modularization: one file per feature (SRP)
- Builder Pattern: Query and Request objects chain configuration calls
- Dependency Injection: Client injects API key and settings into EventRegistry
- Promise/async-await for asynchronous calls
- Type safety: TypeScript interfaces for requests/responses

d. Relevant technologies and libraries
- TypeScript (tsconfig.json)
- Node.js (package.json)
- Jasmine for testing (test/spec/*.spec.ts)
- ESLint/TSlint for linting
- npm scripts for build/test

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client Application"
        Examples["Examples / Client Code"]:::client
    end

    subgraph "eventregistry Library"
        subgraph "Core"
            Index["index.ts"]:::library
            EventRegistryTS["eventRegistry.ts"]:::library
            BaseTS["base.ts"]:::library
        end
        subgraph "Query Layer"
            Query["query.ts"]:::library
            QueryArticle["queryArticle.ts"]:::library
            QueryArticles["queryArticles.ts"]:::library
            QueryEvent["queryEvent.ts"]:::library
            QueryEvents["queryEvents.ts"]:::library
            QueryMentions["queryMentions.ts"]:::library
            QueryStory["queryStory.ts"]:::library
            Recent["recent.ts"]:::library
            TopicPage["topicPage.ts"]:::library
        end
        subgraph "Request/Result Layer"
            Info["info.ts"]:::library
            ReturnInfo["returnInfo.ts"]:::library
        end
        subgraph "Data Models"
            Types["types.ts"]:::library
            Data["data.ts"]:::library
        end
        subgraph "Utilities"
            Logger["logger.ts"]:::library
            Analytics["analytics.ts"]:::library
            Counts["counts.ts"]:::library
            DailyShares["dailyShares.ts"]:::library
            EventForText["eventForText.ts"]:::library
            Trends["trends.ts"]:::library
        end
        subgraph "HTTP Transport"
            HTTPBase["base.ts"]:::library
        end
    end

    ExternalAPI["Event Registry REST API"]:::external

    Examples -->|instantiates| Index
    Examples -->|creates queries| QueryArticles
    Examples -->|attaches RequestInfo| ReturnInfo
    Examples -->|calls execQuery| Index
    Index -->|uses| HTTPBase
    HTTPBase -->|sends HTTP| ExternalAPI
    ExternalAPI -->|returns JSON| HTTPBase
    HTTPBase -->|passes response| Index
    Index -->|parses to Data Models| Types
    Index -->|parses to Data Models| Data
    Index -->|returns Promise| Examples

    click Examples "https://github.com/eventregistry/event-registry-node-js/tree/master/examples/"
    click Index "https://github.com/eventregistry/event-registry-node-js/blob/master/src/index.ts"
    click EventRegistryTS "https://github.com/eventregistry/event-registry-node-js/blob/master/src/eventRegistry.ts"
    click BaseTS "https://github.com/eventregistry/event-registry-node-js/blob/master/src/base.ts"
    click Query "https://github.com/eventregistry/event-registry-node-js/blob/master/src/query.ts"
    click QueryArticle "https://github.com/eventregistry/event-registry-node-js/blob/master/src/queryArticle.ts"
    click QueryArticles "https://github.com/eventregistry/event-registry-node-js/blob/master/src/queryArticles.ts"
    click QueryEvent "https://github.com/eventregistry/event-registry-node-js/blob/master/src/queryEvent.ts"
    click QueryEvents "https://github.com/eventregistry/event-registry-node-js/blob/master/src/queryEvents.ts"
    click QueryMentions "https://github.com/eventregistry/event-registry-node-js/blob/master/src/queryMentions.ts"
    click QueryStory "https://github.com/eventregistry/event-registry-node-js/blob/master/src/queryStory.ts"
    click Recent "https://github.com/eventregistry/event-registry-node-js/blob/master/src/recent.ts"
    click TopicPage "https://github.com/eventregistry/event-registry-node-js/blob/master/src/topicPage.ts"
    click Info "https://github.com/eventregistry/event-registry-node-js/blob/master/src/info.ts"
    click ReturnInfo "https://github.com/eventregistry/event-registry-node-js/blob/master/src/returnInfo.ts"
    click Types "https://github.com/eventregistry/event-registry-node-js/blob/master/src/types.ts"
    click Data "https://github.com/eventregistry/event-registry-node-js/blob/master/src/data.ts"
    click Logger "https://github.com/eventregistry/event-registry-node-js/blob/master/src/logger.ts"
    click Analytics "https://github.com/eventregistry/event-registry-node-js/blob/master/src/analytics.ts"
    click Counts "https://github.com/eventregistry/event-registry-node-js/blob/master/src/counts.ts"
    click DailyShares "https://github.com/eventregistry/event-registry-node-js/blob/master/src/dailyShares.ts"
    click EventForText "https://github.com/eventregistry/event-registry-node-js/blob/master/src/eventForText.ts"
    click Trends "https://github.com/eventregistry/event-registry-node-js/blob/master/src/trends.ts"
    click HTTPBase "https://github.com/eventregistry/event-registry-node-js/blob/master/src/base.ts"

    classDef library fill:#D0E6FF,stroke:#555,stroke-width:1px;
    classDef external fill:#CFFFB0,stroke:#555,stroke-width:1px;
    classDef client fill:#FFE5B4,stroke:#555,stroke-width:1px;
```
