Skip to content

devcode8/stock-home-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

170 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

StockX – Decentralized AI-Powered Stock Exchange

License TypeScript Solidity React

StockX is a decentralized, AI-powered stock exchange platform designed to enable secure, transparent, and near-real-time trading of tokenized equities. By combining blockchain-based settlement, smart contract automation, decentralized identity, and AI-driven market intelligence, StockX removes traditional intermediaries while preserving regulatory compliance and institutional-grade reliability.

🎯 Key Features

  • πŸͺ™ Tokenized Equities: ERC-20/ERC-1400 security tokens representing real-world equities with fractional ownership
  • ⚑ High-Performance Matching: Off-chain matching engine for fast order processing and low-latency trades
  • πŸ€– AI-Powered Insights: Market intelligence, sentiment analysis, and personalized trading recommendations
  • πŸ” Compliance & Security: On-chain KYC/AML enforcement with decentralized identity (DID)
  • πŸ›οΈ DAO Governance: Token-holder voting on protocol upgrades, fee structures, and market parameters
  • βš–οΈ Transparent Settlement: Atomic trade settlement with delivery-versus-payment (DvP) logic

πŸ“‹ Table of Contents

πŸ—οΈ Architecture

StockX follows a hybrid on-chain / off-chain architecture:

Users & Institutions
        ↓
Frontend (Web / Mobile)
        ↓
Backend APIs & Relayers
        ↓
Off-chain Matching Engine + AI Services
        ↓
Smart Contracts (EVM)
        ↓
Blockchain Ledger & DAO Governance

Architecture Layers

  1. On-Chain Layer: Trust, ownership, settlement, and governance
  2. Off-Chain Layer: Performance-critical logic, AI computation, and user experience
  3. Integration Layer: External data providers, compliance services, and custodial systems

πŸ› οΈ Tech Stack

Blockchain & Smart Contracts

  • EVM-compatible chain (Ethereum L2 / Besu-based permissioned network)
  • Solidity with OpenZeppelin libraries
  • Hardhat for development and testing

Backend

  • Node.js + Express (JavaScript)
  • Event-driven architecture
  • WebSocket for real-time updates
  • Redis for caching
  • PostgreSQL for data persistence

Frontend

  • React + TypeScript
  • Tailwind CSS for styling
  • Framer Motion for animations
  • Recharts for data visualization
  • Wallet integration (Web3)

AI & Data Services

  • Python + FastAPI
  • NLP & ML models for sentiment analysis
  • Streaming data pipelines
  • Portfolio optimization algorithms

Infrastructure

  • Docker & Docker Compose for containerization
  • Kubernetes for orchestration
  • Terraform for infrastructure as code
  • Prometheus for monitoring
  • GitHub Actions for CI/CD

πŸš€ Getting Started

Prerequisites

  • Node.js >= 18.0.0
  • Python >= 3.9
  • Docker & Docker Compose (optional)
  • Git

Installation

  1. Clone the repository

    git clone https://github.com/your-org/stockx.git
    cd stockx
  2. Install dependencies

    Root dependencies:

    npm install

    Frontend:

    cd frontend
    npm install
    cd ..

    Backend:

    cd backend
    npm install
    cd ..

    Smart Contracts:

    cd smart-contracts
    npm install
    cd ..
  3. Install Python dependencies

    cd ai-services
    pip install -r requirements.txt
    cd ..
  4. Set up environment variables

    Copy .env.example files in respective directories and configure:

    • frontend/.env
    • backend/.env
    • smart-contracts/.env
    • ai-services/.env

Running Locally

  1. Start the backend

    cd backend
    npm run dev
  2. Start the frontend

    cd frontend
    npm run dev
  3. Start AI services (optional)

    cd ai-services
    python -m uvicorn src.api.main:app --reload
  4. Run smart contracts locally

    cd smart-contracts
    npx hardhat node

Take-Home Update: Market Summary Endpoint

This submission adds a read-only backend endpoint:

GET /api/market/summary

The endpoint returns exactly these top-level JSON fields:

{
  "tokensListed": 247,
  "totalTrades": 5432,
  "totalVolume": "12400000",
  "generatedAt": "2026-04-28T15:17:12.209Z"
}

Implementation files:

  • backend/src/controllers/market.controller.js
  • backend/src/routes/market.routes.js

To test locally:

cd backend
npm run dev

Then call the endpoint from another terminal:

curl -s http://localhost:3001/api/market/summary

Run the curl command twice to confirm generatedAt changes between requests.

πŸ“ Project Structure

stocks/
β”œβ”€β”€ frontend/              # React frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”‚   β”œβ”€β”€ contexts/      # React contexts
β”‚   β”‚   β”œβ”€β”€ services/      # API services
β”‚   β”‚   └── utils/         # Utility functions
β”‚   └── package.json
β”‚
β”œβ”€β”€ backend/               # Node.js backend API
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/   # Request handlers
β”‚   β”‚   β”œβ”€β”€ services/      # Business logic
β”‚   β”‚   β”œβ”€β”€ middleware/    # Express middleware
β”‚   β”‚   β”œβ”€β”€ models/        # Data models
β”‚   β”‚   └── routes/        # API routes
β”‚   └── package.json
β”‚
β”œβ”€β”€ smart-contracts/       # Solidity smart contracts
β”‚   β”œβ”€β”€ contracts/
β”‚   β”‚   β”œβ”€β”€ core/          # Core contracts (TokenizedStock, OrderBook)
β”‚   β”‚   β”œβ”€β”€ compliance/    # Compliance contracts
β”‚   β”‚   β”œβ”€β”€ governance/    # DAO governance
β”‚   β”‚   └── oracles/       # Price oracles
β”‚   β”œβ”€β”€ test/              # Contract tests
β”‚   └── scripts/           # Deployment scripts
β”‚
β”œβ”€β”€ ai-services/           # Python AI services
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ analytics/     # Market analysis
β”‚   β”‚   β”œβ”€β”€ sentiment/     # Sentiment analysis
β”‚   β”‚   β”œβ”€β”€ models/        # ML models
β”‚   β”‚   └── api/           # FastAPI endpoints
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ infrastructure/        # DevOps configuration
β”‚   β”œβ”€β”€ docker/            # Dockerfiles
β”‚   β”œβ”€β”€ kubernetes/        # K8s manifests
β”‚   β”œβ”€β”€ terraform/         # Infrastructure as code
β”‚   └── ci-cd/             # CI/CD pipelines
β”‚
β”œβ”€β”€ docs/                  # Documentation
β”‚   β”œβ”€β”€ api/               # API documentation
β”‚   β”œβ”€β”€ architecture/      # Architecture docs
β”‚   β”œβ”€β”€ deployment/        # Deployment guides
β”‚   └── user-guide/        # User guides
β”‚
β”œβ”€β”€ scripts/               # Utility scripts
β”œβ”€β”€ shared/                # Shared types and utilities
└── README.md

πŸ’» Development

Running Tests

Backend tests:

cd backend
npm test

Smart contract tests:

cd smart-contracts
npx hardhat test

AI services tests:

cd ai-services
pytest tests/

Code Style

  • JavaScript: ESLint
  • TypeScript: ESLint + TypeScript compiler
  • Solidity: Solhint
  • Python: Black + Flake8

Building for Production

Frontend:

cd frontend
npm run build

Backend:

cd backend
npm run build

Smart Contracts:

cd smart-contracts
npx hardhat compile

πŸ” Smart Contracts

The platform uses several core smart contracts:

  • TokenizedStock: ERC-20 security tokens with compliance checks
  • OrderBook: Trade settlement and order matching coordination
  • ComplianceRegistry: KYC/AML status management
  • CustodyVault: Multi-signature custody for assets
  • DAO: Governance and voting system
  • PriceOracle: External price feed integration

See smart-contracts/README.md for detailed documentation.

πŸ€– AI Services

The AI layer provides:

  • Sentiment Analysis: News, social media, and earnings report analysis
  • Signal Generation: Bullish/bearish indicators and trading signals
  • Price Prediction: ML-based price forecasting
  • Portfolio Optimization: Risk-adjusted portfolio recommendations

See ai-services/README.md for more details.

πŸ“š Documentation

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘₯ Team

Developed by the StockX team at LynqEx Labs:

  • Alex Chen - AI/ML Engineer
  • Sarah Martinez - Full Stack Developer
  • David Kim - DevOps/Infrastructure
  • Emma Wilson - Technical Writer
  • Michael Brown - Smart Contract Developer

πŸ“ž Contact

For questions and support:

πŸ™ Acknowledgments

  • OpenZeppelin for security-tested smart contract libraries
  • Chainlink for oracle solutions
  • The Ethereum community for inspiration and tools

Note: This is a Proof of Concept (PoC) implementation. Production deployment requires additional security audits, compliance reviews, and infrastructure hardening.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors