nyxcore-systems
7 min read

Leveling Up Our AI: A Deep Dive into Smarter Personas, Analytics, and Reports

We just wrapped a major development sprint focused on making our AI tools smarter, more insightful, and a joy to use. From evolving AI personas to deep-dive analytics and on-demand reports, here's how we did it.

AIUXAnalyticsPrismaTypeScriptNext.jsDeveloperToolsFullstack

Just wrapped up a monumental session, and I'm buzzing. The goal was ambitious: a major UX and intelligence upgrade across the board. We're talking about making our AI interactions more intelligent, our insights clearer, and our overall dev experience smoother.

It was a three-phase sprint that touched nearly every part of the application, from database schemas to client-side UI, and I'm thrilled to report: all phases are implemented, type-checked, and running cleanly on the dev server. The user is currently clicking through the new features, and honestly, it feels good.

Let's break down how we injected a whole lot more brainpower and usability into our system.

Phase 1: Building the Brain – The Foundation for Intelligence

The core idea here was to move beyond static AI interactions. We wanted our AI 'personas' to evolve, to have traits, and for their usage to be tracked intelligently. This meant a significant overhaul of our backend data models and services.

First up, the Persona model in prisma/schema.prisma got a serious upgrade. We added nine new fields: level, xp, traits, specializations, tags, category, usageCount, successRate, and metadata. This transforms our personas from simple labels into dynamic entities that can grow and specialize.

prisma
// prisma/schema.prisma
model Persona {
  id              String           @id @default(cuid())
  name            String           @unique
  description     String?
  // ... existing fields
  level           Int              @default(1)
  xp              Int              @default(0)
  traits          String[]         @default([]) // e.g., ["detail-oriented", "creative"]
  specializations String[]         @default([]) // e.g., ["frontend-dev", "security-auditor"]
  tags            String[]         @default([]) // for filtering and categorization
  category        String?          // e.g., "Developer", "Analyst"
  usageCount      Int              @default(0)
  successRate     Float            @default(0.0) // 0.0 to 1.0
  metadata        Json?
  // ...
}

After updating the schema, a quick db:push and db:generate got the database and Prisma client in sync. The beauty of additive changes with safe defaults meant no migration headaches—existing persona rows simply picked up their default level=1, xp=0, and empty arrays.

To make these personas come alive, I created src/server/services/persona-stats.ts. This service handles the core logic for tracking persona usage and calculating XP and levels. Every time a persona is used, incrementPersonaUsage() is called, dishing out 10 XP and updating the level based on floor(xp/100)+1.

typescript
// src/server/services/persona-stats.ts (simplified)
export const incrementPersonaUsage = async (personaId: string) => {
  const persona = await prisma.persona.findUnique({ where: { id: personaId } });
  if (!persona) return;

  const newXp = persona.xp + 10;
  const newLevel = Math.floor(newXp / 100) + 1;

  await prisma.persona.update({
    where: { id: personaId },
    data: {
      xp: newXp,
      level: newLevel,
      usageCount: { increment: 1 },
    },
  });
};

This tracking is integrated as a fire-and-forget operation within workflow-engine.ts (for per-step and workflow-level personas) and discussion-service.ts. This ensures usage data is passively collected without blocking the main execution flow.

On the UI front, the sidebar navigation (src/components/layout/sidebar.tsx) got a much-needed organizational pass, grouping items into logical sections like Main, AI Studio, Development, Knowledge, and System. This immediately makes the app feel more structured and less overwhelming.

Finally, we expanded our analytics backend in src/server/trpc/routers/dashboard.ts to expose modelUsage (per provider:model), successRates (for workflows, autofixes, and refactors), and personaStats. This data forms the backbone of our new analytics dashboards.

Phase 2: Visualizing the Insights – The Analytics Dashboard

With the data plumbing in place, the next step was to make it visible and actionable. This meant building out a new suite of UI components for our analytics dashboard.

  • Model Usage Table (src/components/dashboard/analytics/model-usage-table.tsx): A sortable, 7-column table that shows which LLMs are being used, by whom, and how often. The little provider-colored dots next to each model name are a subtle but effective visual cue.
  • Success Rates Panel (src/components/dashboard/analytics/success-rates-panel.tsx): Simple, clear progress bars—green, yellow, or red—to instantly convey the success rates of workflows, autofixes, and refactors. This is critical for understanding where our AI assistance is excelling and where it might need tuning.
  • Persona Overview Panel (src/components/dashboard/analytics/persona-overview-panel.tsx): A grid of persona cards, each displaying its current level, XP, traits, and specializations. This panel truly brings the persona evolution to life, allowing users to see their AI assistants grow.

These components were then composed into src/components/dashboard/analytics/analytics-dashboard.tsx. Additionally, the src/app/(dashboard)/dashboard/personas/page.tsx got a significant facelift, now featuring level badges, XP bars, trait/specialization badges, and filters for categories and tags. It's a joy to browse through your evolving AI team!

Phase 3: Actionable Intelligence – On-Demand Reports

Collecting data and visualizing it is great, but often, you need to distill that information into a concise, shareable format. Enter report generation.

I created src/server/services/report-generator.ts, a powerful service capable of generating reports in four distinct styles: executive, security, marketing, and technical. What makes this truly intelligent is its persona-awareness and BYOK (Bring Your Own Key) provider resolution. This means reports can be tailored to the audience and leverage the user's preferred LLM.

typescript
// src/server/services/report-generator.ts (simplified concept)
async function generateReport(
  context: ReportContext,
  style: ReportStyle,
  personaId?: string,
  llmProvider?: string
): Promise<string> {
  const prompt = buildPromptForStyle(context, style, personaId);
  const llm = resolveLlmProvider(llmProvider || 'default'); // BYOK resolution
  const report = await llm.generate(prompt);
  return report;
}

To provide rich context for these reports, src/server/services/report-context.ts was built with functions like formatAutoFixContext, formatRefactorContext, and formatWorkflowContext. These ensure the LLM receives all the necessary details to generate a relevant report.

Finally, we integrated report generation directly into the user workflow. generateReport mutations were added to auto-fix.ts, refactor.ts, and workflows.ts routers. A reusable src/components/shared/report-generator-modal.tsx was created, allowing users to pick a style, choose a persona, and generate/download their report right from the detail pages (auto-fix/[id]/page.tsx, refactor/[id]/page.tsx, workflows/[id]/page.tsx).

Lessons from the Trenches: Smooth Sailing

One of the most satisfying aspects of this sprint was the almost complete lack of major issues. This wasn't just luck; it was a testament to a few architectural decisions:

  • Additive Changes: All schema modifications were additive, and new fields had safe defaults. This meant db:push was a breeze, requiring no complex migrations and preserving existing data seamlessly. It's a valuable reminder of how to evolve a schema gracefully.
  • Parallel Development: I used parallel "Task agents" (in my head, at least!) for Phase 2 (UI) and Phase 3 (reports). Because the backend foundation (Phase 1) was solid and well-defined, these two major feature sets could be developed and type-checked independently, then integrated with minimal friction. This modular approach significantly sped up development.
  • Clear Contracts: The tRPC layer between frontend and backend ensured type safety and clear API contracts, preventing a lot of potential integration bugs.

What's Next? Immediate Post-Launch Thoughts

While the core functionality is shipped, a few immediate next steps come to mind:

  1. User Feedback & UI Polish: The user is currently exploring. Their feedback will be crucial for any minor UI adjustments or usability tweaks.
  2. End-to-End Report Verification: We need to thoroughly test report generation with a completed autofix/refactor/workflow run and a properly configured LLM API key to ensure the output is exactly as expected.
  3. Enhanced Persona Display: Consider adding persona XP/level display directly into the workflow detail page's persona picker. This would provide immediate context to the user.
  4. Refined Success Rate Calculation: Currently, updatePersonaStats isn't automatically called on workflow completion. Integrating this would ensure persona success rates are dynamically recalculated, offering even more accurate insights into persona performance.

This was a massive undertaking, touching 7 new files and modifying 14 existing ones. But seeing the system come alive with new intelligence and a much-improved user experience makes every line of code worth it. Here's to building smarter tools!

json
{"thingsDone":["Implemented major UX and intelligence upgrade","Expanded Persona model with level, XP, traits, etc.","Created persona usage and stats tracking service","Grouped sidebar navigation","Expanded analytics backend with model usage, success rates, persona stats","Built new analytics UI components (model usage table, success rates panel, persona overview)","Enhanced persona display pages with new stats","Developed persona-aware, multi-style report generator service","Integrated report generation into autofix, refactor, and workflow pages via a modal"],"pains":["No major issues encountered. Additive changes with safe defaults made schema updates smooth. Parallel development of UI and reports worked efficiently."],"successes":["All 3 phases implemented, typecheck clean, dev server running. User is clicking through new features. Smooth development process due to architectural choices."],"techStack":["Prisma","TypeScript","Next.js","tRPC","React","TailwindCSS (implied by components)","LLM APIs (for report generation)"]}