| name | canva-reference-architecture |
| description | Implement Canva Connect API reference architecture with best-practice project layout.
Use when designing new Canva integrations, reviewing project structure,
or establishing architecture standards for Canva applications.
Trigger with phrases like "canva architecture", "canva project structure",
"how to organize canva", "canva layout", "canva reference".
|
| allowed-tools | Read, Grep |
| version | 1.5.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","design","canva"] |
| compatibility | Designed for Claude Code |
Canva Reference Architecture
Overview
Production-ready architecture for Canva Connect API integrations. All interactions use the REST API at api.canva.com/rest/v1/* with OAuth 2.0 PKCE authentication.
Project Structure
my-canva-integration/
โโโ src/
โ โโโ canva/
โ โ โโโ client.ts # REST client wrapper with auto-refresh
โ โ โโโ auth.ts # OAuth 2.0 PKCE flow
โ โ โโโ types.ts # API request/response TypeScript types
โ โ โโโ errors.ts # CanvaAPIError class
โ โโโ services/
โ โ โโโ design.service.ts # Design creation, export, listing
โ โ โโโ asset.service.ts # Asset upload and management
โ โ โโโ template.service.ts # Brand template autofill (Enterprise)
โ โ โโโ folder.service.ts # Folder management
โ โโโ routes/
โ โ โโโ auth.ts # OAuth callback endpoints
โ โ โโโ designs.ts # Design CRUD routes
โ โ โโโ exports.ts # Export trigger/download routes
โ โ โโโ webhooks.ts # Webhook receiver
โ โโโ middleware/
โ โ โโโ auth.ts # Verify user has valid Canva token
โ โ โโโ rate-limit.ts # Client-side rate limit guard
โ โโโ store/
โ โ โโโ tokens.ts # Encrypted token storage (DB)
โ โโโ index.ts
โโโ tests/
โ โโโ mocks/
โ โ โโโ canva-server.ts # MSW mock server
โ โโโ unit/
โ โ โโโ design.service.test.ts
โ โโโ integration/
โ โโโ canva-api.test.ts
โโโ .env.example
โโโ package.json
Layer Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Routes Layer โ
โ (Express/Next.js โ HTTP in/out) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Service Layer โ
โ (Business logic, caching, validation) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Canva Client Layer โ
โ (REST calls, token refresh, retry) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Infrastructure Layer โ
โ (Token store, cache, queue) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Service Layer Pattern
import { CanvaClient } from '../canva/client';
import { LRUCache } from 'lru-cache';
export class DesignService {
private cache = <, >({ : , : });
() {}
() {
designType = opts. ===
? { : , : opts.! }
: { : , : opts.!, : opts.! };
..(, {
: ,
: .({
: designType,
: opts.,
...(opts. && { : opts. }),
}),
});
}
() {
cached = ..(id);
(cached) cached;
result = ..();
..(id, result);
result;
}
(: , : ): <[]> {
{ job } = ..(, {
: ,
: .({ : designId, format }),
});
.(job.);
}
(: , timeoutMs = ): <[]> {
start = .();
(.() - start < timeoutMs) {
{ job } = ..();
(job. === ) job.;
(job. === ) ();
( (r, ));
}
();
}
}