1
---
2
name: power-apps-code-app-scaffold
3
description: 'Scaffold a complete Power Apps Code App project with PAC CLI setup, SDK integration, and connector configuration'
4
---
5
6
# Power Apps Code Apps Project Scaffolding
7
8
You are an expert Power Platform developer who specializes in creating Power Apps Code Apps. Your task is to scaffold a complete Power Apps Code App project following Microsoft's best practices and current preview capabilities.
9
10
## Context
11
12
Power Apps Code Apps (preview) allow developers to build custom web applications using code-first approaches while integrating with Power Platform capabilities. These apps can access 1,500+ connectors, use Microsoft Entra authentication, and run on managed Power Platform infrastructure.
13
14
## Task
15
16
Create a complete Power Apps Code App project structure with the following components:
17
18
### 1. Project Initialization
19
- Set up a Vite + React + TypeScript project configured for Code Apps
20
- Configure the project to run on port 3000 (required by Power Apps SDK)
21
- Install and configure the Power Apps SDK (@microsoft/power-apps ^0.3.1)
22
- Initialize the project with PAC CLI (pac code init)
23
24
### 2. Essential Configuration Files
25
- **vite.config.ts**: Configure for Power Apps Code Apps requirements
26
- **power.config.json**: Generated by PAC CLI for Power Platform metadata
27
- **PowerProvider.tsx**: React provider component for Power Platform initialization
28
- **tsconfig.json**: TypeScript configuration compatible with Power Apps SDK
29
- **package.json**: Scripts for development and deployment
30
31
### 3. Project Structure
32
Create a well-organized folder structure:
33
```
34
src/
35
├── components/ # Reusable UI components
36
├── services/ # Generated connector services (created by PAC CLI)
37
├── models/ # Generated TypeScript models (created by PAC CLI)
38
├── hooks/ # Custom React hooks for Power Platform integration
39
├── utils/ # Utility functions
40
├── types/ # TypeScript type definitions
41
├── PowerProvider.tsx # Power Platform initialization component
42
└── main.tsx # Application entry point
43
```
44
45
### 4. Development Scripts Setup
46
Configure package.json scripts based on official Microsoft samples:
47
- `dev`: "concurrently \"vite\" \"pac code run\"" for parallel execution
48
- `build`: "tsc -b && vite build" for TypeScript compilation and Vite build
49
- `preview`: "vite preview" for production preview
50
- `lint`: "eslint ." for code quality
51
52
### 5. Sample Implementation
53
Include a basic sample that demonstrates:
54
- Power Platform authentication and initialization using PowerProvider component
55
- Connection to at least one supported connector (Office 365 Users recommended)
56
- TypeScript usage with generated models and services
57
- Error handling and loading states with try/catch patterns
58
- Responsive UI using Fluent UI React components (following official samples)
59
- Proper PowerProvider implementation with useEffect and async initialization
60
61
#### Advanced Patterns to Consider (Optional)
62
- **Multi-environment configuration**: Environment-specific settings for dev/test/prod
63
- **Offline-first architecture**: Service worker and local storage for offline functionality
64
- **Accessibility features**: ARIA attributes, keyboard navigation, screen reader support
65
- **Internationalization setup**: Basic i18n structure for multi-language support
66
- **Theme system foundation**: Light/dark mode toggle implementation
67
- **Responsive design patterns**: Mobile-first approach with breakpoint system
68
- **Animation framework integration**: Framer Motion for smooth transitions
69
70
### 6. Documentation
71
Create comprehensive README.md with:
72
- Prerequisites and setup instructions
73
- Authentication and environment configuration
74
- Connector setup and data source configuration
75
- Local development and deployment processes
76
- Troubleshooting common issues
77
78
## Implementation Guidelines
79
80
### Prerequisites to Mention
81
- Visual Studio Code with Power Platform Tools extension
82
- Node.js (LTS version - v18.x or v20.x recommended)
83
- Git for version control
84
- Power Platform CLI (PAC CLI) - latest version
85
- Power Platform environment with Code Apps enabled (admin setting required)
86
- Power Apps Premium licenses for end users
87
- Azure account (if using Azure SQL or other Azure connectors)
88
89
### PAC CLI Commands to Include
90
- `pac auth create --environment {environment-id}` - Authenticate with specific environment
91
- `pac env select --environment {environment-url}` - Select target environment
92
- `pac code init --displayName "App Name"` - Initialize code app project
93
- `pac connection list` - List available connections
94
- `pac code add-data-source -a {api-name} -c {connection-id}` - Add connector
95
- `pac code push` - Deploy to Power Platform
96
97
### Officially Supported Connectors
98
Focus on these officially supported connectors with setup examples:
99
- **SQL Server (including Azure SQL)**: Full CRUD operations, stored procedures
100
- **SharePoint**: Document libraries, lists, and sites
101
- **Office 365 Users**: Profile information, user photos, group memberships
102
- **Office 365 Groups**: Team information and collaboration
103
- **Azure Data Explorer**: Analytics and big data queries
104
- **OneDrive for Business**: File storage and sharing
105
- **Microsoft Teams**: Team collaboration and notifications
106
- **MSN Weather**: Weather data integration
107
- **Microsoft Translator V2**: Multi-language translation
108
- **Dataverse**: Full CRUD operations, relationships, and business logic
109
110
### Sample Connector Integration
111
Include working examples for Office 365 Users:
112
```typescript
113
// Example: Get current user profile
114
const profile = await Office365UsersService.MyProfile_V2("id,displayName,jobTitle,userPrincipalName");
115
116
// Example: Get user photo
117
const photoData = await Office365UsersService.UserPhoto_V2(profile.data.id);
118
```
119
120
### Current Limitations to Document
121
- Content Security Policy (CSP) not yet supported
122
- Storage SAS IP restrictions not supported
123
- No Power Platform Git integration
124
- No Dataverse solutions support
125
- No native Azure Application Insights integration
126
127
### Best Practices to Include
128
- Use port 3000 for local development (required by Power Apps SDK)
129
- Set `verbatimModuleSyntax: false` in TypeScript config
130
- Configure vite.config.ts with `base: "./"` and proper path aliases
131
- Store sensitive data in data sources, not app code
132
- Follow Power Platform managed platform policies
133
- Implement proper error handling for connector operations
134
- Use generated TypeScript models and services from PAC CLI
135
- Include PowerProvider with proper async initialization and error handling
136
137
## Deliverables
138
139
1. Complete project scaffolding with all necessary files
140
2. Working sample application with connector integration
141
3. Comprehensive documentation and setup instructions
142
4. Development and deployment scripts
143
5. TypeScript configuration optimized for Power Apps Code Apps
144
6. Best practices implementation examples
145
146
Ensure the generated project follows Microsoft's official Power Apps Code Apps documentation and samples from https://github.com/microsoft/PowerAppsCodeApps, and can be successfully deployed to Power Platform using the `pac code push` command.
147