Skip to content
twinmind-reference-architecture logo

TwinMind Reference Architecture

twinmind-reference-architecture

Implement TwinMind reference architecture with best-practice project layout. Use when designing new TwinMind integrations, reviewing project structure, or establishing architecture standards for meeting AI applications. Trigger with phrases like "twinmind architecture", "twinmind best practices",...

SKILL.md

Full skill instructions

TwinMind Reference Architecture

Overview

Production-ready architecture patterns for TwinMind meeting AI integrations.

Prerequisites

  • Understanding of layered architecture
  • TwinMind API knowledge
  • TypeScript project setup
  • Testing framework configured

Project Structure

my-twinmind-project/
├── src/
│   ├── twinmind/
│   │   ├── client.ts           # Singleton client wrapper
│   │   ├── config.ts           # Environment configuration
│   │   ├── types.ts            # TypeScript types
│   │   ├── errors.ts           # Custom error classes
│   │   └── handlers/
│   │       ├── webhooks.ts     # Webhook handlers
│   │       └── events.ts       # Event processing
│   ├── services/
│   │   └── meeting/
│   │       ├── index.ts        # Service facade
│   │       ├── transcription.ts # Transcription service
│   │       ├── summary.ts      # Summary generation
│   │       ├── actions.ts      # Action item extraction
│   │       └── cache.ts        # Caching layer
│   ├── integrations/
│   │   ├── calendar/           # Calendar sync
│   │   ├── slack/              # Slack notifications
│   │   ├── linear/             # Task management
│   │   └── email/              # Follow-up emails
│   ├── api/
│   │   ├── routes/
│   │   │   ├── meetings.ts     # Meeting endpoints
│   │   │   ├── transcripts.ts  # Transcript endpoints
│   │   │   └── webhooks.ts     # Webhook endpoint
│   │   └── middleware/
│   │       ├── auth.ts         # Authentication
│   │       ├── rateLimit.ts    # Rate limiting
│   │       └── validation.ts   # Request validation
│   ├── jobs/
│   │   ├── sync.ts             # Background sync job
│   │   ├── cleanup.ts          # Data cleanup job
│   │   └── reports.ts          # Report generation
│   └── utils/
│       ├── audio.ts            # Audio processing
│       ├── logging.ts          # Structured logging
│       └── metrics.ts          # Prometheus metrics
├── tests/
│   ├── unit/
│   │   └── twinmind/
│   ├── integration/
│   │   └── twinmind/
│   └── e2e/
│       └── meeting-flow.test.ts
├── config/
│   ├── twinmind.development.json
│   ├── twinmind.staging.json
│   └── twinmind.production.json
└── docs/
    ├── ARCHITECTURE.md
    └── RUNBOOK.md

Layer Architecture

┌─────────────────────────────────────────────────────┐
│                   API Layer                          │
│        (Controllers, Routes, Webhooks)               │
├─────────────────────────────────────────────────────┤
│                Service Layer                         │
│      (Business Logic, Orchestration)                 │
├─────────────────────────────────────────────────────┤
│              TwinMind Layer                          │
│       (Client, Types, Error Handling)                │
├─────────────────────────────────────────────────────┤
│             Integration Layer                        │
│    (Calendar, Slack, Linear, Email)                  │
├─────────────────────────────────────────────────────┤
│            Infrastructure Layer                      │
│       (Cache, Queue, Monitoring)                     │
└─────────────────────────────────────────────────────┘

Key Components

Step 1: Client Wrapper

// src/​twinmind/​client.ts
import axios, { AxiosInstance } from 'axios';
import { TwinMindConfig, loadConfig } from './​config';
import { TranscriptCache } from '../​services/​meeting/​cache';
import { MetricsCollector } from '../​utils/​metrics';

export class TwinMindService {
  private client: AxiosInstance;
  private cache: TranscriptCache;
  private metrics: MetricsCollector;
  private config: TwinMindConfig;

  constructor(config?: TwinMindConfig) {
    this.config = config || loadConfig();

    this.client = axios.create({
      baseURL: this.config.baseUrl,
      headers: {
        'Authorization': `Bearer ${this.config.apiKey}`,
        'Content-Type': 'application/​json',
      },
      timeout: this.config.timeout,
    });

    this.cache = new TranscriptCache(this.config.cacheOptions);
    this.metrics = new MetricsCollector('twinmind');

    this.setupInterceptors();
  }

  private setupInterceptors(): void {
    // Request logging
    this.client.interceptors.request.use((config) => {
      this.metrics.incrementCounter('requests', { method: config.method });
      return config;
    });

    // Response handling
    this.client.interceptors.response.use(
      (response) => {
        this.metrics.recordLatency(
          'request_duration',
          response.config.metadata?.startTime
        );
        return response;
      },
      (error) => {
        this.metrics.incrementCounter('errors', {
          status: error.response?.status || 'network',
        });
        throw error;
      }
    );
  }

  async transcribe(audioUrl: string, options?: TranscriptionOptions): Promise<Transcript> {
    return this.cache.getOrFetch(
      `transcript:${audioUrl}`,
      () => this.metrics.track(
        'transcribe',
        () => this.client.post('/​transcribe', { audio_url: audioUrl, ...options })
      )
    );
  }

  async summarize(transcriptId: string): Promise<Summary> {
    return this.metrics.track(
      'summarize',
      () => this.client.post('/​summarize', { transcript_id: transcriptId })
    );
  }

  async search(query: string, options?: SearchOptions): Promise<SearchResult[]> {
    return this.client.get('/​search', { params: { q: query, ...options } });
  }
}

// Singleton instance
let instance: TwinMindService | null = null;

export function getTwinMindService(): TwinMindService {
  if (!instance) {
    instance = new TwinMindService();
  }
  return instance;
}

Step 2: Service Layer

// src/​services/​meeting/​index.ts
import { getTwinMindService } from '../​../​twinmind/​client';
import { TranscriptionService } from './​transcription';
import { SummaryService } from './​summary';
import { ActionItemService } from './​actions';
import { CalendarIntegration } from '../​../​integrations/​calendar';
import { SlackIntegration } from '../​../​integrations/​slack';

export interface MeetingResult {
  transcriptId: string;
  transcript: Transcript;
  summary: Summary;
  actionItems: ActionItem[];
  participants: Participant[];
}

export class MeetingService {
  private twinmind = getTwinMindService();
  private transcription = new TranscriptionService();
  private summaryService = new SummaryService();
  private actionService = new ActionItemService();
  private calendar = new CalendarIntegration();
  private slack = new SlackIntegration();

  async processMeeting(
    audioUrl: string,
    options: ProcessMeetingOptions = {}
  ): Promise<MeetingResult> {
    // Get calendar context
    const calendarEvent = options.calendarEventId
      ? await this.calendar.getEvent(options.calendarEventId)
      : null;

    // Transcribe
    const transcript = await this.transcription.transcribe(audioUrl, {
      title: calendarEvent?.title || options.title,
      attendees: calendarEvent?.attendees,
    });

    // Generate summary and extract action items in parallel
    const [summary, actionItems] = await Promise.all([
      this.summaryService.generate(transcript.id),
      this.actionService.extract(transcript.id),
    ]);

    // Identify participants
    const participants = await this.identifyParticipants(
      transcript,
      calendarEvent?.attendees
    );

    // Notify if configured
    if (options.notifySlack) {
      await this.slack.notifyMeetingComplete({
        title: transcript.title,
        summary: summary.summary,
        actionItems,
      });
    }

    return {
      transcriptId: transcript.id,
      transcript,
      summary,
      actionItems,
      participants,
    };
  }

  private async identifyParticipants(
    transcript: Transcript,
    attendees?: string[]
  ): Promise<Participant[]> {
    // Match speakers to attendees
    const speakers = transcript.speakers || [];

    return speakers.map((speaker, index) => ({
      id: speaker.id,
      name: attendees?.[index] || speaker.name || `Speaker ${index + 1}`,
      speakingTime: this.calculateSpeakingTime(transcript.segments, speaker.id),
    }));
  }

  private calculateSpeakingTime(segments: Segment[], speakerId: string): number {
    return segments
      .filter(s => s.speaker_id === speakerId)
      .reduce((total, s) => total + (s.end - s.start), 0);
  }
}

Step 3: Error Boundary

// src/​twinmind/​errors.ts
export class TwinMindError extends Error {
  constructor(
    message: string,
    public readonly code: string,
    public readonly statusCode?: number,
    public readonly retryable: boolean = false,
    public readonly originalError?: Error
  ) {
    super(message);
    this.name = 'TwinMindError';
  }

  static fromApiError(error: any): TwinMindError {
    const status = error.response?.status;
    const message = error.response?.data?.message || error.message;
    const code = error.response?.data?.code || 'UNKNOWN';

    switch (status) {
      case 401:
        return new TwinMindError(message, 'AUTH_FAILED', status, false);
      case 429:
        return new TwinMindError(message, 'RATE_LIMITED', status, true);
      case 500:
      case 502:
      case 503:
        return new TwinMindError(message, 'SERVER_ERROR', status, true);
      default:
        return new TwinMindError(message, code, status, false, error);
    }
  }
}

export function wrapWithErrorHandling<T>(
  operation: () => Promise<T>
): Promise<T> {
  return operation().catch((error) => {
    throw TwinMindError.fromApiError(error);
  });
}

Step 4: Health Check

// src/​twinmind/​health.ts
export interface HealthStatus {
  status: 'healthy' | 'degraded' | 'unhealthy';
  checks: HealthCheck[];
  timestamp: Date;
}

export interface HealthCheck {
  name: string;
  status: 'pass' | 'warn' | 'fail';
  latencyMs?: number;
  message?: string;
}

export async function checkHealth(): Promise<HealthStatus> {
  const checks: HealthCheck[] = [];

  // Check TwinMind API
  const apiCheck = await checkApiHealth();
  checks.push(apiCheck);

  // Check cache
  const cacheCheck = await checkCacheHealth();
  checks.push(cacheCheck);

  // Check database
  const dbCheck = await checkDatabaseHealth();
  checks.push(dbCheck);

  // Determine overall status
  const hasFailure = checks.some(c => c.status === 'fail');
  const hasWarning = checks.some(c => c.status === 'warn');

  return {
    status: hasFailure ? 'unhealthy' : hasWarning ? 'degraded' : 'healthy',
    checks,
    timestamp: new Date(),
  };
}

async function checkApiHealth(): Promise<HealthCheck> {
  const start = Date.now();
  try {
    const service = getTwinMindService();
    await service.healthCheck();
    return {
      name: 'twinmind_api',
      status: 'pass',
      latencyMs: Date.now() - start,
    };
  } catch (error: any) {
    return {
      name: 'twinmind_api',
      status: 'fail',
      latencyMs: Date.now() - start,
      message: error.message,
    };
  }
}

Data Flow Diagram

                              ┌───────────────┐
                              │   Calendar    │
                              │   (Google)    │
                              └───────┬───────┘
                                      │ sync
┌──────────┐                 ┌────────▼────────┐
│  Client  │─────request────►│   API Gateway   │
│   App    │◄────response────│                 │
└──────────┘                 └────────┬────────┘
                                      │
                             ┌────────▼────────┐
                             │  Meeting        │
                             │  Service        │
                             └────────┬────────┘
                                      │
              ┌───────────────────────┼───────────────────────┐
              │                       │                       │
     ┌────────▼────────┐    ┌────────▼────────┐    ┌────────▼────────┐
     │  Transcription  │    │    Summary      │    │  Action Items   │
     │    Service      │    │    Service      │    │    Service      │
     └────────┬────────┘    └────────┬────────┘    └────────┬────────┘
              │                       │                       │
              └───────────────────────┼───────────────────────┘
                                      │
                             ┌────────▼────────┐
                             │   TwinMind      │
                             │     API         │
                             └────────┬────────┘
                                      │
              ┌───────────────────────┼───────────────────────┐
              │                       │                       │
     ┌────────▼────────┐    ┌────────▼────────┐    ┌────────▼────────┐
     │     Slack       │    │     Linear      │    │     Email       │
     │  (notifications)│    │    (tasks)      │    │  (follow-ups)   │
     └─────────────────┘    └─────────────────┘    └─────────────────┘

Configuration Management

// config/​twinmind.ts
export interface TwinMindConfig {
  apiKey: string;
  baseUrl: string;
  environment: 'development' | 'staging' | 'production';
  timeout: number;
  retries: number;
  cacheOptions: {
    enabled: boolean;
    ttlSeconds: number;
  };
  features: {
    diarization: boolean;
    autoSummary: boolean;
    actionItemExtraction: boolean;
  };
}

export function loadConfig(): TwinMindConfig {
  const env = process.env.NODE_ENV || 'development';
  const envConfig = require(`./​twinmind.${env}.json`);

  return {
    apiKey: process.env.TWINMIND_API_KEY!,
    baseUrl: process.env.TWINMIND_API_URL || 'https://api.twinmind.com/​v1',
    environment: env as any,
    timeout: parseInt(process.env.TWINMIND_TIMEOUT || '30000'),
    retries: parseInt(process.env.TWINMIND_RETRIES || '3'),
    ...envConfig,
  };
}

Output

  • Structured project layout
  • Client wrapper with caching and metrics
  • Service layer with business logic
  • Error boundary implemented
  • Health checks configured
  • Configuration management

Error Handling

IssueCauseSolution
Circular dependenciesWrong layeringSeparate concerns by layer
Config not loadingWrong pathsVerify config file locations
Type errorsMissing typesAdd TwinMind types
Test isolationShared stateUse dependency injection

Resources

Flagship Skills

For multi-environment setup, see twinmind-multi-env-setup.

More skills from Dicklesworthstone

environment-setup-guide logo
Dicklesworthstone/pi_agent_rust

environment-setup-guide

Guide developers through setting up development environments with proper tools, dependencies, and configurations

1.8K 0
View
exa-policy-guardrails logo
Dicklesworthstone/pi_agent_rust

exa-policy-guardrails

Implement Exa lint rules, policy enforcement, and automated guardrails. Use when setting up code quality rules for Exa integrations, implementing pre-commit hooks, or configuring CI policy checks for Exa best practices. Trigger with phrases like "exa policy", "exa lint", "exa guardrails", "exa be...

1.8K 0
View
documenso-ci-integration logo
Dicklesworthstone/pi_agent_rust

documenso-ci-integration

Configure CI/CD pipelines for Documenso integrations. Use when setting up automated testing, deployment pipelines, or continuous integration for Documenso projects. Trigger with phrases like "documenso CI", "documenso GitHub Actions", "documenso pipeline", "documenso automated testing".

1.8K 0
View
openrouter-model-availability logo
Dicklesworthstone/pi_agent_rust

openrouter-model-availability

Build check model availability and implement fallback chains. Use when building resilient systems or handling model outages. Trigger with phrases like 'openrouter availability', 'openrouter fallback', 'openrouter model down', 'openrouter health check'.

1.8K 0
View
langfuse-enterprise-rbac logo
Dicklesworthstone/pi_agent_rust

langfuse-enterprise-rbac

Configure Langfuse enterprise organization management and access control. Use when implementing team access controls, configuring organization settings, or setting up role-based permissions for Langfuse projects. Trigger with phrases like "langfuse RBAC", "langfuse teams", "langfuse organization"...

1.8K 0
View
cursor-compliance-audit logo
Dicklesworthstone/pi_agent_rust

cursor-compliance-audit

Execute compliance and security auditing for Cursor usage. Triggers on "cursor compliance", "cursor audit", "cursor security review", "cursor soc2", "cursor gdpr". Use when analyzing or auditing cursor compliance audit. Trigger with phrases like "cursor compliance audit", "cursor audit", "cursor".

1.8K 0
View
apollo-ci-integration logo
Dicklesworthstone/pi_agent_rust

apollo-ci-integration

Configure Apollo.io CI/CD integration. Use when setting up automated testing, continuous integration, or deployment pipelines for Apollo integrations. Trigger with phrases like "apollo ci", "apollo github actions", "apollo pipeline", "apollo ci/cd", "apollo automated tests".

1.8K 0
View
python-script logo
Dicklesworthstone/pi_agent_rust

python-script

Create robust Python automation with full logging and safety checks. Use when tasks need complex data processing, authenticated API work, conditional file operations, or error handling beyond simple shell commands.

1.8K 0
View
posthog-multi-env-setup logo
Dicklesworthstone/pi_agent_rust

posthog-multi-env-setup

Configure PostHog across development, staging, and production environments. Use when setting up multi-environment deployments, configuring per-environment secrets, or implementing environment-specific PostHog configurations. Trigger with phrases like "posthog environments", "posthog staging", "po...

1.8K 0
View
ai-agents-architect logo
Dicklesworthstone/pi_agent_rust

ai-agents-architect

Expert in designing and building autonomous AI agents. Masters tool use, memory systems, planning strategies, and multi-agent orchestration. Use when: build agent, AI agent, autonomous agent, tool use, function calling.

1.8K 0
View
insecure-deserialization-checker logo
Dicklesworthstone/pi_agent_rust

insecure-deserialization-checker

Validate insecure deserialization checker operations. Auto-activating skill for Security Fundamentals. Triggers on: insecure deserialization checker, insecure deserialization checker Part of the Security Fundamentals skill category. Use when working with insecure deserialization checker functiona...

1.8K 0
View
path-traversal-finder logo
Dicklesworthstone/pi_agent_rust

path-traversal-finder

Manage path traversal finder operations. Auto-activating skill for Security Fundamentals. Triggers on: path traversal finder, path traversal finder Part of the Security Fundamentals skill category. Use when working with path traversal finder functionality. Trigger with phrases like "path traversa...

1.8K 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View