# gatiskevans/stock-trader architecture

> Architecture diagram of the GitHub repository gatiskevans/stock-trader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/gatiskevans/stock-trader
- Repository: https://github.com/gatiskevans/stock-trader

## Overview

Stock Trader is a Laravel application for browsing company market data and buying or selling stocks. The main workflow is a user request handled by stock controllers, which delegate trade rules and updates to services and repositories; repositories retrieve Finnhub data and persist portfolio and transaction state. README documents viewing, buying, and selling, and the source excerpts confirm the trade path. Event-driven mail and some route/view wiring are visible in the tree but not sampled, so those links are omitted or marked unverified.

Main entry points: [`app/Repositories/StocksRepositories/FinnhubStocksRepository.php`](https://github.com/gatiskevans/stock-trader/blob/main/app/Repositories/StocksRepositories/FinnhubStocksRepository.php) (Stock repository), [`app/Http/Controllers/Stocks/StocksController.php`](https://github.com/gatiskevans/stock-trader/blob/main/app/Http/Controllers/Stocks/StocksController.php) (Stock controller), [`app/Services/BuyStocksService.php`](https://github.com/gatiskevans/stock-trader/blob/main/app/Services/BuyStocksService.php) (Purchase service), [`app/Services/SellStocksService.php`](https://github.com/gatiskevans/stock-trader/blob/main/app/Services/SellStocksService.php) (Sale service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web and accounts"]
  node_route_provider["Route registration"]
  node_stock_controller["Stock controller"]
  node_funds_controller["Funds controller"]
  node_transactions_controller["Transactions controller"]
  node_auth_controller["Session authentication"]
  node_stock_views["Stock and company views<br/>[stock.blade.php]"]
  node_fund_views["Funds view"]
end

subgraph group_trading["Trading workflow"]
  node_buy_service["Purchase service"]
  node_sell_service["Sale service"]
  node_market_hours["Market hours"]
end

subgraph group_market["Market data"]
  node_stock_repository["Stock repository"]
  node_company_profile["Company profile data<br/>[CompanyProfile.php]"]
  node_quote_data["Quote data<br/>[QuoteData.php]"]
end

subgraph group_state["Persistence and notifications"]
  node_transactions_repository["Transaction repository"]
  node_database[("Application database<br/>[Transaction.php]")]
  node_stock_model[("Portfolio stock model<br/>[Stock.php]")]
  node_trade_events["Trade events"]
  node_mail_jobs["Trade email jobs<br/>[PurchaseStock.php]"]
end

node_trader(("Trader"))
node_finnhub["Finnhub API"]

node_trader -.->|"requests trading"| node_stock_controller
node_route_provider -.->|"routes requests"| node_stock_controller
node_stock_controller -->|"invokes purchase"| node_buy_service
node_stock_controller -->|"invokes sale"| node_sell_service
node_stock_controller -->|"fetches market and holdings"| node_stock_repository
node_stock_controller -->|"renders stock pages"| node_stock_views
node_buy_service -->|"checks trading hours"| node_market_hours
node_sell_service -->|"checks trading hours"| node_market_hours
node_buy_service -->|"reads and updates holdings"| node_stock_repository
node_sell_service -->|"reads and updates holdings"| node_stock_repository
node_buy_service -->|"records purchase"| node_transactions_repository
node_sell_service -->|"records sale"| node_transactions_repository
node_stock_repository -->|"requests company and quote data"| node_finnhub
node_stock_repository -->|"constructs profile"| node_company_profile
node_stock_repository -->|"constructs quote"| node_quote_data
node_stock_repository -->|"queries portfolio records"| node_database
node_transactions_repository -.->|"persists transactions"| node_database
node_buy_service -->|"dispatches purchase event"| node_trade_events
node_sell_service -->|"dispatches sale event"| node_trade_events
node_trade_events -.->|"queues trade email"| node_mail_jobs
node_trader -.->|"authenticates"| node_auth_controller
node_funds_controller -.->|"renders funds page"| node_fund_views
node_transactions_controller -.->|"loads transaction history"| node_transactions_repository

click node_route_provider "https://github.com/gatiskevans/stock-trader/blob/main/app/Providers/RouteServiceProvider.php"
click node_stock_controller "https://github.com/gatiskevans/stock-trader/blob/main/app/Http/Controllers/Stocks/StocksController.php"
click node_funds_controller "https://github.com/gatiskevans/stock-trader/blob/main/app/Http/Controllers/Funds/FundsController.php"
click node_transactions_controller "https://github.com/gatiskevans/stock-trader/blob/main/app/Http/Controllers/Transactions/TransactionsController.php"
click node_auth_controller "https://github.com/gatiskevans/stock-trader/blob/main/app/Http/Controllers/Auth/AuthenticatedSessionController.php"
click node_stock_views "https://github.com/gatiskevans/stock-trader/blob/main/resources/views/stocks/stock.blade.php"
click node_fund_views "https://github.com/gatiskevans/stock-trader/blob/main/resources/views/funds/show-funds.blade.php"
click node_buy_service "https://github.com/gatiskevans/stock-trader/blob/main/app/Services/BuyStocksService.php"
click node_sell_service "https://github.com/gatiskevans/stock-trader/blob/main/app/Services/SellStocksService.php"
click node_market_hours "https://github.com/gatiskevans/stock-trader/blob/main/app/Services/MarketOpenService.php"
click node_stock_repository "https://github.com/gatiskevans/stock-trader/blob/main/app/Repositories/StocksRepositories/FinnhubStocksRepository.php"
click node_company_profile "https://github.com/gatiskevans/stock-trader/blob/main/app/Models/Companies/CompanyProfile.php"
click node_quote_data "https://github.com/gatiskevans/stock-trader/blob/main/app/Models/QuoteData.php"
click node_transactions_repository "https://github.com/gatiskevans/stock-trader/blob/main/app/Repositories/TransactionsRepositories/MySQLTransactionsRepository.php"
click node_database "https://github.com/gatiskevans/stock-trader/blob/main/app/Models/Transaction.php"
click node_stock_model "https://github.com/gatiskevans/stock-trader/blob/main/app/Models/Stock.php"
click node_trade_events "https://github.com/gatiskevans/stock-trader/blob/main/app/Events/StockPurchasedEvent.php"
click node_mail_jobs "https://github.com/gatiskevans/stock-trader/blob/main/app/Jobs/PurchaseStock.php"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_route_provider,node_stock_controller,node_funds_controller,node_transactions_controller,node_auth_controller,node_stock_views,node_fund_views toneBlue
class node_buy_service,node_sell_service,node_market_hours toneAmber
class node_stock_repository,node_company_profile,node_quote_data,node_finnhub toneMint
class node_transactions_repository,node_database,node_stock_model,node_trade_events,node_mail_jobs toneRose
class node_trader toneIndigo
```

## Components

### Web and accounts

- [Route registration](https://github.com/gatiskevans/stock-trader/blob/main/app/Providers/RouteServiceProvider.php): `app/Providers/RouteServiceProvider.php`
- [Stock controller](https://github.com/gatiskevans/stock-trader/blob/main/app/Http/Controllers/Stocks/StocksController.php): `app/Http/Controllers/Stocks/StocksController.php`
- [Funds controller](https://github.com/gatiskevans/stock-trader/blob/main/app/Http/Controllers/Funds/FundsController.php): `app/Http/Controllers/Funds/FundsController.php`
- [Transactions controller](https://github.com/gatiskevans/stock-trader/blob/main/app/Http/Controllers/Transactions/TransactionsController.php): `app/Http/Controllers/Transactions/TransactionsController.php`
- [Session authentication](https://github.com/gatiskevans/stock-trader/blob/main/app/Http/Controllers/Auth/AuthenticatedSessionController.php): `app/Http/Controllers/Auth/AuthenticatedSessionController.php`
- [Stock and company views](https://github.com/gatiskevans/stock-trader/blob/main/resources/views/stocks/stock.blade.php): `resources/views/stocks/stock.blade.php`
- [Funds view](https://github.com/gatiskevans/stock-trader/blob/main/resources/views/funds/show-funds.blade.php): `resources/views/funds/show-funds.blade.php`

### Trading workflow

- [Purchase service](https://github.com/gatiskevans/stock-trader/blob/main/app/Services/BuyStocksService.php): `app/Services/BuyStocksService.php`
- [Sale service](https://github.com/gatiskevans/stock-trader/blob/main/app/Services/SellStocksService.php): `app/Services/SellStocksService.php`
- [Market hours](https://github.com/gatiskevans/stock-trader/blob/main/app/Services/MarketOpenService.php): `app/Services/MarketOpenService.php`

### Market data

- [Stock repository](https://github.com/gatiskevans/stock-trader/blob/main/app/Repositories/StocksRepositories/FinnhubStocksRepository.php): `app/Repositories/StocksRepositories/FinnhubStocksRepository.php`
- [Company profile data](https://github.com/gatiskevans/stock-trader/blob/main/app/Models/Companies/CompanyProfile.php): `app/Models/Companies/CompanyProfile.php`
- [Quote data](https://github.com/gatiskevans/stock-trader/blob/main/app/Models/QuoteData.php): `app/Models/QuoteData.php`

### Persistence and notifications

- [Transaction repository](https://github.com/gatiskevans/stock-trader/blob/main/app/Repositories/TransactionsRepositories/MySQLTransactionsRepository.php): `app/Repositories/TransactionsRepositories/MySQLTransactionsRepository.php`
- [Application database](https://github.com/gatiskevans/stock-trader/blob/main/app/Models/Transaction.php): `app/Models/Transaction.php`
- [Portfolio stock model](https://github.com/gatiskevans/stock-trader/blob/main/app/Models/Stock.php): `app/Models/Stock.php`
- [Trade events](https://github.com/gatiskevans/stock-trader/blob/main/app/Events/StockPurchasedEvent.php): `app/Events/StockPurchasedEvent.php`
- [Trade email jobs](https://github.com/gatiskevans/stock-trader/blob/main/app/Jobs/PurchaseStock.php): `app/Jobs/PurchaseStock.php`

### Other components

- **Trader**
- **Finnhub API**

## Connections

- Trader → Stock controller: requests trading
- Route registration → Stock controller: routes requests
- Stock controller → Purchase service: invokes purchase (evidence: `app/Http/Controllers/Stocks/StocksController.php`)
- Stock controller → Sale service: invokes sale (evidence: `app/Http/Controllers/Stocks/StocksController.php`)
- Stock controller → Stock repository: fetches market and holdings (evidence: `app/Http/Controllers/Stocks/StocksController.php`)
- Stock controller → Stock and company views: renders stock pages (evidence: `app/Http/Controllers/Stocks/StocksController.php`)
- Purchase service → Market hours: checks trading hours (evidence: `app/Services/BuyStocksService.php`)
- Sale service → Market hours: checks trading hours (evidence: `app/Services/SellStocksService.php`)
- Purchase service → Stock repository: reads and updates holdings (evidence: `app/Services/BuyStocksService.php`)
- Sale service → Stock repository: reads and updates holdings (evidence: `app/Services/SellStocksService.php`)
- Purchase service → Transaction repository: records purchase (evidence: `app/Services/BuyStocksService.php`)
- Sale service → Transaction repository: records sale (evidence: `app/Services/SellStocksService.php`)
- Stock repository → Finnhub API: requests company and quote data (evidence: `app/Repositories/StocksRepositories/FinnhubStocksRepository.php`)
- Stock repository → Company profile data: constructs profile (evidence: `app/Repositories/StocksRepositories/FinnhubStocksRepository.php`)
- Stock repository → Quote data: constructs quote (evidence: `app/Repositories/StocksRepositories/FinnhubStocksRepository.php`)
- Stock repository → Application database: queries portfolio records (evidence: `app/Repositories/StocksRepositories/FinnhubStocksRepository.php`)
- Transaction repository → Application database: persists transactions (evidence: `app/Repositories/TransactionsRepositories/MySQLTransactionsRepository.php`)
- Purchase service → Trade events: dispatches purchase event (evidence: `app/Services/BuyStocksService.php`)
- Sale service → Trade events: dispatches sale event (evidence: `app/Services/SellStocksService.php`)
- Trade events → Trade email jobs: queues trade email
- Trader → Session authentication: authenticates (evidence: `app/Http/Controllers/Auth/AuthenticatedSessionController.php`)
- Funds controller → Funds view: renders funds page
- Transactions controller → Transaction repository: loads transaction history
