# dedotdev/typink architecture

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

- Interactive diagram: https://gitdiagram.com/dedotdev/typink
- Repository: https://github.com/dedotdev/typink

## Overview

##### Main Project Components
- CLI Module (create-typink): Represented in the “packages/create-typink” folder. This component is responsible for scaffolding new projects, copying template files, and setting up initial Git and package configurations.
- Core Library (typink): Located in “packages/typink.” This module provides the heart of the functionality with:
– Typesafe React hooks for interacting with smart contracts (e.g., useContract, useBalance, etc.),
– Wallet and network providers (WalletProvider, ClientProvider, etc.),
– Contract helper utilities and network configurations.
- Smart Contract & Blockchain Interaction Layer: Notice the contract-related files (artifacts, types, and contract directories) that are used by both the core library and the example projects. These represent how the dApp communicates with ink! smart contracts on various networks (development, mainnet, testnet).
- Frontend/Application Demos: Found in the “examples” folder (both “demo” and “demo-subconnect”). These are full-stack dApp examples that integrate the UI (React components) with the typink hooks and providers, showcasing wallet integration and contract interactions.
- End-to-End (e2e) Testing: The “e2e” directory, which includes a folder for “zombienet” tests, Dockerfiles, and test scripts, represents the test infrastructure that simulates blockchain network interactions.
- CI/CD Pipelines & Configuration: The .github workflows and various configuration files (yarn, tsconfig, prettier, etc.) should be represented as supporting infrastructure influencing build, testing, and deployment processes.

a. Lay Out the Layers:
– Include the “CLI/Project Scaffolding” component to the side as it interacts with developers, helping them generate projects via create-typink.
– Finally, show the “Testing & CI Infrastructure” (e2e scripts, Docker, GitHub workflows) as connected utilities that validate the proper functioning of other components.

b. Data & Dependency Flows:
– Link the CLI component to the Core Library and Example Dapps by showing that it generates starter code and project setup (copying templates, including contract and UI scaffolding).

c. Architectural Patterns & Key Principles:
– Emphasize the separation of concerns: Frontend (UI) is separate from the core business logic (typink hooks, providers) and further detached from the blockchain interactions.
– Highlight that the system is built in a monorepo using a multi-package architecture (using Lerna, Yarn workspaces, etc.) to share common configurations and testing setups.
– Illustrate that the project enforces type safety (via Typescript) throughout, from contract interactions to the React front end.

d. Technologies and Frameworks:
– For the UI, note that React and Vite are used (as seen in examples).
– For type-safety and compile-time checks, show the reliance on Typescript.
– Mention Yarn as the package manager and the existence of CI workflows on GitHub.
– Include specific contract artifacts and Wallet Connector implementations (SubConnect, Talisman Connect) that offer extensibility for dApp development.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend/UI (Example dapps)"
        demo["Demo App (React/Vite)"]:::frontend
        demoSub["Demo Subconnect App (React)"]:::frontend
    end

    core["Typink Core Library"]:::core

    cli["CLI (create-typink)"]:::cli

    subgraph "Smart Contracts & Blockchain"
        contractDemo["Contracts (Demo)"]:::contract
        contractSub["Contracts (Demo Subconnect)"]:::contract
        contractE2E["Contracts (E2E)"]:::contract
        blockchain["Blockchain Networks (Dev/Mainnet/Testnet)"]:::contract
    end

    test_ci["E2E Testing & CI/CD"]:::test

    ci_cd["CI/CD & Config"]:::test

    %% Data & Dependency Flows
    demo -->|"ReactHooks&Providers"| core
    demoSub -->|"ReactHooks&Providers"| core

    cli -->|"ScaffoldStarter"| core
    cli -->|"ScaffoldsUI"| demo

    core -->|"CallsContracts"| contractDemo
    core -->|"CallsContracts"| contractSub
    core -->|"CallsContracts"| contractE2E
    core -->|"UsesNetworks"| blockchain

    test_ci -->|"Tests"| demo
    test_ci -->|"Tests"| demoSub
    test_ci -->|"Tests"| core
    test_ci -->|"Tests"| cli
    test_ci -->|"Tests"| contractDemo
    test_ci -->|"Tests"| contractSub
    test_ci -->|"Tests"| contractE2E
    test_ci -->|"Tests"| blockchain

    ci_cd -->|"Build&Deploy"| core
    ci_cd -->|"Build&Deploy"| cli

    %% Click Events
    click cli "https://github.com/dedotdev/typink/tree/main/packages/create-typink"
    click core "https://github.com/dedotdev/typink/tree/main/packages/typink"
    click demo "https://github.com/dedotdev/typink/tree/main/examples/demo"
    click demoSub "https://github.com/dedotdev/typink/tree/main/examples/demo-subconnect"
    click contractDemo "https://github.com/dedotdev/typink/tree/main/examples/demo/src/contracts"
    click contractSub "https://github.com/dedotdev/typink/tree/main/examples/demo-subconnect/src/contracts"
    click contractE2E "https://github.com/dedotdev/typink/tree/main/e2e/zombienet/src/contracts"
    click test_ci "https://github.com/dedotdev/typink/tree/main/e2e"
    click ci_cd "https://github.com/dedotdev/typink/blob/main/.github"

    %% Styles
    classDef frontend fill:#f9c,stroke:#333,stroke-width:2px;
    classDef core fill:#ccf,stroke:#333,stroke-width:2px;
    classDef cli fill:#cfc,stroke:#333,stroke-width:2px;
    classDef contract fill:#fcf,stroke:#333,stroke-width:2px;
    classDef test fill:#ffe,stroke:#333,stroke-width:2px;
```
