Skip to main content

Local Development Setup

Zero configuration required! Just clone, install, and run.

Quick Start (3 Commands)โ€‹

# 1. Clone the repository
git clone https://github.com/LuiseFreese/mermaid.git
cd mermaid

# 2. Install dependencies
npm install

# 3. Start development server
npm run dev

That's it! ๐ŸŽ‰

  • Frontend: http://localhost:3003
  • Backend API: http://localhost:8080
  • Authentication: Disabled (no Azure AD needed for local dev)

What's Running?โ€‹

When you run npm run dev, two servers start automatically:

Frontend (Port 3003)โ€‹

  • Vite dev server with hot module replacement
  • React application with real-time updates
  • No build step needed during development

Backend (Port 8080)โ€‹

  • Express API server
  • Mock data for rapid development
  • No Dataverse connection needed (unless you want to test against real data)

Authenticationโ€‹

  • Disabled by default (AUTH_ENABLED=false)
  • No Azure AD configuration required
  • No login prompts
  • Perfect for rapid feature development

Prerequisitesโ€‹

  • Node.js 20+ (required)
  • PowerShell 7+ or Windows PowerShell 5.1 (for scripts)

That's all! No Azure setup needed for local development.

Advanced: Testing with Real Dataverse (Optional)โ€‹

Want to test against a real Dataverse environment? Create a .env.local file:

# Authentication Method
USE_CLIENT_SECRET=true
USE_MANAGED_IDENTITY=false

# Microsoft Entra Configuration
TENANT_ID=your-tenant-id
CLIENT_ID=your-app-registration-id
CLIENT_SECRET=your-client-secret

# Optional: Connect to real Dataverse
DATAVERSE_URL=https://your-org.crm.dynamics.com

# Authentication still disabled for local dev
AUTH_ENABLED=false

Note: You'll need to create an App Registration with a client secret for local Dataverse access. See DEPLOYMENT.md for production deployment (which uses managed identity, no secrets!).

Advanced: Testing with Azure AD Authentication (Optional)โ€‹

Want to test the full authentication flow locally?

Prerequisitesโ€‹

  1. Deploy to Azure first: .\scripts\setup-secretless.ps1
  2. This creates the Azure AD App Registration you need

Configurationโ€‹

1. Add localhost redirect URI to your Azure AD App Registration:

# Get your environment suffix (e.g., "owspth")
$envSuffix = "your-env-suffix"

# Get App Registration ID
$appId = az ad app list --display-name "mermaid-user-auth-$envSuffix" --query "[0].appId" -o tsv

# Get Object ID
$objectId = az ad app list --display-name "mermaid-user-auth-$envSuffix" --query "[0].id" -o tsv

# Add localhost redirect URI (for local dev)
$spaConfig = @{ spa = @{ redirectUris = @(
"https://app-mermaid-$envSuffix.azurewebsites.net",
"http://localhost:3003"
) } } | ConvertTo-Json -Depth 3 | Out-File spa-config.json

az rest --method PATCH `
--uri "https://graph.microsoft.com/v1.0/applications/$objectId" `
--headers "Content-Type=application/json" `
--body "@spa-config.json"

Remove-Item spa-config.json

2. Create .env.local in project root:

# Enable authentication
AUTH_ENABLED=true

# Azure AD Configuration (from your deployed environment)
AZURE_AD_TENANT_ID=your-tenant-id
AZURE_AD_CLIENT_ID=your-azure-ad-client-id

# Optional: Test with real Dataverse
DATAVERSE_URL=https://your-org.crm.dynamics.com

3. Create src/frontend/.env.local:

VITE_AZURE_AD_CLIENT_ID=your-azure-ad-client-id
VITE_AZURE_AD_TENANT_ID=your-tenant-id
VITE_AZURE_AD_REDIRECT_URI=http://localhost:3003

4. Restart dev server:

npm run dev

Now you'll see the Microsoft login page when accessing http://localhost:3003!

Testing Your Setupโ€‹

Health Checkโ€‹

curl http://localhost:8080/health

Expected: {"status":"ok"}

Frontend Accessโ€‹

Open browser to http://localhost:3003

Authentication Methods:

  1. Local Development: Uses client secret โ†’ Microsoft Entra โ†’ Dataverse
  2. Azure Production: Uses managed identity โ†’ Microsoft Entra โ†’ Dataverse

Without Auth (default): Loads immediately โœ…
With Auth (optional): Redirects to Microsoft login first โœ…

Advanced: Testing with Dev Proxy (Optional)โ€‹

Want to test how your app handles API failures, rate limiting, and network issues? Use Microsoft Dev Proxy!

What is Dev Proxy?โ€‹

Dev Proxy intercepts your API calls to Dataverse and simulates:

  • โŒ API Failures (503, 500 errors)
  • โฑ๏ธ Rate Limiting (429 Too Many Requests)
  • ๐Ÿ”„ Mock Responses (offline development)

No code changes needed - it works as a network proxy!

Quick Setupโ€‹

1. Install Dev Proxy:

winget install Microsoft.DevProxy

๐Ÿ” First-Time Certificate Setup:

The first time you run Dev Proxy, you'll be prompted for administrator password to install a trusted root certificate. This is required to intercept HTTPS traffic securely.

Click "Yes" when prompted - this is a one-time setup and the certificate is only used for local development.

2. Choose Your Method:

Option A: npm Scripts (Easiest! โšก)โ€‹

Just run one command - everything is automated:

# Test API error handling (50% failure rate)
npm run dev:proxy

# Offline development with mocks (no Dataverse needed)
npm run dev:mock

# Test rate limiting
npm run dev:proxy:ratelimit


These scripts automatically:

  • โœ… Start Dev Proxy with the right config
  • โœ… Start your dev server
  • โœ… Clean up on exit (Ctrl+C stops both)

Option B: PowerShell Wrapper (More Control)โ€‹

Interactive menu with these testing scenarios:

# Run interactive menu
.\devproxy\start-with-devproxy.ps1

# Or specify mode directly:
.\devproxy\start-with-devproxy.ps1 -Mode errors -FailureRate 75
.\devproxy\start-with-devproxy.ps1 -Mode mocks
.\devproxy\start-with-devproxy.ps1 -Mode ratelimit

Option C: VS Code Tasks (One-Click)โ€‹

Press Ctrl+Shift+P โ†’ "Tasks: Run Task" โ†’ Select:

  • Dev Proxy: Error Simulation - Test API failures
  • Dev Proxy: Rate Limiting - Test 429 responses
  • Dev Proxy: Mock Mode - Offline development

Option D: Manual (Two Terminals)โ€‹

# Terminal 1: Start Dev Proxy
devproxy --config-file devproxy/devproxyrc.json

# Terminal 2: Start your app
npm run dev

Common Testing Scenariosโ€‹

1. Test API Error Handling:

# Using npm (recommended)
npm run dev:proxy

# Upload an ERD and deploy
# Verify your app shows helpful error messages

2. Test Rate Limiting:

# Using npm
npm run dev:proxy:ratelimit

# Deploy a large ERD (50+ entities)
# Watch how your app handles 429 responses

3. Offline Development (No Dataverse Needed):

# Using npm
npm run dev:mock

# Now you can develop without:
# - VPN connection
# - Dataverse environment
# - Internet access
# Perfect for airplane coding! โœˆ๏ธ

5. Custom Failure Rate:

# Using PowerShell wrapper
.\devproxy\start-with-devproxy.ps1 -Mode errors -FailureRate 75

# 75% of API calls will fail
# Test how your app handles extreme conditions

Configuration Filesโ€‹

All Dev Proxy configs are in devproxy/ folder:

  • devproxyrc.json - Error simulation (default)
  • devproxyrc-mocks.json - Mock mode for offline dev
  • devproxyrc-ratelimit.json - Rate limiting simulation
  • dataverse-errors.json - Define error responses
  • dataverse-mocks.json - Mock Dataverse responses
  • README.md - Detailed usage guide

VS Code Integrationโ€‹

Pre-configured tasks in .vscode/tasks.json for easy testing:

Available Tasks:

  1. Dev Proxy: Error Simulation
  2. Dev Proxy: Rate Limiting
  3. Dev Proxy: Mock Mode
  4. Dev Proxy: Slow API

Usage:

  • Press Ctrl+Shift+B to see all tasks
  • Select a task to start
  • Press Ctrl+C to stop

Benefitsโ€‹

โœ… Find bugs before production - Test failure scenarios you can't easily reproduce
โœ… Faster development - Use mocks instead of waiting for real API calls
โœ… Work offline - No Dataverse needed during initial development
โœ… Better error handling - Verify your error messages help users
โœ… Production confidence - Know your app handles edge cases
โœ… Easy to use - Just run npm run dev:proxy and you're testing!

Learn Moreโ€‹

Troubleshootingโ€‹

Port Already in Useโ€‹

Error: EADDRINUSE: address already in use :::3003

Solution:

# Find and kill process on port 3003
Get-NetTCPConnection -LocalPort 3003 -ErrorAction SilentlyContinue | ForEach-Object {
Stop-Process -Id $_.OwningProcess -Force
}

# Or use a different port
npm run dev -- --port 3004

Module Not Found Errorsโ€‹

Solution:

# Reinstall dependencies
Remove-Item node_modules -Recurse -Force
Remove-Item package-lock.json -Force
npm install

<<<<<<< HEAD
# Also check frontend
cd src/frontend
Remove-Item node_modules -Recurse -Force
Remove-Item package-lock.json -Force
npm install
cd ../..

Hot Reload Not Workingโ€‹

Solution:

# Restart the dev server
# Press Ctrl+C to stop, then:
npm run dev

Environment Variables Not Loadingโ€‹

Common Issue: Changed .env.local but changes not reflected

Solution: Restart the dev server (environment variables load on startup only)

CORS Errorsโ€‹

Issue: Frontend can't reach backend API

Check:

  1. Backend is running on port 8080
  2. Frontend is running on port 3003
  3. Vite proxy is configured (should be automatic)

Verify Vite config (src/frontend/vite.config.ts):

server: {
proxy: {
'/api': 'http://localhost:8080'
}
}

Development vs Productionโ€‹

FeatureLocal DevelopmentAzure Production
Setup Timeโšก 30 seconds๐ŸŒ 5-10 minutes
AuthenticationโŒ Disabledโœ… Azure AD Required
Dataverse๐Ÿ”„ Optional (mock or real)โœ… Required
Hot Reloadโœ… YesโŒ No
Debugging๐Ÿ” Full (breakpoints, logs)๐Ÿ“ Limited (logs only)
Cost๐Ÿ’ฐ Free๐Ÿ’ฐ ~$20-50/month
Secretsโš ๏ธ Client secrets OKโœ… Managed Identity (no secrets!)

When to Use What?โ€‹

Use Local Development When:โ€‹

  • ๐ŸŽจ Building UI components
  • ๐Ÿงช Testing business logic
  • ๏ฟฝ Debugging issues
  • โšก Need fast iteration
  • ๐Ÿ“š Learning the codebase

Deploy to Azure When:โ€‹

  • ๏ฟฝ Ready to share with others
  • ๏ฟฝ Testing authentication flow
  • ๐ŸŒ Need public URL
  • ๐Ÿ“Š Testing with production Dataverse
  • โœ… Final validation before release

Quick Referenceโ€‹

# Start development
npm run dev

# Install dependencies
npm install

# Build for production (test locally)
npm run build

# Run tests
npm test

# Deploy to Azure
.\scripts\setup-secretless.ps1 # First time setup
.\scripts\deploy-secretless.ps1 # Deploy code updates

Next Stepsโ€‹

Happy coding! ๐ŸŽ‰