diff --git a/README.md b/README.md new file mode 100644 index 0000000..086ce4f --- /dev/null +++ b/README.md @@ -0,0 +1,220 @@ +# Power Apps Code Apps — Google-Style Search Demo + +A complete, production-ready example of a **Power Apps code app** with a Google-style search UI. Built with React, TypeScript, and Vite — deployed inside Power Platform while maintaining full code-first developer experience. + +--- + +## What Are Power Apps Code Apps? + +Code apps let you build custom web applications using your own frontend stack (React, Vue, Svelte, etc.), develop locally with standard tooling, and run them on **Power Platform's managed runtime**. You get: + +- ✅ True code-first development (VS Code, npm, ESLint, tests) +- ✅ Platform identity, connectors, and governance controls built-in +- ✅ Environment strategy, DLP policies, and ALM discipline from day one +- ✅ No need to build your own hosting or authentication infrastructure + +> **Official docs:** [Power Apps Code Apps Overview](https://learn.microsoft.com/en-us/power-apps/developer/code-apps/overview) + +--- + +## When Does This Model Make Sense? + +- You need a **custom UI** that goes beyond what Canvas or Model-Driven apps offer +- Your team wants **source control and CI/CD** from the start +- You need to combine **developer velocity** with **enterprise governance** +- You want a **single deployment model** across Dev → Test → Prod instead of ad-hoc hosting + +--- + +## Trade-offs to Consider + +| Consideration | Detail | +|---|---| +| **Not zero-process** | Without ALM discipline, deployments become fragile fast | +| **Feature maturity** | Some scenarios still require design workarounds | +| **Security is your job** | CSP, connector scopes, and identity boundaries must be explicitly planned | +| **Licensing** | Validate cost and access model before broad rollout | + +--- + +## Prerequisites + +Before you start, make sure you have: + +- **Power Platform environment** with code apps enabled +- **Node.js LTS** (18.x or later) +- **Power Apps CLI (PAC)** — install via: + ```bash + dotnet tool install --global Microsoft.PowerApps_CLI + ``` +- A **non-default solution** strategy for ALM (avoid the default solution) + +--- + +## Step-by-Step Setup + +### 1. Clone the Repository + +```bash +git clone https://git.lago.dev/Lago/power-apps-codeapps-blog.git +cd power-apps-codeapps-blog +``` + +### 2. Install Dependencies + +```bash +npm install +``` + +This installs React 19, TypeScript, Vite 7, and the `@microsoft/power-apps` package. + +### 3. Authenticate with Power Platform + +```bash +pac auth create +``` + +Follow the prompts to sign in to your Microsoft 365 / Power Platform tenant. + +### 4. Select Your Target Environment + +```bash +pac env select --environment +``` + +> ⚠️ **Important:** Always use the exact environment you plan to deploy into. Many issues come from pushing to the wrong one. + +Find your environment ID in the [Power Platform Admin Center](https://admin.powerplatform.microsoft.com/). + +### 5. Initialize the Code App Metadata + +```bash +pac code init --displayname "Google Search Demo" +``` + +This creates the `power.config.json` file that links your local project to Power Platform. + +### 6. Run Local Development + +```bash +npm run dev +``` + +Opens at `http://localhost:5173` by default. The app hot-reloads as you edit. + +> 💡 **Tip:** Keep your browser profile aligned with your tenant authentication context to avoid confusing auth behavior during local runs. + +### 7. Build and Push to Power Platform + +```bash +npm run build +pac code push +``` + +After deployment: +1. Open your target environment in [make.powerapps.com](https://make.powerapps.com) +2. Find your app under **Apps** +3. Share it with users and assign security roles + +### 8. Test with Non-Admin Users + +Before rolling out broadly, validate that regular users (non-admin) can access and use the app correctly. + +--- + +## Project Structure + +``` +power-apps-codeapps-blog/ +├── public/ +│ └── vite.svg +├── src/ +│ ├── assets/ +│ │ └── react.svg +│ ├── App.css ← All styles (Google dark theme) +│ ├── App.tsx ← Main search UI component +│ ├── index.css ← Global reset styles +│ └── main.tsx ← React entry point +├── index.html +├── package.json +├── tsconfig.json +└── vite.config.ts +``` + +--- + +## The UI: What You're Getting + +The demo implements a **Google-style search interface** with: + +- 🔍 Search box with focus ring animation +- 📄 Search results list with title, URL, and description +- 🌙 Dark mode by default +- 📱 Responsive layout +- 🦎 "CrotolamoSearch" branding as a demo logo + +The component is entirely **dummy data** — no real search engine. Replace `dummyResults` in `App.tsx` with your actual Dataverse queries, Power Automate calls, or custom API integrations. + +--- + +## Connecting to Real Data + +The `@microsoft/power-apps` package provides the runtime SDK. Example pattern: + +```typescript +import { powerPlatform } from "@microsoft/power-apps"; + +const client = powerPlatform.getClient(); +// Use client to call Dataverse APIs, connectors, etc. +``` + +For authentication patterns using **Entra ID (Azure AD) client credentials**, see: +- [Dataverse Web API with OAuth](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/quick-start-org-aad-car) +- [Azure Functions + Dataverse integration](https://www.thatsagoodquestion.info/) + +--- + +## Best Practices for Production + +1. **Use solution-based ALM from day one** — avoid default solution chaos +2. **Pin toolchain versions in CI** — Node, PAC, and package versions should be explicit in `package.json` and `package-lock.json` +3. **Treat CSP as production configuration** — every source allow-list entry needs a clear reason +4. **Adopt read-first, write-later rollout** — safer adoption and easier troubleshooting +5. **Instrument early** — track failures, latency, and usage before scaling + +--- + +## Common Mistakes to Avoid + +- ❌ Deploying "wherever it works" instead of following environment discipline +- ❌ Treating security headers and CSP as optional +- ❌ Introducing write operations before observability is in place +- ❌ Mixing identity assumptions between local dev and production + +--- + +## Official References + +| Resource | URL | +|---|---| +| Code Apps Overview | https://learn.microsoft.com/en-us/power-apps/developer/code-apps/overview | +| Create from Scratch | https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/create-an-app-from-scratch | +| Architecture | https://learn.microsoft.com/en-us/power-apps/developer/code-apps/architecture | +| ALM Guide | https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/alm | +| Content Security Policy | https://learn.microsoft.com/en-us/power-apps/developer/code-apps/how-to/content-security-policy | +| Power Platform CLI (PAC) | https://learn.microsoft.com/en-us/power-apps/developer/cli/introduction | + +--- + +## Related Articles on That's A Good Question + +- [CVE-2026-20960: What Microsoft Power Apps Admins Need to Do Now](https://www.thatsagoodquestion.info/cve-2026-20960-what-microsoft-power-apps-admins-need-to-do-now/) +- [Azure Functions + Dataverse: Architecture, Value, and Trade-offs](https://www.thatsagoodquestion.info/azure-functions-dataverse-integration-architecture-value-and-trade-offs/) +- [Power Automate Error Handling: Patterns That Survive Production](https://www.thatsagoodquestion.info/power-automate-error-handling-guide-patterns-that-survive-production/) +- [Dataverse MCP Server Setup Guide for Power Platform Teams](https://www.thatsagoodquestion.info/dataverse-mcp-server-setup-guide-for-power-platform-teams/) + +--- + +## License + +MIT — use freely for learning and building.