|
| 1 | +# Dynamic SDUI Generation Framework with Angular and AI |
| 2 | + |
| 3 | +This repository contains an *experimental and exploratory* framework for building and running dynamic, AI-powered, Server-Driven UI (SDUI) applications using Angular and a generative AI backend. The system uses a unique two-AI architecture: a **Generator AI** to help developers scaffold application assets and an **Executor AI** to render UIs dynamically at runtime. |
| 4 | + |
| 5 | +**Please note: This is an experimental project and not an official Angular solution for generating SDUI apps.** |
| 6 | + |
| 7 | +## Core Concepts |
| 8 | + |
| 9 | +The framework is built on the idea of separating the application's UI components from the logic that assembles them. An AI-powered backend takes on the role of a real-time UI/UX designer, constructing views on the fly based on user intent. |
| 10 | + |
| 11 | +### The Two-AI Architecture |
| 12 | + |
| 13 | +1. **Generator AI**: An interactive command-line tool, powered by a Python MCP (Model-Centric Programming) server. It guides a developer through a series of questions to design, define, and generate all the necessary assets for a new dynamic application. This includes creating Angular components, configuration files, and theme variables. |
| 14 | + |
| 15 | +2. **Executor AI**: A runtime AI, powered by [Genkit](https://genkit.dev/) flows. When a user interacts with the running application (e.g., through a chat interface), the Executor AI receives the user's prompt, analyzes the available data and UI components, and generates a JSON-based `componentSchema` that represents the entire view layout. The Angular frontend then renders this schema into a fully interactive UI. |
| 16 | + |
| 17 | +### The `app-context.ts` File |
| 18 | + |
| 19 | +Each dynamic application has a central manifest file called `app-context.ts`. This file is crucial as it provides the Executor AI with all the context it needs to build a UI. It contains: |
| 20 | +* **App Metadata**: The application's name, theme, and welcome messages. |
| 21 | +* **Component Map**: A registry that maps component names to their actual Angular component classes. |
| 22 | +* **Component Context**: Detailed metadata for each component, including its purpose and input properties. |
| 23 | +* **App Description & Layout Rules**: A detailed prompt for the Executor AI, explaining the application's domain and defining `LayoutCompositions`—rules for how to assemble components for different scenarios (e.g., a "list view" vs. a "detail view"). |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## How It Works: The Rendering Flow |
| 28 | + |
| 29 | +1. **User Interaction**: A user types a prompt into the chat interface of the running Angular application (e.g., "show me modern lofts in New York"). |
| 30 | +2. **Genkit Flow**: The prompt is sent to the Genkit backend, which triggers the Executor AI flow. |
| 31 | +3. **AI-Powered Layout Generation**: The Executor AI analyzes the user's prompt, the `app-context.ts` for the current application, and the available data (from `data-store.ts`). It then constructs a detailed JSON `componentSchema` that represents the optimal UI layout for the user's request. |
| 32 | +4. **Dynamic Rendering**: The Angular frontend receives this JSON schema. |
| 33 | +5. **UI Display**: The `MagicAiRendererComponent` recursively walks the JSON tree and dynamically creates and renders the corresponding Angular components, resulting in a fully interactive view generated in real-time. |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## Sample Applications |
| 38 | + |
| 39 | +This repository includes three sample applications to demonstrate the framework's capabilities. You can switch between these applications by updating the `APP_NAME` constant in `src/app/magic-ai/app-context.ts`. |
| 40 | + |
| 41 | +### 1. Haven - Vacation Rentals |
| 42 | + |
| 43 | +* **Description**: An application for discovering and booking vacation rentals. The AI can generate views for property listings, detailed property pages, and inspirational destination cards. |
| 44 | +* **Directory**: `src/app/apps/vacation-rentals` |
| 45 | + |
| 46 | +### 2. Magic Bookstore |
| 47 | + |
| 48 | +* **Description**: An e-commerce application for a bookstore. The AI can create layouts for book search results, detailed product pages with author bios and reviews, and carousels of related books. |
| 49 | +* **Directory**: `src/app/apps/magic-bookstore` |
| 50 | + |
| 51 | +### 3. Adev Docs - Angular Documentation |
| 52 | + |
| 53 | +* **Description**: A dynamic documentation site for the Angular framework. The AI can assemble complex, informative pages by combining concept explanations, API references, code snippets, and full code examples in response to a user's query. |
| 54 | +* **Directory**: `src/app/apps/adev-docs` |
| 55 | +* **Please note**: This is a sample application and is not intended to be used as an official source for Angular documentation. |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## Getting Started |
| 60 | + |
| 61 | +### Prerequisites |
| 62 | + |
| 63 | +* [Node.js](https://nodejs.org/) (LTS version recommended) |
| 64 | +* [pnpm](https://pnpm.io/installation) |
| 65 | +* [Angular CLI](https://angular.io/cli) |
| 66 | +* [Python](https://www.python.org/downloads/) (3.x recommended) |
| 67 | + |
| 68 | +### Installation |
| 69 | + |
| 70 | +1. Clone the repository: |
| 71 | + ```bash |
| 72 | + git clone <repository-url> |
| 73 | + cd <repository-directory> |
| 74 | + ``` |
| 75 | + |
| 76 | +2. Install the Node.js dependencies: |
| 77 | + ```bash |
| 78 | + pnpm install |
| 79 | + ``` |
| 80 | + |
| 81 | +### Running the Application |
| 82 | + |
| 83 | +1. **Start the Angular Development Server**: |
| 84 | + This will serve the frontend application. |
| 85 | + ```bash |
| 86 | + ng serve |
| 87 | + ``` |
| 88 | + The application will be available at `http://localhost:4200/`. |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## Creating a New Dynamic Application |
| 95 | + |
| 96 | +This application comes packaged with an MCP server that allows you to easily create your own SDUI application like the provided samples. For detailed instructions on how to use the Generator AI, please refer to the [MCP Server README](mcp-server/README.md). |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## Project Structure |
| 101 | + |
| 102 | +``` |
| 103 | +/ |
| 104 | +├── mcp-server/ # Python server for the Generator AI |
| 105 | +│ └── server.py |
| 106 | +├── src/ |
| 107 | +│ ├── app/ |
| 108 | +│ │ ├── apps/ # Contains the dynamic application packages |
| 109 | +│ │ │ ├── vacation-rentals/ |
| 110 | +│ │ │ │ ├── components/ |
| 111 | +│ │ │ │ └── app-context.ts # The "manifest" for the Haven app |
| 112 | +│ │ │ └── ... |
| 113 | +│ │ ├── magic-ai/ # Core logic for rendering AI-generated schemas |
| 114 | +│ │ │ └── magic-ai-renderer.component.ts |
| 115 | +│ │ └── chat/ # The main chat interface component |
| 116 | +│ └── genkit-utils/ # Genkit flows and prompts for the Executor AI |
| 117 | +│ ├── flows.ts |
| 118 | +│ └── prompts.ts |
| 119 | +└── angular.json |
| 120 | +└── package.json |
| 121 | +``` |
0 commit comments