# crptbddst/typescriptwebresourcetemplate architecture

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

- Interactive diagram: https://gitdiagram.com/crptbddst/typescriptwebresourcetemplate
- Repository: https://github.com/crptbddst/typescriptwebresourcetemplate

## Overview

The project is a template designed for Dynamics 365 Customer Engagement (CE) webresource development using TypeScript. It is split into two main parts:

1. TSWebresourceTemplate – This directory houses the actual webresource code written in TypeScript. It contains source files for various components such as forms, ribbons, data models, constants, and services. The presence of multiple webpack configuration files (webpack.common.js, webpack.dev.js, webpack.prod.js) as well as ESLint and Prettier configuration files indicate that the template leverages modern front-end build pipelines. The “dist” folder contains the compiled JavaScript that will become the webresource.

2. spklSolution – This part of the project handles the Dynamics 365 packaging and deployment. It contains deployment scripts (e.g., deploy-webresources.bat, deploy-plugins.bat), configuration files like spkl.json, and references to Dynamics SDK tools (e.g., CrmSvcUtil.exe, SolutionPackager.exe). The inclusion of spkl packages points to an integration with the spkl framework, which manages Dynamics 365 solution creation, webresource deployment, and early-bound class generation.

A. Identify the Main Components:
- Webresource Development Module (TSWebresourceTemplate):
- Source Code Component: Contains folders for services, forms, ribbons, data models, and constants.
- Build and Deployment Configuration: Webpack configurations (webpack.common.js, webpack.dev.js, webpack.prod.js) along with TypeScript compiler (tsconfig.json) and linting (ESLint, Prettier).
- Build Artifacts: Precompiled files in the “dist” folder, notably the main output (WebresourceToName.js).
- Deployment / Packaging Module (spklSolution):
- Deployment Scripts: Batch files for deploying plugins, webresources, and workflows.
- Configuration: spkl.json defining solution-specific settings.
- Dynamics SDK Tools: External tools located in the “bin/coretools” (e.g., CrmSvcUtil.exe, SolutionPackager.exe).
- Integrated Packages: spkl packages and Microsoft.CrmSdk.CoreTools are referenced.

B. Define Relationships and Data Flow:
- Source Code Flow: Write code in TSWebresourceTemplate → Build using webpack → Output into “dist” folder.
- Deployment Flow: Use spklSolution scripts (e.g., deploy-webresources.bat) which pick up the compiled webresource files and deploy them into Dynamics 365 CE.
- Configuration/Authorization: The process includes authentication with Dynamics 365 (using “npx dataverse-auth”) and generating early-bound classes (“npx dataverse-gen init”), aligning the development with the target CRM environment.

C. Highlight Architectural Patterns/Design Principles:
- Separation of Concerns: Notice the clear division between development (TSWebresourceTemplate) and deployment (spklSolution).
- Build Pipeline Integration: A modern JavaScript/TypeScript build setup is implemented with webpack and TypeScript.
- External Tool Integration: spkl and Dynamics SDK tools provide an abstraction layer for packaging and deploying solutions into Dynamics 365.

D. Relevant Technologies & Frameworks:
- TypeScript for writing robust, strongly typed code.
- Webpack for bundling and asset management.
- ESLint and Prettier for code quality and formatting.
- Dynamics 365 CE as the target environment.
- spkl Framework and Microsoft.CrmSdk.CoreTools for solution packaging and deployment.

- The Deployment/Integration Side (spklSolution): Represent deployment scripts, spkl.json configuration, and the integration with Dynamics SDK Tools leading to the target Dynamics 365 environment.
- From the “Source Code Component” → “Build Process” → “Compiled Artifacts” → “Deployment Scripts in spklSolution”.
- A reverse feedback loop from the deployed Dynamics 365 environment back to the development cycle for future updates.
3. Use clear labels for each component:
- External services (Dynamics 365 CE, spkl tools).
5. To include integration points:
- Authentication and early-bound generation process (using tools like “dataverse-auth” and “dataverse-gen”) as part of the cycle, showing their connection between the development and deployment modules.

- Since this is not a typical full-stack web application but a Dynamics 365 webresource template, focus on:
- The toolchain and process from authoring to deployment.
- Separation between code development (with a modular structure in TSWebresourceTemplate) and the Dynamics solution packaging (spklSolution).
- The use of spkl and Dynamics SDK tools as crucial linking components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% TSWebresourceTemplate (Development)
    subgraph "TSWebresourceTemplate (Development)"
        subgraph "Source Code"
            Forms["Forms"]:::source
            Ribbons["Ribbons"]:::source
            Services["Services"]:::source
            DataModels["Data Models"]:::source
            Constants["Constants"]:::source
        end
        subgraph "Build Tools & Config"
            WebpackCommon["Webpack Common"]:::build
            WebpackDev["Webpack Dev"]:::build
            WebpackProd["Webpack Prod"]:::build
            TSConfig["TypeScript Config"]:::build
            ESLint["ESLint Config"]:::build
            Prettier["Prettier Config"]:::build
        end
        BuildArtifacts["Build Artifacts"]:::build
    end

    %% spklSolution (Deployment)
    subgraph "spklSolution (Deployment)"
        subgraph "Deployment Scripts"
            DeployWebresources["Deploy Webresources"]:::deploy
            DeployPlugins["Deploy Plugins"]:::deploy
        end
        DeploymentConfig["Deployment Configuration"]:::deploy
        DynamicsSDK["Dynamics SDK Tools"]:::deploy
        AuthGen["Auth & EarlyBound Gen"]:::deploy
    end

    %% External Dynamics 365 Environment
    Dynamics365["Dynamics 365 CE Environment"]:::external

    %% Connections in Development
    Forms -->|"code"| WebpackCommon
    Ribbons -->|"code"| WebpackDev
    Services -->|"code"| WebpackProd
    DataModels -->|"code"| TSConfig
    Constants -->|"code"| ESLint
    %% Link Build Tools to Build Artifacts
    WebpackCommon -->|"build"| BuildArtifacts
    WebpackDev -->|"build"| BuildArtifacts
    WebpackProd -->|"build"| BuildArtifacts
    TSConfig -->|"compile"| BuildArtifacts
    ESLint -->|"lint"| BuildArtifacts
    Prettier -->|"format"| BuildArtifacts

    %% Deployment Flow
    BuildArtifacts -->|"deploy"| DeployWebresources
    %% Deployment Scripts trigger deployment configuration and SDK Tools
    DeployWebresources -->|"uses"| DeploymentConfig
    DeployWebresources -->|"calls"| DynamicsSDK
    %% Dynamics SDK Tools interact with Dynamics 365
    DynamicsSDK -->|"package & deploy"| Dynamics365
    AuthGen -->|"authenticate & generate"| Dynamics365
    %% Feedback Loop
    Dynamics365 -->|"feedback"| Forms

    %% Click Events for TSWebresourceTemplate Source Code
    click Forms "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/src/forms/Form.ts"
    click Ribbons "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/src/ribbons/SendRequestRibbon.ts"
    click Services "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/src/services/DataverseService.ts"
    click DataModels "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/src/dataModels/dataModel.ts"
    click Constants "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/src/constants/envVariables.ts"

    %% Click Events for Build Tools & Config
    click WebpackCommon "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/webpack.common.js"
    click WebpackDev "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/webpack.dev.js"
    click WebpackProd "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/webpack.prod.js"
    click TSConfig "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/tsconfig.json"
    click ESLint "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/.eslintrc.json"
    click Prettier "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/.prettierrc.json"

    %% Click Event for Build Artifacts
    click BuildArtifacts "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/TSWebresourceTemplate/dist/WebresourceToName.js"

    %% Click Events for Deployment Scripts
    click DeployWebresources "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/spklSolution/spkl/deploy-webresources.bat"
    click DeployPlugins "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/spklSolution/spkl/deploy-plugins.bat"

    %% Click Event for Deployment Configuration
    click DeploymentConfig "https://github.com/crptbddst/typescriptwebresourcetemplate/blob/main/spklSolution/spkl.json"

    %% Click Event for Dynamics SDK Tools
    click DynamicsSDK "https://github.com/crptbddst/typescriptwebresourcetemplate/tree/main/spklSolution/bin/coretools"

    %% Styling classes
    classDef source fill:#cce5ff,stroke:#0066cc,stroke-width:2px;
    classDef build fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef deploy fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#dc3545,stroke-width:2px;
```
