Monorepo Structure
The project follows a workspace-based monorepo pattern:The monorepo currently has no shared packages, but the structure supports adding them in
packages/ for code sharing between web and mobile apps.Workspace Organization
Package Manager: Bun
The project uses Bun 1.2.21 as the package manager:- Fast installation: 10-20x faster than npm
- TypeScript support: Native TypeScript execution
- Drop-in replacement: Compatible with npm packages
- Built-in tools: Bundler, test runner, and package manager
Workspaces
- apps/web
- apps/native
- packages/*
Next.js 16 Web Application
- Framework: Next.js 16 with App Router
- Runtime: Node.js / Vercel Edge
- Database: PostgreSQL with Drizzle ORM
- AI: Anthropic Claude, OpenAI, Google AI
- Styling: TailwindCSS 4 + shadcn/ui
- AI chat interface with streaming
- Canvas LMS integration
- Todo and study material management
- Better-Auth authentication
Build System: Turborepo
Turborepo orchestrates tasks across the monorepo with intelligent caching and parallel execution.Turborepo Configuration
Theturbo.json file defines the build pipeline:
Pipeline Tasks
build
Production builds with dependency ordering and output caching
dev
Development servers with hot reload (no caching)
lint
Code quality checks across all workspaces
check-types
TypeScript type checking for all apps
Database Tasks
Special tasks for database operations (run on web app only):- db:push: Push schema changes to database (development)
- db:studio: Open Drizzle Studio UI
- db:generate: Generate migration files
- db:migrate: Run migrations (production)
cache: false and persistent: true.
Development Workflow
Starting Development
- All Apps
- Web Only
- Mobile Only
Building Applications
Database Management
Code Quality
- Code formatting (double quotes, space indentation)
- Linting rules (correctness, style, nursery)
- Import organization
- Tailwind class sorting
Code Conventions
Biome Configuration
The project uses Biome (not ESLint/Prettier) for code quality:Formatter
Double quotes, space indentation, 80-character line width
Linter
Recommended rules + custom style rules for consistency
Organizer
Automatic import organization on save
Tailwind Sorter
Automatic class sorting for cn(), clsx(), cva()
File Naming Conventions
- Components: PascalCase (
Button.tsx,UserProfile.tsx) - Utilities: kebab-case (
date-helpers.ts,filter-builders.ts) - Types: kebab-case (
filters.ts,auth-types.ts) - Routes: kebab-case or
(groups)for Next.js App Router
Import Organization
Biome automatically organizes imports:- External packages (React, Next.js, third-party)
- Internal modules (
@/ai,@/db,@/lib) - Relative imports (
./components,../utils)
TypeScript Conventions
- Use
interfacefor object shapes - Use
typefor unions, intersections, and mapped types - Path alias:
@/maps tosrc/in each app - Strict mode enabled in all workspaces
Environment Variables
Global Environment
All environment variables are stored in the root.env file:
The
globalEnv array in turbo.json ensures these variables are available to all tasks and invalidates cache when they change.Environment Validation
The web app validates environment variables at build time using@t3-oss/env-nextjs:
- Type safety for environment variables
- Runtime validation on build
- Clear error messages for missing or invalid variables
Turborepo Features
Remote Caching
Turborepo supports remote caching for CI/CD:- Share build cache across team and CI
- Skip redundant builds
- Faster CI/CD pipelines
Task Filtering
Run tasks on specific workspaces:Dependency Graph
Visualize the dependency graph:Database Architecture
Schema Organization
Database schemas are modular and located inapps/web/src/db/schema/:
- Authentication
- Todo System
- Study Materials
- AI Memory
auth.ts
user: Core user accounts with settings JSONBsession: User sessions with IP trackingaccount: OAuth provider credentialsverification: Email verification tokens
Migration Strategy
Development
Use
bun db:push to sync schema changes directly without migrationsProduction
Use
bun db:generate and bun db:migrate for version-controlled migrationsapps/web/src/db/migrations/.
Performance Optimizations
Build Performance
- Turborepo caching: Skips unchanged tasks
- Parallel execution: Runs independent tasks simultaneously
- Incremental builds: Only rebuilds changed files
- Bun speed: 10-20x faster package installation
Runtime Performance
- Next.js Server Components: Reduced client bundle size
- React Native New Architecture: Improved rendering performance
- Streaming SSR: Faster time-to-first-byte
- Code splitting: Automatic chunking via Next.js
CI/CD Integration
Typical CI/CD pipeline with Turborepo:Remote caching with Vercel Turborepo requires
TURBO_TOKEN and TURBO_TEAM secrets for authentication.Deployment Architecture
- Web App
- Mobile App
- Database
Vercel (Recommended)
- Automatic deployments from Git
- Edge runtime support
- Environment variable management
- Preview deployments for PRs
Monitoring & Observability
Web App
- Vercel Analytics: Page views and Web Vitals
- AI SDK DevTools: AI interaction debugging
- React Query DevTools: Server state inspection
- Drizzle Studio: Database GUI for development
Mobile App
- Expo Development Tools: Metro bundler and debugging
- React DevTools: Component inspection
- Flipper: Native debugging and network inspection
Best Practices
Monorepo
Keep shared code in packages, app-specific code in apps
Environment
Store all variables in root .env, validate with Zod
Database
Use migrations in production, db:push in development
Code Quality
Run
bun check before committing, use Biome auto-fixTroubleshooting
Common Issues
Problem: Turborepo cache not invalidating- Ensure variables are in root
.env, notapps/web/.env - Verify
globalEnvarray inturbo.json - Restart dev server after changing
.env
- Always use
bun install, nevernpm install - Delete
node_modulesand reinstall if needed
Future Enhancements
Shared Packages
Extract common code into
packages/ for reuseTesting
Add Jest, Vitest, or Bun test for unit testing
Storybook
Document UI components with interactive stories
E2E Tests
Implement Playwright or Cypress for end-to-end testing