Overview
Thepackages/ directory contains shared libraries used across all apps. This enables code reuse, consistent patterns, and a single source of truth.
Monorepo Rule: Business logic lives in
packages/. Apps contain only thin wrappers.Package Registry
| Package | Name | Purpose |
|---|---|---|
| db | @trendingsociety/db | Supabase client, types, query helpers |
| api | @trendingsociety/api | Response utilities, errors, logger |
| ui | @trendingsociety/ui | 42 shadcn/ui components |
| auth | @trendingsociety/auth | Supabase Auth utilities |
| integrations | @trendingsociety/integrations | Linear, Shopify, Slack, Tavily clients |
| jarvis | @trendingsociety/jarvis | AI assistant (voice, chat, contexts) |
| orchestration | @trendingsociety/orchestration | Agent routing, delegation |
| usage | @trendingsociety/usage | AI cost metering |
| content-engine | @trendingsociety/content-engine | Publishing pipeline |
| config | @trendingsociety/config | Env variables, feature flags |
| validation | @trendingsociety/validation | Schema validation |
| error-boundary | @trendingsociety/error-boundary | Error handling |
Architecture
Using Packages
Installation
Packages are automatically linked in the monorepo. Just add topackage.json:
Building
Packages are built before apps via Turborepo:Type Generation
For@trendingsociety/db, regenerate types after schema changes:
Package Location Rules
| Code Type | MUST Go In | Never In |
|---|---|---|
| Business logic (API calls) | packages/integrations/ | apps/*/src/app/api/ |
| Route handler factories | packages/api/src/{feature}/ | apps/*/src/app/api/ |
| Database queries | packages/db/src/queries/ | apps/*/lib/ |
| Shared UI components | packages/ui/ | apps/* (duplicated) |
| Thin API wrappers (10-15 lines) | apps/{app}/src/app/api/ | N/A (correct location) |
The 10-15 Line Rule
App-layer API routes should be thin wrappers that:- Extract tenant context (from auth/headers)
- Call shared handler from
packages/api/ - Return response
Creating New Packages
1
Create Directory
2
Initialize package.json
3
Add to Root
The package is auto-discovered by pnpm workspaces.
4
Use in Apps