Learn how to set up a complete local development environment for Pika, enabling rapid iteration without deploying to AWS.
What You'll Accomplish
Section titled “What You'll Accomplish”By the end of this guide, you will:
- Install required development tools
- Set up the Pika repository locally
- Configure environment variables
- Run the development server
- Test agents and tools locally
- Use local development features
- Debug common issues
Prerequisites
Section titled “Prerequisites”- macOS, Linux, or Windows with WSL2
- Git installed
- Basic command line knowledge
- Text editor or IDE (VS Code recommended)
Step 1: Install Required Tools
Section titled “Step 1: Install Required Tools”Install the necessary development tools.
Node.js 22+
Section titled “Node.js 22+”# Using nvm (recommended)curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bashnvm install 22nvm use 22
# Verify installationnode --version # Should show v22.x.xpnpm Package Manager
Section titled “pnpm Package Manager”# Install pnpmnpm install -g pnpm
# Verify installationpnpm --versionAWS CLI (for cloud features)
Section titled “AWS CLI (for cloud features)”# macOSbrew install awscli
# Linuxcurl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"unzip awscliv2.zipsudo ./aws/install
# Verify installationaws --versionStep 2: Clone Pika Repository
Section titled “Step 2: Clone Pika Repository”Get the Pika framework code.
Clone Repository
Section titled “Clone Repository”# Clone from GitHubgit clone https://github.com/rithum/pika.gitcd pika
# Or if you forked itgit clone https://github.com/your-username/pika.gitcd pikaInstall Dependencies
Section titled “Install Dependencies”# Install all project dependenciespnpm installThis installs dependencies for all packages in the monorepo.
Step 3: Configure Environment Variables
Section titled “Step 3: Configure Environment Variables”Set up local environment configuration.
Pika Service Configuration
Section titled “Pika Service Configuration”Location: services/pika/.env
# Deployment stageSTAGE=local
# AWS Configuration (optional for local dev)AWS_REGION=us-east-1AWS_PROFILE=default
# OpenAI API Key (if using OpenAI models)OPENAI_API_KEY=your-openai-api-key-here
# Anthropic API Key (if using Claude via API)ANTHROPIC_API_KEY=your-anthropic-api-key-here
# Local DynamoDBDYNAMODB_ENDPOINT=http://localhost:8000
# Debug modeDEBUG=trueLOG_LEVEL=debugChat Application Configuration
Section titled “Chat Application Configuration”Location: apps/pika-chat/.env
# Public environment variablesPUBLIC_STAGE=local
# API endpoints (when running local backend)PUBLIC_API_URL=http://localhost:3001PUBLIC_CONVERSE_URL=http://localhost:3002
# AWS regionPUBLIC_AWS_REGION=us-east-1
# Feature flags for local developmentPUBLIC_DEV_MODE=truePUBLIC_ENABLE_DEBUG=trueStep 4: Set Up Local DynamoDB (Optional)
Section titled “Step 4: Set Up Local DynamoDB (Optional)”Run DynamoDB locally for offline development.
Install DynamoDB Local
Section titled “Install DynamoDB Local”# Download DynamoDB Localcd ~/mkdir dynamodb-localcd dynamodb-localwget https://s3.us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.tar.gztar -xzf dynamodb_local_latest.tar.gzRun DynamoDB Local
Section titled “Run DynamoDB Local”# Start DynamoDB on port 8000java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
# Or use Dockerdocker run -p 8000:8000 amazon/dynamodb-localCreate Tables
Section titled “Create Tables”# Run table creation scriptcd pika/services/pikapnpm run create-local-tablesStep 5: Run Development Server
Section titled “Step 5: Run Development Server”Start the Pika chat application locally.
Start Chat Application
Section titled “Start Chat Application”cd apps/pika-chat
# Start development serverpnpm run devThe application will be available at http://localhost:5173
Development Server Features
Section titled “Development Server Features”- Hot Module Replacement: Changes reflect immediately
- Error Overlay: See errors in browser
- Fast Refresh: Preserves component state
- Source Maps: Debug with original source code
Step 6: Run Local Backend (Optional)
Section titled “Step 6: Run Local Backend (Optional)”Run Pika backend services locally for full functionality.
Start Backend Services
Section titled “Start Backend Services”cd services/pika
# Run local Lambda simulatorpnpm run dev:localThis starts:
- Converse function on
http://localhost:3002 - API Gateway simulator on
http://localhost:3001
Configure Agents Locally
Section titled “Configure Agents Locally”Location: services/pika/local-config.ts
import { AgentDataRequest } from 'pika-shared/types/chatbot/chatbot-types';
export const localAgents: AgentDataRequest[] = [ { userId: 'local-dev', agent: { agentId: 'test-agent', basePrompt: 'You are a helpful assistant for local development testing.', modelId: 'anthropic.claude-3-5-sonnet-20241022-v2:0' } }];Step 7: Local Development Features
Section titled “Step 7: Local Development Features”Take advantage of Pika's local development tools.
Hot Reload
Section titled “Hot Reload”Changes to code are automatically reflected:
<script lang="ts"> // Edit and save - changes appear immediately let greeting = "Hello, Pika!";</script>
<h1>{greeting}</h1>Debug Mode
Section titled “Debug Mode”Enable detailed logging:
export const DEBUG = import.meta.env.PUBLIC_DEV_MODE === 'true';
if (DEBUG) { console.log('Debug mode enabled');}Mock Data
Section titled “Mock Data”Use mock data for testing without AWS:
export const mockAgents = [ { agentId: 'test-agent', title: 'Test Agent', description: 'For local testing' }];
// Use in developmentconst agents = import.meta.env.DEV ? mockAgents : await fetchAgents();Local Web Component Development
Section titled “Local Web Component Development”Override web component URLs to load from local:
export const webComponentOverrides = { 'acme.dashboard': 'http://localhost:5174/dashboard.js'};Start your web component dev server:
cd your-web-component-projectpnpm run dev # Runs on port 5174Step 8: Testing and Debugging
Section titled “Step 8: Testing and Debugging”Use development tools for testing.
Browser DevTools
Section titled “Browser DevTools”- Console: View logs and errors
- Network: Monitor API calls
- Sources: Debug with breakpoints
- React DevTools: Inspect component state (if using React)
VS Code Debugging
Section titled “VS Code Debugging”Location: .vscode/launch.json
{ "version": "0.2.0", "configurations": [ { "type": "chrome", "request": "launch", "name": "Launch Chrome", "url": "http://localhost:5173", "webRoot": "${workspaceFolder}/apps/pika-chat" } ]}Curl Testing
Section titled “Curl Testing”Test backend endpoints:
# Test converse endpointcurl -X POST http://localhost:3002/converse \ -H "Content-Type: application/json" \ -d '{ "agentId": "test-agent", "message": "Hello", "userId": "test-user" }'Testing Checklist
Section titled “Testing Checklist”Best Practices
Section titled “Best Practices”Code Organization
Section titled “Code Organization”- Keep Components Small: Easier to understand and test
- Use TypeScript: Catch errors early
- Follow Project Structure: Maintain consistency
- Write Tests: Unit and integration tests
Development Workflow
Section titled “Development Workflow”# 1. Create feature branchgit checkout -b feature/my-feature
# 2. Make changes and test locallypnpm run dev
# 3. Run lintingpnpm run lint
# 4. Run testspnpm run test
# 5. Commit changesgit add .git commit -m "feat: add my feature"
# 6. Push and create PRgit push origin feature/my-featurePerformance
Section titled “Performance”- Use Dev Tools Profiler: Identify slow components
- Monitor Bundle Size: Keep bundles small
- Lazy Load: Load components when needed
- Optimize Images: Compress and use appropriate formats
Troubleshooting
Section titled “Troubleshooting”Port Already in Use
Section titled “Port Already in Use”# Find process using port 5173lsof -ti:5173
# Kill the processkill -9 $(lsof -ti:5173)
# Or use different portpnpm run dev -- --port 5174Module Not Found
Section titled “Module Not Found”# Clear node_modules and reinstallrm -rf node_modulesrm pnpm-lock.yamlpnpm installHot Reload Not Working
Section titled “Hot Reload Not Working”# Restart dev server# Press Ctrl+C to stoppnpm run devAWS Credentials Error
Section titled “AWS Credentials Error”# Configure AWS CLIaws configure
# Or set credentialsexport AWS_ACCESS_KEY_ID=your-keyexport AWS_SECRET_ACCESS_KEY=your-secretexport AWS_REGION=us-east-1TypeScript Errors
Section titled “TypeScript Errors”# Restart TypeScript server in VS Code# Command Palette (Cmd/Ctrl+Shift+P)# > TypeScript: Restart TS Server
# Or rebuildpnpm run buildCommon Development Tasks
Section titled “Common Development Tasks”Add New Package
Section titled “Add New Package”# Add to specific packagecd apps/pika-chatpnpm add some-package
# Add to root (development tool)pnpm add -D some-package -wRun Specific Script
Section titled “Run Specific Script”# From workspace rootpnpm --filter pika-chat devpnpm --filter @pika/shared build
# From package directorycd apps/pika-chatpnpm run devView Logs
Section titled “View Logs”# Application logs in browser console# Backend logs in terminal
# Verbose modeDEBUG=* pnpm run devNext Steps
Section titled “Next Steps”- Deploy to AWS with CDK - Deploy to cloud
- Build Custom Web Components - Create components
- Define Agents - Configure agents
Related Documentation
Section titled “Related Documentation”- Project Structure - Understand codebase
- Contributing Guide - How to contribute
- Troubleshooting - Common issues