A full-stack stock market intelligence platform for Indian equities โ built with Node.js, MySQL and React.
Stock Data Warehouse is a personal Bloomberg Terminal for Indian stocks. It:
- ๐ฅ Fetches live data from the IndianAPI (prices, profiles, news)
- ๐๏ธ Stores everything locally in a MySQL database (zero repeat API calls after first load)
- ๐ Visualises it through a modern dark-theme React dashboard
- ๐ Screens stocks using 15+ financial & technical filters
- ๐งฎ Analyses data using advanced SQL โ Window Functions, Views, Stored Procedures
| Layer | Technology |
|---|---|
| Database | MySQL 8.0 |
| Backend | Node.js 18 + Express |
| Frontend | React 18 (Vite) |
| Styling | Tailwind CSS (utility classes) + Vanilla CSS |
| External Data | IndianAPI |
| HTTP | undici (backend), axios (frontend) |
7 tables + 1 View + 1 Stored Procedure:
exchanges โ Stock exchanges (NSE, BSE)
companies โ 22 tracked Indian stocks + cached profile JSON
stock_prices โ Daily OHLCV candles (1 year per company)
technical_indicators โ MA50, MA200, RSI per company per day
market_news โ News headlines
trades โ Buy/sell trade records
corporate_actions โ Dividends, splits (schema ready)
vw_screener_base โ VIEW: pre-joins companies + prices + indicators
sp_refresh_technicals โ PROCEDURE: recalculates MA50/MA200/RSI from raw data
profile_data JSONcolumn stores the full IndianAPI response (avoids 50+ extra columns)UNIQUE KEY (company_id, timestamp, span)onstock_pricesprevents duplicatesBIGINTprimary keys for price/indicator tables โ they grow fastDECIMAL(10,2)for prices โ avoids floating-point rounding errors- Indexes on
(company_id, timestamp)make time-series queries fast
- Node.js v18+
- MySQL 8.0+ running locally
mysql -u root -p < backend/schema.sqlOr open backend/schema.sql in MySQL Workbench and execute it.
cd backend
npm installCopy .env.example to .env and fill in your credentials:
PORT=5000
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_mysql_password
DB_NAME=stock_data_warehouse
INDIAN_API_KEY=your_api_key_hereStart the backend:
npm run dev
# Server runs on http://localhost:5000Creates the vw_screener_base View and sp_refresh_technicals Stored Procedure:
node migrations/run_migration.jsAdds 20 Nifty 50 companies with full profile + historical data:
node seed_nifty20.js
โ ๏ธ This makes ~3 API calls per company. Make sure you have sufficient IndianAPI credits.
cd frontend
npm install
npm run dev
# Opens on http://localhost:5173Home screen โ lists all tracked companies with live price and 1-day change.
Full financial deep-dive for a single stock:
- P/E Ratio, Market Cap, ROE, 52W High/Low โ parsed from cached JSON
- Interactive candlestick price chart (1yr history)
- MA50, MA200, RSI overlays
- Analyst buy/hold/sell sentiment
- Latest news feed
Filter stocks by 15+ criteria simultaneously:
| Category | Filters |
|---|---|
| Price & Volume | Min/Max price, Min/Max volume |
| Returns | 1-Day %, 30-Day % change |
| Fundamentals | ROE, Debt/Equity, Net Profit Margin, Revenue Growth 5Y |
| Size | Market Cap range |
| Momentum | Distance from 52W High, Price vs 50DMA |
| Category | Sector |
| Signals | Golden Cross, Death Cross, Volume Spike, Near 52W High/Low |
5 panels powered by distinct SQL techniques:
| Panel | SQL Feature |
|---|---|
| Sector Heatmap | GROUP BY sector, AVG(), GROUP_CONCAT() |
| Sector Rankings | RANK() OVER (PARTITION BY sector ORDER BY change_pct) |
| Streak Detector | LAG(close_price) OVER (PARTITION BY company_id ORDER BY timestamp) |
| DB Objects | SELECT FROM information_schema.VIEWS / ROUTINES |
| Refresh Technicals | CALL sp_refresh_technicals(company_id) |
Market news + price chart exploration across multiple time frames.
Add any NSE/BSE-listed stock by ticker. One form submission triggers:
- Company record creation (DB)
- Full profile cache (IndianAPI โ
profile_datacolumn) - 1-year historical prices (โ
stock_pricestable) - News fetch (โ
market_newstable)
Add Company
โโ POST /api/companies โ creates DB record
โโ POST /api/external/profile โ fetches + caches JSON blob
โโ POST /api/external/historical โ populates stock_prices + technical_indicators
โโ POST /api/external/news โ populates market_news
View Company Page
โโ GET /api/companies/:symbol โ reads from DB (zero API calls)
โโ GET /api/stocks/:id โ reads stock_prices from DB
Run Screener
โโ GET /api/screener?filters...
โโ Pre-query: JSON_EXTRACT financials from profile_data
โโ Main query: filters applied via vw_screener_base
โโ JS merge: ranks computed, results returned
| Concept | Where |
|---|---|
| Normalisation (3NF) | 7 tables with foreign keys |
| Referential Integrity | FOREIGN KEY constraints throughout |
| Indexing | idx_stock_time, idx_indicator_time, idx_trade_time |
| JSON data type | profile_data column in companies |
| Aggregate Functions | AVG(), MAX(), MIN(), COUNT(), SUM() |
| Correlated Subqueries | Latest price per company in screener JOINs |
| Window Functions | RANK(), DENSE_RANK(), LAG() in analytics |
| Database Views | vw_screener_base โ abstraction over complex JOINs |
| Stored Procedures | sp_refresh_technicals โ procedural SQL in DB engine |
| UPSERT | INSERT ... ON DUPLICATE KEY UPDATE |
| GROUP_CONCAT | Best/worst performer per sector in heatmap |
| information_schema | Live inventory of DB objects |
| Connection Pooling | mysql2 pool in config/db.js |
| Parameterised Queries | All queries use ? placeholders (SQL injection safe) |
Stock-Data-Warehouse/
โโโ backend/
โ โโโ server.js # Express entry point
โ โโโ schema.sql # Database DDL
โ โโโ .env # Secrets (not in git)
โ โโโ seed_nifty20.js # Seeds 20 companies
โ โโโ config/db.js # MySQL pool
โ โโโ middleware/errorHandler.js
โ โโโ controllers/
โ โ โโโ companyController.js # CRUD for companies table
โ โ โโโ stockController.js # Historical price queries
โ โ โโโ externalController.js # IndianAPI integration + caching
โ โ โโโ screenerController.js # Dynamic filter query builder
โ โ โโโ analyticsController.js # Window functions, heatmap, procedures
โ โโโ routes/ # URL โ controller mappings
โ โโโ migrations/
โ โโโ run_migration.js # Creates VIEW + PROCEDURE
โ โโโ check_sector.js # Backfills sector data from JSON
โโโ frontend/
โโโ src/
โโโ App.jsx # React Router routes
โโโ components/Layout.jsx # Navigation bar
โโโ services/api.js # Centralised API calls
โโโ pages/
โโโ Dashboard.jsx
โโโ CompanyDetail.jsx # Rich stock detail page
โโโ Screener.jsx # Multi-filter stock screener
โโโ Analytics.jsx # Advanced SQL showcase
โโโ Research.jsx
โโโ TradeData.jsx
โโโ AddCompany.jsx
| Metric | Value |
|---|---|
| Companies tracked | 22 |
| Distinct sectors | 13 |
| Screener filters | 15+ |
| Analytics SQL techniques | 5 |
| DB Tables | 7 |
| DB Views | 1 |
| Stored Procedures | 1 |
| API calls per page view (after seeding) | 0 |
This project is for educational/academic use โ DBMS coursework project.