# amaymani/strocker architecture

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

- Interactive diagram: https://gitdiagram.com/amaymani/strocker
- Repository: https://github.com/amaymani/strocker

## Overview

##### Main Components

Frontend Layer:
- Client-Side Pages (src/pages/)
- Home (index.js)
- Authentication pages (login.js, register.js)
- Trading interface (buy-sell.js)
- Portfolio view (portfolio.js)
- Stock details ([stockName].js)
- Top stocks listing (top-stocks.js)

- UI Components (src/components/)
- Trading modals (BuyModal, SellModal)
- Stock visualization (StockModel)
- Theme management
- UI utilities (3D cards, animations, etc.)

Backend Layer:
- API Routes (src/pages/api/)
- Authentication endpoints (/auth/[...nextauth].js)
- Trading operations (buy-stock.js, sell-stock.js)
- Stock data fetching (fetch-stockData.js)
- Portfolio management (get-portfolio-data.js)
- User management (login.js, register.js)

Data Layer:
- Database Models (src/utils/models/)
- User model
- Stock model
- Database connection (src/utils/db.js)

**[Client Layer]**
- ↕
**[API Layer]**
- ↕
**[Data Layer]**

##### Specific Elements

Frontend Section:
**[Pages] → [Components] → [UI Elements]**
- ↓
**[API Calls]**

API Layer:
**[Next.js API Routes]**
- ↙         ↘
**[Auth Service]  [Stock Operations]**

Data Layer:
**[Database Models] ← [Database Connection]**

##### Implementation Details

Top Section:
- Client-side components
- Page routing
- UI components

Middle Section:
- API routes
- Authentication middleware
- Business logic

Bottom Section:
- Database models
- Data persistence
- External services

##### Notes

- Keep the main flow clear and centered
- Related components together
- Clear separation between client and server components
- Security boundaries
- Public vs. protected routes

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Pages["Client Pages"]
        Pages --> |routes to| HomePage["Home Page"]:::page
        Pages --> |routes to| TradingPage["Trading Interface"]:::page
        Pages --> |routes to| PortfolioPage["Portfolio View"]:::page
        Pages --> |routes to| StockDetailsPage["Stock Details"]:::page
        Pages --> |routes to| TopStocksPage["Top Stocks"]:::page

        subgraph UIComponents["UI Components"]
            direction TB
            ThemeChanger["Theme Management"]:::ui
            Card3D["3D Card"]:::ui
            BGEffects["Background Effects"]:::ui
            CanvasEffects["Canvas Effects"]:::ui
        end

        subgraph TradingComponents["Trading Components"]
            direction TB
            BuyModal["Buy Modal"]:::component
            SellModal["Sell Modal"]:::component
            StockModel["Stock Model"]:::component
        end
    end

    subgraph APILayer["API Layer"]
        direction TB
        subgraph AuthAPI["Authentication API"]
            NextAuth["NextAuth"]:::api
            LoginAPI["Login API"]:::api
            RegisterAPI["Register API"]:::api
        end

        subgraph TradingAPI["Trading Operations"]
            BuyStockAPI["Buy Stock API"]:::api
            SellStockAPI["Sell Stock API"]:::api
            StockDataAPI["Stock Data API"]:::api
            PortfolioAPI["Portfolio Data API"]:::api
        end
    end

    subgraph DataLayer["Data Layer"]
        direction TB
        DBConnection["Database Connection"]:::db
        UserModel["User Model"]:::model
        StockModel2["Stock Model"]:::model
        Utils["Utilities"]:::util
    end

    %% Connections
    Pages --> UIComponents
    Pages --> TradingComponents
    TradingComponents --> TradingAPI
    Pages --> AuthAPI
    AuthAPI --> DBConnection
    TradingAPI --> DBConnection
    DBConnection --> UserModel
    DBConnection --> StockModel2
    Utils --> Pages

    %% Click Events
    click HomePage "https://github.com/Amaymani/strocker/blob/main/src/pages/index.js"
    click TradingPage "https://github.com/Amaymani/strocker/blob/main/src/pages/buy-sell.js"
    click PortfolioPage "https://github.com/Amaymani/strocker/blob/main/src/pages/portfolio.js"
    click StockDetailsPage "https://github.com/Amaymani/strocker/blob/main/src/pages/stock/[stockName].js"
    click TopStocksPage "https://github.com/Amaymani/strocker/blob/main/src/pages/top-stocks.js"
    click BuyModal "https://github.com/Amaymani/strocker/blob/main/src/components/BuyModal.jsx"
    click SellModal "https://github.com/Amaymani/strocker/blob/main/src/components/SellModal.jsx"
    click StockModel "https://github.com/Amaymani/strocker/blob/main/src/components/StockModel.jsx"
    click Card3D "https://github.com/Amaymani/strocker/blob/main/src/components/ui/3d-card.jsx"
    click BGEffects "https://github.com/Amaymani/strocker/blob/main/src/components/ui/background-beams.jsx"
    click CanvasEffects "https://github.com/Amaymani/strocker/blob/main/src/components/ui/canvas-reveal-effect.jsx"
    click ThemeChanger "https://github.com/Amaymani/strocker/blob/main/src/components/theme-changer.jsx"
    click NextAuth "https://github.com/Amaymani/strocker/blob/main/src/pages/api/auth/[...nextauth].js"
    click LoginAPI "https://github.com/Amaymani/strocker/blob/main/src/pages/api/login.js"
    click RegisterAPI "https://github.com/Amaymani/strocker/blob/main/src/pages/api/register.js"
    click BuyStockAPI "https://github.com/Amaymani/strocker/blob/main/src/pages/api/buy-stock.js"
    click SellStockAPI "https://github.com/Amaymani/strocker/blob/main/src/pages/api/sell-stock.js"
    click StockDataAPI "https://github.com/Amaymani/strocker/blob/main/src/pages/api/fetch-stockData.js"
    click PortfolioAPI "https://github.com/Amaymani/strocker/blob/main/src/pages/api/get-portfolio-data.js"
    click DBConnection "https://github.com/Amaymani/strocker/blob/main/src/utils/db.js"
    click UserModel "https://github.com/Amaymani/strocker/blob/main/src/utils/models/user.js"
    click StockModel2 "https://github.com/Amaymani/strocker/blob/main/src/utils/models/stock.js"
    click Utils "https://github.com/Amaymani/strocker/blob/main/src/lib/utils.js"

    %% Styling
    classDef page fill:#2563eb,color:white
    classDef component fill:#4ade80,color:black
    classDef ui fill:#a855f7,color:white
    classDef api fill:#eab308,color:black
    classDef db fill:#ef4444,color:white
    classDef model fill:#f97316,color:white
    classDef util fill:#64748b,color:white

    %% Legend
    subgraph Legend
        L1["Page"]:::page
        L2["Component"]:::component
        L3["UI Element"]:::ui
        L4["API"]:::api
        L5["Database"]:::db
        L6["Model"]:::model
        L7["Utility"]:::util
    end
```
