This guide covers the complete development workflow for AuthentiVoice, including environment setup, architecture patterns, and best practices for contributing to the codebase.

๐Ÿš€ Development Environment Setup

1

Prerequisites

Ensure you have all required tools installed:
  • Node.js 18+ for frontend development
  • Python 3.10+ for backend development
  • Docker for containerized services
  • ffmpeg for audio processing
  • Git for version control
2

Clone and Install

# Clone the repository
git clone https://github.com/authentivoice/authentivoice.git
cd authentivoice

# Install frontend dependencies
cd frontend && npm install

# Install backend dependencies
cd ../backend
pip install uv  # Fast Python package manager
uv sync
3

Environment Configuration

Create .env files from templates:
# Frontend
cp frontend/.env.example frontend/.env

# Backend
cp backend/.env.example backend/.env
Frontend (.env):
  • VITE_SUPABASE_URL - Your Supabase project URL
  • VITE_SUPABASE_ANON_KEY - Supabase anonymous key
  • VITE_API_BASE_URL - Backend API URL (default: http://localhost:8006)
  • VITE_API_KEY - API key for backend authentication
  • VITE_DEMO_ENABLED - Enable demo mode features
  • VITE_LOCAL_DEV - Enable local development features
Backend (.env):
  • GEMINI_API_KEY - Google AI API key for fraud analysis
  • S3_* - MinIO/S3 configuration for file storage
  • SUPABASE_* - Supabase service key and URL
  • API_KEY - Must match frontend API key
4

Start Development Servers

Use the Makefile for easy startup:
# Terminal 1 - Frontend (http://localhost:5173)
make run-frontend

# Terminal 2 - Backend (http://localhost:8006)
make run-backend

# Terminal 3 - Documentation (http://localhost:3333)
make docs-dev

๐Ÿ—๏ธ Architecture Overview

Frontend Architecture

frontend/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/         # Reusable UI components
โ”‚   โ”‚   โ”œโ”€โ”€ dashboard/     # Dashboard-specific components
โ”‚   โ”‚   โ”œโ”€โ”€ landing/       # Landing page components
โ”‚   โ”‚   โ”œโ”€โ”€ analysis/      # Call analysis components
โ”‚   โ”‚   โ”œโ”€โ”€ review/        # Review system components
โ”‚   โ”‚   โ””โ”€โ”€ ui/           # shadcn-ui base components
โ”‚   โ”œโ”€โ”€ pages/            # Route-based page components
โ”‚   โ”‚   โ”œโ”€โ”€ Index.tsx     # Landing page
โ”‚   โ”‚   โ”œโ”€โ”€ Dashboard.tsx # Main dashboard
โ”‚   โ”‚   โ”œโ”€โ”€ AnalysisDetail.tsx # Analysis details
โ”‚   โ”‚   โ””โ”€โ”€ Settings/     # Settings pages
โ”‚   โ”œโ”€โ”€ hooks/            # Custom React hooks
โ”‚   โ”‚   โ”œโ”€โ”€ useAnalyses.ts # Analysis data hooks
โ”‚   โ”‚   โ”œโ”€โ”€ useReviews.ts  # Review system hooks
โ”‚   โ”‚   โ””โ”€โ”€ useIntegrations.ts # Integration hooks
โ”‚   โ”œโ”€โ”€ lib/              # Utilities and configurations
โ”‚   โ”‚   โ”œโ”€โ”€ api.ts        # API client
โ”‚   โ”‚   โ”œโ”€โ”€ supabase.ts   # Supabase client
โ”‚   โ”‚   โ””โ”€โ”€ utils.ts      # Helper functions
โ”‚   โ”œโ”€โ”€ types/            # TypeScript definitions
โ”‚   โ”‚   โ”œโ”€โ”€ analysis.ts   # Analysis types
โ”‚   โ”‚   โ”œโ”€โ”€ review.ts     # Review types
โ”‚   โ”‚   โ””โ”€โ”€ integration.ts # Integration types
โ”‚   โ””โ”€โ”€ integrations/     # Third-party integrations
โ”œโ”€โ”€ public/               # Static assets
โ””โ”€โ”€ supabase/            # Database migrations and types

Backend Architecture

backend/
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ api/             # API route handlers
โ”‚   โ”‚   โ””โ”€โ”€ endpoints/   # Endpoint modules
โ”‚   โ”‚       โ”œโ”€โ”€ audio.py # Audio processing
โ”‚   โ”‚       โ”œโ”€โ”€ analysis.py # Analysis endpoints
โ”‚   โ”‚       โ”œโ”€โ”€ review.py # Review endpoints
โ”‚   โ”‚       โ””โ”€โ”€ integrations.py # Integration APIs
โ”‚   โ”œโ”€โ”€ core/            # Core business logic
โ”‚   โ”‚   โ”œโ”€โ”€ audio_processing/ # Audio manipulation
โ”‚   โ”‚   โ”œโ”€โ”€ transcription/    # Multiple engines
โ”‚   โ”‚   โ”œโ”€โ”€ analysis/         # AI fraud detection
โ”‚   โ”‚   โ””โ”€โ”€ review/          # Review logic
โ”‚   โ”œโ”€โ”€ services/        # External services
โ”‚   โ”‚   โ”œโ”€โ”€ s3_service.py    # File storage
โ”‚   โ”‚   โ”œโ”€โ”€ supabase_service.py # Database
โ”‚   โ”‚   โ”œโ”€โ”€ ai_service.py    # AI providers
โ”‚   โ”‚   โ””โ”€โ”€ notification_service.py # Alerts
โ”‚   โ”œโ”€โ”€ models/          # Pydantic models
โ”‚   โ”‚   โ”œโ”€โ”€ audio.py     # Audio models
โ”‚   โ”‚   โ”œโ”€โ”€ analysis.py  # Analysis models
โ”‚   โ”‚   โ””โ”€โ”€ review.py    # Review models
โ”‚   โ””โ”€โ”€ utils/           # Helper utilities
โ”œโ”€โ”€ modal/               # Modal cloud deployment
โ”œโ”€โ”€ tests/              # Test suite
โ””โ”€โ”€ alembic/            # Database migrations (if needed)

๐Ÿ› ๏ธ Common Development Tasks

Working with New Features

Our platform has recently added several major features. Hereโ€™s how to work with them:
  • Multi-Reviewer Workflows
  • PDF Export
  • Integrations
Backend Implementation:
# app/api/endpoints/review.py
@router.post("/analyses/{analysis_id}/reviews")
async def create_review(
    analysis_id: str,
    review: ReviewCreate,
    current_user: User = Depends(get_current_user)
) -> ReviewResponse:
    # Implement review creation with scoring
    pass

@router.post("/reviews/bulk-assign")
async def bulk_assign_reviews(
    assignments: BulkAssignmentRequest,
    current_user: User = Depends(require_supervisor)
) -> BulkAssignmentResponse:
    # Assign multiple calls to reviewers
    pass
Frontend Implementation:
// hooks/useReviews.ts
export function useCreateReview(analysisId: string) {
  return useMutation({
    mutationFn: (review: ReviewCreate) => 
      createReview(analysisId, review),
    onSuccess: () => {
      queryClient.invalidateQueries(['reviews', analysisId]);
    }
  });
}

Development Patterns

All API calls go through a centralized client:
// lib/api.ts
async function request<T>(
  endpoint: string,
  options?: RequestInit
): Promise<T> {
  const token = await supabase.auth.getSession();
  const headers = {
    'Content-Type': 'application/json',
    'X-API-Key': import.meta.env.VITE_API_KEY,
    ...options?.headers,
  };
  
  if (token?.session?.access_token) {
    headers['Authorization'] = `Bearer ${token.session.access_token}`;
  }
  
  const response = await fetch(`${API_BASE_URL}${endpoint}`, {
    ...options,
    headers,
  });
  
  if (!response.ok) {
    throw new APIError(response);
  }
  
  return response.json();
}
Use React Query for all data fetching:
// hooks/useAnalyses.ts
export function useAnalyses(filters?: AnalysisFilters) {
  return useQuery({
    queryKey: ['analyses', filters],
    queryFn: () => fetchAnalyses(filters),
    staleTime: 5 * 60 * 1000, // 5 minutes
  });
}

export function useAnalysis(id: string) {
  return useQuery({
    queryKey: ['analysis', id],
    queryFn: () => fetchAnalysis(id),
    enabled: !!id,
  });
}
Consistent error handling across the app:
// components/ErrorBoundary.tsx
export function QueryErrorBoundary({ children }: Props) {
  return (
    <ErrorBoundary
      fallbackRender={({ error, resetErrorBoundary }) => (
        <Alert variant="destructive">
          <AlertCircle className="h-4 w-4" />
          <AlertTitle>Error</AlertTitle>
          <AlertDescription>
            {error.message}
            <Button onClick={resetErrorBoundary}>Try again</Button>
          </AlertDescription>
        </Alert>
      )}
    >
      {children}
    </ErrorBoundary>
  );
}

๐Ÿงช Testing Strategy

Frontend Testing

npm run typecheck

Backend Testing

uv run mypy app

Writing Tests

  • Frontend Tests
  • Backend Tests
// __tests__/hooks/useAnalyses.test.ts
import { renderHook, waitFor } from '@testing-library/react';
import { useAnalyses } from '@/hooks/useAnalyses';

describe('useAnalyses', () => {
  it('fetches analyses successfully', async () => {
    const { result } = renderHook(() => useAnalyses());
    
    await waitFor(() => {
      expect(result.current.isSuccess).toBe(true);
    });
    
    expect(result.current.data).toHaveLength(10);
  });
});

๐Ÿ”ง Advanced Development

Performance Optimization

Code Splitting:
// Lazy load heavy components
const AnalysisDetail = lazy(() => import('./pages/AnalysisDetail'));
const PDFViewer = lazy(() => import('./components/PDFViewer'));
Memoization:
// Memoize expensive computations
const fraudScore = useMemo(() => 
  calculateFraudScore(analysis), [analysis]
);

// Memoize components
const ExpensiveChart = memo(({ data }) => {
  return <Chart data={data} />;
});
Virtual Scrolling:
// Use virtualization for long lists
import { VirtualList } from '@tanstack/react-virtual';
Async Processing:
# Use background tasks for heavy operations
from fastapi import BackgroundTasks

@router.post("/analyses")
async def create_analysis(
    file: UploadFile,
    background_tasks: BackgroundTasks
):
    # Quick response
    analysis_id = create_initial_analysis()
    
    # Process in background
    background_tasks.add_task(
        process_audio_analysis,
        analysis_id,
        file
    )
    
    return {"id": analysis_id, "status": "processing"}
Caching:
from functools import lru_cache

@lru_cache(maxsize=100)
def get_ai_prompt(analysis_type: str) -> str:
    # Cache frequently used prompts
    return load_prompt(analysis_type)

Security Best Practices

Always follow these security practices when developing AuthentiVoice features.
1

Input Validation

# Always validate input
from pydantic import BaseModel, validator

class AudioUpload(BaseModel):
    file_size: int
    file_type: str
    
    @validator('file_size')
    def validate_size(cls, v):
        if v > 100 * 1024 * 1024:  # 100MB
            raise ValueError('File too large')
        return v
2

Authentication

# Always verify user permissions
from app.core.auth import require_role

@router.delete("/analyses/{id}")
@require_role(["admin", "supervisor"])
async def delete_analysis(id: str):
    # Only admins/supervisors can delete
    pass
3

Rate Limiting

# Implement rate limiting
from slowapi import Limiter

limiter = Limiter(key_func=get_remote_address)

@router.post("/analyses")
@limiter.limit("10/minute")
async def create_analysis():
    pass

๐Ÿš€ Deployment

Local Docker Development

# Build and run with docker-compose
docker-compose up --build

# Run specific service
docker-compose up frontend backend

# View logs
docker-compose logs -f backend

Production Build

cd frontend
npm run build
# Output in dist/

๐Ÿ“š Resources & References

๐Ÿค Contributing

We welcome contributions! Please:
  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Submit a pull request
See our Contributing Guide for detailed instructions.