Overview
The OneGlanse web app is built with Next.js 15 using the App Router, tRPC for type-safe APIs, and Better Auth for authentication. It provides the user interface for managing workspaces, prompts, and viewing brand intelligence analytics.Tech Stack
- Framework: Next.js 15 with App Router
- API Layer: tRPC v11 with React Query
- Authentication: Better Auth with Drizzle adapter
- Database: PostgreSQL via Drizzle ORM
- UI: React 19, Tailwind CSS 4
- State Management: React Query (TanStack Query)
Project Structure
tRPC Setup
Server-Side Context
The tRPC context provides database access and session information to all procedures:apps/web/src/server/api/trpc.ts
apps/web/src/server/api/trpc.ts:10-37
Client-Side Provider
The client useshttpBatchStreamLink for efficient request batching:
apps/web/src/trpc/react.tsx
apps/web/src/trpc/react.tsx:41-72
Router Composition
All API routers are composed in a singleappRouter:
apps/web/src/server/api/root.ts
apps/web/src/server/api/root.ts:10-18
Authentication
Better Auth Configuration
Better Auth is configured with Google OAuth and email/password authentication:apps/web/src/lib/auth/auth.ts
apps/web/src/lib/auth/auth.ts:10-48
Authentication Middleware
Protected procedures use theisAuthenticated middleware:
apps/web/src/server/api/procedures.ts
apps/web/src/server/api/procedures.ts:14-17
Key Routes and Pages
Dashboard Page
The main analytics dashboard displays brand intelligence data:apps/web/src/app/(auth)/dashboard/page.tsx
apps/web/src/app/(auth)/dashboard/page.tsx:34-209
Prompt Management
Users can store and manage prompts through the prompts router:apps/web/src/server/api/routers/prompt/prompt.ts
apps/web/src/server/api/routers/prompt/prompt.ts:14-54
Adding New Features
1. Create a New tRPC Router
Create a new router file inserver/api/routers/:
server/api/routers/myfeature/myfeature.ts
2. Add Router to Root
Register the router inserver/api/root.ts:
3. Create a Page
Add a new page inapp/(auth)/myfeature/page.tsx:
4. Implement Service Layer
Create service functions inpackages/services/src/myfeature/:
5. Add Middleware (Optional)
For rate limiting or custom authorization:Environment Variables
Required environment variables for the web app:Performance Considerations
React Query Configuration
The query client is configured with optimal stale time for SSR:apps/web/src/trpc/query-client.ts
apps/web/src/trpc/query-client.ts:7-25
Request Batching
tRPC automatically batches multiple queries made within the same tick:Development Commands
Related Documentation
- Services Layer - Business logic and data access
- Database - Schema and migrations
- Agent Worker - Background job processing