# luqian923/databasehelperlib architecture

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

- Interactive diagram: https://gitdiagram.com/luqian923/databasehelperlib
- Repository: https://github.com/luqian923/databasehelperlib

## Overview

DatabaseHelperLib is a .NET persistence library for typed, per-user table data. Consumers register attributed entity types and create a manager; the manager initializes and loads critical data, while dynamic packs load tables on demand. Consumers modify tables through packs and request saves; the manager batches queued saves to the database and unloads inactive dynamic packs. A Roslyn generator discovers entity attributes and emits registration and JSON/AOT support. The README provides no further capability details, so generator relationships beyond those visible in its source are omitted.

Main entry points: [`DatabaseHelper/LDbManager.cs`](https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbManager.cs) (Database Manager), [`TestProgram/Program.cs`](https://github.com/luqian923/databasehelperlib/blob/master/TestProgram/Program.cs) (Usage Sample), [`DatabaseHelper/LDbPlayerPack.cs`](https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbPlayerPack.cs) (Player Pack), [`DatabaseHelper/LDbBaseTable.cs`](https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbBaseTable.cs) (Base Table)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Library API"]
  node_helper["Database Helper<br/>[LDatabaseHelper.cs]"]
  node_entity_metadata["Entity Metadata<br/>[LDbEntity.cs]"]
  node_base_table["Base Table<br/>[LDbBaseTable.cs]"]
end

subgraph group_runtime["Persistence Runtime"]
  node_manager["Database Manager<br/>[LDbManager.cs]"]
  node_player_pack["Player Pack<br/>[LDbPlayerPack.cs]"]
end

subgraph group_generation["Entity Generation"]
  node_generator["Table Generator"]
  node_json_context["JSON Context<br/>[DbJsonContext.cs]"]
end

subgraph group_sample["Sample Models"]
  node_account_table["Account Table<br/>[AccountTable.cs]"]
  node_player_table["Player Table<br/>[PlayerTable.cs]"]
  node_sample_program["Usage Sample<br/>[Program.cs]"]
end

node_consumer(("Library Consumer"))
node_database[("SQL Database")]

node_consumer -->|"creates manager"| node_manager
node_manager -->|"reads registrations"| node_helper
node_helper -->|"constructs manager"| node_manager
node_manager -->|"creates packs"| node_player_pack
node_player_pack -->|"loads and saves tables"| node_manager
node_manager -->|"reads and writes"| node_database
node_player_pack -->|"stores tables"| node_base_table
node_entity_metadata -->|"describes table entities"| node_base_table
node_generator -->|"emits registrations"| node_helper
node_account_table -->|"inherits from"| node_base_table
node_player_table -->|"inherits from"| node_base_table
node_sample_program -->|"exercises API"| node_manager
node_sample_program -->|"uses packs"| node_player_pack
node_sample_program -->|"creates records"| node_account_table
node_sample_program -->|"creates records"| node_player_table
node_json_context -->|"declares JSON type"| node_account_table
node_json_context -->|"declares JSON type"| node_player_table

click node_helper "https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDatabaseHelper.cs"
click node_entity_metadata "https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbEntity.cs"
click node_base_table "https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbBaseTable.cs"
click node_manager "https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbManager.cs"
click node_player_pack "https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbPlayerPack.cs"
click node_generator "https://github.com/luqian923/databasehelperlib/blob/master/LDatabaseAnalyser/DbTableGenerator.cs"
click node_json_context "https://github.com/luqian923/databasehelperlib/blob/master/TestProgram/DbJsonContext.cs"
click node_account_table "https://github.com/luqian923/databasehelperlib/blob/master/TestProgram/AccountTable.cs"
click node_player_table "https://github.com/luqian923/databasehelperlib/blob/master/TestProgram/PlayerTable.cs"
click node_sample_program "https://github.com/luqian923/databasehelperlib/blob/master/TestProgram/Program.cs"

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_helper,node_entity_metadata,node_base_table toneBlue
class node_manager,node_player_pack,node_database toneAmber
class node_generator,node_json_context toneMint
class node_account_table,node_player_table,node_sample_program toneRose
class node_consumer toneIndigo
```

## Components

### Library API

- [Database Helper](https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDatabaseHelper.cs): `DatabaseHelper/LDatabaseHelper.cs`
- [Entity Metadata](https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbEntity.cs): `DatabaseHelper/LDbEntity.cs`
- [Base Table](https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbBaseTable.cs): `DatabaseHelper/LDbBaseTable.cs`

### Persistence Runtime

- [Database Manager](https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbManager.cs): `DatabaseHelper/LDbManager.cs`
- [Player Pack](https://github.com/luqian923/databasehelperlib/blob/master/DatabaseHelper/LDbPlayerPack.cs): `DatabaseHelper/LDbPlayerPack.cs`

### Entity Generation

- [Table Generator](https://github.com/luqian923/databasehelperlib/blob/master/LDatabaseAnalyser/DbTableGenerator.cs): `LDatabaseAnalyser/DbTableGenerator.cs`
- [JSON Context](https://github.com/luqian923/databasehelperlib/blob/master/TestProgram/DbJsonContext.cs): `TestProgram/DbJsonContext.cs`

### Sample Models

- [Account Table](https://github.com/luqian923/databasehelperlib/blob/master/TestProgram/AccountTable.cs): `TestProgram/AccountTable.cs`
- [Player Table](https://github.com/luqian923/databasehelperlib/blob/master/TestProgram/PlayerTable.cs): `TestProgram/PlayerTable.cs`
- [Usage Sample](https://github.com/luqian923/databasehelperlib/blob/master/TestProgram/Program.cs): `TestProgram/Program.cs`

### Other components

- **Library Consumer**
- **SQL Database**

## Connections

- Library Consumer → Database Manager: creates manager
- Database Manager → Database Helper: reads registrations (evidence: `DatabaseHelper/LDbManager.cs`)
- Database Helper → Database Manager: constructs manager (evidence: `DatabaseHelper/LDatabaseHelper.cs`)
- Database Manager → Player Pack: creates packs (evidence: `DatabaseHelper/LDbManager.cs`)
- Player Pack → Database Manager: loads and saves tables (evidence: `DatabaseHelper/LDbPlayerPack.cs`)
- Database Manager → SQL Database: reads and writes (evidence: `DatabaseHelper/LDbManager.cs`)
- Player Pack → Base Table: stores tables (evidence: `DatabaseHelper/LDbPlayerPack.cs`)
- Entity Metadata → Base Table: describes table entities (evidence: `DatabaseHelper/LDbEntity.cs`)
- Table Generator → Database Helper: emits registrations (evidence: `LDatabaseAnalyser/DbTableGenerator.cs`)
- Account Table → Base Table: inherits from (evidence: `TestProgram/AccountTable.cs`)
- Player Table → Base Table: inherits from (evidence: `TestProgram/PlayerTable.cs`)
- Usage Sample → Database Manager: exercises API (evidence: `TestProgram/Program.cs`)
- Usage Sample → Player Pack: uses packs (evidence: `TestProgram/Program.cs`)
- Usage Sample → Account Table: creates records (evidence: `TestProgram/Program.cs`)
- Usage Sample → Player Table: creates records (evidence: `TestProgram/Program.cs`)
- JSON Context → Account Table: declares JSON type (evidence: `TestProgram/DbJsonContext.cs`)
- JSON Context → Player Table: declares JSON type (evidence: `TestProgram/DbJsonContext.cs`)
