# user4000/tj-ms-sql-server-scripter architecture

> Architecture diagram of the GitHub repository user4000/tj-ms-sql-server-scripter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/user4000/tj-ms-sql-server-scripter
- Repository: https://github.com/user4000/tj-ms-sql-server-scripter

## Overview

##### Project type and purpose
- This is a Windows desktop application (built with .NET and Telerik WinForms) whose sole purpose is to automate “scripting” of MS SQL Server database objects on a schedule.
- It consists of two subprojects in one solution:
– ProjectStandard: A common utility/standard library.
– TJMsSqlScripter: The actual scheduler and script generator.

##### File structure
- ProjectStandard:
– Extensions, Grid, Models, ModelsFactory, ReturnCode, Security, Tools – these form a reusable utility library (logging, data models, grid helpers, error codes, security stubs, async tools, etc.).
– Provides interfaces (ILoginFormManager, ISqlConnectionFactory) and default implementations.
- TJMsSqlScripter:
– UI Layer: RadFormAdmin (Telerik WinForms).
– Core: TTJobManager, TTJobFactory, TTManager, TTScriptMaker, TTConnection.
– Data Models: TTDay, TTPeriod, TTSession, TTProjectSettings.
– Entry point: Program.cs (bootstraps UI or scheduling host).

##### README insights
- “Tool for scripting objects of MS SQL Server database.”
- “Designed for permanent work on a schedule” – implies integration with Windows Task Scheduler (or an internal timer).

a. Components
1) User Interface Layer
– RadFormAdmin (admin settings)
– (Optionally) RadFormLogin if used or inherited from ProjectStandard
2) Core Scheduler/Orchestrator
– Program.cs (host)
– TTManager & TTManagerFactory (initialization, DI)
– TTJobManager & TTJobFactory (job creation, lifecycle)
– TTSession (holds context, credentials)
3) Script Generation Engine
– TTScriptMaker (builds SQL scripts for database objects)
4) Data Access
– TTConnection / ISqlConnectionFactory (connects to MS SQL Server via ADO.NET)
5) Standard Library
– ProjectStandard (shared utilities, models, error handling, extensions)
6) External Services
– MS SQL Server (the database server you’re scripting)
– Windows Task Scheduler or internal timer component
– File system (output scripts), Logging sink (text files or console)

b. Relationships & data flows
- On schedule trigger → Program host starts a session → TTJobManager picks up configured jobs → for each job:
– JobManager uses TTConnection to connect → TTScriptMaker queries sys tables → generates .sql files → writes to disk.
- Admin UI calls into Manager layer to create/update jobs & schedule settings (persisted in TTProjectSettings).
- The Standard Library underpins all layers (interfaces, models, error codes).

c. Architectural patterns & principles
- Layered architecture: UI → Orchestration → Data Access → External.
- Factory pattern: TTManagerFactory, TTJobFactory, TTReturnCodeFactory.
- Dependency inversion: interfaces (ISqlConnectionFactory, ILoginFormManager) with concrete in ProjectStandard.
- Separation of concerns: UI vs scheduling vs script generation vs data models.

d. Key technologies/frameworks
- .NET Framework (C#)
- Telerik WinForms (RadForm controls)
- ADO.NET or SqlClient (TTConnection)
- ProjectStandard custom library
- Windows Task Scheduler or internal timer loop

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "UI Layer"
        UIAdmin["RadFormAdmin"]:::ui
        UILogin["RadFormLogin"]:::ui
    end

    subgraph "Core Layer"
        Program["Program.cs"]:::core
        TTManagerFactory["TTManagerFactory"]:::core
        TTManager["TTManager"]:::core
        TTJobFactory["TTJobFactory"]:::core
        TTJobManager["TTJobManager"]:::core
        TTJob["TTJob"]:::core
        TTSession["TTSession"]:::core
        TTProjectSettings["TTProjectSettings"]:::core
    end

    subgraph "Data Access Layer"
        TTConnection["TTConnection"]:::data
        ISqlCF["ISqlConnectionFactory"]:::data
    end

    subgraph "Script Generation Engine"
        TTScriptMaker["TTScriptMaker"]:::core
    end

    SharedLib["ProjectStandard\n(Utilities, Models, Extensions, ReturnCode,\nGrid, ModelsFactory, Security, Tools)"]:::shared

    subgraph "External Systems"
        Scheduler["Windows Task Scheduler / Timer"]:::external
        SQLServer["MS SQL Server"]:::external
        FileSystem["File System\n(Script Output)"]:::external
    end

    %% Connections
    Scheduler -->|"trigger"| Program
    UIAdmin -->|"ManageSettings()"| Program
    UILogin -->|"Authenticate()"| Program
    Program -->|"Init via Factory"| TTManagerFactory
    TTManagerFactory -->|"creates"| TTManager
    TTManager -->|"manages jobs"| TTJobManager
    TTJobFactory -->|"creates"| TTJob
    TTJobManager -->|"runs"| TTJob
    Program -->|"holds context"| TTSession
    Program -->|"load/save settings"| TTProjectSettings
    TTJobManager -->|"connect()"| TTConnection
    TTConnection -->|"ExecuteQuery()"| SQLServer
    TTJobManager -->|"GenerateScript()"| TTScriptMaker
    TTScriptMaker -->|"write()"| FileSystem
    SharedLib --> UIAdmin
    SharedLib --> UILogin
    SharedLib --> Program
    SharedLib --> TTManager
    SharedLib --> TTJobManager
    SharedLib --> TTConnection

    %% Click Events
    click SharedLib "https://github.com/user4000/tj-ms-sql-server-scripter/tree/master/ProjectStandard/"
    click UIAdmin "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/Form/RadFormAdmin.cs"
    click UILogin "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/ProjectStandard/Forms/RadFormLogin.cs"
    click Program "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/Program.cs"
    click TTManager "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/TTManager.cs"
    click TTManagerFactory "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/TTManagerFactory.cs"
    click TTJobManager "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/TTJobManager.cs"
    click TTJobFactory "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/TTJobFactory.cs"
    click TTJob "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/TTJob.cs"
    click TTSession "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/TTSession.cs"
    click TTProjectSettings "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/TTProjectSettings.cs"
    click TTScriptMaker "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/Script/TTScriptMaker.cs"
    click TTConnection "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/TJMsSqlScripter/TTConnection.cs"
    click ISqlCF "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/ProjectStandard/Standard/ISqlConnectionFactory.cs"
    click ILoginFM "https://github.com/user4000/tj-ms-sql-server-scripter/blob/master/ProjectStandard/Standard/ILoginFormManager.cs"
    click Ext "https://github.com/user4000/tj-ms-sql-server-scripter/tree/master/ProjectStandard/Extensions/"
    click Grid "https://github.com/user4000/tj-ms-sql-server-scripter/tree/master/ProjectStandard/Grid/"
    click Models "https://github.com/user4000/tj-ms-sql-server-scripter/tree/master/ProjectStandard/Models/"
    click ModelsFactory "https://github.com/user4000/tj-ms-sql-server-scripter/tree/master/ProjectStandard/ModelsFactory/"
    click ReturnCode "https://github.com/user4000/tj-ms-sql-server-scripter/tree/master/ProjectStandard/ReturnCode/"
    click Security "https://github.com/user4000/tj-ms-sql-server-scripter/tree/master/ProjectStandard/Security/"
    click Tools "https://github.com/user4000/tj-ms-sql-server-scripter/tree/master/ProjectStandard/Tools/"

    %% Styles
    classDef ui fill:#blue,stroke:#000,color:#fff;
    classDef core fill:#0f0,stroke:#000,color:#000;
    classDef data fill:#f90,stroke:#000,color:#000;
    classDef external fill:#ccc,stroke:#000,color:#000;
    classDef shared fill:#ff0,stroke:#000,color:#000;
```
