Local Development

This guide explains how to run your Pika application locally for development and testing.

Prerequisites

Before running locally, make sure you have:

  1. Node.js 22+ installed
  2. pnpm package manager
  3. AWS CLI useful for aws config/auth
  4. AWS CDK installed globally

Install AWS CDK

pnpm install -g aws-cdk
bash

Configure AWS CLI

aws configure
bash

Enter your AWS access key, secret key, region, and output format.

Local Development Architecture

When running locally, Pika uses a hybrid approach:

Hybrid Architecture
  • Frontend: Runs locally on your machine
  • Backend Services: Deployed to AWS (required for functionality)
  • Sample Services: Deployed to AWS for testing

This approach ensures you're testing against the same infrastructure you'll use in production.

Step-by-Step Local Setup

1. Configure Your Project

First, update your project configuration:

# Edit pika-config.ts to update project names (used for stack/resource names)
# This is recommended to avoid conflicts with other projects
bash

Example configuration:

export const pikaConfig: PikaConfig = {
    pika: {
        projNameL: 'mycompany',
        projNameKebabCase: 'mycompany',
        projNameTitleCase: 'MyCompany',
        projNameCamel: 'mycompany',
        projNameHuman: 'My Company'
    },
    pikaChat: {
        projNameL: 'mycompanychat',
        projNameKebabCase: 'mycompany-chat',
        projNameTitleCase: 'MyCompanyChat',
        projNameCamel: 'myCompanyChat',
        projNameHuman: 'My Company Chat'
    }
};
js

2. Deploy Backend Services

Backend First

The frontend depends on the backend services, so you need to deploy them first.

Deploy Core Backend Service

# Navigate to the core Pika backend service
cd services/pika

# Build the service
pnpm build

# Deploy to AWS (make sure you are AWS local config is set to where you want to deploy)
pnpm run cdk:deploy
bash

Deploy Sample Weather Service

# Navigate to the weather service
cd services/weather

# Build the service
pnpm build

# Deploy to AWS
pnpm run cdk:deploy
bash

3. Start the Frontend

# Navigate to the chat application
cd apps/pika-chat

# Build the application
pnpm build

# Start the development server
pnpm run dev
bash

4. Access Your Application

  • Main Chat Interface: http://localhost:3000
  • Weather Chat App: http://localhost:3000/chat/weather
  • Sample Enterprise Site: http://localhost:3000/samples/enterprise-site

5. Start the Enterprise Site Front End

Make sure the main chat interface is running (see #4).

# Navigate to the chat application
cd apps/samples/enterprise-site

# Build the application
pnpm build

# Start the development server
pnpm run dev
bash

Then access it with http://localhost:5173. Click the AI icon top right to show the pika chat front end embedded in an iframe.

What You Can Test Locally

1. Generic Chat Interface

The main chat interface at http://localhost:3000 provides:

  • User authentication
  • Chat history management
  • File upload capabilities
  • Custom component rendering

2. Weather Chat Application

Visit http://localhost:3000/chat/weather to test:

  • Agent-based weather queries
  • Tool orchestration
  • Dynamic response generation
  • Rich media rendering

3. Embedded Chat Mode

Visit http://localhost:5173 to test. The sample enterprise site demonstrates:

  • Iframe integration
  • Embedded chat functionality
  • Cross-origin communication
  • Responsive design

Development Workflow

Making Changes

Custom Components: Add components in the custom-markdown-tag-components directory

Frontend Stack Changes: Use apps/pika-chat/infra/lib/stacks/custom-stack-defs.ts to customize stack

Authentication: Modify the auth-provider directory

Hot Reloading

The frontend development server supports hot reloading:

  • Changes to Svelte components reload automatically
  • TypeScript compilation happens in real-time
  • CSS changes are applied immediately

Debugging

# Start with debugging enabled
pnpm run dev -- --debug

# Check browser console for errors
# Use browser dev tools for component inspection
bash

Common Issues

1. Backend Services Not Deployed

Service Unavailable

Symptoms:

  • Frontend loads but chat doesn't work
  • 404 errors when trying to send messages
  • "Service unavailable" errors

Solution:

# Deploy the backend services first
cd services/pika && pnpm build && pnpm run cdk:deploy
cd services/weather && pnpm build && pnpm run cdk:deploy
bash

2. AWS Credentials Not Configured

Credentials Missing

Symptoms:

  • CDK deployment fails
  • "Unable to locate credentials" errors

Solution:

```bash # Configure AWS CLI aws configure ```

3. Port Already in Use

Port Conflict

Symptoms:

  • "Port 3000 is already in use" error

Solution:

# Kill the process using port 3000
lsof -ti:3000 | xargs kill -9
bash

4. Build Errors

Build Issues

Symptoms:

  • TypeScript compilation errors
  • Missing dependencies

Solution:

# Clean and reinstall dependencies
pnpm clean
pnpm install

# Rebuild the project
pnpm build
bash

Development Tips

1. Use Environment Variables

Create a .env.local file for local development:

# .env.local
VITE_API_URL=http://localhost:3000
VITE_AUTH_PROVIDER=local
VITE_DEBUG=true
bash

2. Monitor AWS Costs

Cost Monitoring

Local development still uses AWS resources:

  • Monitor your AWS billing dashboard
  • Use AWS Cost Explorer to track expenses
  • Consider using AWS Free Tier for development

3. Use AWS CloudWatch

Monitor your deployed services:

# View recent logs
aws logs tail /aws/lambda/mycompany-pika-service --follow
bash

4. Test Different Scenarios

  • Authentication flows: Test login/logout
  • File uploads: Test document processing
  • Custom components: Test your custom UI components
  • Error handling: Test various error scenarios

Local Lambda Tool Development

For local Lambda tool development, you can redirect Lambda tools to run on local endpoints instead of calling deployed Lambda functions. This is useful when developing and testing custom Lambda tools.

Configuration

Create a custom-local-action-group-endpoints.json file in your project root:

{
    "oa_elasticsearch": "http://localhost:3002",
    "oa_account_data": "http://localhost:3002",
    "oa_order_data": "http://localhost:3002"
}
json

Set the environment variable to use this file:

export LOCAL_TOOLS="./custom-local-action-group-endpoints.json"
bash

How It Works

  • Maps tool IDs to local endpoint URLs where your Lambda functions are running locally
  • When an agent tries to call a tool, it redirects to the local endpoint instead of AWS Lambda
  • Useful for development and testing of Lambda tools without deploying to AWS
  • Only affects Lambda tools (not MCP tools, which connect to remote MCP servers)

Next Steps

Now that you can run Pika locally:

  1. Customize your application - Read the Customization Guide
  2. Set up authentication - Follow the Authentication Setup
  3. Deploy to production - Check out AWS Deployment
  4. Learn about the sync system - Read Sync System

Getting Help

If you encounter issues:

  1. Check the troubleshooting guide for common solutions
  2. Review AWS CloudWatch logs for backend errors
  3. Check browser console for frontend errors
  4. Search existing issues on the GitHub repository
  5. Create a new issue with detailed error information

Ready to customize your application? Check out the Customization Guide to start building your own features!

Last update at: 2025/09/17 14:37:11