How adiwanwade/everynote works
Project Type and Purpose
• This is a full-stack monorepo starter built with Turborepo (“T3 Turbo”), featuring two front-ends (a Next.js web app and an Expo mobile app) and a shared backend API.
• It demonstrates a modular, package-based architecture: front-ends in apps/, shared business logic and services in packages/, plus centralized tooling in tooling/.
High-Level Architecture Components
a. Frontend Apps
• apps/nextjs – Next.js 14 web application, serves pages, static assets, and tRPC API routes.
• apps/expo – Expo SDK React Native mobile application, uses Expo Router and NativeWind.
b. Shared Backend & Business Logic
• packages/api – tRPC v11 router definitions (auth, notes, post) used by Next.js to serve JSON-RPC.
• packages/auth – Better Auth server/client code (JWT, middleware, environment).
• packages/db – Drizzle ORM schema and client configured for Supabase (edge runtime).
• packages/validators – Shared Zod or custom validators for input sanitization.
• packages/ui – Shadcn-style React UI components consumed by both front-ends.
c. External Services
• Supabase / Vercel Postgres – hosted database for Drizzle ORM.
• Vercel – hosts Next.js; indispensible for API and tRPC endpoints.
• Expo / EAS – mobile build, OTA update, and App Store distribution.
d. Tooling
• Turborepo (turbo.json) – orchestrates builds, lint, tests across packages/apps.
• pnpm – workspace package manager (pnpm-workspace.yaml).
• Shared ESLint/Prettier/Tailwind/TypeScript configs in tooling/.
Component Interactions & Data Flows
• Next.js App
→ imports packages/api to expose tRPC endpoint under /api/trpc.
→ uses packages/auth middleware to secure routes and issue JWTs.
→ uses packages/db to read/write from Supabase (edge).
→ consumes packages/ui for consistent UI.
• Expo App
→ imports packages/api as a dev-only dependency for typesafety.
→ uses a custom getBaseUrl to call tRPC endpoints on the deployed Next.js server.
→ stores session via session-store, fetches via AuthContext powered by Better Auth.
→ consumes packages/ui for mobile UI components.
• Database & Auth
→ packages/db and packages/auth coordinate to enforce schema and auth rules.
→ tRPC resolvers call into packages/db and packages/auth to perform business operations.
Architectural Patterns & Design Principles
• Monorepo with strict module boundaries: each package has its own tsconfig, package.json, build outputs.
• Layered architecture: front-end → API layer (tRPC) → services (auth, db) → external systems.
• Code sharing via packages: UI, validation, API contracts are single-sourced.
• Edge-first patterns: Next.js API routes configured with export const runtime = "edge".
• Convention-based routing in Next.js and Expo Router.
Essential Elements to Capture
• Monorepo root orchestrated by Turborepo & pnpm.
• Two app entry points: Next.js (web, server + client) and Expo (native mobile).
• API layer (tRPC) sitting inside Next.js, backed by packages/api, packages/auth, packages/db.
• Shared packages: ui, validators.
• External dependencies: Supabase, Vercel, EAS/Expo build services.
• Data flows: Front-end → tRPC → Auth/DB → External DB.