@startuml architecture
skinparam packageStyle rect
skinparam defaultFontName "Arial"
skinparam classFontSize 12
skinparam classAttributeFontSize 11
skinparam classStereotypeFontSize 11
skinparam classPadding 8
skinparam classBorderThickness 1
skinparam classBorderColor DarkGray
skinparam classBackgroundColor #0404c507
skinparam shadowing true
left to right direction

package api {
    namespace GLOBAL {
        class App {
            + DB *sql.DB
            + Store memd.InMemStore
            + MStore memd.MapStore
            + Lg *logd.Logd
            + Run()
            + Mount()
            + JSONWriter()
            + RunGraceful()
        }
        class MapStore {
            + mu sync.RWMutex
            + Maps *StMaps
            + Setup()
            + Set()
            + Rebuild()
        }
        class InMemStore {
            + Players []Player
            + Seasons []Season
            + Teams []Team
            + CurrentSzns CurrentSeasons
            + TeamRecs TeamRecords
            + TopLgPlayers LgTopPlayers
        }
    }
    
    namespace handlers {
        namespace bball {
            left to right direction
            namespace aggs {
                class top_players {
                    + HndlTopLgPlayers()
                }
                class team_records {
                    + HndlTeamRecords()
                }
                class recent_game {
                    + HndlRecentGames()
                }
            }
            
            class selectors {
                + HndlTeams()
                + HndlSeasons()
            }
            namespace og_player {
                class PlayerQuery {
                    + Player string
                    + Team string
                    + Season string
                }
                class PlayerTeamSeason {
                    + Player string
                    + Team string
                    + Season string
                }
                class PQueryIds {
                    + PId uint64x
                    + TId uint64x
                    + SId uint64x
                }
                class og_handle_player {
                    + HndlPlayer()
                }
                
            }
            namespace v2_player {
                class v2_handle_player {
                    + HndlPlayerV2()
                    + PlayerFromQ()
                    + SeasonFromQ()
                    + TeamFromQ()
                }
            }
        }
        class static {
            + HndlRoot()
            + HndlAbt()
            + HndlBronto()
            + HndlBBall()
            + HndlBBallAbt()
            + CSSNostore()
            + JSNostore()
        }
    }
    PlayerTeamSeason ..|> og_handle_player
    PQueryIds ..|> og_handle_player
    PlayerQuery ..|> og_handle_player
    
    namespace response {
        left to right direction
        class Resp {
            + Results []RespObj
            + ErrorMsg string
            + BuildPlayerRespStructs()
            + GetPlayerDash()
        }
        class RespObj {
            + Meta RespPlayerMeta
            + SeasonOvw RespPlayerSznOvw
            + Totals RespPlayerStats
            + PerGame RespPlayerStats
            + HandleStatTypeSznOvw()
        }
        RespObj ..|> Resp
        class RespPlayerMeta {
            + PlayerId uint64
            + TeamId uint64
            + League string
            + SeasonId uint64
            + StatType string
            + Player string
            + Team string
            + TeamName string
            + Season string
            + Caption string
            + CaptionShort string
            + BoxCapTot string
            + BoxCapAvg string
            + ShtgCapTot string
            + ShtgCapAvg string
            + HeadshotUrl string
            + TeamLogoUrl string
            + MakeHeadshotUrl()
            + MakePlayerDashCaptions()
        }
        RespPlayerMeta ..|> RespObj
        class RespPlayerSznOvw {
            + GamesPlayed uint16
            + Minutes float32
            + MinutesPerGame float32
        }
        RespPlayerSznOvw ..|> RespObj
        class RespPlayerStats {
            + Box RespPlayerStatsBox
            + Shtg RespPlayerStatsShtg
        }
        RespPlayerStats ..|> RespObj
        class RespPlayerStatsBox {
            + Points float32
            + Assists float32
            + Rebounds float32
            + Steals float32
            + Blocks float32
        }
        RespPlayerStatsBox ..|> RespPlayerStats
        class RespPlayerStatsShtg {
            + Fg RespPlayerStatsShtgType
            + Fg3 RespPlayerStatsShtgType
            + Ft RespPlayerStatsShtgType
        }
        RespPlayerStatsShtg ..|> RespPlayerStats
        class RespPlayerStatsShtgType {
            + Makes float32
            + Attempts float32
            + Percent string
        }
        RespPlayerStatsShtgType ..|> RespPlayerStatsShtg
        class RespSeasonTmp {
            + Season string
            + WSeason string
            + SwitchSznByLeague()
        }
    }
}
package pgdb {
    class Connection {
        + PostgresConn()
    }
    namespace QUERIES {
        class mapstore_q {
            + QPlayerStore
            + VerifyTeamSzn
            + PlayerTeamBool
            + AllSeasons
            + PlayersSeason
            + Teams
            + PlayerDash
            + TeamTopScorerDash
            + RecGameTopScorers
            + LeagueTopScorers
            + TeamSznRecords
        }
    }
    
    Connection --> App
    ' mapstore_q ..|> StMaps
}
package clnd {
    class CleanNames {
        + RemoveDiacritics()
    }
}
package logd {
    class Logd {
        + lw *LogW
        + lg *log.Logger
    }
    class LogW {
        + mu sync.Mutex
        + out io.writer
    }
}
package memd {

    class StMaps {
        + mu sync.RWMutex
        + TeamIds [string]:int
        + PlrIds [playerId]:
        + PlrNms [playerName]:
        + PlayerIdDtl   [playerId]:*StPlayer
        + PlayerNameDtl [playerName]:*StPlayer
        + PlayerIdName [pId]:name
        + PlayerNameId [name]:pId
        + SeasonPlrNms [szn][pName]:pId
        + SeasonPlrIds [szn][pId]:pName
        + SznTmPlrIds [szn][tmId][pId]
        + MapTeamIdUints()
        + MapSeasons()
        + MapSznTeams()
        + SplitTeams()
        + PlrExistsInSzn()
        + PlrSznExists()
        + PlrIdExists()
        + PlrNmExists()
        + PlrSznTmExists()
    }
    
    namespace current_seasons {
        class CurrentSeasons {
            + PrevSznId uint64
            + CurSznId uint64
            + PrevSzn string
            + CurSzn string
            + GetCurrentSzns()
            + LgSznsByMonth()
        }

        class SeasonLeague {
            + SznId uint64
            + WSznId uint64
            + Szn string
            + WSzn string
        }
    }
    namespace og_inmem_arrays_store {
        class Player {
            + PlayerId uint64
            + Name string
            + League string
            + SeasonIdMax uint64
            + SeasonIdMin uint64
            + PSeasonIdMax uint64
            + PSeasonIdMin uint64
        }
        class Season {
            + SeasonId string
            + Season string
            + WSeason string
        }
        class Team {
            + League string
            + TeamId string
            + TeamAbbr string
            + CityTeam string
            + LogoUrl string
        }
    }
    namespace statagg_tables {
        class TopPlayers {
            + PlayerId uint64
            + Player   string
            + Season   string
            + Team     string
            + Points   uint32
        }
        class LgTopPlayers {
            + NBATop  []TopPlayers
            + WNBATop []TopPlayers
        }
        class TeamRecords {
            + NBARecords  []TeamRecord
            + WNBARecords []TeamRecord
        }
        class TeamRecord {
            + League     string
            + SeasonId   uint64
            + Season     string
            + SeasonDesc string
            + TeamId     uint64
            + Team       string
            + TeamLong   string
            + Wins       uint16
            + Losses     uint16
        }
    
        class RecentGames {
            + TopScorers []PlayerBasic
            + Games      []RecentGame
        }

        class PlayerBasic {
            + PlayerId uint64
            + TeamId   uint64
            + Player   string
            + League   string
            + Points   uint16
            + Assists  uint16
            + Rebounds uint16
        }

        class RecentGame {
            + GameId    uint64
            + TeamId    uint64
            + PlayerId  uint64
            + Player    string
            + League    string
            + Team      string
            + TeamName  string
            + GameDate  string
            + Matchup   string
            + WinLoss   string
            + Points    uint16
            + OppPoints uint16
            + GetRecentGames()
            + ScanRecentGamesRows()
        }
    }
}

CleanNames ..|> og_handle_player
CleanNames ..|> v2_player
CleanNames ..|> StMaps


MapStore --> App
InMemStore --> App
Logd ..|> App

Player --|> InMemStore
Season --|> InMemStore
Team --|> InMemStore
CurrentSeasons --|> InMemStore
TeamRecords --|> InMemStore
LgTopPlayers --|> InMemStore

RecentGames --|> recent_game
LgTopPlayers --|> top_players
TeamRecords --|> team_records

TeamRecord --|> TeamRecords
TopPlayers --|> LgTopPlayers

PlayerBasic --|> RecentGames
RecentGame --|> RecentGames

StMaps --|> MapStore
Resp <|--|> handlers
Resp <--> og_handle_player
Resp <--> v2_handle_player

@enduml