Production-grade AI system architecture
A sophisticated, enterprise-scale LLM integration framework built for Microsoft Teams, featuring advanced middleware patterns, zero-downtime deployment strategies, and production-proven scalability architectures.
This repository contains the production architecture and implementation of an enterprise-grade LLM integration system for Microsoft Teams that I've architected and deployed across multiple organizations. The system demonstrates advanced patterns in:
- Middleware orchestration using Power Automate as a flexible abstraction layer
- Zero-downtime deployment strategies for model updates and provider switching
- Enterprise-scale architecture handling production workloads
- Advanced integration patterns between Microsoft Bot Framework, Azure services, and LLM providers
This is not a plug-and-play template—it's a reference implementation showcasing enterprise architecture patterns, requiring deep understanding of Azure services, Bot Framework, Power Automate, and LLM integration strategies.
- 🏗️ Advanced Architecture - Multi-layer middleware pattern with Power Automate abstraction
- 🔄 Zero-downtime Operations - Model/provider switching without service interruption
- 📊 Production Monitoring - Comprehensive observability and analytics integration
- 🔐 Enterprise Security - Secure credential management, authentication, and audit trails
- ⚡ Performance Optimization - Low-latency design patterns and connection pooling
- 🧩 Modular Design - Flexible architecture supporting multiple LLM providers and deployment strategies
Ali Mansouri - AI/ML Engineer & Enterprise Solutions Architect
I specialize in designing and implementing production-grade LLM systems and AI architectures for enterprise environments. This Teams integration represents one of several enterprise AI systems I've architected, developed, and deployed for organizations, handling real-world production workloads at scale.
My Expertise:
- Custom LLM Development - Building and fine-tuning LLM models for specific enterprise use cases
- Enterprise AI Architecture - Designing scalable, production-ready AI systems
- Microsoft Ecosystem Integration - Deep expertise in Teams, Azure, Power Automate, and Bot Framework
- Production Deployment - Systems handling thousands of daily requests with high availability
- Advanced Integration Patterns - Complex middleware architectures and service orchestration
Let's Connect:
- 📧 Email: ali.mansouri1998@gmail.com | ali.mansourii@ut.ac.ir
- 💼 LinkedIn: linkedin.com/in/ali-mansouri-a7984215b
Available for enterprise AI architecture consulting, custom LLM development, and complex integration projects.
┌─────────────────────────────────────────────────────────────┐
│ Microsoft Teams Client │
└───────────────────────────┬─────────────────────────────────┘
│
│ Bot Framework Protocol
▼
┌─────────────────────────────────────────────────────────────┐
│ Azure Bot Service (Authentication) │
└───────────────────────────┬─────────────────────────────────┘
│
│ REST API
▼
┌─────────────────────────────────────────────────────────────┐
│ Teams Bot Application (Node.js/Express) │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Bot Framework SDK │ │
│ │ - Activity Handler │ │
│ │ - Message Processing │ │
│ │ - Context Management │ │
│ └──────────────────────────────────────────────────────┘ │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Middleware Layer │ │
│ │ - Power Automate Integration │ │
│ │ - Direct API Fallback │ │
│ │ - Error Handling & Retry Logic │ │
│ └──────────────────────────────────────────────────────┘ │
└───────────────────────────┬─────────────────────────────────┘
│
│ HTTP/REST
▼
┌─────────────────────────────────────────────────────────────┐
│ Power Automate (Middleware Orchestration) │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ Request Transformation │ │
│ │ Provider Abstraction │ │
│ │ Rate Limiting & Throttling │ │
│ │ Logging & Analytics │ │
│ └──────────────────────────────────────────────────────┘ │
└───────────────────────────┬─────────────────────────────────┘
│
│ Provider-Agnostic Interface
▼
┌─────────────────────────────────────────────────────────────┐
│ LLM Provider Layer │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ OpenAI │ │ Azure AI │ │ Custom │ │
│ │ API │ │ Services │ │ Models │ │
│ └──────────┘ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘
Why Power Automate as Middleware?
- Abstraction Layer: Decouples bot logic from LLM provider specifics
- Operational Flexibility: Model/provider changes without code deployment
- Built-in Capabilities: Native integration with Azure services, logging, monitoring
- Enterprise Features: Secure parameter management, compliance, audit trails
- Scalability: Auto-scaling and load distribution handled by Azure
Why This Pattern?
- Maintainability: Clear separation of concerns
- Testability: Each layer can be tested independently
- Extensibility: Easy to add new providers or features
- Production-Ready: Handles errors, retries, and edge cases
This implementation requires expertise in:
- Microsoft Bot Framework and Teams development
- Azure services (Bot Service, App Service, Key Vault)
- Power Automate flow design and HTTP connectors
- Node.js and Express.js
- LLM API integration patterns
- Enterprise security practices
Technical Requirements:
- Node.js 16+
- Azure subscription with Bot Service access
- Power Automate account (for middleware pattern)
- LLM API credentials (OpenAI, Azure OpenAI, or custom provider)
- Create Azure Bot resource in Azure Portal
- Configure authentication (Microsoft App ID/Password)
- Set up messaging endpoint (will be configured after deployment)
- Note App ID and generate client secret
The Power Automate layer serves as the abstraction between your bot and LLM providers. This requires:
- Flow Design: HTTP-triggered flow with request/response transformation
- Provider Integration: HTTP actions configured for your LLM provider
- Security: Secure parameter storage for API keys
- Monitoring: Logging and analytics actions
See POWER_AUTOMATE_SETUP.md for detailed architecture patterns.
# Clone repository
git clone https://github.com/ali-m07/teams-llm-bot.git
cd teams-llm-bot
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Edit .env with your Azure Bot credentials and Power Automate endpoint
# Deploy to Azure App Service
az webapp up --name your-bot-name --runtime "NODE:18-lts" --location westus- Update
manifest.jsonwith your Bot App ID - Create app icons (192x192px)
- Package manifest and icons as ZIP
- Upload to Teams Admin Center or distribute via App Catalog
teams-llm-bot/
├── manifest.json # Teams app manifest configuration
├── bot.js # Core bot logic with middleware integration
│ ├── LLMBot class # Bot Framework activity handler
│ ├── Power Automate client # Middleware communication layer
│ └── Direct API fallback # Provider abstraction
├── index.js # Express server and Bot Framework adapter
├── package.json # Dependencies and scripts
├── .env.example # Environment configuration template
├── power-automate-flow.json # Power Automate flow definition (reference)
├── deploy.sh # Deployment automation script
├── README.md # This file
├── QUICK_START.md # Setup guide
└── POWER_AUTOMATE_SETUP.md # Middleware architecture guide
- ✅ Multi-scope Bot Framework Integration - Personal, team, and group chat support
- ✅ Message Extensions - Teams compose extension for quick access
- ✅ Activity Handling - Typing indicators, error recovery, context management
- ✅ Health Monitoring - Built-in health check endpoints for observability
- ✅ Middleware Abstraction - Power Automate layer for provider independence
- ✅ Zero-downtime Updates - Model/provider switching without service interruption
- ✅ Provider Flexibility - Support for multiple LLM providers via abstraction
- ✅ Production Scalability - Architecture designed for high-volume workloads
- ✅ Security Architecture - Secure credential management, authentication, audit trails
- ✅ Error Handling - Comprehensive error recovery and retry patterns
- ✅ Monitoring Integration - Built-in observability and analytics hooks
Via Power Automate Middleware:
- Update Power Automate flow HTTP action
- Modify model parameter in request body
- Save flow → Instant update (no bot code deployment)
Via Direct API:
- Update environment variable
LLM_MODEL - Restart application service
- Minimal downtime (typically < 30 seconds)
Via Power Automate:
- Update HTTP action URI and headers
- Adjust request/response transformation logic
- Save → Immediate provider switch
Via Power Automate:
- Modify system message in HTTP action body
- Save → Instant prompt update
Via Power Automate:
- Add Azure Log Analytics or Application Insights actions
- Configure logging steps in flow
- Save → Enhanced monitoring without code changes
- ✅ Credential Management - Environment variables excluded from version control
- ✅ Azure Key Vault - Production secret storage integration
- ✅ Power Automate Security - Secure parameters for API keys
- ✅ Authentication - Bot Framework authentication and OAuth flows
- ✅ Rate Limiting - Built into Power Automate and application layer
- ✅ Audit Logging - Comprehensive audit trails for compliance
- ✅ Network Security - HTTPS-only communication, certificate validation
This architecture implements defense-in-depth principles:
- Application Layer: Bot Framework authentication
- Middleware Layer: Power Automate secure parameters and authentication
- Provider Layer: API key management and request signing
- Infrastructure Layer: Azure security features and network isolation
# Azure CLI deployment
az webapp up --name teams-llm-bot --runtime "NODE:18-lts" --location westus
# Configure application settings
az webapp config appsettings set --name teams-llm-bot --settings \
MicrosoftAppId="<app-id>" \
MicrosoftAppPassword="<password>" \
USE_POWER_AUTOMATE="true" \
POWER_AUTOMATE_URL="<endpoint-url>" \
NODE_ENV="production"FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 3978
HEALTHCHECK --interval=30s --timeout=3s \
CMD node -e "require('http').get('http://localhost:3978/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
CMD ["node", "index.js"]- Scaling: Configure App Service auto-scaling based on metrics
- Monitoring: Integrate Application Insights for application telemetry
- Backup: Configure automated backups for configuration and state
- Disaster Recovery: Multi-region deployment for high availability
# Install dependencies
npm install
# Run application
npm start
# Health check
curl http://localhost:3978/health
# Teams integration testing (requires ngrok)
ngrok http 3978
# Update Azure Bot messaging endpoint to ngrok URL- Unit Tests: Bot logic and middleware communication
- Integration Tests: End-to-end flow with Power Automate
- Load Testing: Performance under production-like conditions
- Security Testing: Authentication and authorization flows
Bot not responding:
- Verify Azure Bot Service configuration
- Check application health endpoint:
GET /health - Review Application Insights logs
- Verify Power Automate flow status
Power Automate errors:
- Check flow run history in Power Automate portal
- Verify secure parameters are configured
- Review HTTP action configuration
- Check API rate limits and quotas
Teams integration issues:
- Validate
manifest.jsonschema - Verify bot registration in Azure
- Check app installation in Teams Admin Center
- Review Bot Framework diagnostic logs
- Application Insights: Application telemetry and performance metrics
- Power Automate Analytics: Flow execution history and performance
- Azure Bot Service Logs: Bot Framework diagnostic information
- Custom Logging: Application-specific logging via Power Automate
- QUICK_START.md - Setup guide for developers
- POWER_AUTOMATE_SETUP.md - Middleware architecture patterns
- Microsoft Bot Framework Docs
- Power Automate Docs
- Azure Bot Service Docs
This repository demonstrates enterprise architecture patterns. Contributions that enhance the architecture, add new patterns, or improve documentation are welcome.
Areas for Contribution:
- Additional LLM provider integrations
- Enhanced monitoring and observability patterns
- Security improvements
- Performance optimizations
- Documentation enhancements
MIT License - This architecture and implementation can be used as a reference for enterprise projects.
Ali Mansouri
AI/ML Engineer & Enterprise Solutions Architect
- 📧 Email: ali.mansouri1998@gmail.com | ali.mansourii@ut.ac.ir
- 💼 LinkedIn: linkedin.com/in/ali-mansouri-a7984215b
Available for:
- Enterprise AI architecture consulting
- Custom LLM model development and fine-tuning
- Production AI system design and implementation
- Microsoft Teams and Azure integration projects
- Complex middleware architecture design
- Power Automate and Azure services optimization
Let's architect something exceptional together. 🚀
If this architecture has been valuable for your organization or learning:
- ⭐ Star the repository
- 🔗 Share with your professional network
- 💼 Connect on LinkedIn
- 📧 Reach out for architecture consulting or collaboration opportunities
Architected & Implemented by Ali Mansouri
Enterprise AI Architecture | Production LLM Systems | Microsoft Teams Integration | Advanced Middleware Patterns