# stokay/mysqlclient architecture

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

- Interactive diagram: https://gitdiagram.com/stokay/mysqlclient
- Repository: https://github.com/stokay/mysqlclient

## Overview

MySQL Client is a native macOS database-management app. The main workflow is to save/select a connection, connect to MySQL, browse schema or run SQL, then inspect or modify data; import, export, and backup are separate task branches. The graph follows the documented MVVM structure and sampled call/reference evidence. Several view models and feature implementations are unsampled, so their internal calls are not expanded beyond documented relationships.

Main entry points: [`Sources/MySQLMacClient/Views/MainWindowView.swift`](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/MainWindowView.swift) (Main window), [`Sources/MySQLMacClient/Services/MySQLService.swift`](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Services/MySQLService.swift) (MySQL service), [`Sources/MySQLMacClient/App/MySQLMacClientApp.swift`](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/App/MySQLMacClientApp.swift) (App lifecycle), [`Sources/MySQLMacClient/Views/QueryPanelView.swift`](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/QueryPanelView.swift) (SQL panel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and UI"]
  node_app["App lifecycle"]
  node_mainwindow["Main window"]
  node_connectionform["Connection form"]
end

subgraph group_connection["Connections and schema"]
  node_connectionvm["Connection profiles"]
  node_appstate["Session state<br/>[AppState.swift]"]
  node_keychain["Credential vault"]
  node_mysql["MySQL service<br/>[MySQLService.swift]"]
  node_schemavm["Schema browser"]
  node_introspection["Schema introspection"]
end

subgraph group_query["Queries and data"]
  node_sqlpanel["SQL panel"]
  node_sqltext["SQL editor<br/>[SQLTextView.swift]"]
  node_sqlvm["SQL console"]
  node_results["Query results"]
  node_historyvm["Query history"]
  node_tabledata["Table data grid"]
end

subgraph group_transfer["Import and export"]
  node_importvm["Table import"]
  node_importparsers["CSV and XLSX readers"]
  node_exportvm["Table export"]
  node_exporters["Export formats"]
  node_backupvm["Database backup"]
  node_atomic["Atomic file writer"]
end

subgraph group_state["Local state"]
  node_connectionstore[("Profile storage")]
  node_settings[("Settings storage")]
  node_historystore[("History storage")]
end

node_user(("Database user"))
node_server[("MySQL server")]

node_user -->|"launches"| node_app
node_app -->|"presents"| node_connectionform
node_app -->|"presents"| node_mainwindow
node_connectionform -.->|"uses"| node_connectionvm
node_connectionvm -.->|"persists profiles"| node_connectionstore
node_connectionvm -.->|"stores passwords"| node_keychain
node_connectionform -.->|"initiates session"| node_appstate
node_appstate -->|"manages connection"| node_mysql
node_appstate -->|"creates"| node_introspection
node_mysql -->|"queries"| node_server
node_mainwindow -.->|"presents browser"| node_schemavm
node_schemavm -.->|"loads schema"| node_introspection
node_introspection -->|"runs metadata queries"| node_mysql
node_mainwindow -.->|"presents"| node_sqlpanel
node_sqlpanel -->|"embeds editor"| node_sqltext
node_sqlpanel -->|"uses"| node_sqlvm
node_sqlvm -->|"runs SQL"| node_mysql
node_sqlvm -->|"records queries"| node_historyvm
node_historyvm -->|"persists entries"| node_historystore
node_sqlpanel -->|"displays results"| node_results
node_mainwindow -.->|"presents table data"| node_tabledata
node_tabledata -.->|"reads and edits rows"| node_mysql
node_mainwindow -.->|"offers import"| node_importvm
node_importvm -.->|"parses files"| node_importparsers
node_importvm -.->|"imports rows"| node_mysql
node_mainwindow -.->|"offers export"| node_exportvm
node_exportvm -.->|"reads table pages"| node_mysql
node_exportvm -.->|"formats output"| node_exporters
node_exportvm -.->|"writes file"| node_atomic
node_mainwindow -->|"offers backup"| node_backupvm
node_backupvm -->|"reads database objects"| node_mysql
node_backupvm -->|"loads metadata"| node_introspection
node_backupvm -->|"writes dump"| node_atomic
node_app -->|"owns profiles"| node_connectionstore
node_app -->|"owns settings"| node_settings

click node_app "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/App/MySQLMacClientApp.swift"
click node_mainwindow "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/MainWindowView.swift"
click node_connectionform "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/ConnectionFormView.swift"
click node_connectionvm "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/ConnectionFormViewModel.swift"
click node_appstate "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/App/AppState.swift"
click node_keychain "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Services/KeychainService.swift"
click node_mysql "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Services/MySQLService.swift"
click node_schemavm "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/SchemaTreeViewModel.swift"
click node_introspection "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Services/SchemaIntrospectionService.swift"
click node_sqlpanel "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/QueryPanelView.swift"
click node_sqltext "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/SQLTextView.swift"
click node_sqlvm "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/SQLConsoleViewModel.swift"
click node_results "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/QueryResultGridView.swift"
click node_historyvm "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Persistence/QueryHistoryRecorder.swift"
click node_tabledata "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/TableDataViewModel.swift"
click node_importvm "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/TableImportViewModel.swift"
click node_importparsers "https://github.com/stokay/mysqlclient/tree/main/Sources/MySQLMacClient/Import"
click node_exportvm "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/TableExportViewModel.swift"
click node_exporters "https://github.com/stokay/mysqlclient/tree/main/Sources/MySQLMacClient/Export"
click node_backupvm "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/DatabaseBackupViewModel.swift"
click node_atomic "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Export/AtomicFileWriter.swift"
click node_connectionstore "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Persistence/ConnectionStore.swift"
click node_settings "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Persistence/SettingsStore.swift"
click node_historystore "https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Persistence/QueryHistoryStore.swift"

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_app,node_mainwindow,node_connectionform toneBlue
class node_connectionvm,node_appstate,node_keychain,node_mysql,node_schemavm,node_introspection,node_user,node_server toneAmber
class node_sqlpanel,node_sqltext,node_sqlvm,node_results,node_historyvm,node_tabledata toneMint
class node_importvm,node_importparsers,node_exportvm,node_exporters,node_backupvm,node_atomic toneRose
class node_connectionstore,node_settings,node_historystore toneIndigo
```

## Components

### App and UI

- [App lifecycle](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/App/MySQLMacClientApp.swift): `Sources/MySQLMacClient/App/MySQLMacClientApp.swift`
- [Main window](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/MainWindowView.swift): `Sources/MySQLMacClient/Views/MainWindowView.swift`
- [Connection form](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/ConnectionFormView.swift): `Sources/MySQLMacClient/Views/ConnectionFormView.swift`

### Connections and schema

- [Connection profiles](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/ConnectionFormViewModel.swift): `Sources/MySQLMacClient/ViewModels/ConnectionFormViewModel.swift`
- [Session state](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/App/AppState.swift): `Sources/MySQLMacClient/App/AppState.swift`
- [Credential vault](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Services/KeychainService.swift): `Sources/MySQLMacClient/Services/KeychainService.swift`
- [MySQL service](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Services/MySQLService.swift): `Sources/MySQLMacClient/Services/MySQLService.swift`
- [Schema browser](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/SchemaTreeViewModel.swift): `Sources/MySQLMacClient/ViewModels/SchemaTreeViewModel.swift`
- [Schema introspection](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Services/SchemaIntrospectionService.swift): `Sources/MySQLMacClient/Services/SchemaIntrospectionService.swift`

### Queries and data

- [SQL panel](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/QueryPanelView.swift): `Sources/MySQLMacClient/Views/QueryPanelView.swift`
- [SQL editor](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/SQLTextView.swift): `Sources/MySQLMacClient/Views/SQLTextView.swift`
- [SQL console](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/SQLConsoleViewModel.swift): `Sources/MySQLMacClient/ViewModels/SQLConsoleViewModel.swift`
- [Query results](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Views/QueryResultGridView.swift): `Sources/MySQLMacClient/Views/QueryResultGridView.swift`
- [Query history](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Persistence/QueryHistoryRecorder.swift): `Sources/MySQLMacClient/Persistence/QueryHistoryRecorder.swift`
- [Table data grid](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/TableDataViewModel.swift): `Sources/MySQLMacClient/ViewModels/TableDataViewModel.swift`

### Import and export

- [Table import](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/TableImportViewModel.swift): `Sources/MySQLMacClient/ViewModels/TableImportViewModel.swift`
- [CSV and XLSX readers](https://github.com/stokay/mysqlclient/tree/main/Sources/MySQLMacClient/Import): `Sources/MySQLMacClient/Import`
- [Table export](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/TableExportViewModel.swift): `Sources/MySQLMacClient/ViewModels/TableExportViewModel.swift`
- [Export formats](https://github.com/stokay/mysqlclient/tree/main/Sources/MySQLMacClient/Export): `Sources/MySQLMacClient/Export`
- [Database backup](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/ViewModels/DatabaseBackupViewModel.swift): `Sources/MySQLMacClient/ViewModels/DatabaseBackupViewModel.swift`
- [Atomic file writer](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Export/AtomicFileWriter.swift): `Sources/MySQLMacClient/Export/AtomicFileWriter.swift`

### Local state

- [Profile storage](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Persistence/ConnectionStore.swift): `Sources/MySQLMacClient/Persistence/ConnectionStore.swift`
- [Settings storage](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Persistence/SettingsStore.swift): `Sources/MySQLMacClient/Persistence/SettingsStore.swift`
- [History storage](https://github.com/stokay/mysqlclient/blob/main/Sources/MySQLMacClient/Persistence/QueryHistoryStore.swift): `Sources/MySQLMacClient/Persistence/QueryHistoryStore.swift`

### Other components

- **Database user**
- **MySQL server**

## Connections

- Database user → App lifecycle: launches (evidence: `README.md`)
- App lifecycle → Connection form: presents (evidence: `Sources/MySQLMacClient/App/MySQLMacClientApp.swift`)
- App lifecycle → Main window: presents (evidence: `Sources/MySQLMacClient/App/MySQLMacClientApp.swift`)
- Connection form → Connection profiles: uses
- Connection profiles → Profile storage: persists profiles
- Connection profiles → Credential vault: stores passwords
- Connection form → Session state: initiates session
- Session state → MySQL service: manages connection (evidence: `Sources/MySQLMacClient/App/AppState.swift`)
- Session state → Schema introspection: creates (evidence: `Sources/MySQLMacClient/App/AppState.swift`)
- MySQL service → MySQL server: queries (evidence: `README.md`)
- Main window → Schema browser: presents browser
- Schema browser → Schema introspection: loads schema
- Schema introspection → MySQL service: runs metadata queries (evidence: `Sources/MySQLMacClient/Services/SchemaIntrospectionService.swift`)
- Main window → SQL panel: presents
- SQL panel → SQL editor: embeds editor (evidence: `Sources/MySQLMacClient/Views/QueryPanelView.swift`)
- SQL panel → SQL console: uses (evidence: `Sources/MySQLMacClient/Views/QueryPanelView.swift`)
- SQL console → MySQL service: runs SQL (evidence: `Sources/MySQLMacClient/ViewModels/SQLConsoleViewModel.swift`)
- SQL console → Query history: records queries (evidence: `Sources/MySQLMacClient/ViewModels/SQLConsoleViewModel.swift`)
- Query history → History storage: persists entries (evidence: `Sources/MySQLMacClient/Persistence/QueryHistoryRecorder.swift`)
- SQL panel → Query results: displays results (evidence: `Sources/MySQLMacClient/Views/QueryPanelView.swift`)
- Main window → Table data grid: presents table data
- Table data grid → MySQL service: reads and edits rows
- Main window → Table import: offers import
- Table import → CSV and XLSX readers: parses files
- Table import → MySQL service: imports rows
- Main window → Table export: offers export
- Table export → MySQL service: reads table pages
- Table export → Export formats: formats output
- Table export → Atomic file writer: writes file
- Main window → Database backup: offers backup
- Database backup → MySQL service: reads database objects (evidence: `Sources/MySQLMacClient/ViewModels/DatabaseBackupViewModel.swift`)
- Database backup → Schema introspection: loads metadata (evidence: `Sources/MySQLMacClient/ViewModels/DatabaseBackupViewModel.swift`)
- Database backup → Atomic file writer: writes dump (evidence: `Sources/MySQLMacClient/ViewModels/DatabaseBackupViewModel.swift`)
- App lifecycle → Profile storage: owns profiles (evidence: `Sources/MySQLMacClient/App/MySQLMacClientApp.swift`)
- App lifecycle → Settings storage: owns settings (evidence: `Sources/MySQLMacClient/App/MySQLMacClientApp.swift`)
