# log795-pfe020/stock-ai architecture

> Architecture diagram of the GitHub repository log795-pfe020/stock-ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/log795-pfe020/stock-ai
- Repository: https://github.com/log795-pfe020/stock-ai

## Overview

##### Main System Components
- Stock Prediction Service (located under stock-prediction): This segment includes subcomponents for model management (trained models in the "models" folder), data handling (data preprocessing and scripts under "data"), inference (API server and prediction service), and training (model training scripts).
- News Analyzer Service (located under news-analyzer): Contains API endpoints (routes), core configurations (logging, middleware [rate_limit]), sentiment models, and services for fetching/publishing news and handling sentiment analysis.
- Chatbot Interface (located under chatbot): Provides the chatbot functionality which uses a mock prediction and sentiment service, along with integration for OpenAI via environment variables.
- RabbitMQ Message Queue: Acts as the backbone for inter-service communication – used by at least the stock-prediction and news analyzer services (and possibly the chatbot) to enable distributed processing.
- Backend (Not fully contained in the file tree but referenced in the README): Mentioned as a C# service managing authentication and API coordination. Although its file structure is separate, include it as an external service that interfaces with RabbitMQ and other services.
- Docker & Deployment Components: Dockerfiles, docker-compose.yml, and network configurations indicate containerization as a primary deployment model. Represent these elements to show how services are isolated yet interconnected.

##### Relationships and Interactions
- If depicting the external C# backend, indicate its interaction with RabbitMQ and direct API calls (e.g., for authentication or additional business logic).

##### Architectural Patterns and Design Principles
- Extensibility: Show how models, data, and processing flows are modular (e.g., different folders for data processing, model training, etc.).

##### Relevant Technologies
- Optionally, add additional smaller components like logging, middleware (e.g., rate limiting), and API routing (e.g., Swagger UI endpoint for stock prediction) to underscore design details.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Stock Prediction Service Subgraph
    subgraph "Stock Prediction Service"
        direction TB
        PS1["Model Management"]:::service
        PS2["Data Handling"]:::service
        PS2a["Scripts"]:::service
        PS3["Inference (api_server.py, prediction_service.py, rabbitmq_publisher.py)"]:::service
        PS4["Training"]:::service
        PS2 --> PS2a
    end

    %% News Analyzer Service Subgraph
    subgraph "News Analyzer Service"
        direction TB
        NA1["API Endpoints"]:::service
        NA2["Core Configurations"]:::service
        NA3["Middleware"]:::service
        NA4["Sentiment Models"]:::service
        NA5["News & Messaging Services"]:::service
    end

    %% Chatbot Interface Subgraph
    subgraph "Chatbot Interface"
        direction TB
        CB1["Chatbot Functionality"]:::service
        CB2["Mock Prediction Service"]:::service
        CB3["Mock Sentiment Service"]:::service
    end

    %% Infrastructure Components
    RMQ["RabbitMQ Message Queue"]:::infrastructure
    BE["External Backend (C# Service)"]:::infrastructure

    %% Deployment & Containerization Subgraph
    subgraph "Deployment & Containerization"
        direction TB
        D1["Dockerfile (root)"]:::deployment
        D2["news-analyzer/Dockerfile"]:::deployment
        D3["docker-compose.yml"]:::deployment
        D4[".dockerignore"]:::deployment
    end

    %% Inter-Service Interactions
    CB1 -->|"APICall"| PS3
    CB1 -->|"APICall"| NA4
    PS3 -->|"publish"| RMQ
    NA5 -->|"publish"| RMQ
    BE -->|"calls"| PS3
    BE -->|"calls"| NA1
    BE -->|"integrates"| RMQ

    %% Deployment Connections (dashed lines)
    PS3 -.-> D3
    NA5 -.-> D3
    CB1 -.-> D3

    %% Click Events for Stock Prediction Service
    click PS1 "https://github.com/log795-pfe020/stock-ai/tree/main/stock-prediction/models/"
    click PS2 "https://github.com/log795-pfe020/stock-ai/tree/main/stock-prediction/data/"
    click PS2a "https://github.com/log795-pfe020/stock-ai/tree/main/stock-prediction/data/script/"
    click PS3 "https://github.com/log795-pfe020/stock-ai/tree/main/stock-prediction/inference/"
    click PS4 "https://github.com/log795-pfe020/stock-ai/blob/main/stock-prediction/training/trainer.py"

    %% Click Events for News Analyzer Service
    click NA1 "https://github.com/log795-pfe020/stock-ai/blob/main/news-analyzer/src/api/routes.py"
    click NA2 "https://github.com/log795-pfe020/stock-ai/tree/main/news-analyzer/src/core/"
    click NA3 "https://github.com/log795-pfe020/stock-ai/blob/main/news-analyzer/src/middleware/rate_limit.py"
    click NA4 "https://github.com/log795-pfe020/stock-ai/blob/main/news-analyzer/src/models/sentiment_model.py"
    click NA5 "https://github.com/log795-pfe020/stock-ai/tree/main/news-analyzer/src/services/"

    %% Click Events for Chatbot Interface
    click CB1 "https://github.com/log795-pfe020/stock-ai/blob/main/chatbot/chatbot.py"
    click CB2 "https://github.com/log795-pfe020/stock-ai/blob/main/chatbot/mock_prediction_service.py"
    click CB3 "https://github.com/log795-pfe020/stock-ai/blob/main/chatbot/mock_sentiment_service.py"

    %% Click Event for RabbitMQ (representative)
    click RMQ "https://github.com/log795-pfe020/stock-ai/blob/main/stock-prediction/inference/rabbitmq_publisher.py"

    %% Click Events for Deployment & Containerization
    click D1 "https://github.com/log795-pfe020/stock-ai/tree/main/Dockerfile"
    click D2 "https://github.com/log795-pfe020/stock-ai/tree/main/news-analyzer/Dockerfile"
    click D3 "https://github.com/log795-pfe020/stock-ai/blob/main/docker-compose.yml"
    click D4 "https://github.com/log795-pfe020/stock-ai/blob/main/.dockerignore"

    %% Style Classes
    classDef service fill:#AED6F1,stroke:#2874A6,stroke-width:2px,color:#000;
    classDef infrastructure fill:#F9E79F,stroke:#B7950B,stroke-width:2px,color:#000;
    classDef deployment fill:#D5F5E3,stroke:#27AE60,stroke-width:2px,color:#000;
```
