# danielthatu47/major-project architecture

> Architecture diagram of the GitHub repository danielthatu47/major-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/danielthatu47/major-project
- Repository: https://github.com/danielthatu47/major-project

## Overview

##### High-Level Components

a. Frontend Service (StockMarketPrediction)
- Use a blue container
- Sub-components:
- UI Components Layer (shadcn-ui)
- State Management (AuthContext)
- API Services Layer
- Pages/Routes

b. Backend Service (Backend)
- Use a green container
- Sub-components:
- API Routes Layer
- Controllers Layer
- Authentication Middleware
- Models Layer (MongoDB Schemas)

c. ML Service (Model_Backend)
- Use a purple container
- Include:
- Prediction Model
- Flask API Endpoints

##### Database and External Services
- MongoDB Database (connected to Backend)
- External APIs:
- Twelve Data API
- News API
- Alpha Vantage API

##### Connection Flows
- Frontend → Backend: REST API calls
- Frontend → ML Service: Prediction requests
- Backend → MongoDB: Data persistence
- Backend → External APIs: Market data fetching
- Authentication flow paths

##### Detailed Component Breakdown

Frontend Components:
- Frontend
- Authentication (Login/Signup/Reset)
- Stock Analysis
- Charts (TradingView)
- Predictions
- Search
- User Features
- Dashboard
- Portfolio
- Watchlist
- Shared Components

Backend Components:
- Backend
- Auth Routes
- Stock Routes
- Watchlist Routes
- Prediction Routes
- Search Routes

##### Additional Elements
- Security layer (JWT authentication)
- Data flow directions
- API endpoints grouping
- Caching mechanisms (if any)
- Error handling paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend["Frontend Service (Vite + React)"]
        UI["UI Components Layer"]:::frontend
        State["State Management"]:::frontend
        APIServices["API Services Layer"]:::frontend
        Pages["Pages/Routes"]:::frontend
        Auth["Authentication Components"]:::frontend
        StockAnalysis["Stock Analysis"]:::frontend
        UserFeatures["User Features"]:::frontend
        
        StockAnalysis --> |Contains| Charts["Charts (TradingView)"]
        StockAnalysis --> |Contains| PredictionView["Predictions View"]
        StockAnalysis --> |Contains| Search["Search"]
        
        UserFeatures --> |Contains| Dashboard["Dashboard"]
        UserFeatures --> |Contains| Portfolio["Portfolio"]
        UserFeatures --> |Contains| Profile["Profile"]
    end

    subgraph Backend["Backend Service (Node.js + Express)"]
        APIRoutes["API Routes Layer"]:::backend
        Controllers["Controllers Layer"]:::backend
        AuthMiddleware["Authentication Middleware"]:::backend
        Models["Models Layer"]:::backend
        
        APIRoutes --> |Uses| Controllers
        Controllers --> |Uses| Models
        APIRoutes --> |Protected by| AuthMiddleware
    end

    subgraph MLService["ML Service (Flask)"]
        FlaskAPI["Flask API"]:::ml
        PredModel["Prediction Model"]:::ml
        
        FlaskAPI --> PredModel
    end

    subgraph External["External Services"]
        TwelveData["Twelve Data API"]:::external
        NewsAPI["News API"]:::external
        AlphaVantage["Alpha Vantage API"]:::external
    end

    Database[(MongoDB)]:::database

    Frontend --> |REST API Calls| Backend
    Frontend --> |Prediction Requests| MLService
    Backend --> |Data Persistence| Database
    Backend --> |Market Data| TwelveData
    Backend --> |News Data| NewsAPI
    Backend --> |Financial Data| AlphaVantage

    %% Click Events
    click UI "https://github.com/DanielThatu47/major-project/tree/main/StockMarketPrediction/src/components/ui"
    click State "https://github.com/DanielThatu47/major-project/blob/main/StockMarketPrediction/src/contexts/AuthContext.jsx"
    click Pages "https://github.com/DanielThatu47/major-project/tree/main/StockMarketPrediction/src/pages"
    click APIServices "https://github.com/DanielThatu47/major-project/blob/main/StockMarketPrediction/src/services/stockApi.js"
    click Auth "https://github.com/DanielThatu47/major-project/blob/main/StockMarketPrediction/src/components/ForgotPassword.jsx"
    click APIRoutes "https://github.com/DanielThatu47/major-project/tree/main/Backend/routes"
    click Controllers "https://github.com/DanielThatu47/major-project/tree/main/Backend/controllers"
    click AuthMiddleware "https://github.com/DanielThatu47/major-project/blob/main/Backend/middleware/auth.js"
    click Models "https://github.com/DanielThatu47/major-project/tree/main/Backend/models"
    click FlaskAPI "https://github.com/DanielThatu47/major-project/blob/main/Model_Backend/app.py"
    click PredModel "https://github.com/DanielThatu47/major-project/blob/main/Model_Backend/model.py"
    click Charts "https://github.com/DanielThatu47/major-project/blob/main/StockMarketPrediction/src/components/TradingViewWidget.jsx"
    click PredictionView "https://github.com/DanielThatu47/major-project/blob/main/StockMarketPrediction/src/pages/StockPrediction.jsx"
    click Dashboard "https://github.com/DanielThatu47/major-project/blob/main/StockMarketPrediction/src/pages/Dashboard.jsx"
    click Portfolio "https://github.com/DanielThatu47/major-project/blob/main/StockMarketPrediction/src/pages/Portfolio.jsx"
    click Profile "https://github.com/DanielThatu47/major-project/blob/main/StockMarketPrediction/src/pages/UserProfile.jsx"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef ml fill:#9b59b6,stroke:#8e44ad,color:white
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:white

    %% Legend
    subgraph Legend
        Frontend_L[Frontend Components]:::frontend
        Backend_L[Backend Components]:::backend
        ML_L[ML Components]:::ml
        External_L[External Services]:::external
        DB_L[(Database)]:::database
    end
```
