# 3s3s/opentrade architecture

> Architecture diagram of the GitHub repository 3s3s/opentrade, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/3s3s/opentrade
- Repository: https://github.com/3s3s/opentrade

## Overview

##### Project Type and Purpose
- OpenTrade is a full-stack, microservices-style cryptocurrency exchange platform written in Node.js.
- It consists of three cooperating Node.js services:
- databaseServer – a custom data-access API for all persistent data (users, orders, trades, balances)
- accountsserver – the authentication/account-management service
- server – the main HTTP/HTTPS web server delivering UI pages, JSON API, WebSockets, admin console, and RPC logic for trading
- It also integrates with external cryptocurrency daemon processes (e.g. bitcoind/litecoind clones) via JSON-RPC, an SMTP mailer, and Google reCAPTCHA.

##### File‐Structure Analysis
- Top-level directories:
- databaseServer/: data-service microservice
- accountsserver/: authentication microservice
- server/: main web microservice (modules/, views/, static pages)
- static_pages/: pure front-end HTML/CSS/JS (used for offline test, chart page, etc.)
- ssl_certificates/: TLS keys for HTTPS
- Configuration files: private_constants.js (API keys, SSL paths), constants.js (exchange parameters), chart.html (front-end config), package.json, databaseServer/utils, server/database.js

##### README Insights
- Deploys three Node services via forever
- Uses NVM/Node 12.x
- Requires external coin-daemon processes on RPC ports
- First user becomes admin, coins added via admin UI
- Captures both static and server-rendered front-end (EJS templates + client JS)

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef client fill:#bbf,stroke:#000,color:#000
    classDef infra fill:#ddd,stroke:#000,color:#000
    classDef service fill:#f96,stroke:#000,color:#000
    classDef module fill:#f96,stroke:#000,color:#000
    classDef view fill:#9f6,stroke:#000,color:#000
    classDef static fill:#9f6,stroke:#000,color:#000
    classDef external fill:#aaa,stroke:#000,color:#000
    classDef annot fill:#fff,stroke:#000,color:#000

    subgraph "Clients/UI"
        C["Web Browser"]:::client
    end

    C -->|HTTPS 443| LB["HTTPS Load Balancer / Nginx"]:::infra

    LB -->|HTTPS 443| WS["Main Web Service\n(server)"]:::service

    subgraph "Main Web Service"
        WS_main["server/main.js"]:::service
        WS_req["server/reqHandler.js"]:::service
        WS_dbproxy["server/database.js"]:::service
        WS_const["server/constants.js"]:::service
        WS_utils["server/utils.js"]:::service

        subgraph Modules
            Admin["Admin\nserver/modules/admin"]:::module
            API["API v1\nserver/modules/api/v1.js"]:::module
            Reg["Registration\nserver/modules/registration"]:::module
            Users["Users\nserver/modules/users"]:::module
            WSmod["WebSocket\nserver/modules/websocket.js"]:::module
            Mailer["Mailer\nserver/modules/mailer.js"]:::module
            Support["Support\nserver/modules/support.js"]:::module
            RPCmod["RPC Integrator\nserver/modules/rpc.js"]:::module
            PrivConst["Private Constants\nserver/modules/private_constants.js"]:::module
            Index["Module Loader\nserver/modules/index.js"]:::module
        end

        subgraph Views
            Views["EJS Templates\nserver/views/"]:::view
        end

        subgraph StaticAssets
            Static["Static Pages\nstatic_pages/"]:::static
        end

        Note["Config: private_constants.js"]:::annot
    end

    WS --> WS_main
    WS_main --> WS_req
    WS_main --> WS_dbproxy
    WS_main --> WS_const
    WS_main --> WS_utils

    WS_main --> Admin
    WS_main --> API
    WS_main --> Reg
    WS_main --> Users
    WS_main --> WSmod
    WS_main --> Mailer
    WS_main --> Support
    WS_main --> RPCmod
    WS_main --> PrivConst
    WS_main --> Index

    WS_main --> Views
    WS_main --> Static
    WS_main --> Note

    WS --> Acc["Account Service\n(accountsserver)"]:::service
    WS --> DBService["Data Service\n(databaseServer)"]:::service
    Acc -->|RPC/HTTP| DBService

    subgraph "Data Service"
        DBService_main["databaseServer/main.js"]:::service
        DBService_req["databaseServer/reqHandler.js"]:::service
        DBService_db["databaseServer/database.js"]:::service
        DBService_const["databaseServer/constants.js"]:::service
        DBService_utils["databaseServer/utils.js"]:::service
    end

    DBService --> DBService_main
    DBService_main --> DBService_req
    DBService_req --> DBService_db
    DBService_db --> DBService_const
    DBService_const --> DBService_utils

    subgraph "External Systems"
        Coin["Crypto Daemons\n(JSON-RPC)"]:::external
        SMTP["SMTP Mail Server"]:::external
        Recap["Google reCAPTCHA"]:::external
    end

    WS_main -->|JSON-RPC| Coin
    Reg -->|Email async| SMTP
    WS_main -->|Validate| Recap
    WSmod <-->|WS 40443| C

    click DBService_main "https://github.com/3s3s/opentrade/blob/master/databaseServer/main.js"
    click DBService_req "https://github.com/3s3s/opentrade/blob/master/databaseServer/reqHandler.js"
    click DBService_db "https://github.com/3s3s/opentrade/blob/master/databaseServer/database.js"
    click DBService_const "https://github.com/3s3s/opentrade/blob/master/databaseServer/constants.js"
    click DBService_utils "https://github.com/3s3s/opentrade/blob/master/databaseServer/utils.js"
    click Acc "https://github.com/3s3s/opentrade/tree/master/accountsserver/"
    click WS_main "https://github.com/3s3s/opentrade/blob/master/server/main.js"
    click WS_req "https://github.com/3s3s/opentrade/blob/master/server/reqHandler.js"
    click WS_dbproxy "https://github.com/3s3s/opentrade/blob/master/server/database.js"
    click WS_const "https://github.com/3s3s/opentrade/blob/master/server/constants.js"
    click WS_utils "https://github.com/3s3s/opentrade/blob/master/server/utils.js"
    click Admin "https://github.com/3s3s/opentrade/tree/master/server/modules/admin/"
    click API "https://github.com/3s3s/opentrade/blob/master/server/modules/api/v1.js"
    click Reg "https://github.com/3s3s/opentrade/tree/master/server/modules/registration/"
    click Users "https://github.com/3s3s/opentrade/tree/master/server/modules/users/"
    click WSmod "https://github.com/3s3s/opentrade/blob/master/server/modules/websocket.js"
    click Mailer "https://github.com/3s3s/opentrade/blob/master/server/modules/mailer.js"
    click Support "https://github.com/3s3s/opentrade/blob/master/server/modules/support.js"
    click RPCmod "https://github.com/3s3s/opentrade/blob/master/server/modules/rpc.js"
    click PrivConst "https://github.com/3s3s/opentrade/blob/master/server/modules/private_constants.js"
    click Index "https://github.com/3s3s/opentrade/blob/master/server/modules/index.js"
    click Views "https://github.com/3s3s/opentrade/tree/master/server/views/"
    click Static "https://github.com/3s3s/opentrade/tree/master/static_pages/"
```
