# prabuselvamnatarajan/moneymaker_aws architecture

> Architecture diagram of the GitHub repository prabuselvamnatarajan/moneymaker_aws, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prabuselvamnatarajan/moneymaker_aws
- Repository: https://github.com/prabuselvamnatarajan/moneymaker_aws

## Overview

#### Purpose and topology
MoneyMaker is a containerized trading platform supporting backtesting and live strategy execution. It combines a management API/UI, market-data and broker integration services, Kafka-driven strategy/processing workers, and scheduled/bootstrap jobs. Compose/Swarm deployment is centered on `docker-compose.yml`, `docker-compose.ci.yml`, and `scripts/deploy-stack.sh`.

#### Operator-facing API and UI
The primary management backend is a Node.js application entered through `BackTest/BackTestApp/src/server.js` and assembled in `BackTest/BackTestApp/src/app.js`. Its route/controller/service layers manage accounts, brokers, strategies, deployments, trades, positions, ledgers, symbols, Docker resources, and volumes; representative boundaries are `BackTest/BackTestApp/src/routes/deploymentRoute.js`, `BackTest/BackTestApp/src/controllers/trade.js`, and `BackTest/BackTestApp/src/services/strategy.js`.

The main richer frontend is a Vite/React TypeScript UI entered at `BackTest/BackTestUI/src/main.tsx`, with shell/API integration in `BackTest/BackTestUI/src/App.tsx` and `BackTest/BackTestUI/src/api.ts`. A separate lightweight React client exists at `client/src/main.jsx`, with a backtest page at `client/src/pages/BackTest.jsx`.

#### Identity and persistent state
The API has a dedicated IAM subsystem for JWT/session, MFA, roles, permissions, and personal access tokens: `BackTest/BackTestApp/src/iam/index.js`, `BackTest/BackTestApp/src/iam/services/authService.js`, and `BackTest/BackTestApp/src/iam/middlewares/authorizationMiddleware.js`. It also retains older/general authentication middleware under `BackTest/BackTestApp/src/middlewares/authMiddleware.js`.

MongoDB is the durable domain store, with connection and model boundaries at `BackTest/BackTestApp/src/db/connection.js`, `BackTest/BackTestApp/src/models/deployment.js`, and `BackTest/BackTestApp/src/models/trade.js`. Redis is used for operational/state coordination through `BackTest/BackTestApp/src/utils/positionRedis.js` and reusable wrappers in `redis_operations/index.js`; Mongo replica-set setup is represented by `mongo/mongod.conf` and `init-mongo-replica.sh`.

#### Backtest lifecycle
The API creates and tracks strategy deployments/runs, while specialized backtest processes execute and stream results. Relevant execution entry points are `BackTest/BacktestClient/clientServer.js` and `BackTest/BacktestStreamer/streamer.js`; completion reconciliation is isolated in `BackTest/BackTestApp/src/services/backtestCompletionWatcher.js`. Backtest state must remain scoped per run/deployment, as indicated by dedicated run-ID synchronization and parallel-isolation service tests.

The UI consumes API and streaming outcomes for deployment analysis, transactions, positions, and candle views, notably `BackTest/BackTestUI/src/components/DeploymentAnalysisView.tsx`, `BackTest/BackTestUI/src/components/TransactionList.tsx`, and `BackTest/BackTestUI/src/components/LiveCandlestickView.tsx`.

#### Live market-data and execution boundary
Upstox is the evident external broker/vendor boundary. Microservices provide login, WebSocket market feed connectivity, quotes, option-chain data, order placement/order book access, and funds/margin retrieval: `MicroServices/UpstoxLogin/server.js`, `MicroServices/ConnectWS-Upstox/server.js`, and `MicroServices/Orders/placeOrders/server.js`. Shared authorization/client logic is at `MicroServices/Shared/AuthorisedUpstox/AuthoriseUpstoxClient.js`.

The API’s broker abstraction and external-broker identity mapping separate platform entities from vendor credentials: `BackTest/BackTestApp/src/services/broker.js`, `BackTest/BackTestApp/src/services/externalBroker.js`, and `BackTest/BackTestApp/src/models/externalBrokerId.js`.

#### Event pipeline and strategy execution
Kafka is the principal asynchronous control/data plane. Incoming WebSocket data is split and forwarded by `kafka/services/wsDataSplitterConsumer/wsDataSplitterConsumer.js`; strategy selection and deployment-symbol resolution are handled by `kafka/services/StrategyChooserConsumer/StrategyChooserConsumer.js` and `kafka/services/deploymentSymbolResolverConsumer/deploymentSymbolResolverConsumer.js`. Positions and persisted events are processed by `kafka/services/positionTrackerConsumer/positionTrackerConsumer.js` and `kafka/services/storerConsumer/storerConsumer.js`; client streaming has its own WebSocket service at `kafka/services/streamToClient/wsServer.js`.

Runnable strategy workers include MSB, MSB PTS, and liquidity sweep: `kafka/services/Strategies/MSB/server.js`, `kafka/services/Strategies/msb_pts/server.js`, and `kafka/services/Strategies/liquidity_sweep/server.js`. They consume market events, use Redis-backed strategy state/concurrency controls, and can lead to broker order calls.

#### Bootstrap, scheduling, and runtime infrastructure
Startup orchestration initializes live strategy choice and WebSocket listening via `appInit/start.js`, `appInit/Init/strategyChooser_Live.js`, and `appInit/Init/webSocketListening_Live.js`. Periodic services export data and initialize MSB strategy work through `ScheduledServices/ExportToFile/scheduler.js` and `ScheduledServices/MSBStrategyInit/scheduler.js`.

Docker is the material runtime for each service, with Kafka/Zookeeper images under `kafka/broker/Dockerfile` and `kafka/zookeeper/Dockerfile`; reverse-proxy TLS configuration resides at `certs/nginx.conf`. System-level intended flows are additionally documented in `system_flows/live_trading_flow.md` and `system_flows/backtest_flow.md`.

Main entry points: [`BackTest/BackTestApp/src/server.js`](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/server.js) (Management API), [`kafka/broker/Dockerfile`](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/broker/Dockerfile) (Kafka), [`kafka/services/Strategies/MSB/server.js`](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/Strategies/MSB/server.js) (Strategy workers), [`MicroServices/ConnectWS-Upstox/server.js`](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/MicroServices/ConnectWS-Upstox/server.js) (Upstox integration services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_operator["Operator surfaces"]
  node_rich_ui["React management UI<br/>Vite React<br/>[main.tsx]"]
  node_light_ui["Lightweight backtest UI<br/>React<br/>[main.jsx]"]
end

subgraph group_core["Management platform"]
  node_api["Management API<br/>Node.js<br/>[server.js]"]
  node_iam["IAM<br/>auth subsystem<br/>[index.js]"]
  node_mongo[("Domain store<br/>MongoDB<br/>[connection.js]")]
  node_redis[("Operational state<br/>Redis<br/>[positionRedis.js]")]
  node_broker_service["Broker abstraction<br/>API service<br/>[broker.js]"]
end

subgraph group_backtest["Backtest runtime"]
  node_completion["Backtest completion watcher<br/>API service"]
  node_backtest_client["Backtest executor<br/>process<br/>[clientServer.js]"]
  node_backtest_streamer["Backtest streamer<br/>process<br/>[streamer.js]"]
end

subgraph group_events["Live event pipeline"]
  node_kafka["Kafka<br/>event bus"]
  node_market_splitter["Market data splitter<br/>Kafka consumer"]
  node_strategy_router["Strategy routing<br/>Kafka consumers"]
  node_strategy_workers["Strategy workers<br/>[server.js]"]
  node_position_storer["Position and event persistence<br/>Kafka consumers"]
  node_client_stream["Live client stream<br/>WebSocket service<br/>[wsServer.js]"]
end

subgraph group_integration["Broker and runtime"]
  node_upstox_services["Upstox integration services<br/>broker adapters<br/>[server.js]"]
  node_upstox{{"Upstox<br/>external broker"}}
  node_bootstrap["Live startup orchestration<br/>bootstrap job<br/>[start.js]"]
  node_schedulers["Scheduled jobs<br/>scheduler<br/>[scheduler.js]"]
  node_docker["Container deployment<br/>Compose / Swarm<br/>[docker-compose.yml]"]
end

node_rich_ui -->|"management API"| node_api
node_light_ui -->|"backtest API"| node_api
node_api -->|"authenticates requests"| node_iam
node_api -->|"domain reads/writes"| node_mongo
node_api -->|"position coordination"| node_redis
node_api -->|"broker operations"| node_broker_service
node_broker_service -->|"vendor calls"| node_upstox_services
node_upstox_services -->|"broker API and feed"| node_upstox
node_api -->|"starts and tracks runs"| node_backtest_client
node_backtest_client -->|"run results"| node_backtest_streamer
node_backtest_streamer -->|"analysis stream"| node_rich_ui
node_backtest_streamer -->|"completion outcome"| node_completion
node_completion -->|"reconciles run state"| node_mongo
node_upstox_services -->|"market events"| node_kafka
node_kafka -->|"raw feed"| node_market_splitter
node_market_splitter -->|"split events"| node_kafka
node_kafka -->|"market events"| node_strategy_router
node_strategy_router -->|"selected deployment events"| node_strategy_workers
node_strategy_workers -->|"strategy state and locks"| node_redis
node_strategy_workers -->|"order requests"| node_upstox_services
node_kafka -->|"trade and position events"| node_position_storer
node_position_storer -->|"persists events"| node_mongo
node_kafka -->|"live updates"| node_client_stream
node_client_stream -->|"live candles and positions"| node_rich_ui
node_bootstrap -->|"starts live selection"| node_kafka
node_schedulers -->|"initializes MSB work"| node_strategy_workers
node_docker -.->|"runs"| node_api
node_docker -.->|"runs"| node_kafka

click node_rich_ui "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestUI/src/main.tsx"
click node_light_ui "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/client/src/main.jsx"
click node_api "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/server.js"
click node_iam "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/iam/index.js"
click node_mongo "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/db/connection.js"
click node_redis "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/utils/positionRedis.js"
click node_broker_service "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/services/broker.js"
click node_completion "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/services/backtestCompletionWatcher.js"
click node_backtest_client "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BacktestClient/clientServer.js"
click node_backtest_streamer "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BacktestStreamer/streamer.js"
click node_kafka "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/broker/Dockerfile"
click node_market_splitter "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/wsDataSplitterConsumer/wsDataSplitterConsumer.js"
click node_strategy_router "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/StrategyChooserConsumer/StrategyChooserConsumer.js"
click node_strategy_workers "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/Strategies/MSB/server.js"
click node_position_storer "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/positionTrackerConsumer/positionTrackerConsumer.js"
click node_client_stream "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/streamToClient/wsServer.js"
click node_upstox_services "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/MicroServices/ConnectWS-Upstox/server.js"
click node_bootstrap "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/appInit/start.js"
click node_schedulers "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/ScheduledServices/MSBStrategyInit/scheduler.js"
click node_docker "https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_rich_ui,node_light_ui toneBlue
class node_api,node_iam,node_mongo,node_redis,node_broker_service toneAmber
class node_completion,node_backtest_client,node_backtest_streamer toneMint
class node_kafka,node_market_splitter,node_strategy_router,node_strategy_workers,node_position_storer,node_client_stream toneRose
class node_upstox_services,node_upstox,node_bootstrap,node_schedulers,node_docker toneIndigo
```

## Components

### Operator surfaces

- [React management UI](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestUI/src/main.tsx): Vite React · `BackTest/BackTestUI/src/main.tsx`
- [Lightweight backtest UI](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/client/src/main.jsx): React · `client/src/main.jsx`

### Management platform

- [Management API](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/server.js): Node.js · Routes and services manage platform entities and deployments. · `BackTest/BackTestApp/src/server.js`
- [IAM](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/iam/index.js): auth subsystem · JWT, sessions, MFA, roles, permissions, and access tokens. · `BackTest/BackTestApp/src/iam/index.js`
- [Domain store](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/db/connection.js): MongoDB · `BackTest/BackTestApp/src/db/connection.js`
- [Operational state](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/utils/positionRedis.js): Redis · Position and strategy coordination state. · `BackTest/BackTestApp/src/utils/positionRedis.js`
- [Broker abstraction](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/services/broker.js): API service · Maps platform brokers to external broker identities. · `BackTest/BackTestApp/src/services/broker.js`

### Backtest runtime

- [Backtest completion watcher](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BackTestApp/src/services/backtestCompletionWatcher.js): API service · Reconciles completed runs into deployment state. · `BackTest/BackTestApp/src/services/backtestCompletionWatcher.js`
- [Backtest executor](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BacktestClient/clientServer.js): process · `BackTest/BacktestClient/clientServer.js`
- [Backtest streamer](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/BackTest/BacktestStreamer/streamer.js): process · Streams run-scoped backtest results. · `BackTest/BacktestStreamer/streamer.js`

### Live event pipeline

- [Kafka](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/broker/Dockerfile): event bus · Asynchronous market-data and strategy control plane. · `kafka/broker/Dockerfile`
- [Market data splitter](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/wsDataSplitterConsumer/wsDataSplitterConsumer.js): Kafka consumer · `kafka/services/wsDataSplitterConsumer/wsDataSplitterConsumer.js`
- [Strategy routing](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/StrategyChooserConsumer/StrategyChooserConsumer.js): Kafka consumers · Chooses strategies and resolves deployment symbols. · `kafka/services/StrategyChooserConsumer/StrategyChooserConsumer.js`
- [Strategy workers](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/Strategies/MSB/server.js): MSB / PTS / liquidity sweep · Execute live trading logic from market events. · `kafka/services/Strategies/MSB/server.js`
- [Position and event persistence](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/positionTrackerConsumer/positionTrackerConsumer.js): Kafka consumers · `kafka/services/positionTrackerConsumer/positionTrackerConsumer.js`
- [Live client stream](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/kafka/services/streamToClient/wsServer.js): WebSocket service · `kafka/services/streamToClient/wsServer.js`

### Broker and runtime

- [Upstox integration services](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/MicroServices/ConnectWS-Upstox/server.js): broker adapters · Login, market feed, quotes, orders, and funds integration. · `MicroServices/ConnectWS-Upstox/server.js`
- **Upstox**: external broker
- [Live startup orchestration](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/appInit/start.js): bootstrap job · Initializes strategy selection and WebSocket listening. · `appInit/start.js`
- [Scheduled jobs](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/ScheduledServices/MSBStrategyInit/scheduler.js): scheduler · Exports data and initializes MSB work. · `ScheduledServices/MSBStrategyInit/scheduler.js`
- [Container deployment](https://github.com/prabuselvamnatarajan/moneymaker_aws/blob/main/docker-compose.yml): Compose / Swarm · `docker-compose.yml`

## Connections

- React management UI → Management API: management API
- Lightweight backtest UI → Management API: backtest API
- Management API → IAM: authenticates requests
- Management API → Domain store: domain reads/writes
- Management API → Operational state: position coordination
- Management API → Broker abstraction: broker operations
- Broker abstraction → Upstox integration services: vendor calls
- Upstox integration services → Upstox: broker API and feed
- Management API → Backtest executor: starts and tracks runs
- Backtest executor → Backtest streamer: run results
- Backtest streamer → React management UI: analysis stream
- Backtest streamer → Backtest completion watcher: completion outcome
- Backtest completion watcher → Domain store: reconciles run state
- Upstox integration services → Kafka: market events
- Kafka → Market data splitter: raw feed
- Market data splitter → Kafka: split events
- Kafka → Strategy routing: market events
- Strategy routing → Strategy workers: selected deployment events
- Strategy workers → Operational state: strategy state and locks
- Strategy workers → Upstox integration services: order requests
- Kafka → Position and event persistence: trade and position events
- Position and event persistence → Domain store: persists events
- Kafka → Live client stream: live updates
- Live client stream → React management UI: live candles and positions
- Live startup orchestration → Kafka: starts live selection
- Scheduled jobs → Strategy workers: initializes MSB work
- Container deployment → Management API: runs
- Container deployment → Kafka: runs
