# being-underscore-me-dot-rajat/stockinews architecture

> Architecture diagram of the GitHub repository being-underscore-me-dot-rajat/stockinews, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/being-underscore-me-dot-rajat/stockinews
- Repository: https://github.com/being-underscore-me-dot-rajat/stockinews

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“StockiNews”) combining a Vite+React SPA on the frontend with a Python Flask REST API on the backend.
- Purpose: empower Indian retail investors with portfolio management, live stock/market monitoring, sentiment analysis, and curated news within one unified dashboard.

##### File Structure
- Top-level:
- public/ (static assets served by Vite)
- src/ (all source code)
– App.jsx, routing, CSS
– Feature folders: Login, Portfolio, Sentiment, Stock, dashboard, home
– backend/ (Flask API, controllers: add.py, delete.py, get.py, auth.py, companies.py, portfolios.py, ticker_data.py; models and setupdb; stockinews.db; .env)
- Build/config files: package.json, vite.config.js, eslint.config.js, index.html.
- Tests: App.test.js, setupTests.js.

##### Extract Key Architectural Insights from the README
- Two-tier architecture: decoupled React frontend <→ Flask backend over REST.
- JWT authentication for protected routes.
- SQLite as the data store, with SQLAlchemy models.
- Chart.js on frontend for interactive charts, Bootstrap for UI.
- Potential external data sources: real-time stock price API, news API, sentiment-analysis engine.

##### Main Components & Their Relationships
- End User (Browser/Client)
- React/Vite Dev Server or Static Hosting
- Frontend Application
- Feature Modules:
– Authentication (Login.jsx)
– Dashboard (Portfolio, MarketWatch, Watchlist, News)
– Stock Detail Page (Chartgen.jsx, SentimentGauge.jsx, News Feed)
- UI libraries: Bootstrap, Chart.js
- HTTP Client layer (Axios or fetch) attaching JWT in headers
- Backend REST API (Flask)
- Routing/Controllers: auth.py, add.py, delete.py, get.py, companies.py, portfolios.py, ticker_data.py
- Business Logic: portfolio operations, P&L calculations, news aggregation, sentiment analysis
- JWT handling (PyJWT), CORS
- Data Layer
- SQLite database (stockinews.db) via SQLAlchemy models
- Initial data load from EQUITY_L.csv
- External Services (optional)
- Stock Price Feeds (WebSockets or REST)
- News API for headlines & sentiment analysis

##### Architectural Patterns & Design Principles
- Two-Tier / Client-Server: clear separation of concerns
- Feature-based modularity on frontend for maintainability
- RESTful resource-oriented API design on the backend
- Stateless JWT authentication
- MVC-style separation in Flask: controllers vs. models
- Single Page App (SPA) with client-side routing

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User((User Browser)):::user

    %% Frontend Layer
    subgraph "Frontend (React / Vite / Bootstrap / Chart.js)"
        style Frontend fill:#E0F2FE,stroke:#0284C7,stroke-width:2px
        FE_Entry["React SPA\n(main.jsx, App.jsx)"]:::frontend
        HTTPClient["HTTP Client Layer\n(Axios/Fetch with JWT)"]:::frontend
        Auth["Authentication Module\n(Login.jsx)"]:::frontend
        Dashboard["Dashboard Module\n(dashboard.jsx)"]:::frontend
        MarketWatch["MarketWatch Component\n(Marketwatch.jsx)"]:::frontend
        NewsComp["News Component\n(News.jsx)"]:::frontend
        PortfolioComp["Portfolio Component\n(Portfolio.jsx)"]:::frontend
        Watchlist["Watchlist Component\n(Watchlist.jsx)"]:::frontend
        HomeLayout["Home/Layout Components\n(Navbar, Footer, Dropdown)"]:::frontend
        PortFeature["Portfolio Feature\n(Portfoliopage.jsx, Chartgen.jsx)"]:::frontend
        StockDetail["Stock Detail Feature\n(stock.jsx, Banner.jsx)"]:::frontend
        Sentiment["Sentiment Gauge\n(SenitmentGauge.jsx)"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (Flask / SQLAlchemy / PyJWT / CORS / SQLite)"
        style Backend fill:#ECFDF5,stroke:#059669,stroke-width:2px
        API_Server["Flask API Server\n(app.py)"]:::backend
        AuthService["Auth Controller\n(auth.py)"]:::backend
        PortfolioService["Portfolio Controller\n(portfolios.py)"]:::backend
        CompaniesService["Companies Controller\n(companies.py)"]:::backend
        TickerService["Ticker Data Controller\n(ticker_data.py)"]:::backend
        CRUDService["General CRUD Controllers\n(add.py, get.py, delete.py)"]:::backend
        Models["Database Models\n(models.py)"]:::backend
        SetupDB["DB Setup Script\n(setupdb.py)"]:::backend
        EnvConfig["Environment Config\n(.env)"]:::backend
    end

    %% Database
    DB["SQLite Database\n(stockinews.db)"]:::db

    %% External Services
    subgraph "External Services"
        style External fill:#F3F4F6,stroke:#6B7280,stroke-width:2px
        StockAPI["Stock Price API"]:::external
        NewsAPI["News API"]:::external
    end

    %% Connections
    User -->|"HTTPS"| FE_Entry
    FE_Entry --> Auth
    FE_Entry --> Dashboard
    FE_Entry --> StockDetail
    FE_Entry --> PortFeature
    FE_Entry --> Sentiment
    FE_Entry --> HomeLayout

    Dashboard --> MarketWatch
    Dashboard --> NewsComp
    Dashboard --> PortfolioComp
    Dashboard --> Watchlist

    FE_Entry --> HTTPClient
    HTTPClient -->|"REST / JWT"| API_Server

    API_Server --> AuthService
    API_Server --> PortfolioService
    API_Server --> CompaniesService
    API_Server --> TickerService
    API_Server --> CRUDService
    API_Server --> Models
    API_Server --> SetupDB
    API_Server --> EnvConfig

    Models --> DB
    SetupDB --> DB

    API_Server -->|"REST"| StockAPI
    API_Server -->|"REST"| NewsAPI

    %% Click Events - Frontend
    click FE_Entry "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/main.jsx"
    click Auth "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/Login/Login.jsx"
    click Dashboard "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/dashboard/dashboard.jsx"
    click MarketWatch "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/dashboard/components/marketwatch/Marketwatch.jsx"
    click NewsComp "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/dashboard/components/news/News.jsx"
    click PortfolioComp "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/dashboard/components/portfolio/Portfolio.jsx"
    click Watchlist "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/dashboard/components/watchlist/Watchlist.jsx"
    click HomeLayout "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/home/navbar/Navbar.jsx"
    click PortFeature "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/Portfolio/Portfoliopage.jsx"
    click StockDetail "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/Stock/stock.jsx"
    click Sentiment "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/Sentiment/SenitmentGauge.jsx"
    click HTTPClient "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/App.jsx"

    %% Click Events - Backend
    click API_Server "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/backend/app.py"
    click AuthService "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/backend/auth.py"
    click PortfolioService "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/backend/portfolios.py"
    click CompaniesService "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/backend/companies.py"
    click TickerService "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/backend/ticker_data.py"
    click CRUDService "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/backend/add.py"
    click Models "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/backend/models/models.py"
    click SetupDB "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/backend/models/setupdb.py"

    %% Database click
    click DB "https://github.com/being-underscore-me-dot-rajat/stockinews/blob/master/src/backend/stockinews.db"

    %% External - no click

    %% Styles
    classDef frontend fill:#DBEAFE,stroke:#3B82F6,stroke-width:1px,font-weight:bold
    classDef backend fill:#D1FAE5,stroke:#10B981,stroke-width:1px,font-weight:bold
    classDef db fill:#FEF3C7,stroke:#F59E0B,stroke-width:1px,font-weight:bold
    classDef external fill:#F3F4F6,stroke:#6B7280,stroke-width:1px,font-style:italic
    classDef user fill:#FEE2E2,stroke:#EF4444,stroke-width:1px,font-weight:bold
```
