# aryan7691/stockerr-main architecture

> Architecture diagram of the GitHub repository aryan7691/stockerr-main, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aryan7691/stockerr-main
- Repository: https://github.com/aryan7691/stockerr-main

## Overview

##### Project type and purpose
- Stocker is a full-stack web application for simulated stock trading (ReactJS front end, Express/Node back end) plus a separate Discord bot for on-demand stock quotes and alerts.
- It provides real-time stock data, financial news, user authentication, virtual currency management, and chatbot commands driven by Alpha Vantage API.

##### File structure
- Top-level directories:
- client/ : React application (public, src, components, context)
- server/ : Express REST API (config, controllers, models, routes, server.js)
- bot/    : Standalone Node.js Discord bot (commands, alphaVantage.js, index.js)
- Shared config files: package.json for each module, .gitignore, static.json
- server/config/stocksData.js holds API keys or endpoints
- Routes/controllers/models follow MVC-style pattern in server/

##### README for additional insights
- Tech stack: React, Express, Node.js, Nodemon
- No explicit DB in README, but server/models indicate a database (likely MongoDB via Mongoose)
- Features: real-time data, virtual currency, charts, news integration

##### Main components and their interactions
a. Frontend (React):
- User Interface: Authentication pages, Dashboard, Search pages, Charts, Modals
- Communicates via REST (HTTPS) with the backend
b. Backend API (Express/Node):
- AuthController, UserController → handle signup/login, user virtual wallet
- StockController, DataController, NewsController → fetch data from Alpha Vantage & news APIs
- Models (User, Stock) → persist user data, trade history, portfolio in Database
c. Database:
- Stores user credentials, portfolio balances, transaction records
d. External Services:
- Alpha Vantage API (stock quotes, historical data)
- News API or RSS feed for financial news
e. Discord Bot:
- Listens on Discord, handles slash commands (quote, search, autosearch)
- Uses alphaVantage.js internally to fetch data directly from Alpha Vantage

##### Architectural patterns and design principles
- 3-tier architecture: Presentation (client), Application/API (server), Data (DB)
- MVC on the server: routes → controllers → models
- Modular separation: client, server, and bot are deployable services
- Single-page application in React with context for user state

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Users
    Browser((User Browser)):::user
    DiscordClient((Discord Client)):::user

    %% Client Layer
    subgraph "client/" 
        direction TB
        AppJS["App.js"]:::frontend
        Components["components/"]:::frontend
        UserContext["UserContext.js"]:::frontend
    end

    %% Bot Service
    subgraph "bot/"
        direction TB
        BotIndex["index.js"]:::bot
        AlphaHelper["alphaVantage.js"]:::bot
        subgraph "commands/"
            direction TB
            QuoteCmd["quote.js"]:::bot
            SearchCmd["search.js"]:::bot
            AutoSearchCmd["autosearch.js"]:::bot
        end
    end

    %% Backend API
    subgraph "server/"
        direction TB
        ServerEntry["server.js"]:::backend
        StocksConfig["stocksData.js"]:::backend

        subgraph "controllers/"
            direction TB
            AuthCtrl["authController.js"]:::backend
            AuthMW["authMiddleware.js"]:::backend
            UserCtrl["userController.js"]:::backend
            StockCtrl["stockController.js"]:::backend
            DataCtrl["dataController.js"]:::backend
            NewsCtrl["newsController.js"]:::backend
        end

        subgraph "routes/"
            direction TB
            AuthRoutes["authRoutes.js"]:::backend
            DataRoutes["dataRoutes.js"]:::backend
            StockRoutes["stockRoutes.js"]:::backend
            NewsRoutes["newsRoutes.js"]:::backend
        end

        subgraph "models/"
            direction TB
            UserModel["userModel.js"]:::backend
            StockModel["stockModel.js"]:::backend
        end
    end

    %% Data Stores & External
    Database[(MongoDB)]:::database
    AlphaVantage[(Alpha Vantage API)]:::external
    NewsAPI[(News API)]:::external

    %% Connections
    Browser --> AppJS
    AppJS -->|"HTTPS REST"| ServerEntry
    ServerEntry --> AuthRoutes
    ServerEntry --> DataRoutes
    ServerEntry --> StockRoutes
    ServerEntry --> NewsRoutes

    AuthRoutes --> AuthCtrl
    AuthRoutes --> AuthMW
    DataRoutes --> DataCtrl
    StockRoutes --> StockCtrl
    NewsRoutes --> NewsCtrl

    AuthCtrl --> UserModel
    StockCtrl --> StockModel
    DataCtrl --> StocksConfig
    NewsCtrl --> StocksConfig

    ServerEntry --> Database
    ServerEntry --> AlphaVantage
    ServerEntry --> NewsAPI

    DiscordClient --> BotIndex
    BotIndex --> QuoteCmd
    BotIndex --> SearchCmd
    BotIndex --> AutoSearchCmd
    BotIndex --> AlphaHelper
    AlphaHelper --> AlphaVantage

    BotIndex -->|"optional logs"| ServerEntry

    %% Click Events
    click AppJS "https://github.com/aryan7691/stockerr-main/blob/main/client/src/App.js"
    click Components "https://github.com/aryan7691/stockerr-main/tree/main/client/src/components/"
    click UserContext "https://github.com/aryan7691/stockerr-main/blob/main/client/src/context/UserContext.js"
    click ServerEntry "https://github.com/aryan7691/stockerr-main/blob/main/server/server.js"
    click StocksConfig "https://github.com/aryan7691/stockerr-main/blob/main/server/config/stocksData.js"
    click AuthCtrl "https://github.com/aryan7691/stockerr-main/blob/main/server/controllers/authController.js"
    click AuthMW "https://github.com/aryan7691/stockerr-main/blob/main/server/controllers/authMiddleware.js"
    click UserCtrl "https://github.com/aryan7691/stockerr-main/blob/main/server/controllers/userController.js"
    click StockCtrl "https://github.com/aryan7691/stockerr-main/blob/main/server/controllers/stockController.js"
    click DataCtrl "https://github.com/aryan7691/stockerr-main/blob/main/server/controllers/dataController.js"
    click NewsCtrl "https://github.com/aryan7691/stockerr-main/blob/main/server/controllers/newsController.js"
    click AuthRoutes "https://github.com/aryan7691/stockerr-main/blob/main/server/routes/authRoutes.js"
    click DataRoutes "https://github.com/aryan7691/stockerr-main/blob/main/server/routes/dataRoutes.js"
    click StockRoutes "https://github.com/aryan7691/stockerr-main/blob/main/server/routes/stockRoutes.js"
    click NewsRoutes "https://github.com/aryan7691/stockerr-main/blob/main/server/routes/newsRoutes.js"
    click UserModel "https://github.com/aryan7691/stockerr-main/blob/main/server/models/userModel.js"
    click StockModel "https://github.com/aryan7691/stockerr-main/blob/main/server/models/stockModel.js"
    click BotIndex "https://github.com/aryan7691/stockerr-main/blob/main/bot/index.js"
    click AlphaHelper "https://github.com/aryan7691/stockerr-main/blob/main/bot/alphaVantage.js"
    click QuoteCmd "https://github.com/aryan7691/stockerr-main/blob/main/bot/commands/quote.js"
    click SearchCmd "https://github.com/aryan7691/stockerr-main/blob/main/bot/commands/search.js"
    click AutoSearchCmd "https://github.com/aryan7691/stockerr-main/blob/main/bot/commands/autosearch.js"

    %% Styles
    classDef user fill:#f9f,stroke:#333,stroke-width:1px
    classDef frontend fill:#bbf,stroke:#333,stroke-width:1px
    classDef bot fill:#bfb,stroke:#333,stroke-width:1px
    classDef backend fill:#fbf,stroke:#333,stroke-width:1px
    classDef database fill:#ffb,stroke:#333,stroke-width:1px
    classDef external fill:#fea,stroke:#333,stroke-width:1px
```
