How manascb1344/tensorforce works
Project Type and Purpose
• This is a full-stack, microservices-driven web application (“TensorForce”) for automated stock trading.
• It consists of:
• A React-based Single Page Application (SPA) in WebD/
• A Node.js/Express REST backend in backend/
• Multiple Python-based ML services in ML/ (model training, inference, deployment)
• A MongoDB database for user and model metadata
• Integrations with external services (Alpaca trading API, news feeds)
Key Top-Level Directories & Roles
• WebD/
• React + Tailwind UI, Vite bundler, client-side routing (AppRoutes.jsx)
• Features: Dashboard, Heatmap, News, Shop, Sentiment, Charts
• backend/
• Node.js (Express) REST API: index.js exposes endpoints for userDetails, modelDetails
• Talks to MongoDB to store users, orders, marketplace listings
• ML/
• Subfolders for model development (model1/, model2/), news sentiment (News/), deployment scripts (Deployment/), Alpaca trading utilities
• content/models/
• Stores pre-built .h5 model artifacts for direct load
• Config & infra: .env (API keys), vercel.json (frontend hosting), Render or similar for backend
High-Level System Components
A. Client Tier (WebD SPA)
– Browser-based React app
– UI modules: Login, Dashboard, Charts, Sentiment Bot
– Communicates over HTTPS with Backend Tier
B. Application Tier (Node.js Backend)
– REST API endpoints:
• Auth & Profile (/login, /userDetails)
• Model marketplace (/modelDetails, /shop)
• Trade orchestration
– Interacts with:
• MongoDB (User, Marketplace, Trade logs)
• ML Inference Services (Flask microservices)
• External Alpaca API for order placement
C. ML Tier (Python/Flask Microservices)
– Inference endpoints:
• Stock-prediction models (exposed via Deployment/ scripts)
• Sentiment analysis service (ML/News/SentimentBot.py)
– Model registry: .h5 files served from content/models/ or cloud storage
– Training pipelines live in ML/model1/, ML/model2/ (Jupyter notebooks, Keras/TensorFlow)
D. Data Tier
– MongoDB cluster (hosted)
– Model artifacts store (local content/models/ or S3)
E. External Services
– Alpaca Trading REST API (order execution)
– Public News/API feeds for sentiment
– (Optional) Authentication provider (OAuth)
Relationships & Data Flows
1. User loads React SPA → Browser
2. SPA → Node.js Backend (HTTPS REST)
3. Backend → MongoDB (CRUD user, portfolio, model listings)
4. When user requests a prediction or auto-trade:
a. Backend forwards request to ML Inference Service (Flask) → returns prediction/sentiment
b. Backend uses prediction to call Alpaca API → executes trade
c. Backend writes trade result back to MongoDB → portfolio updated
5. Frontend polls or websockets → Backend → updates UI
Architectural Patterns & Design Principles
• Microservices: Separate ML inference from core business logic
• 3-Tier separation: Presentation / Application / Data
• Component-based UI (React) with Context Providers
• RESTful APIs for inter-service communication
• Model registry pattern: store and version .h5 artifacts
Technologies & Libraries to Annotate
• Frontend: React, Vite, Tailwind CSS, React Router
• Backend: Node.js, Express, Mongoose (MongoDB driver)
• ML: Python, Flask, TensorFlow/Keras, PyTorch, Jupyter (for training)
• External: Alpaca trading API, News APIs