# shadowlion/transactapi-js architecture

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

- Interactive diagram: https://gitdiagram.com/shadowlion/transactapi-js
- Repository: https://github.com/shadowlion/transactapi-js

## Overview

##### Project type and purpose
- This is an open-source JavaScript/TypeScript SDK (library) that wraps the TransactAPI REST endpoints provided by North Capital Private Securities (NCPS).
- Its purpose is to expose each Transact API endpoint as a simple function call (e.g., getAccount, createTrade) with strong TypeScript types, mock‐based testing, and easy installation via npm/pnpm/yarn.

##### File structure
- Top‐level files:
- Configuration: .eslintrc, .prettierrc, tsconfig.json
- CI pipelines: .github/workflows/*.yml
- Build/test: jest.config.ts, package.json, pnpm-lock.yaml
- Documentation: README.md, CONTRIBUTE.md, example-doc.pdf
- src/ directory:
- base.ts – core HTTP client builder
- index.ts – aggregator that exports all endpoint modules
- One subfolder per endpoint (e.g., src/getAccount, src/createTrade), each containing:
– index.ts: main function
– types.ts: request/response interfaces
– enums.ts (where applicable)
– index.spec.ts: Jest unit tests using mocks
- Patterns:
- Single‐responsibility for each endpoint
- Shared base HTTP client
- Central export for package entry point

##### README for additional insights
- Clarifies it’s a community‐maintained wrapper (not official)
- Emphasizes use of mocks for tests (no real NCPS credentials needed during development)
- Shows usage examples in CJS, ES6, and TypeScript

a. Main components
1. SDK Entry Point (index.ts)
2. Endpoint Modules (each folder under src/)
3. Core HTTP Client (base.ts)
4. Type Definitions (types.ts, enums.ts)
5. Test Suite (Jest + mocks)
6. CI/CD (GitHub Actions workflows)
7. External Service (NCPS TransactAPI)
8. Package Manager / Registry (npm / pnpm)
b. Relationships and interactions
- The SDK Entry Point re-exports each Endpoint Module.
- Each Endpoint Module imports the Core HTTP Client and its own types.
- When a user calls an endpoint function, it invokes the Core HTTP Client to make an HTTP request to the TransactAPI.
- The Core HTTP Client attaches clientID & developerAPIKey headers and serializes payloads.
- Responses flow back through the endpoint function to the user.
- During development, Jest tests invoke endpoint modules but intercept HTTP calls with mocks.
- CI workflows run lint, type checks, and unit tests on push/PR.
- On publish, package.json metadata + index.ts define the library’s entry points, and pnpm/npm publishes to the registry.
c. Architectural patterns and design principles
- Modular design – one folder per endpoint
- DRY – shared Core HTTP client logic in base.ts
- Strong typing – all payloads/responses in types.ts
- Test isolation – mocks for every endpoint
- CI/CD ensures code quality and test coverage
d. Relevant technologies
- Node.js + TypeScript
- Jest for unit testing
- ESLint & Prettier for code style
- GitHub Actions for CI/CD
- pnpm (lockfile), npm registry

- Components as labeled rectangles:
- Blue: SDK code (Entry Point, Endpoint Modules, Core Client)
- Green: Type definitions
- Orange: Test Suite / Mocks
- Purple: CI/CD
- From “User Application” to “SDK Entry Point” to “Endpoint Module” to “Core HTTP Client” to “TransactAPI”
- From “Endpoint Module” to “types.ts/enums.ts” for payload schemas
- From “CI/CD” to lint, test, build jobs
- From “Build Output” to “npm registry” (publish)
- Rectangles for code modules

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Application
    UA["User Application"]:::external -->|"import SDK"| SDKIndex

    %% SDK Layer
    SDKIndex["SDK Entry Point<br/>(src/index.ts)"]:::sdk -->|"re-exports"| Endpoints
    click SDKIndex "https://github.com/shadowlion/transactapi-js/blob/master/src/index.ts"

    subgraph "Endpoint Modules" 
        direction TB
        GA["GetAccount Module<br/>(src/getAccount/index.ts)"]:::sdk 
        CT["CreateTrade Module<br/>(src/createTrade/index.ts)"]:::sdk 
        UA2["UpdateAccount Module<br/>(src/updateAccount/index.ts)"]:::sdk 
        PK["PerformKycAml Module<br/>(src/performKycAml/index.ts)"]:::sdk 
        %% more endpoint modules...
        click GA "https://github.com/shadowlion/transactapi-js/blob/master/src/getAccount/index.ts"
        click CT "https://github.com/shadowlion/transactapi-js/blob/master/src/createTrade/index.ts"
        click UA2 "https://github.com/shadowlion/transactapi-js/blob/master/src/updateAccount/index.ts"
        click PK "https://github.com/shadowlion/transactapi-js/blob/master/src/performKycAml/index.ts"
    end

    Endpoints --> GA
    Endpoints --> CT
    Endpoints --> UA2
    Endpoints --> PK

    %% Type Definitions
    subgraph "Type Definitions" 
        direction TB
        Types["types.ts"]:::types 
        Enums["enums.ts"]:::types 
    end

    GA -->|"uses"| Types
    GA -->|"uses"| Enums
    CT -->|"uses"| Types
    UA2 -->|"uses"| Types
    PK -->|"uses"| Types

    %% Core HTTP Client
    CoreClient["Core HTTP Client<br/>(src/base.ts)"]:::sdk
    click CoreClient "https://github.com/shadowlion/transactapi-js/blob/master/src/base.ts"
    GA -->|"calls"| CoreClient
    CT -->|"calls"| CoreClient
    UA2 -->|"calls"| CoreClient
    PK -->|"calls"| CoreClient

    %% External Service
    API["NCPS TransactAPI"]:::externalService
    CoreClient -->|"HTTP POST/GET"| API

    %% Test Suite
    subgraph "Test Suite (Jest + Mocks)" 
        direction TB
        Jest["Jest Test Runner<br/>(jest.config.ts)"]:::test 
        click Jest "https://github.com/shadowlion/transactapi-js/blob/master/jest.config.ts"
        GA_TEST["GetAccount Tests<br/>(src/getAccount/index.spec.ts)"]:::test 
        click GA_TEST "https://github.com/shadowlion/transactapi-js/blob/master/src/getAccount/index.spec.ts"
        CT_TEST["CreateTrade Tests<br/>(src/createTrade/index.spec.ts)"]:::test 
        click CT_TEST "https://github.com/shadowlion/transactapi-js/blob/master/src/createTrade/index.spec.ts"
    end

    Jest -->|"runs"| GA_TEST
    Jest -->|"runs"| CT_TEST
    GA_TEST -.->|"mocks HTTP"| CoreClient
    CT_TEST -.->|"mocks HTTP"| CoreClient

    %% CI/CD
    subgraph "CI/CD (GitHub Actions)" 
        direction TB
        CI["CI Workflow<br/>(.github/workflows/ci.yml)"]:::ci 
        click CI "https://github.com/shadowlion/transactapi-js/blob/master/.github/workflows/ci.yml"
        CodeQL["CodeQL Analysis<br/>(.github/workflows/codeql-analysis.yml)"]:::ci 
        click CodeQL "https://github.com/shadowlion/transactapi-js/blob/master/.github/workflows/codeql-analysis.yml"
    end

    CI -->|"lint/typecheck"| ESLint
    CI -->|"run tests"| Jest
    CI -->|"build"| Build
    CodeQL -->|"security scan"| CI

    %% Build & Publish
    Build["Build Output"]:::sdk -->|"publish"| NPM
    NPM["npm/pnpm Registry"]:::registry

    %% Package & Config
    ESLint["ESLint Config<br/>(.eslintrc)"]:::config
    Prettier["Prettier Config<br/>(.prettierrc)"]:::config
    TSConfig["TypeScript Config<br/>(tsconfig.json)"]:::config
    Husky["Husky Hooks<br/>(.huskyrc)"]:::config
    PackageJSON["package.json"]:::config
    Lockfile["pnpm-lock.yaml"]:::config

    CI --> ESLint
    CI --> Prettier
    CI --> TSConfig

    %% Legend styles
    classDef sdk fill:#D0E8FF,stroke:#4A90E2,stroke-width:1px
    classDef types fill:#DFFFE0,stroke:#3C763D,stroke-width:1px
    classDef test fill:#FFE8B0,stroke:#E67E22,stroke-width:1px
    classDef ci fill:#F0DEFF,stroke:#8E44AD,stroke-width:1px
    classDef externalService fill:#F8D7DA,stroke:#C0392B,stroke-width:1px,stroke-dasharray: 5 5
    classDef registry fill:#E0F7FF,stroke:#3498DB,stroke-width:1px
    classDef config fill:#F2F2F2,stroke:#7F8C8D,stroke-width:1px
    classDef external fill:#FFFFFF,stroke:#7F8C8D,stroke-width:1px
```
