---
issue: 135
title: Cross-Language Type Definitions
analyzed: 2025-10-13T19:54:10Z
estimated_hours: 8
parallelization_factor: 1.5
---

# Parallel Work Analysis: Issue #135

## Overview

Create shared type definitions for data structures used in both TypeScript and Python codebases. This task involves identifying shared types, creating TypeScript canonical definitions, generating Python TypedDict equivalents, and documenting the synchronization process. Limited parallelization due to need for consistency between languages.

## Parallel Streams

### Stream A: TypeScript Type Definitions & Library Setup
**Scope**: Create TypeScript library structure and canonical type definitions
**Files**:
- `libs/shared/types/src/lib/supabase.ts` (create - database schema types)
- `libs/shared/types/src/lib/api.ts` (create - API request/response types)
- `libs/shared/types/src/lib/bot.ts` (create - bot configuration types)
- `libs/shared/types/src/index.ts` (create - barrel export)
- `libs/shared/types/project.json` (create/update - Nx project config)
- `libs/shared/types/tsconfig.json` (create - TypeScript config)
- `libs/shared/types/package.json` (create - package metadata)
- `tsconfig.base.json` (update - add path alias for @buzztrail/shared/types)
**Agent Type**: general-purpose
**Can Start**: immediately
**Estimated Hours**: 4h
**Dependencies**: none

**Rationale**: TypeScript types must be created first as they are the canonical source of truth. Setting up the library structure and creating all TypeScript definitions is the foundation for the Python equivalents.

### Stream B: Python TypedDict Definitions & Documentation
**Scope**: Create Python type equivalents and comprehensive synchronization documentation
**Files**:
- `libs/shared/types/types.py` (create - Python TypedDict definitions)
- `libs/shared/types/__init__.py` (create - Python package init)
- `libs/shared/types/TYPES.md` (create - synchronization documentation)
- `libs/shared/types/README.md` (create - library documentation with examples)
- `libs/shared/types/pyproject.toml` (create - Python project metadata)
**Agent Type**: general-purpose
**Can Start**: after Stream A completes (needs TypeScript types as reference)
**Estimated Hours**: 3h
**Dependencies**: Stream A (needs to see final TypeScript types)

**Rationale**: Python types must match TypeScript types exactly. Documentation needs complete picture of both implementations. Must wait for Stream A to complete to ensure accuracy.

### Stream C: Integration & Validation
**Scope**: Update bots to use shared types and validate end-to-end
**Files**:
- `apps/slide-system/bots/screenshare-bot/bot.py` (update imports)
- `apps/slide-system/bots/tavus-tool-forwarder/bot.py` (update imports)
- `apps/slide-system/src/lib/*.ts` (update to use shared types)
**Agent Type**: general-purpose
**Can Start**: after Stream B completes
**Estimated Hours**: 1h
**Dependencies**: Stream B (needs Python types ready)

**Rationale**: Integration requires both TypeScript and Python types to be complete. Validation ensures types work correctly in actual usage.

## Coordination Points

### Shared Files
Minimal overlap:
- No shared files between streams - clean separation
- Each stream owns its output files completely

### Sequential Requirements
1. **Stream A → Stream B**: Python types must exactly match TypeScript types
2. **Stream B → Stream C**: Integration needs both type systems ready
3. **Type consistency critical**: Manual verification needed between A and B

### Type Consistency Checks
Stream B must verify each Python type against TypeScript:
- Field names match exactly (including casing)
- Types map correctly (string→str, number→int/float, etc.)
- Optionality matches (T|null → Optional[T])
- Literal types match exactly
- Array types map to List[T]

## Conflict Risk Assessment

- **Very Low Risk**: Each stream works on completely different files
- **No shared files** being modified simultaneously
- **Clear dependencies** prevent premature integration
- **Manual verification** required for type consistency (not automatable yet)

## Parallelization Strategy

**Recommended Approach**: sequential with overlap

**Execution Plan**:
1. Start Stream A (TypeScript types) - **4 hours**
2. When A is ~75% done, start Stream B (Python types + docs) - **3 hours overlap**
   - Stream B can begin with types A has already completed
   - Stream B waits for A to fully complete before finalizing
3. Start Stream C (integration) when B completes - **1 hour**

**Why sequential with overlap?**
- TypeScript must be canonical source (A first)
- Python needs to match TypeScript exactly (B depends on A)
- Integration needs both ready (C depends on B)
- Small overlap possible: B can start on completed A types

## Expected Timeline

**With sequential + overlap execution**:
- Wall time: 4h (Stream A) + 2h (Stream B overlap) + 1h (Stream C) = **7 hours total**
- Total work: 8 hours
- Efficiency gain: **12.5% faster** than pure sequential

**Without any parallelization**:
- Wall time: 4h + 3h + 1h = **8 hours total**

**Parallelization factor**: 1.14x speedup (modest due to dependencies)

## Type Definition Patterns

### TypeScript Patterns
```typescript
// Database types - exact match to Supabase schema
export interface ConversationSession {
  id: string;
  tavus_conversation_id: string;
  status: 'generating_deck' | 'deck_ready' | 'bot_active' | 'completed';
  created_at: string;  // ISO 8601 timestamp
}

// API request/response types
export interface GenerateCustomDeckRequest {
  company: string;
  slides: SlideData[];
  template_id?: string;  // optional field
}

export interface SlideData {
  title: string;
  content: string;
}
```

### Python Patterns
```python
from typing import TypedDict, Literal, Optional, List

# Database types - exact TypeScript match
class ConversationSession(TypedDict):
    id: str
    tavus_conversation_id: str
    status: Literal['generating_deck', 'deck_ready', 'bot_active', 'completed']
    created_at: str  # ISO 8601 timestamp

# API types
class SlideData(TypedDict):
    title: str
    content: str

class GenerateCustomDeckRequest(TypedDict):
    company: str
    slides: List[SlideData]
    template_id: Optional[str]  # optional field using Optional
```

## Testing Strategy

### Stream A Validation
```bash
# TypeScript compilation check
pnpm nx typecheck shared-types

# Verify exports work
pnpm nx build shared-types
```

### Stream B Validation
```bash
# Python type checking
cd libs/shared/types
mypy types.py --strict

# Manual verification against TypeScript
# (automated comparison tool would be future work)
```

### Stream C Validation
```bash
# Verify TypeScript imports work
pnpm nx typecheck slide-system

# Verify Python imports work
cd apps/slide-system/bots/screenshare-bot
source .venv/bin/activate
mypy bot.py

cd ../tavus-tool-forwarder
source .venv/bin/activate
mypy bot.py
```

## Documentation Requirements

### TYPES.md Must Include
1. **Synchronization Process**
   - TypeScript-first workflow
   - Manual update checklist
   - Verification steps

2. **Type Mapping Reference**
   - Complete TypeScript → Python mapping table
   - Edge cases and gotchas
   - When to use Optional vs Union

3. **Usage Examples**
   - TypeScript import and usage
   - Python import and usage
   - Common patterns for each type

4. **Maintenance**
   - How to add new shared types
   - Versioning strategy
   - Breaking change protocol

## Notes

- **No automation yet**: Type synchronization is manual; future work could add code generation
- **Python path handling**: Bots may need sys.path updates to import from libs/shared/types
- **TypeScript path alias**: Must add `"@buzztrail/shared/types": ["libs/shared/types/src/index.ts"]` to tsconfig.base.json
- **Nx integration**: shared-types library needs proper project.json for Nx commands
- **Future enhancements**: Could add runtime validation (Zod for TS, Pydantic for Python)
- **Type evolution**: Document how to handle type changes without breaking existing code

## File Count Summary

| Stream | New Files | Modified Files | Total Operations |
|--------|-----------|----------------|------------------|
| A      | 7         | 1              | 8                |
| B      | 5         | 0              | 5                |
| C      | 0         | 3+             | 3+               |
| **Total** | **12** | **4+**        | **16+**         |
