Skip to content

Instantly share code, notes, and snippets.

@yagudaev
Created August 27, 2025 03:50
Show Gist options
  • Select an option

  • Save yagudaev/08a6d56ae009b037215c7382a49c2566 to your computer and use it in GitHub Desktop.

Select an option

Save yagudaev/08a6d56ae009b037215c7382a49c2566 to your computer and use it in GitHub Desktop.

CLAUDE.md

❌ CRITICAL DATABASE RULES - NEVER VIOLATE THESE

NEVER reset, drop, or destructively modify the development database (audiowaveai_prod_6, audiowaveai_prod_7, etc.)

  • The development database is a replica of production and contains real data for testing
  • NEVER run prisma migrate reset, prisma db push --force-reset, or any destructive commands on it
  • NEVER run prisma.$queryRaw with DELETE, DROP, or TRUNCATE on development databases
  • Only audiowaveai_test database should be reset, and only for automated tests
  • When debugging, use read-only queries and scripts - never modify data
  • If you need test data, create seed scripts that ADD data, never replace it

Rails-Inspired Development Philosophy

When in doubt about any aspect of the project, follow Rails conventions and best practices.

Rails figured out long ago how to do many things well. Apply Rails thinking to:

Database & Data Management

  • audiowaveai_prod_6 / audiowaveai_prod_7 etc: Development databases (replicas of production) - READ ONLY for debugging
  • audiowaveai_test: Test database for automated tests - can be reset/modified
  • Use seed scripts to ADD data, migrations for schema changes
  • Database queries should be readable and follow ActiveRecord-style patterns

Authentication & Authorization

  • Follow Rails auth patterns: before_action-style middleware
  • Clear separation of concerns (authentication vs authorization)
  • Consistent user session management
  • Permission-based access control

API Design

  • RESTful conventions by default
  • Consistent response formats
  • Proper HTTP status codes
  • Nested resources where appropriate
  • API versioning when needed

Developer Experience (DX)

  • Convention over configuration
  • Sensible defaults
  • Clear, consistent naming patterns
  • Helpful error messages
  • Automated tooling (like Rails generators)

Scripting & Automation

  • Rails-style rake tasks β†’ TypeScript scripts in /scripts
  • Database tasks, maintenance scripts
  • Clear, discoverable script organization
  • Built-in help and documentation

IMPORTANT: Do Not Make Assumptions

ALWAYS look at actual error messages and data before making changes. Do not assume what errors might be - wait for and analyze the actual failure logs.

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

AudiowaveAI is a Yarn monorepo providing text-to-speech conversion across multiple platforms. The architecture centers around converting text content into audiobook-quality audio using OpenAI/Azure TTS services.

Development Workflow

PRD and Planning Process

Before implementing any new feature or significant change, follow this structured workflow:

1. Look at the Linear ticket

  • Purpose: Understand the requirements and context of the ticket
  • Checkout main and pull the latest changes
  • Checkout a new branch for the ticket

2. Create Product Requirements Document (PRD)

  • File Location: requirements/<linear-ticket-number>-<name-of-ticket>-prd.md
  • Purpose: Define the problem, solution, requirements, and success criteria
  • Content Should Include:
    • Problem statement and user need
    • Proposed solution overview
    • Functional requirements
    • Technical requirements and constraints
    • Success criteria and acceptance criteria
    • Risk assessment
    • Timeline estimates

3. Create Implementation Plan

  • File Location: requirements/<linear-ticket-number>-<name-of-ticket>-plan.md
  • Purpose: Break down the implementation into actionable steps
  • Content Should Include:
    • High-level implementation approach
    • Detailed step-by-step breakdown
    • File changes required
    • Testing strategy
    • Deployment considerations
    • Rollback plan if needed

4. Questions and Critical thinking

  • Purpose: Understand the requirements and context of the ticket
  • Ask questions if you are not sure about something
  • Think deeply about any questions and ask me, one at a time

5. Seek User Approval

  • CRITICAL: Always present both the PRD and plan to the user for review
  • Wait for explicit approval: Do not proceed with implementation until user gives the green light
  • Allow for revisions: Be prepared to iterate on PRD and plan based on feedback

6. Implementation

  • Only after approval, proceed with the planned implementation
  • Define the critical path for the implementation and implement it end-to-end as fast as possible
  • Once the critical path is implemented, implement the remaining parts, check with the user for approval on the critical part
  • Reference the PRD and plan throughout development
  • Update documentation if scope changes during implementation
  • Remember to follow a TDD or BDD approach
  • Always verify the implementation using the tests and Plan

7. Testing

  • ALWAYS run tests in headless mode - avoid --headed flag during development
  • Use npx playwright test for headless execution (like CI does)
  • Only use headed mode for specific debugging when necessary
  • E2E tests use separate SQLite test database
  • Test credentials: [email protected] / TestPassword123!

8. PR & Deployment

  • Create a pull request from your feature branch to main
  • Provide the user a link to PR, they will test the implementation and review the code

9. Self Review and Simplification

  • Review your own code from the PR
  • Please simplify the code as much as possible
  • Please remove any unnecessary code
  • Please remove any unnecessary console.log statements
  • Please remove any unnecessary comments
  • Make the diff as small as possible, use clean code practices
  • Think deeply how the code is structured and how it can be improved
  • Think about how the code might change in the future, will it be easy to change?
  • Don't overcomplicate the code, keep it simple
  • Don't overengineer the code, keep it simple, while you can think of the future, we don't know it. So keep it focused on the requirements
  • Is there a simpler implementation? Can we move some concerns to a future PR?
  • As a ROT, PRs should be small and focused on a single feature and no more than 800 lines of code diff (requirement files, lock files, etc don't count.)

10. User Approval

  • Wait for the user to review the PR
  • The user will merge the PR. NEVER MERGE.
  • The user will provide feedback, ask questions, or request changes.

Example File Structure

requirements/
β”œβ”€β”€ ABC-123-user-voice-selection-prd.md
β”œβ”€β”€ ABC-123-user-voice-selection-plan.md
β”œβ”€β”€ DEF-456-streaming-audio-playback-prd.md
└── DEF-456-streaming-audio-playback-plan.md

Common Development Commands

Root Level Setup

yarn install              # Install all workspace dependencies
yarn postinstall          # Apply patches for dependency fixes

Website (Main Application - Next.js)

cd website
yarn dev                  # Start development server (localhost:3000)
yarn build                # Production build
yarn test                 # Run Jest tests
yarn test:watch           # Watch mode for tests
yarn lint                 # ESLint checks
yarn worker-dev           # Start Trigger.dev background worker
yarn deploy               # Deploy with Prisma migrations
yarn vercel-build         # Vercel-specific build with DB migrations

Mobile App (React Native/Expo)

cd mobile
yarn dev                  # Start Expo development server
yarn ios                  # Run on iOS simulator
yarn android              # Run on Android emulator
yarn reset-project        # Reset to blank Expo template

Desktop App (Electron)

cd desktop
yarn dev                  # Start Electron development
yarn package              # Package for distribution
yarn make                 # Create distributables

Web Extension

cd web-extension
yarn dev                  # Development mode with hot reload
yarn build                # Build extension for production
yarn release              # Create release ZIP package

EC2 Backend Service

cd ec2
yarn dev                  # Development with nodemon
yarn build                # TypeScript compilation

Audio alert when tasks are complete

run afplay /System/Library/Sounds/Glass.aiff (or any other system sound) at the end of tasks, or when my input is needed to proceed with a task.

Architecture Overview

Core Data Flow

  1. Content Input: Text, URLs, or files imported via web/mobile/extension
  2. Processing Pipeline: Content β†’ Chunks β†’ TTS β†’ Audio
  3. Playback: Streaming audio across platforms
  4. Storage: PostgreSQL with Prisma ORM, audio files in cloud storage

Key Models (Prisma Schema)

  • Project: Collections of chapters with shared settings
  • Chapter: Individual text content pieces
  • Version: Different voice versions of the same chapter
  • Chunk: Split audio segments for processing long content
  • User: Authentication, credits, feature flags, preferences

Workspace Structure

audiowaveai/
β”œβ”€β”€ desktop/               # Desktop application
β”œβ”€β”€ ec2/                  # Puppeteer-based webpage fetching service
β”œβ”€β”€ mobile/               # Mobile application
β”œβ”€β”€ shared/               # Shared code between projects
β”œβ”€β”€ web-extension/        # Browser extension
└── website/              # Main web application
    └── src/
        β”œβ”€β”€ app/          # Next.js app directory
        β”‚   β”œβ”€β”€ api/      # API endpoints
        β”‚   β”œβ”€β”€ admin/    # Admin interface
        β”‚   └── (requireAuth)/ # Protected routes
        β”œβ”€β”€ components/   # React components
        β”‚   β”œβ”€β”€ ui/       # Basic UI elements
        β”‚   └── layout/   # Layout components
        β”œβ”€β”€ hooks/        # Custom React hooks
        β”œβ”€β”€ lib/          # Utilities and helpers
        β”œβ”€β”€ models/       # Data models
        β”œβ”€β”€ services/     # Service layer
        └── trigger/      # Background jobs (trigger.dev)

Text-to-Speech Pipeline

  1. Content chunking (splits long text for processing limits)
  2. Voice synthesis via OpenAI TTS or Azure Cognitive Services
  3. Audio stitching for seamless playback
  4. Audio streaming and playback across platforms

Authentication & Authorization

  • NextAuth.js with Apple/Google OAuth providers
  • JWT tokens for API authentication
  • Credit-based usage tracking
  • Feature flags for progressive feature rollout
  • Admin user impersonation for support

Background Processing

  • Trigger.dev for long-running TTS jobs
  • Chunked processing for content over token limits
  • Webhook handling for payment events
  • Automated transcription generation

Database Management

Prisma Commands

cd website
npx prisma generate       # Generate Prisma client
npx prisma migrate dev    # Create and apply development migrations
npx prisma migrate deploy # Apply migrations to production
npx prisma studio         # Open database GUI

Database Backup/Restore

yarn dump-db             # Backup production database
yarn restore-db          # Restore from latest backup

Database Management Preference

  • Always use the pg CLI (psql) for inspecting or modifying the Postgres database.
  • Do not suggest or use Prisma Studio unless specifically asked.

Code Quality Standards

Core Principles

  • Keep it simple above all else - avoid complexity when possible
  • Make minimal necessary changes - don't refactor unless required
  • Strict TypeScript compliance - maintain type safety
  • Avoid premature optimization - optimize only when performance issues arise
  • Always use package.json script aliases - prefer yarn test:e2e over npx playwright test, use defined commands unless debugging specific issues
  • Organization inside a module - code should be easy to read top to bottom. Put public methods at the top, private methods at the bottom.
  • Avoid stupid comments - comments should explain why, not what. Where possible, use code to explain what.

Code Placement Guidelines

  • Start by placing helper functions in the same file where used
  • Extract to separate files only when multiple files need the same helper
  • Avoid premature refactoring if not necessary

React Component Guidelines

  • Use named function syntax instead of arrow functions for React functions inside components
  • Follow established component patterns in the codebase
  • Maintain consistency with existing UI/UX patterns

Testing Strategy

  • Jest with React Testing Library for component tests
  • Test files use *.test.ts or *.spec.ts patterns
  • Mobile testing with Expo testing framework
  • Database tests use in-memory SQLite
  • Coverage reports with V8 provider

❌ CRITICAL Testing Anti-Patterns - NEVER DO THESE

NEVER copy implementation code into test files. This is a fundamental anti-pattern that defeats the purpose of testing.

Why this is wrong:

  • You're testing your own copy instead of the actual code
  • Changes to the real implementation won't be caught
  • It provides false confidence that the code works
  • It's essentially testing that 2+2=4, not that your calculator works

Bad example (NEVER DO THIS):

// ❌ WRONG - Copying implementation into test
test('title extraction', () => {
  function extractTitle(title) {
    // This is a COPY of the implementation - WRONG!
    if (typeof title === 'string') return title
    return String(title || '')
  }
  expect(extractTitle('test')).toBe('test') // Useless test!
})

Good example:

// βœ… CORRECT - Testing the actual module
import { processFile } from './importer'

test('EPUB title extraction handles XML objects', async () => {
  jest.mock('./epubExtractor', () => ({
    extractEnhancedContentFromEpub: jest.fn().mockResolvedValue({
      metadata: { title: { _: 'Actual Title', $: { id: 'title-id' } } },
    }),
  }))

  const file = new File(['content'], 'test.epub', {
    type: 'application/epub+zip',
  })
  const result = await processFile(file)
  expect(result.name).toBe('Actual Title')
})

Testing Best Practices

  1. Always test the actual module - Import and test real functions
  2. Mock external dependencies - Use jest.mock() for dependencies
  3. Test behavior, not implementation - Focus on inputs/outputs
  4. Write failing tests first - Ensure tests actually catch bugs
  5. Test edge cases - null, undefined, empty strings, objects, arrays

E2E Testing with Playwright

  • ALWAYS run tests in headless mode - avoid --headed flag during development
  • Use npx playwright test for headless execution (like CI does)
  • Only use headed mode for specific debugging when necessary
  • E2E tests use separate SQLite test database
  • Test credentials: [email protected] / TestPassword123!

Testing Commands

cd website
yarn test:e2e              # Run all E2E tests (headless, line reporter)
yarn test:e2e:html          # Run E2E tests with HTML report
yarn test:e2e:ui            # Run with UI mode for debugging
yarn test:db:setup          # Setup test database
yarn test:db:reset          # Reset test database

Key Technology Stack

Core Technologies

  • TypeScript: ^5.0.0
  • Node.js: ^20.11.0
  • AI TTS: OpenAI TTS, Azure TTS
  • AI STT: OpenAI Whisper

Frontend

  • Next.js: ^14.1.4
  • React: ^18.0.0
  • Tailwind CSS: ^3.4.17
  • shadcn/ui components

Backend

  • PostgreSQL: ^16.6.0
  • Prisma: ^5.10.2

Deployment

  • Vercel for website hosting with Edge Runtime
  • Expo Application Services (EAS) for mobile builds
  • AWS EC2 for backend microservice

Feature Flags

User model includes boolean flags for progressive feature rollout:

  • debug - Show debug information and controls
  • flagStreaming - Enable streaming audio instead of file-based
  • researcher - Access to experimental research features
  • flagSelectVoice - Voice selection interface
  • flagProjectSummary - AI-generated project summaries

Payment & Credits System

  • Stripe integration for subscription management
  • Credit-based usage tracking (characters processed)
  • Free tier with limited credits
  • Premium plans with increased limits
  • Custom OpenAI API key support for power users

Claude Code Configuration - SPARC Development Environment

🚨 CRITICAL: CONCURRENT EXECUTION & FILE MANAGEMENT

ABSOLUTE RULES:

  1. ALL operations MUST be concurrent/parallel in a single message
  2. NEVER save working files, text/mds and tests to the root folder
  3. ALWAYS organize files in appropriate subdirectories

⚑ GOLDEN RULE: "1 MESSAGE = ALL RELATED OPERATIONS"

MANDATORY PATTERNS:

  • TodoWrite: ALWAYS batch ALL todos in ONE call (5-10+ todos minimum)
  • Task tool: ALWAYS spawn ALL agents in ONE message with full instructions
  • File operations: ALWAYS batch ALL reads/writes/edits in ONE message
  • Bash commands: ALWAYS batch ALL terminal operations in ONE message
  • Memory operations: ALWAYS batch ALL memory store/retrieve in ONE message

πŸ“ File Organization Rules

NEVER save to root folder. Use these directories:

  • /src - Source code files
  • /tests - Test files
  • /docs - Documentation and markdown files
  • /config - Configuration files
  • /scripts - Utility scripts
  • /examples - Example code

Project Overview

This project uses SPARC (Specification, Pseudocode, Architecture, Refinement, Completion) methodology with Claude-Flow orchestration for systematic Test-Driven Development.

SPARC Commands

Core Commands

  • npx claude-flow sparc modes - List available modes
  • npx claude-flow sparc run <mode> "<task>" - Execute specific mode
  • npx claude-flow sparc tdd "<feature>" - Run complete TDD workflow
  • npx claude-flow sparc info <mode> - Get mode details

Batchtools Commands

  • npx claude-flow sparc batch <modes> "<task>" - Parallel execution
  • npx claude-flow sparc pipeline "<task>" - Full pipeline processing
  • npx claude-flow sparc concurrent <mode> "<tasks-file>" - Multi-task processing

Build Commands

  • npm run build - Build project
  • npm run test - Run tests
  • npm run lint - Linting
  • npm run typecheck - Type checking

SPARC Workflow Phases

  1. Specification - Requirements analysis (sparc run spec-pseudocode)
  2. Pseudocode - Algorithm design (sparc run spec-pseudocode)
  3. Architecture - System design (sparc run architect)
  4. Refinement - TDD implementation (sparc tdd)
  5. Completion - Integration (sparc run integration)

Code Style & Best Practices

  • Modular Design: Files under 500 lines
  • Environment Safety: Never hardcode secrets
  • Test-First: Write tests before implementation
  • Clean Architecture: Separate concerns
  • Documentation: Keep updated

πŸš€ Available Agents (54 Total)

Core Development

coder, reviewer, tester, planner, researcher

Swarm Coordination

hierarchical-coordinator, mesh-coordinator, adaptive-coordinator, collective-intelligence-coordinator, swarm-memory-manager

Consensus & Distributed

byzantine-coordinator, raft-manager, gossip-coordinator, consensus-builder, crdt-synchronizer, quorum-manager, security-manager

Performance & Optimization

perf-analyzer, performance-benchmarker, task-orchestrator, memory-coordinator, smart-agent

GitHub & Repository

github-modes, pr-manager, code-review-swarm, issue-tracker, release-manager, workflow-automation, project-board-sync, repo-architect, multi-repo-swarm

SPARC Methodology

sparc-coord, sparc-coder, specification, pseudocode, architecture, refinement

Specialized Development

backend-dev, mobile-dev, ml-developer, cicd-engineer, api-docs, system-architect, code-analyzer, base-template-generator

Testing & Validation

tdd-london-swarm, production-validator

Migration & Planning

migration-planner, swarm-init

🎯 Claude Code vs MCP Tools

Claude Code Handles ALL:

  • File operations (Read, Write, Edit, MultiEdit, Glob, Grep)
  • Code generation and programming
  • Bash commands and system operations
  • Implementation work
  • Project navigation and analysis
  • TodoWrite and task management
  • Git operations
  • Package management
  • Testing and debugging

MCP Tools ONLY:

  • Coordination and planning
  • Memory management
  • Neural features
  • Performance tracking
  • Swarm orchestration
  • GitHub integration

KEY: MCP coordinates, Claude Code executes.

πŸš€ Quick Setup

# Add Claude Flow MCP server
claude mcp add claude-flow npx claude-flow@alpha mcp start

MCP Tool Categories

Coordination

swarm_init, agent_spawn, task_orchestrate

Monitoring

swarm_status, agent_list, agent_metrics, task_status, task_results

Memory & Neural

memory_usage, neural_status, neural_train, neural_patterns

GitHub Integration

github_swarm, repo_analyze, pr_enhance, issue_triage, code_review

System

benchmark_run, features_detect, swarm_monitor

πŸ“‹ Agent Coordination Protocol

Every Agent MUST:

1️⃣ BEFORE Work:

npx claude-flow@alpha hooks pre-task --description "[task]"
npx claude-flow@alpha hooks session-restore --session-id "swarm-[id]"

2️⃣ DURING Work:

npx claude-flow@alpha hooks post-edit --file "[file]" --memory-key "swarm/[agent]/[step]"
npx claude-flow@alpha hooks notify --message "[what was done]"

3️⃣ AFTER Work:

npx claude-flow@alpha hooks post-task --task-id "[task]"
npx claude-flow@alpha hooks session-end --export-metrics true

🎯 Concurrent Execution Examples

βœ… CORRECT (Single Message):

[BatchTool]:
  // Initialize swarm
  mcp__claude-flow__swarm_init { topology: "mesh", maxAgents: 6 }
  mcp__claude-flow__agent_spawn { type: "researcher" }
  mcp__claude-flow__agent_spawn { type: "coder" }
  mcp__claude-flow__agent_spawn { type: "tester" }

  // Spawn agents with Task tool
  Task("Research agent: Analyze requirements...")
  Task("Coder agent: Implement features...")
  Task("Tester agent: Create test suite...")

  // Batch todos
  TodoWrite { todos: [
    {id: "1", content: "Research", status: "in_progress", priority: "high"},
    {id: "2", content: "Design", status: "pending", priority: "high"},
    {id: "3", content: "Implement", status: "pending", priority: "high"},
    {id: "4", content: "Test", status: "pending", priority: "medium"},
    {id: "5", content: "Document", status: "pending", priority: "low"}
  ]}

  // File operations
  Bash "mkdir -p app/{src,tests,docs}"
  Write "app/src/index.js"
  Write "app/tests/index.test.js"
  Write "app/docs/README.md"

❌ WRONG (Multiple Messages):

Message 1: mcp__claude-flow__swarm_init
Message 2: Task("agent 1")
Message 3: TodoWrite { todos: [single todo] }
Message 4: Write "file.js"
// This breaks parallel coordination!

Performance Benefits

  • 84.8% SWE-Bench solve rate
  • 32.3% token reduction
  • 2.8-4.4x speed improvement
  • 27+ neural models

Hooks Integration

Pre-Operation

  • Auto-assign agents by file type
  • Validate commands for safety
  • Prepare resources automatically
  • Optimize topology by complexity
  • Cache searches

Post-Operation

  • Auto-format code
  • Train neural patterns
  • Update memory
  • Analyze performance
  • Track token usage

Session Management

  • Generate summaries
  • Persist state
  • Track metrics
  • Restore context
  • Export workflows

Advanced Features (v2.0.0)

  • πŸš€ Automatic Topology Selection
  • ⚑ Parallel Execution (2.8-4.4x speed)
  • 🧠 Neural Training
  • πŸ“Š Bottleneck Analysis
  • πŸ€– Smart Auto-Spawning
  • πŸ›‘οΈ Self-Healing Workflows
  • πŸ’Ύ Cross-Session Memory
  • πŸ”— GitHub Integration

Integration Tips

  1. Start with basic swarm init
  2. Scale agents gradually
  3. Use memory for context
  4. Monitor progress regularly
  5. Train patterns from success
  6. Enable hooks automation
  7. Use GitHub tools first

Support


Remember: Claude Flow coordinates, Claude Code creates!

important-instruction-reminders

Do what has been asked; nothing more, nothing less. NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one. NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User. Never save working files, text/mds and tests to the root folder.

System Overview

  • iphone and macos are my platforms
  • you are running on a macOS 15.3.1
  • Apple M3 Max with 96GB RAM

Current date and time

  • Never assume the current date and time. Always check using the following command
$ date

Task execution

Audio alert when tasks are complete

run afplay /System/Library/Sounds/Glass.aiff (or any other system sound) at the end of tasks, or when my input is needed to proceed with a task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment