How canva-sdks/canva-apps-sdk-starter-kit works
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.