A modern React.js application with TypeScript that provides a chat interface for connecting to an existing agent in Azure AI Foundry. This is a prototype application designed for development purposes with a focus on modern UI/UX patterns and seamless AI agent integration.
- Frontend: React.js 18+ with TypeScript (Client-side)
- Backend: Node.js/Express API service wrapper (Server-side)
- Agent Integration: Azure AI Foundry agent (Existing)
- Deployment: Separate hosting for frontend and backend services
- Framework: React.js 18+
- Language: TypeScript
- Build Tool: Webpack with TypeScript transpilation
- Package Manager: npm
- Framework: Node.js with Express.js
- Language: TypeScript
- Purpose: Secure proxy for Azure AI Foundry agent communication
- Hosting: Azure Container Apps or Azure App Service
- Node.js 18+
- TypeScript 4.9+
{
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.0",
"typescript": "^4.9.0",
"@azure/ai-agents": "^1.0.0",
"@azure/identity": "^3.4.0",
"@azure/core-auth": "^1.5.0",
"@azure/core-client": "^1.7.0",
"axios": "^1.6.0"
}- TypeScript Compiler:
typescript,ts-node - Bundling:
webpack,webpack-cli - Testing:
jest,@testing-library/react - Linting:
eslint,@typescript-eslint/parser - Code Formatting:
prettier
- CSS Framework: Material-UI or Tailwind CSS
- Icons: React Icons or Lucide React
- State Management: React Context API or Zustand
- Component Library: Modern component library for consistent design
- Azure Identity: Use
@azure/identityfor secure authentication - Service Principal: Configure service principal for agent access
- Environment Variables:
AZURE_CLIENT_IDAZURE_CLIENT_SECRETAZURE_TENANT_IDAZURE_AI_AGENT_IDAZURE_AI_FOUNDRY_ENDPOINT
- Frontend ↔ Backend: RESTful API + WebSocket for real-time updates
- Backend ↔ Azure AI Foundry:
@azure/ai-agentsSDK for secure agent communication - Real-time: WebSocket connection between frontend and backend service
- Message Handling: Structured message format with request/response validation
- Error Handling: Comprehensive error handling across all communication layers
- API Endpoints: RESTful endpoints for chat operations (send message, get history, etc.)
- WebSocket Server: Real-time bidirectional communication for live chat
- Authentication Proxy: Handle Azure AD authentication and token management
- Rate Limiting: Implement rate limiting and request throttling
- Logging & Monitoring: Comprehensive logging for debugging and monitoring
-
User Interface
- Modern, responsive chat interface
- Message history with timestamps
- Typing indicators and status messages
- Dark/light theme support
- Mobile-responsive design
-
Chat Functionality
- Real-time messaging with Azure AI agent
- Message threading and conversation history
- File upload capabilities (if supported by agent)
- Rich text and markdown support
- Message search and filtering
-
Agent Integration
- Connect to existing Azure AI Foundry agent
- Handle agent responses and formatting
- Support for multimodal interactions (text, images)
- Agent capability discovery and configuration
- Session management and conversation context
-
User Experience
- Loading states and skeleton screens
- Error boundaries and graceful error handling
- Offline capability detection
- Progressive Web App (PWA) features
- Accessibility compliance (WCAG 2.1)
- Azure Active Directory integration
- Token-based authentication for agent access
- Secure credential management
- Role-based access control (if needed)
- Centralized state for chat messages and user session
- Persistent storage for conversation history
- Real-time state synchronization
- Optimistic UI updates
- Code splitting and lazy loading
- Message virtualization for large conversation histories
- Efficient re-rendering with React optimizations
- Asset optimization and caching strategies
- Hot module replacement for development
- Environment-specific configuration
- Comprehensive TypeScript type definitions
- Development server with proxy for API calls
frontend/
├── public/
│ ├── index.html
│ ├── manifest.json
│ └── favicon.ico
├── src/
│ ├── components/
│ │ ├── Chat/
│ │ │ ├── ChatContainer.tsx
│ │ │ ├── MessageList.tsx
│ │ │ ├── MessageInput.tsx
│ │ │ └── TypingIndicator.tsx
│ │ ├── UI/
│ │ │ ├── Button.tsx
│ │ │ ├── Input.tsx
│ │ │ └── Modal.tsx
│ │ └── Layout/
│ │ ├── Header.tsx
│ │ ├── Sidebar.tsx
│ │ └── Footer.tsx
│ ├── services/
│ │ ├── apiClient.ts # Backend API communication
│ │ ├── websocket.ts # WebSocket client
│ │ ├── auth.ts # Frontend authentication
│ │ └── types.ts # API response types
│ ├── hooks/
│ │ ├── useChat.ts
│ │ ├── useAuth.ts
│ │ └── useWebSocket.ts
│ ├── types/
│ │ ├── chat.ts
│ │ ├── agent.ts
│ │ └── user.ts
│ ├── utils/
│ │ ├── formatters.ts
│ │ ├── constants.ts
│ │ └── helpers.ts
│ ├── styles/
│ │ ├── globals.css
│ │ └── components/
│ ├── App.tsx
│ ├── index.tsx
│ └── setupTests.ts
├── package.json
├── tsconfig.json
├── webpack.config.js
├── jest.config.js
├── .eslintrc.js
├── .prettierrc
├── .env.example
└── README.md
infra/
├── main.bicep # Main infrastructure template
├── main.parameters.dev.json # Development environment parameters
├── main.parameters.prod.json # Production environment parameters (future)
├── modules/
│ ├── containerApps.bicep # Container Apps environment and app
│ ├── staticWebApp.bicep # Static Web Apps configuration
│ ├── keyVault.bicep # Key Vault and secrets
│ ├── monitoring.bicep # Application Insights and Log Analytics
│ ├── identity.bicep # Managed identities and app registrations
│ └── storage.bicep # Storage account (optional)
├── scripts/
│ ├── deploy.sh # Deployment script (Bash)
│ ├── deploy.ps1 # Deployment script (PowerShell)
│ └── cleanup.sh # Resource cleanup script
├── .env.bicep.example # Bicep deployment environment variables
└── README.md # Infrastructure documentation
react-ai-chat-prototype/
├── azure.yaml # Azure Developer CLI configuration
├── frontend/ # React application (as detailed above)
├── backend/ # Node.js service wrapper (as detailed above)
├── infra/ # Bicep infrastructure templates (as detailed above)
├── .github/
│ └── workflows/
│ ├── deploy-dev.yml # GitHub Actions for development deployment
│ └── deploy-prod.yml # GitHub Actions for production deployment
├── docs/
│ ├── DEVELOPMENT.md # Development setup guide
│ ├── DEPLOYMENT.md # Deployment instructions
│ └── API.md # API documentation
├── package.json # Root package.json for workspace commands
├── .gitignore # Git ignore file
├── .env.example # Root environment variables example
└── README.md # Project overview and getting started
backend/
├── src/
│ ├── controllers/
│ │ ├── chatController.ts # Chat API endpoints
│ │ ├── authController.ts # Authentication endpoints
│ │ └── healthController.ts # Health check endpoints
│ ├── services/
│ │ ├── azureAgentService.ts # Azure AI Foundry integration
│ │ ├── authService.ts # Azure AD authentication
│ │ ├── websocketService.ts # WebSocket server logic
│ │ └── loggingService.ts # Logging and monitoring
│ ├── middleware/
│ │ ├── auth.ts # Authentication middleware
│ │ ├── rateLimiter.ts # Rate limiting
│ │ ├── errorHandler.ts # Error handling
│ │ └── validation.ts # Request validation
│ ├── routes/
│ │ ├── chat.ts # Chat routes
│ │ ├── auth.ts # Auth routes
│ │ └── health.ts # Health routes
│ ├── types/
│ │ ├── agent.ts # Azure AI agent types
│ │ ├── api.ts # API request/response types
│ │ └── auth.ts # Authentication types
│ ├── utils/
│ │ ├── config.ts # Configuration management
│ │ ├── logger.ts # Logging utilities
│ │ └── validators.ts # Input validation
│ ├── app.ts # Express app setup
│ └── server.ts # Server entry point
├── tests/
│ ├── unit/
│ ├── integration/
│ └── e2e/
├── package.json
├── tsconfig.json
├── jest.config.js
├── Dockerfile
├── .env.example
└── README.md
- Azure AI Foundry (Premium)
- Existing agent hosting and management
- Agent runtime and conversation handling
- Model orchestration and prompt management
- Azure Static Web Apps (Free Tier)
- React frontend application hosting
- Built-in CI/CD with GitHub integration
- Custom domain support
- Automatic HTTPS
- Azure Container Apps (Consumption Plan)
- Backend service wrapper hosting
- Auto-scaling based on demand
- Container-based deployment
- Built-in load balancing
- Alternative: Azure App Service (Basic B1) for simpler deployment
-
Azure Active Directory (Entra ID) (Free Tier)
- User authentication and authorization
- Service principal management for backend
- Token validation and security
- API app registrations
-
Azure Key Vault (Standard)
- Secure storage for Azure AI Foundry credentials
- Connection strings and secrets management
- Certificate management
- Backend service authentication keys
- Azure Monitor + Application Insights (Basic)
- Frontend and backend performance monitoring
- Error tracking and debugging
- User interaction analytics
- Custom telemetry and logging
- API request/response monitoring
-
Azure Storage Account (Standard)
- File upload and storage (if needed)
- Static asset hosting
- Blob storage for conversation logs
-
Azure CDN (Standard)
- Global content delivery
- Asset optimization and caching
- Improved loading performance
# Backend API Configuration
REACT_APP_API_BASE_URL=http://localhost:8080/api
REACT_APP_WS_URL=ws://localhost:8080
# Azure Authentication (Public - Client-side)
REACT_APP_AZURE_CLIENT_ID=your-frontend-client-id
REACT_APP_AZURE_TENANT_ID=your-tenant-id
# Development Settings
REACT_APP_ENVIRONMENT=development
REACT_APP_LOG_LEVEL=debug# Server Configuration
PORT=8080
NODE_ENV=development
# Azure AI Foundry Configuration (Secure - Server-side only)
AZURE_AI_FOUNDRY_ENDPOINT=https://your-foundry-endpoint.azure.com
AZURE_AI_AGENT_ID=your-agent-id
# Azure Authentication (Service Principal)
AZURE_CLIENT_ID=your-backend-service-principal-id
AZURE_CLIENT_SECRET=your-backend-service-principal-secret
AZURE_TENANT_ID=your-tenant-id
# Azure Key Vault
AZURE_KEY_VAULT_URL=https://your-keyvault.vault.azure.net/
# CORS Configuration
ALLOWED_ORIGINS=http://localhost:3000,https://your-frontend-domain.com
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100
# Logging
LOG_LEVEL=debug
APPLICATION_INSIGHTS_CONNECTION_STRING=your-app-insights-connection-string{
"compilerOptions": {
"target": "ES2020",
"lib": ["dom", "dom.iterable", "ES6"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}@description('Environment name (dev, staging, prod)')
param environmentName string = 'dev'
@description('Application name')
param appName string = 'react-ai-chat'
@description('Primary location for resources')
param location string = resourceGroup().location
@description('Azure AI Foundry endpoint')
param aiFoundryEndpoint string
@description('Azure AI Agent ID')
param aiAgentId string
// Variables
var resourceToken = toLower(uniqueString(subscription().id, resourceGroup().id, location))
var tags = {
'azd-service-name': appName
environment: environmentName
project: 'react-ai-chat-prototype'
}
// Modules
module containerApps 'modules/containerApps.bicep' = {
name: 'containerApps'
params: {
environmentName: environmentName
appName: appName
location: location
resourceToken: resourceToken
tags: tags
}
}
module staticWebApp 'modules/staticWebApp.bicep' = {
name: 'staticWebApp'
params: {
environmentName: environmentName
appName: appName
location: location
resourceToken: resourceToken
tags: tags
backendUrl: containerApps.outputs.backendUrl
}
}
module keyVault 'modules/keyVault.bicep' = {
name: 'keyVault'
params: {
environmentName: environmentName
appName: appName
location: location
resourceToken: resourceToken
tags: tags
principalId: containerApps.outputs.principalId
aiFoundryEndpoint: aiFoundryEndpoint
aiAgentId: aiAgentId
}
}
module monitoring 'modules/monitoring.bicep' = {
name: 'monitoring'
params: {
environmentName: environmentName
appName: appName
location: location
resourceToken: resourceToken
tags: tags
}
}
// Outputs
output AZURE_CONTAINER_APPS_ENVIRONMENT_ID string = containerApps.outputs.environmentId
output BACKEND_URL string = containerApps.outputs.backendUrl
output FRONTEND_URL string = staticWebApp.outputs.defaultHostname
output KEY_VAULT_NAME string = keyVault.outputs.keyVaultName
output APPLICATION_INSIGHTS_CONNECTION_STRING string = monitoring.outputs.applicationInsightsConnectionString# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
name: react-ai-chat-prototype
metadata:
template: react-ai-chat-prototype@0.0.1-beta
services:
backend:
project: ./backend
language: ts
host: containerapp
docker:
path: ./backend/Dockerfile
context: ./backend
frontend:
project: ./frontend
language: ts
host: staticwebapp
dist: build
hooks:
preprovision:
shell: sh
run: |
echo "Preparing infrastructure provisioning..."
# Validate required environment variables
if [ -z "$AZURE_AI_FOUNDRY_ENDPOINT" ]; then
echo "Error: AZURE_AI_FOUNDRY_ENDPOINT is required"
exit 1
fi
if [ -z "$AZURE_AI_AGENT_ID" ]; then
echo "Error: AZURE_AI_AGENT_ID is required"
exit 1
fi
postprovision:
shell: sh
run: |
echo "Infrastructure provisioning completed"
echo "Setting up application configuration..."
# Additional setup tasks can be added here
prepackage:
shell: sh
run: |
echo "Building application packages..."
npm run build:all{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"environmentName": {
"value": "dev"
},
"appName": {
"value": "react-ai-chat"
},
"location": {
"value": "East US 2"
},
"aiFoundryEndpoint": {
"value": "${AZURE_AI_FOUNDRY_ENDPOINT}"
},
"aiAgentId": {
"value": "${AZURE_AI_AGENT_ID}"
}
}
}- User authenticates with Azure AD
- Application receives access token
- Token used to authenticate with Azure AI Foundry
- Secure agent communication established
- All API communications use HTTPS
- Tokens stored securely in browser storage
- No sensitive data in client-side code
- CORS properly configured for security
- Conversation data handling policies
- User consent for data processing
- Data retention and deletion capabilities
- Audit logging for compliance
- Component testing with React Testing Library
- Service layer testing with Jest
- Mock Azure SDK for isolated testing
- Type safety validation with TypeScript
- End-to-end chat flow testing
- Azure agent integration testing
- Authentication flow validation
- Error scenario handling
- Message rendering performance
- Network request optimization
- Memory usage monitoring
- Load testing for conversation history
- Local development with hot reload
- Git-based version control
- Pull request reviews and testing
- Automated deployment to Azure Static Web Apps
- Automated testing on pull requests
- TypeScript compilation verification
- Security scanning and dependency checks
- Automated deployment to staging and production
- Application Insights integration
- Custom telemetry for chat interactions
- Error tracking and alerting
- Performance monitoring and optimization
- Node.js 18+ installed
- Azure subscription with AI Foundry access
- Existing Azure AI agent configured
- Azure CLI for resource management
- Azure Developer CLI (azd) for infrastructure deployment
- Docker Desktop (for container development)
- Git for version control
- Clone the repository
- Navigate to backend directory:
cd backend - Install dependencies:
npm install - Configure backend environment variables (
.env) - Set up Azure service principal and Key Vault access
- Start backend development server:
npm run dev - Verify backend health endpoint:
http://localhost:8080/health
- Navigate to frontend directory:
cd frontend - Install dependencies:
npm install - Configure frontend environment variables (
.env) - Start frontend development server:
npm start - Access application:
http://localhost:3000 - Test end-to-end chat functionality
# Start backend development server
npm run dev
# Build backend for production
npm run build
# Run backend tests
npm test
# Run backend linting
npm run lint
# Type checking
npm run type-check
# Start production backend
npm start# Start frontend development server
npm start
# Build frontend for production
npm run build
# Run frontend tests
npm test
# Run frontend linting
npm run lint
# Type checking
npm run type-check# Start both services concurrently (from project root)
npm run dev:all
# Build both services
npm run build:all
# Run all tests
npm run test:all# Deploy to development environment using Azure Developer CLI
azd init # Initialize azd environment
azd auth login # Login to Azure
azd provision --environment dev # Provision Azure resources
azd deploy --environment dev # Deploy applications
azd down --environment dev # Clean up resources
# Deploy using custom scripts
./infra/scripts/deploy.sh dev # Bash deployment script
./infra/scripts/deploy.ps1 -Environment dev # PowerShell deployment script
# Manual Bicep deployment
az deployment group create \
--resource-group rg-react-ai-chat-dev \
--template-file infra/main.bicep \
--parameters @infra/main.parameters.dev.json
# Validate Bicep templates
az deployment group validate \
--resource-group rg-react-ai-chat-dev \
--template-file infra/main.bicep \
--parameters @infra/main.parameters.dev.json
# Environment setup
export AZURE_AI_FOUNDRY_ENDPOINT="https://your-foundry-endpoint.azure.com"
export AZURE_AI_AGENT_ID="your-agent-id"
export AZURE_SUBSCRIPTION_ID="your-subscription-id"- Consistent TypeScript usage
- Component composition patterns
- Custom hooks for reusable logic
- Proper error boundaries
- Comprehensive testing coverage
- Efficient state management
- Memoization for expensive operations
- Lazy loading and code splitting
- Optimized bundle size
- Efficient re-rendering strategies
- Responsive design principles
- Accessibility best practices
- Progressive enhancement
- Offline-first considerations
- Smooth animations and transitions
- Multi-agent support
- Voice input/output integration
- Advanced message formatting
- Conversation export capabilities
- Plugin system for extensibility
- Horizontal scaling strategies
- Caching implementations
- Database integration for persistence
- Load balancing for high traffic
- Microservices architecture migration
This specification provides a comprehensive foundation for building a modern React TypeScript application that seamlessly integrates with Azure AI Foundry agents while maintaining high development standards and user experience quality.