# StockDocs Project Overview This document provides a comprehensive overview of the StockDocs financial news analysis platform, including detailed information about each project component, file structures, and how to begin working with the system. ## Project Architecture StockDocs is a sophisticated system designed to collect, process, and analyze financial news from multiple sources. The platform consists of several interconnected components that work together to transform raw news content into valuable market intelligence. ``` +--------------+ +--------------+ +-------------------+ | Scraper | | Article | | AI | | (RSS Feeds) |--> | Server |--> | Processor | | | | | | | +--------------+ +--------------+ +-------------------+ | | v v +--------------+ +-------------------+ | Embedding | | MCPServer | | Service | | (Financial Data) | | | | | +--------------+ +-------------------+ ``` ## Project Components ### 1. Scraper **Location:** `scraper/` The Scraper component is responsible for collecting financial news and articles from multiple sources including major news outlets, financial publications, and market analysis services. It uses RSS feeds to gather content and stores the articles in a structured directory hierarchy for easy access by other components of the system. #### Key Features: - RSS Feed Integration: Supports multiple financial news sources through RSS feeds - Automated Scraping: Regularly fetches and processes new articles from configured feeds - Structured Storage: Organizes articles in a directory structure by news outlet - Duplicate Detection: Prevents re-processing of already collected articles - Caching Mechanism: Maintains a cache of processed articles to optimize performance #### File Structure: ``` scraper/ ├── rss_feeds.json # Configuration file with RSS feed URLs ├── scraper.py # Main scraping logic ├── requirements.txt # Python dependencies ├── dockerfile # Docker configuration ├── dockerfile-selenium # Dockerfile for selenium-based scraping ├── articles/ # Directory where scraped articles are stored │ ├── Reuters – Business News/ │ │ ├── article1.txt │ │ └── ... │ ├── Associated Press – Business/ │ │ ├── article1.txt │ │ └── ... │ └── ... ├── processed_articles_cache.json # Cache of already processed articles └── pyvenv.cfg # Python virtual environment configuration ``` #### Key Files: - `scraper.py`: Main scraping logic with parallel processing capabilities - `rss_feeds.json`: Configuration file with RSS feed URLs for 60+ news outlets - `articles/`: Directory structure for storing scraped articles organized by news source ### 2. Article Server **Location:** `articleServer/` A Flask-based HTTP server that provides access to news articles stored in a directory structure, with time-based filtering and outlet-specific querying capabilities. #### Key Features: - Time-based filtering: Query articles by hour, day, week, or month - Outlet-specific querying: Filter articles by news source - Content retrieval: Get full article content by file path - RESTful API: Clean interfaces for integration with external systems #### File Structure: ``` articleServer/ ├── app.py # Main Flask application ├── requirements.txt # Python dependencies ├── Dockerfile # Docker configuration ├── run_server.py # Server startup script ├── pyvenv.cfg # Python virtual environment configuration └── README.md # Documentation ``` #### API Endpoints: - `GET /articles` - Get articles within time range - `GET /article/content` - Get full article content by path - `GET /outlets` - List all available news outlets - `GET /health` - Health check endpoint ### 3. AI Processor **Location:** `ai_processor/` An AI-powered analytics engine designed to process financial news articles and extract meaningful insights, sentiment analysis, and market indicators from collected content. #### Key Features: - Sentiment Analysis: Determine positive, negative, or neutral sentiment of news articles - Topic Classification: Categorize articles by financial topics - Entity Extraction: Identify key entities mentioned in articles (stocks, companies, people, organizations) - Market Indicator Detection: Extract quantitative indicators that may affect stock prices - Insight Generation: Automated generation of actionable intelligence from news content - Batch Processing: Process large volumes of articles efficiently #### File Structure: ``` ai_processor/ ├── ai_processor.py # Main AI processing application ├── requirements.txt # Python dependencies ├── Dockerfile # Docker configuration ├── README.md # Documentation ├── models/ # Machine learning models and NLP components │ ├── sentiment_analyzer.py # Sentiment analysis module │ ├── topic_classifier.py # News categorization module │ └── entity_extractor.py # Named entity recognition ├── processors/ # Article processing pipelines │ ├── text_processor.py # Text cleaning and preprocessing │ └── analysis_pipeline.py # Full analysis pipeline └── output/ # Processed data storage ├── insights/ └── reports/ ``` #### API Endpoints: - `POST /api/analyze/article` - Analyze a single article for insights - `POST /api/analyze/batch` - Process multiple articles in batch mode - `GET /api/insights/latest` - Get latest analysis insights - `GET /api/models` - List available AI models ### 4. Embedding Service **Location:** `embedding/` An embedding service that converts text content into numerical vectors for machine learning and data analysis purposes. This component transforms financial news articles into vector representations that can be used for similarity comparisons, clustering, and other AI tasks. #### Key Features: - Multiple Model Support: Integrates with various embedding models including BERT, Sentence-BERT, and other transformer-based models - Batch Processing: Efficient processing of large volumes of articles - Caching Mechanism: Caches generated embeddings to avoid reprocessing - Real-time Generation: Generates embeddings on-demand for new content - Vector Similarity: Computes similarity between different pieces of content - Storage Management: Organizes and stores embeddings efficiently #### File Structure: ``` embedding/ ├── embedder.py # Main embedding application ├── requirements.txt # Python dependencies ├── Dockerfile # Docker configuration ├── README.md # Documentation ├── models/ # Pre-trained embedding models │ ├── sentence_transformer.py # Sentence transformer implementation │ └── model_loader.py # Model loading utilities ├── processors/ # Text processing pipeline │ ├── text_cleaner.py # Text cleaning and preprocessing │ └── embedding_generator.py # Embedding generation └── data/ # Processed embeddings storage ├── cache/ └── outputs/ ``` #### API Endpoints: - `POST /api/embeddings/generate` - Generate embeddings for text content - `POST /api/embeddings/batch` - Generate embeddings for multiple texts in batch - `GET /api/embeddings/similarity` - Calculate similarity between two pieces of text/content ### 5. MCPServer **Location:** `MCPServer/` A Flask-based server that provides an API for accessing and analyzing financial data, with integration for stock analysis and news processing. Serves as the backend service for processing financial information and making it available through HTTP endpoints. #### Key Features: - Stock Analysis: Financial metrics calculation and market data processing - News Integration: APIs for retrieving and processing financial news - Data Aggregation: Consolidation of multiple data sources into unified responses - RESTful API: Clean HTTP interface for external services to consume data #### File Structure: ``` MCPServer/ ├── server.py # Main Flask application ├── requirements.txt # Python dependencies ├── Dockerfile # Docker configuration ├── openapi.json # API specification ├── README.md # Documentation └── api/ # API endpoints and handlers ├── stock_analysis.py # Stock analysis functions └── news_processing.py # News processing functions ``` #### API Endpoints: - `POST /query` - Query the vector database with a question - `GET /health` - Server health check - `GET /info` - Returns model and service metadata - `GET /tools` - List available endpoints and their descriptions ## Setup and Installation ### Prerequisites - Python 3.6+ - Docker (for containerized deployment) - Internet connection for RSS feed access ### Installation Steps 1. **Clone the repository:** ```bash git clone cd StockDocs ``` 2. **Set up each component:** ```bash # For each component, follow specific installation instructions cd scraper && pip install -r requirements.txt cd articleServer && pip install -r requirements.txt cd ai_processor && pip install -r requirements.txt cd embedding && pip install -r requirements.txt cd MCPServer && pip install -r requirements.txt ``` 3. **Configure environment variables as needed for each component** 4. **Run individual services:** ```bash python scraper/scraper.py # Start scraping python articleServer/run_server.py # Start article server python ai_processor/app.py # Start AI processor python embedding/app.py # Start embedding service python MCPServer/app.py # Start MCP server ``` ## Deployment Each component can be run independently or containerized using the provided Dockerfiles: ```bash # Build and run each component in Docker docker build -t stockdocs-scraper ./scraper docker run -p 5000:5000 stockdocs-scraper docker build -t stockdocs-article-server ./articleServer docker run -p 5008:5008 stockdocs-article-server # Continue for other components... ``` ## Key Technical Details ### Data Flow 1. **Scraper** collects articles from RSS feeds and stores them in `scraper/articles/` 2. **Article Server** provides API access to these articles 3. **AI Processor** analyzes articles and generates insights in `ai_processor/output/` 4. **Embedding Service** converts article content into vector representations and stores in ChromaDB 5. **MCPServer** provides API access to the vector database for querying ### Environment Variables Each component may require specific environment variables: - `ARTICLE_DIR`: Path to article directory - `AI_SERVICE_URL`: URL for local AI service - `CHROMADB_HOST` and `CHROMADB_PORT`: ChromaDB connection settings - `FEED_FILE`: Path to RSS feed configuration file ### Directory Structure - `scraper/articles/`: Stores raw scraped articles organized by news source - `ai_processor/output/`: Stores processed AI analysis results - `embedding/data/cache/`: Stores cached embeddings - `MCPServer/`: Contains server configuration and API endpoints ## Getting Started Guide To begin working with the StockDocs platform: 1. **Start the Scraper** to collect news articles 2. **Run the Article Server** to make articles accessible via API 3. **Launch the AI Processor** to analyze articles and generate insights 4. **Initialize the Embedding Service** to create vector representations 5. **Start MCPServer** to query the vector database for insights Each component can be run independently or as part of a complete pipeline for comprehensive financial news analysis.