# jeremyhenrickson/token-app-js architecture

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

- Interactive diagram: https://gitdiagram.com/jeremyhenrickson/token-app-js
- Repository: https://github.com/jeremyhenrickson/token-app-js

## Overview

##### Project Type and Purpose
- This is a Node.js/Java “Token app” chatbot service.
- Purpose: run user-facing bot logic (src/bot.js) that interacts with the Token network (end-to-end encrypted chat and payments) via a Java headless client, stores state in Postgres, and uses Redis for inter-process messaging.

##### File Structure Analysis
- Root-level: Dockerfile, Procfile, docker-compose.yml.sample → containerization & deployment.
- dependencies/: prebuilt Docker images for headless-client (Java) and redis.
- config/: environment-specific YAML configs (dev/staging/prod).
- src/: Node.js bot logic + library modules (Bot, Client, Config, Logger, Session, Thread).
- build.gradle + system.properties → Java headless client build config.
- examples/, docs/: usage samples and architecture image.

##### README Insights
- Lists four runtime processes: token-headless-client, redis pub/sub, bot.js, postgres.
- Describes how messages flow (client ↔ redis ↔ bot ↔ redis ↔ client) and session data stored in Postgres.

##### Main Components
b. Token Headless Client (Java process)
c. Redis Pub/Sub (message bus)
d. Bot Service (Node.js process with src/lib modules)
e. PostgreSQL Database

##### Relationships & Data Flows
- Headless Client ←→ Token Backend (HTTPS / Signal protocol)
- Headless Client ↔ Redis Pub/Sub (publish incoming messages, subscribe outgoing messages)
- Bot Service ↔ Redis Pub/Sub (listen for new messages, publish responses)
- Bot Service ↔ PostgreSQL (CRUD session/state data)

##### Architectural Patterns & Technologies
- Micro-process design: separate Java “client proxy” from Node.js “business logic.”
- Pub/Sub messaging for decoupling (Redis).
- Persistent session store (Postgres) for stateful conversations.
- Containerized deployment (Docker + docker-compose, Heroku).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Diagram Info"
        direction TB
        Title["Title: Token Bot Architecture\nDate: 2023-XX-XX\nAuthor: Principal Engineer"]
    end

    subgraph "Infrastructure"
        direction TB
        External["External Token Backend Services"]:::external
        Redis["Redis Pub/Sub"]:::redis
        Postgres["PostgreSQL Database"]:::database
    end

    subgraph "Application"
        direction TB
        HeadlessClient["Token Headless Client (Java)"]:::compute
        BotService["Bot Service (Node.js)"]:::compute
    end

    External <-->|"Encrypted messages (HTTPS/Signal)"| HeadlessClient
    HeadlessClient <-->|"Pub/Sub channels"| Redis
    BotService <-->|"Pub/Sub channels"| Redis
    BotService -->|"SQL queries (CRUD session data)"| Postgres

    click HeadlessClient "https://github.com/jeremyhenrickson/token-app-js/tree/master/dependencies/headless-client/"
    click Redis "https://github.com/jeremyhenrickson/token-app-js/tree/master/dependencies/redis/"
    click BotService "https://github.com/jeremyhenrickson/token-app-js/blob/master/src/bot.js"

    classDef external fill:#d3d3d3,stroke:#000,stroke-width:1px
    classDef redis fill:#f89f1c,stroke:#000,stroke-width:1px
    classDef compute fill:#1f77b4,stroke:#000,stroke-width:1px
    classDef database fill:#2ca02c,stroke:#000,stroke-width:1px
```
