A TypeScript monorepo with tRPC, Drizzle, and InversifyJS
- Monorepo: Turborepo + Bun workspaces
- API: tRPC with automatic transaction management
- Database: Drizzle ORM with PostgreSQL
- Auth: Better Auth with Drizzle adapter
- DI: InversifyJS with request-scoped transactions via AsyncLocalStorage
- Frontend: Vite + React + TanStack Router
├── apps/
│ ├── server/ # Bun tRPC server
│ └── web/ # Vite React frontend
├── packages/
│ ├── auth/ # Better Auth configuration
│ ├── bootstrap/ # DI container initialization
│ ├── db/ # Drizzle ORM schemas & migrations
│ ├── di/ # Dependency injection (InversifyJS)
│ ├── env/ # Type-safe environment variables
│ ├── repository/ # Data access layer
│ ├── routes/ # tRPC routers & procedures
│ ├── service/ # Business logic services
│ ├── use-case/ # Application use cases
│ └── types/ # Shared TypeScript types
└── package.json
- Bun >= 1.3.5
- PostgreSQL database
-
Install dependencies:
bun install
-
Copy environment file and configure:
cp .env.example .env # Edit .env with your database credentials -
Generate and run database migrations:
bun run db:generate bun run db:migrate
-
Start development servers:
bun run dev
bun run dev- Start all development serversbun run build- Build all packagesbun run db:generate- Generate Drizzle migrationsbun run db:migrate- Run database migrationsbun run db:studio- Open Drizzle Studio
- Request arrives → tRPC handler
- Transaction middleware starts DB transaction
- Child DI container created with transaction bound
- Repositories resolved from child container get the transaction
- On success → transaction commits
- On error → transaction rolls back
This ensures all database operations within a single request share the same transaction.