How tamilp/1placetrade works
Purpose and topology
A TypeScript monorepo for an options-trading platform: live market monitoring, broker-connected live execution, paper trading, strategy automation, historical backtesting, reporting, and AI assistance. It has a React/Vite frontend, a Node.js backend API/WebSocket process, and a shared contracts package.
• backend/src/index.ts
• frontend/src/main.tsx
• shared/src/index.ts
Application entry and client boundary
The backend process is the system integration boundary: it exposes feature routes and a WebSocket server. The SPA starts at main.tsx, renders App.tsx, calls HTTP through a centralized client, and consumes server-pushed market/trading updates through a WebSocket hook.
• backend/src/index.ts
• backend/src/ws/wsServer.ts
• frontend/src/App.tsx
• frontend/src/api/client.ts
• frontend/src/api/useWebSocket.ts
Identity, tenancy, and persistence
Authentication/authorization gates protected operations, including entitlement checks. Persistent domain state is abstracted behind StorageAdapter, with PostgreSQL as the material adapter and schema source; trade and journal stores support execution history and reporting. Shared types define broker, market, signal, and strategy contracts across tiers.
• backend/src/auth/requireAuth.ts
• backend/src/auth/requireEntitlement.ts
• backend/src/storage/StorageAdapter.ts
• backend/src/storage/PgStorageAdapter.ts
• backend/src/storage/schema.sql
• shared/src/types/strategy-automation.ts
Broker and market-data integration
BrokerRegistry and broker adapters isolate Angel One, Dhan, Fyers, Upstox, and Zerodha APIs behind normalized execution/feed interfaces. Instrument-master registries resolve broker-specific symbols; feeds, OI snapshots, candle aggregation, and signal engine transform live inputs into dashboard and automation-ready market state.
• backend/src/brokers/BrokerRegistry.ts
• backend/src/brokers/MarketFeedClient.ts
• backend/src/brokers/instrumentMasterRegistry.ts
• backend/src/candle-aggregator/index.ts
• backend/src/signal-engine/index.ts
Trading execution modes and safeguards
Paper trading simulates orders, positions, premiums, and brokerage independently of brokers. Live trading delegates orders through broker connections. Global exit and trading-status services provide cross-cutting controls; frontend pages separate paper and live workflows.
• backend/src/paper-trading/PaperTradingService.ts
• backend/src/live-trading/LiveTradingService.ts
• backend/src/live-trading/liveOrderExecution.ts
• backend/src/services/globalExitService.ts
• frontend/src/features/paper-trading/PaperTradingPage.tsx
• frontend/src/features/live-trading/LiveTradingPage.tsx
Strategy automation pipeline
Schedules invoke strategy execution; market-data services construct inputs, strategy implementations and engine rules generate/filter recommendations, then position adaptation and execution connect decisions to trading state. This is the core automated-trading control loop, including daily account caps and failure protection.
• backend/src/strategy-automation/StrategyScheduleService.ts
• backend/src/strategy-automation/StrategyExecutionService.ts
• backend/src/strategy-automation/StrategyMarketDataService.ts
• backend/src/strategy-automation/StrategyRecommendationService.ts
• backend/src/strategy-automation/strategies/index.ts
• backend/src/strategy-automation/engineRules/failureProtection.ts
Historical analysis and user-facing operations
Backtests run through an engine/runner with worker isolation and historical chain/market providers. Reports consume stored trade/journal data. AI assistance builds trading context, selects Anthropic/Gemini/OpenAI-compatible providers, rate-limits usage, and exposes dedicated routes/UI. Notification services integrate email, Telegram, web push, and webhooks.
• backend/src/backtesting/backtestRunner.ts
• backend/src/backtesting/runBacktestInWorker.ts
• backend/src/backtesting/historicalMarketBuilder.ts
• backend/src/ai-assistant/ProviderManager.ts
• backend/src/ai-assistant/aiContextBuilder.ts
• backend/src/services/alertDispatch.ts
Main entry points: index.ts Backend process · App.tsx Application shell · StrategyExecutionService.ts Strategy execution · LiveTradingService.ts Live trading
Components 21
React SPA
- SPA entry
frontend/src/main.tsx - Application shell
frontend/src/App.tsx - HTTP client
frontend/src/api/client.ts - WebSocket consumer
frontend/src/api/useWebSocket.ts - Paper & live pages · Separate user workflows for simulated and broker-connected trading.
frontend/src/features/live-trading/LiveTradingPage.tsx
Backend boundary
- Backend process · Feature-route and integration boundary.
backend/src/index.ts - WebSocket server
backend/src/ws/wsServer.ts - Auth & entitlements
backend/src/auth/requireAuth.ts - AI assistant · Builds trading context and selects compatible AI providers.
backend/src/ai-assistant/ProviderManager.ts - Alert dispatch · Delivers email, Telegram, push, and webhook notifications.
backend/src/services/alertDispatch.ts
Trading & automation
- Paper trading · Simulates orders, positions, premiums, and brokerage.
backend/src/paper-trading/PaperTradingService.ts - Live trading
backend/src/live-trading/LiveTradingService.ts - Global exit controls
backend/src/services/globalExitService.ts - Strategy scheduler
backend/src/strategy-automation/StrategyScheduleService.ts - Strategy execution · Builds inputs, generates recommendations, and applies failure protection.
backend/src/strategy-automation/StrategyExecutionService.ts - Backtest runner · Runs isolated worker backtests with historical market inputs.
backend/src/backtesting/backtestRunner.ts
Data & integrations
- PostgreSQL storage adapter · Domain-state abstraction backed by PostgreSQL.
backend/src/storage/PgStorageAdapter.ts - Strategy contracts · Cross-tier broker, market, signal, and strategy contracts.
shared/src/types/strategy-automation.ts - Broker registry · Normalizes Angel One, Dhan, Fyers, Upstox, and Zerodha connections.
backend/src/brokers/BrokerRegistry.ts - Market feed client
backend/src/brokers/MarketFeedClient.ts - Candles & signals · Aggregates live feeds into candles and actionable signal state.
backend/src/signal-engine/index.ts
Connections 28
- SPA entry → Application shell: renders
- Application shell → HTTP client: calls APIs
- Application shell → WebSocket consumer: subscribes
- Application shell → Paper & live pages: hosts workflows
- HTTP client → Backend process: HTTP
- WebSocket consumer → WebSocket server: server push
- Backend process → Auth & entitlements: protects operations
- Backend process → PostgreSQL storage adapter: persists domain state
- Backend process → WebSocket server: publishes updates
- Backend process → Paper trading: routes paper orders
- Backend process → Live trading: routes live orders
- Backend process → Backtest runner: runs analyses
- Backend process → AI assistant: serves assistance
- Market feed client → Candles & signals: live inputs
- Broker registry → Market feed client: broker feeds
- Candles & signals → WebSocket server: market updates
- Paper trading → PostgreSQL storage adapter: stores trades
- Live trading → Broker registry: submits orders
- Live trading → Global exit controls: subject to exits
- Strategy scheduler → Strategy execution: invokes
- Candles & signals → Strategy execution: market state
- Strategy execution → Live trading: automated execution
- Strategy execution → Global exit controls: caps & failure protection
- Strategy execution → Alert dispatch: notifies outcomes
- Backtest runner → PostgreSQL storage adapter: reads history
- AI assistant → PostgreSQL storage adapter: builds trading context
- Strategy contracts → Application shell: shared contracts
- Strategy contracts → Backend process: shared contracts