Skip to content

Add Mastra Next.js Postgres Redis sample#628

Draft
raphaeltm wants to merge 9 commits intomainfrom
feat/mastra-nextjs-postgres-redis-sample
Draft

Add Mastra Next.js Postgres Redis sample#628
raphaeltm wants to merge 9 commits intomainfrom
feat/mastra-nextjs-postgres-redis-sample

Conversation

@raphaeltm
Copy link
Copy Markdown
Collaborator

@raphaeltm raphaeltm commented Apr 1, 2026

Summary

  • add a new mastra-nextjs-postgres-redis sample in the samples catalog
  • build a multi-service Mastra prototype with Next.js, BullMQ, Postgres, Redis, and Defang-managed LLM wiring
  • add a local dev path with mock-agent mode and refine the UI after Playwright screenshot review

Verification

  • npm run build
  • docker compose -f compose.dev.yaml up --build -d
  • verified /api/health, /api/jobs/sync, /api/jobs, and /api/chat

Notes

  • local development uses MOCK_AGENT=true for fully functional compose-based verification without external model credentials
  • deployed mode is wired to the managed chat model service via x-defang-llm

Samples Checklist

✅ All good!

@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples April 1, 2026 19:01 — with GitHub Actions Failure
@raphaeltm raphaeltm marked this pull request as draft April 1, 2026 19:09
@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples April 4, 2026 12:29 — with GitHub Actions Failure
@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples April 7, 2026 09:37 — with GitHub Actions Failure
…c models

- Replace 3s polling with SSE endpoint (/api/dashboard/stream) for real-time
  queue progress at 300ms intervals
- Switch from JSONB embeddings to pgvector for cosine similarity search in SQL
- Use Mastra model router with provider/model format (e.g. bedrock/model-name)
  instead of AWS-specific runtime detection
- Update all deps to latest (Mastra 1.x, ai SDK 6.x, zod 4.x)
- Remove separate embedding Docker service from compose.yaml
- Extract hooks (useChat, useDashboard), components (ItemCard, ChatMessage),
  types, and formatting utils from page.tsx for readability
- Refactor chat route into focused functions (parseChatRequest,
  handleStreamingRequest, handleNonStreamingRequest)
- Consolidate duplicate runChatJson/runChatText into shared runChat()
- Extract fallback seed data to seed-data.ts
- Fix Mastra 1.x breaking changes (Agent id, tool execute signature,
  PostgresStore id, telemetry removal, v3 model spec)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples April 7, 2026 19:45 — with GitHub Actions Failure
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples April 7, 2026 19:47 — with GitHub Actions Failure
…e dedup

- Add MOCK_AGENT and LLM_MODEL to worker in compose.dev.yaml (was crashing)
- Add MOCK_AGENT to worker in compose.yaml for clarity
- Align Redis version to 6.2 in both compose files
- Import ChatStreamEvent from shared types instead of duplicating
- Remove unnecessary useMemo wrappers in page.tsx
- Remove dead code: runChatText, answerQuestionWithContext
- Remove unused _query param from searchItemsByEmbedding

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples April 7, 2026 19:56 — with GitHub Actions Failure
… OPENAI_API_KEY

- Add doc comments to chat route, hooks, agent, mastra index, and key
  ai.ts functions (parseJsonFromText, deterministicEmbedding, thinking splitter)
- Move tsx from devDependencies to dependencies (worker needs it at runtime)
- Add EMBEDDING_MODEL to compose.dev.yaml for dev/prod parity
- Remove unused OPENAI_API_KEY from both compose files
- Deduplicate SQL filter logic: extract shared applyFilters() used by both
  getItemsByType and searchItemsByEmbedding
- Share QUEUE_NAME constant between queue.ts and worker.ts

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples April 8, 2026 13:15 — with GitHub Actions Failure
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples April 8, 2026 16:41 — with GitHub Actions Failure
- Add Prerequisites section (Defang CLI, BYOC, Docker)
- Add proper Deployment section with Playground + BYOC subsections
- Add NOTE/WARNING callouts matching other samples
- Add LLM_MODEL/EMBEDDING_MODEL format examples (provider/model)
- Remove non-standard Features section (moved to description)
- Remove inline PostgreSQL TLS documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@raphaeltm raphaeltm had a problem deploying to deploy-changed-samples April 8, 2026 16:56 — with GitHub Actions Failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant