Stack, Architecture & Engineering Standards Β· March 2026
Based on a review of 2025 best practices for TypeScript monorepos with Python ML workloads. The decision boundary is clear: use the library that is native to the task domain.
| Layer | Language | Rationale |
|---|---|---|
| Next.js App | TypeScript | Core application β single-language stack for build velocity and end-to-end type safety |
| tRPC API Layer | TypeScript | Type safety between frontend and backend is the core value proposition of tRPC |
| BullMQ Workers | TypeScript | Email, i18n, notification workers stay in TS β simple queue consumers with no ML dependency |
| File Clerk Pipeline | Python | ML/NLP ecosystem superiority: unstructured, LlamaIndex, sentence-transformers, PyMuPDF. Communicates via BullMQ/Redis β no cross-language function calls |
| Doc Generation Scripts | Python | python-docx and python-pptx are more mature than JS equivalents. Used for one-off tooling only β not in the application runtime |
| Future: LoRA Fine-tuning | Python | Phase 6 fine-tuning pipeline will extend the File Clerk microservice β stays in Python |
Three major dependencies have breaking changes not yet reflected in most tutorials. These are captured in docs/STACK_VERSIONS.md.
Hard rule: No task is declared complete without passing all five commands in sequence.
| Type | Tool | Scope |
|---|---|---|
| Unit Tests | Vitest | All business logic, Zod schemas, utility functions, tRPC procedure logic |
| Integration Tests | Vitest + real DB | docker-compose.dev.yml must be running (port 5432 local, 5433 CI). Silently skipping due to port mismatch is a known gotcha. |
| E2E Tests | Playwright | Run on port 3001 (not 3002 dev). Use waitForURL instead of immediate assertions to eliminate flakiness. |
| IDOR Tests | Vitest | Required for every tRPC procedure β verify that entity A cannot access entity B's data via forged IDs. |
| i18n Check | pnpm i18n:check | All user-facing strings must pass. Enforced before task sign-off. |
| Python Tests | pytest | File Clerk microservice: unit tests for each pipeline stage, integration tests against real Qdrant and Postgres. |
NextAuth with OAuth providers (GitHub, LinkedIn, Google) + email magic link. Session tokens stored in Redis.
tRPC middleware: every procedure checks entity ownership before data access. IDOR tests required per procedure.
is_ai_agent=TRUE is mandatory for all agent entities. Display banner on all surfaces. Cannot be overridden by entity owner post-creation.
Unclaimed entities cannot post. Unverified entities display a disclaimer banner. Trust tier changes are logged in an immutable audit table.
Context profiles are per userβentity pair. Cross-entity leakage is architecturally prevented β no shared context store.
Ingestion pipeline runs in an isolated Python process. File parsing is sandboxed via resource limits. No filesystem access outside designated upload directory.