# canva-sdks/canva-apps-sdk-starter-kit architecture

> Architecture diagram of the GitHub repository canva-sdks/canva-apps-sdk-starter-kit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/canva-sdks/canva-apps-sdk-starter-kit
- Repository: https://github.com/canva-sdks/canva-apps-sdk-starter-kit

## Overview

##### Main Components
- Frontend Application:
- The core boilerplate is in the “src” directory (src/app.tsx, src/index.tsx) that provides the main application code.
- Numerous examples in the “examples” folder show different UI interactions such as drag-and-drop, image editing, design token manipulation, and more. Each example (e.g., “app_element_children”, “app_embed_elements”, “drag_and_drop_image”) contains its own app.tsx and index.tsx.

- Backend Services:
- Some examples (e.g., “design_token”, “digital_asset_management”, “fetch”) include “backend” directories with server.ts and related code. These represent API endpoints that handle tasks like JWT verification and data fetching.
- The utilities under “utils/backend” further confirm modular design principles for backend operations.

- Build & Configuration Tools:
- Tools like “webpack.config.ts”, environment configuration (.env.template, .nvmrc), and scripts (in the “scripts” folder) are important for building and running the application.
- There are also testing tools (jest.config.js, tests directories) and lint/format configs (eslint.config.mjs, .prettierrc) which ensure code quality.

- Integration & Development Workflow:
- The README details integration with the Canva editor (using “CANVA_APP_ORIGIN” and “CANVA_BACKEND_HOST”), Hot Module Replacement (HMR) enabling rapid frontend updates, and HTTPS configuration (in the scripts/ssl folder).

##### Relationships and Interactions
- The Frontend communicates with:
- The Canva Editor/Developer Portal (external integration) for previewing apps.
- The backend API when examples that include server components are running (e.g., requests sent to http://localhost:3001).
- Backend services (when present) are structured to process API requests and facilitate secure data transmission (e.g., via JWT middleware in “utils/backend/jwt_middleware”).
- The build tools (Webpack, npm scripts) and configuration files manage bundling, environment configuration, and development server startup.
- The utility libraries (e.g., use_add_element, use_feature_support) in “utils” help abstract and manage common functionalities.

##### Architectural Patterns and Design Principles
- Modular Design: The separation into a core “src” folder and multiple “examples” shows how the starter kit is modular. Each example encapsulates specific features and best practices.
- Separation of Concerns: Frontend (React components, HMR enabled for development) is clearly split from backend services.
- Environment Configuration: Use of environment variables allows dynamic configuration for development vs. production, particularly for interactivity with Canva’s App Portal.
- Reusability & Extensibility: With utility libraries and common examples, developers can extend functionality or swap out components easily.

##### Relevant Technologies
- Frontend: React, TypeScript, and Webpack (with HMR option) for building and serving the app.
- Backend: Node.js with Express-like engine handling API routes (server.ts in examples) and JWT middleware.
- Tooling: ESLint, Prettier, Jest for testing, and npm scripts for running the development server or bundling the app.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend"
        CF["Core Frontend (src)"]:::frontend
        subgraph "Example Apps"
            EA["App Element Children Example"]:::example
            DD["Drag and Drop Image Example"]:::example
            OE["Other Example Apps"]:::example
        end
    end

    subgraph "Backend Services"
        DT["Design Token Backend API"]:::backend
        DAM["Digital Asset Management Backend API"]:::backend
        FA["Fetch API Backend Service"]:::backend
        JWT["JWT Middleware Utility"]:::backendutil
    end

    subgraph "Build & Configuration Tools"
        BC["Build Configuration"]:::build
        EC["Environment Configuration"]:::build
        DS["Development Scripts"]:::build
    end

    subgraph "Testing & Quality Assurance"
        TQ["Testing & QA Tools"]:::testing
    end

    External["Canva Editor/Developer Portal"]:::external

    %% Frontend interactions with Backend APIs
    CF -->|"API_request"| DT
    CF -->|"API_request"| DAM
    CF -->|"API_request"| FA

    %% Example Apps depend on Core Frontend
    EA -->|"Uses"| CF
    DD -->|"Uses"| CF
    OE -->|"Uses"| CF

    %% Frontend previews via external Canva Editor/Portal
    CF -->|"Preview"| External
    EA -->|"Preview"| External
    DD -->|"Preview"| External

    %% Backend Utilities: JWT Middleware usage
    DT -->|"Utilizes"| JWT
    DAM -->|"Utilizes"| JWT
    FA -->|"Utilizes"| JWT

    %% Build & Configuration dependencies
    BC -->|"Builds"| CF
    BC -->|"Builds"| DT
    EC -->|"Configures"| CF
    EC -->|"Configures"| DT
    DS -->|"Runs"| CF
    DS -->|"Runs"| DT

    %% Testing & QA dependency links
    TQ -->|"Tests"| CF
    TQ -->|"Tests"| DT

    %% Click Events
    click CF "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/blob/main/src/app.tsx"
    click EA "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/tree/main/examples/app_element_children"
    click DD "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/tree/main/examples/drag_and_drop_image"
    click DT "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/tree/main/examples/design_token/backend"
    click DAM "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/tree/main/examples/digital_asset_management/backend"
    click FA "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/tree/main/examples/fetch/backend"
    click JWT "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/tree/main/utils/backend/jwt_middleware"
    click BC "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/blob/main/webpack.config.ts"
    click EC "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/blob/main/.env.template"
    click DS "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/tree/main/scripts"
    click TQ "https://github.com/canva-sdks/canva-apps-sdk-starter-kit/blob/main/jest.config.js"

    %% Style Definitions
    classDef frontend fill:#f9f,stroke:#333,stroke-width:2px;
    classDef example fill:#bbf,stroke:#333,stroke-width:2px;
    classDef backend fill:#afa,stroke:#333,stroke-width:2px;
    classDef backendutil fill:#aaf,stroke:#333,stroke-width:2px;
    classDef build fill:#fea,stroke:#333,stroke-width:2px;
    classDef testing fill:#eef,stroke:#333,stroke-width:2px;
    classDef external fill:#ddd,stroke:#333,stroke-width:2px,stroke-dasharray: 5, 5;
```
