GenUI Data Explorer
Ask questions about your data and explore the answers with interactive charts, tables, and metric cards. A Mastra agent selects React components from a catalog to present each answer in a CopilotKit chat. Start with the included sample Sales dataset to try generative UI without connecting your own database.
Why we built this
A text answer is not always the best way to explore data. Trends need charts, comparisons need context, and individual records need tables. This template shows how to build generative UI with Mastra: the agent chooses what to display as the conversation evolves, while your components control how it looks and behaves.
Demo
Prerequisites
- Node.js 24.15.0 or later and NPM.
- OpenAI API key: set
OPENAI_API_KEYin.envfor the defaultgpt-4.1-minimodel. Optionally setANALYSIS_MODELto another OpenAI model ID available to your account.
Quickstart π
- Create the project
- Run
npx create-mastra@latest genui-data-explorer --template genui-data-explorer. - Run
cd genui-data-explorer, thennpm install.
- Run
- Add your API key
- Run
cp .env.example .envand fill in the key described under Prerequisites.
- Run
- Start the app
- Run
npm run dev. This starts the Mastra server and web app and prepares the sample data automatically on the first run. - Open the data explorer and ask βShow monthly bookings over the last twelve complete months.β Look for a trend chart with the underlying values.
- Run
Try it out
- Ask βCompare bookings by segment over the last twelve complete monthsβ to see a ranked comparison.
- Follow up with βShow the same analysis for SMBβ to explore a filtered view.
- Ask βShow closed-won opportunity records for the last complete monthβ to inspect a table of deals.
- Ask βShow a customer retention cohort heatmap for the last twelve complete monthsβ to explore retention by activation month.
- Use Correct this view to change an answer's interpretation. The correction updates that card without changing source records. Return through Chat history to continue a saved conversation.
Customization
- Ask your coding agent: βAdd a compact bookings summary component and teach the agent when to choose it. Explore the code and propose a plan before making changes.β Follow Adding UI components for catalog registration, rendering, and selection instructions.
- Connect your own data or adapt the example to another domain. See Data sources for the source contract and related Mastra templates for databases, PDFs, CSVs, and documents.
For the startup flow, server/client boundaries, and independent deployment commands, see Architecture and deployment.
About Mastra templates
Mastra templates are starting points you can run, explore, and adapt. Official templates live in the Mastra monorepo and are synchronized to standalone repositories.
