Monorepo Overview
ZeroStarter is organized as a monorepo using Bun workspaces and Turborepo. This structure promotes code sharing, consistent tooling, and efficient development workflows.Root Directory Structure
Workspaces Configuration
The monorepo is configured in the rootpackage.json:
- Shared dependencies across workspaces
- Internal package references using
workspace:* - Single
bun installfor the entire monorepo
Backend: api/hono/
The Hono backend API provides a type-safe REST API with authentication, rate limiting, and auto-generated documentation.Directory Structure
Key Files
src/index.ts - Application Entry Point
src/index.ts - Application Entry Point
The main entry point that:
- Initializes the Hono app
- Registers middleware (CORS, rate limiting, etc.)
- Mounts route handlers from
routers/ - Exports
AppTypefor frontend type safety - Starts the server
src/routers/ - API Routes
src/routers/ - API Routes
Each file in
routers/ defines a set of related endpoints:- Modular: Group related endpoints together
- Type-Safe: Export route types for frontend
- Composable: Import and mount in main app
src/middlewares/ - Custom Middleware
src/middlewares/ - Custom Middleware
Custom middleware for:
- Authentication checks
- Request validation
- Error handling
- Logging
- Rate limiting
Package Configuration
package.json
dev- Development with hot reloadbuild- Bundle with tsdownstart- Run production buildcheck-types- TypeScript type checking
Frontend: web/next/
The Next.js frontend provides the user interface with server components, client-side interactions, and type-safe API integration.Directory Structure
Key Directories
src/app/ - App Router
src/app/ - App Router
Next.js 13+ App Router with:Route Groups:
(content)/- Public content pages (docs, blog)(protected)/- Authenticated pages (dashboard)(llms.txt)/- AI-optimized documentation
layout.tsx- Shared layoutpage.tsx- Route componentloading.tsx- Loading stateerror.tsx- Error boundary
src/components/ - React Components
src/components/ - React Components
Organization:
ui/- Shadcn UI components (Button, Card, etc.)navbar/- Navigation and header componentssidebar/- Sidebar for docs and dashboardzeroui/- Custom ZeroStarter components
src/lib/api/ - Type-Safe API Client
src/lib/api/ - Type-Safe API Client
The Hono RPC client for type-safe API calls:Usage:
content/ - MDX Content
content/ - MDX Content
Package Configuration
package.json
Shared Packages: packages/
Shared packages contain code used by both frontend and backend, promoting code reuse and consistency.packages/auth/
Authentication logic using Better Auth.- Auth configuration
- Session management
- OAuth provider setup
better-auth@packages/db(for user storage)@packages/env(for secrets)
packages/db/
Database schema and Drizzle ORM client.src/schema/- Database table schemasdrizzle.config.ts- Migration configurationdrizzle/- Generated migration files
drizzle-orm- ORM librarydrizzle-kit- Migration toolpostgres- PostgreSQL driver
packages/env/
Type-safe environment variable validation.@t3-oss/env-core- Environment validationzod- Schema validationdotenv- Load .env files
packages/tsconfig/
Shared TypeScript configurations.tsconfig.json
Build System: Turborepo
Configuration
Theturbo.json at the project root configures build pipelines:
turbo.json
Task Dependencies
Turborepo automatically handles build order:Development Workflow
Starting Development
turbo run dev --ui tui- Starts all workspace dev servers
- Shows Turbo TUI with logs
Building for Production
- Builds packages in dependency order
- Uses Turbo’s cache for unchanged packages
- Outputs to
dist/and.next/directories
Adding Dependencies
Internal Package References
Workspaces can reference each other usingworkspace:*:
- Always uses local version
- No publishing required
- Hot reload during development
File Naming Conventions
TypeScript Files
- Components:
PascalCase.tsx(e.g.,Button.tsx) - Utilities:
kebab-case.ts(e.g.,api-client.ts) - Routes:
kebab-case.tsorroute.ts - Config:
*.config.ts
React Components
- UI Components:
button.tsx,card.tsx - Page Components:
page.tsx - Layout Components:
layout.tsx
Directories
- Route Groups:
(group-name)/ - Features:
kebab-case/ - Components:
kebab-case/
Environment Files
Generated Directories
These are automatically generated and should be in.gitignore:
Best Practices
Organizing Code
- Keep packages focused - Each package should have a single responsibility
- Use barrel exports - Export from
index.tsfor clean imports - Colocate related code - Keep components, hooks, and utils together
- Shared code in packages - Move reusable code to
packages/
Import Paths
Type Safety
- Export types from packages
- Use
AppTypefor API type safety - Validate env vars with Zod
- Enable strict mode in
tsconfig.json
Next Steps
Type-Safe API
Learn how to use Hono RPC for type-safe API calls
Database
Work with Drizzle ORM and database schema
Authentication
Implement authentication with Better Auth
Scripts
Explore available npm scripts and commands