How stevedylandev/bhvr works
1. Overall shape
- This repo is a Bun-based TypeScript monorepo starter with three first-class packages: client, server, and shared.
- The architecture is intentionally split so the frontend and backend can be built and deployed independently while still sharing types.
2. Root workspace and orchestration
- The root contains the workspace configuration and monorepo tooling: package.json, turbo.json, and the root tsconfig.json.
- Turbo is the build/dev orchestrator across packages; it coordinates tasks like dev, build, lint, type-check, and test across the workspaces.
3. Shared contract layer
- shared/ is the cross-cutting boundary for code used by both client and server.
- Its main role is to hold TypeScript types/contracts, especially ApiResponse, so API payloads are typed consistently on both sides.
- This is the repo’s main type-safety mechanism: the frontend imports the same response shape that the backend returns.
4. Server subsystem
- server/ is a minimal Hono HTTP API.
- The entry point is server/src/index.ts, which defines the app, enables CORS, and exposes routes.
- The backend currently serves:
- / returning plain text
- /hello returning a JSON ApiResponse
- This server is framework-light and designed to be portable across deployment targets.
5. Client subsystem
- client/ is a Vite + React application.
- The app entry is client/src/main.tsx, with the main UI in client/src/App.tsx.
- The UI is mostly a starter/demo shell, but it contains the important integration point: a button that calls the backend API and renders the response.
6. Client-to-server data flow
- The key runtime flow is:
- User clicks “Call API” in the React client
- Client sends fetch(${SERVER_URL}/hello)
- Server returns JSON shaped as ApiResponse
- Client stores the response in component state and renders it
- SERVER_URL comes from import.meta.env.VITE_SERVER_URL, with a localhost fallback, so the client can target different environments without code changes.
7. CORS and cross-origin boundary
- The server enables CORS, which is necessary because the client and server are expected to run on separate origins during development and possibly in deployment.
- This is a meaningful architectural boundary: the frontend is not coupled to same-origin hosting.
8. Type sharing and module resolution
- Shared types are imported from the shared package by both app layers, e.g. import { ApiResponse } from 'shared'.
- TypeScript path/workspace setup is doing important work here; the repo is structured so the shared package is treated as a local dependency rather than copied code.
9. Runtime and build stack
- Bun is the package manager and JavaScript runtime for the repo.
- Vite handles frontend dev server and bundling.
- Hono handles backend request routing.
- React provides the UI layer.
- These choices matter architecturally because they keep client and server decoupled and deployable in different environments.
10. File-level boundaries
- The repo is deliberately sparse:
- client/src/ = presentation and browser-side API calls
- server/src/ = HTTP endpoints and server middleware
- shared/src/ = reusable contracts and types
- There is no database, auth system, or external service integration in the current codebase; those would be added behind the server boundary later.
11. What an architecture diagram should show
- A monorepo container with three packages.
- client and server as separate runtime processes/services.
- shared as a dependency feeding both sides.
- A request arrow from the React UI to the Hono API, with CORS on the server side.
- Type flow from shared into both client and server, especially around ApiResponse.
12. Current maturity
- This is a starter template, not a full product system.
- Its architecture is centered on establishing a clean, type-safe full-stack boundary that can later grow to include routing, persistence, auth, and deployment-specific adapters without changing the core structure.
Main entry points: src/index.ts API entry · package.json Client pkg · App.tsx App shell · types/index.ts Api types
Components 13
Workspace
Monorepo orchestration and build tooling
Client
Vite + React browser application
- Client pkg · Frontend workspace package
client/package.json - Main entry · Browser app bootstrap
client/src/main.tsx - App shell · Starter UI and API call flow
client/src/App.tsx - Vite · Dev server and bundler for the client
client/vite.config.ts
Server
Hono HTTP API service
- Server pkg · Backend workspace package
server/package.json - API entry · HTTP app setup and middleware
server/src/index.ts - Hono · Lightweight request routing layer
Shared
Cross-package TypeScript contracts
- Shared pkg · Cross-package contract workspace
shared/package.json - Contracts · Shared exports for client and server
shared/src/index.ts - Api types · API response shapes and shared contracts
shared/src/types/index.ts
Connections 15
- Monorepo → Turbo: orchestrates · Workspace tasks are coordinated through Turbo
- Monorepo → Bun: uses · Bun provides the package/runtime layer
- Monorepo → Client pkg: contains · Frontend workspace
- Monorepo → Server pkg: contains · Backend workspace
- Monorepo → Shared pkg: contains · Shared contracts workspace
- Client pkg → Vite: builds with · Client package is bundled and served by Vite
- Client pkg → Main entry: starts at · Client runtime entry point
- Main entry → App shell: renders · Bootstraps the main UI component
- App shell → API entry: fetches API · Browser UI calls the backend hello endpoint
- App shell → Api types: types · Client uses shared response contracts
- Server pkg → API entry: starts at · Backend entry point
- API entry → Hono: uses · Request routing and middleware come from Hono
- API entry → Api types: returns · API responses follow shared contracts
- Shared pkg → Contracts: exports · Package surface for shared imports
- Contracts → Api types: re-exports · Shared type definitions are exposed to consumers