# stevedylandev/bhvr architecture

> Architecture diagram of the GitHub repository stevedylandev/bhvr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stevedylandev/bhvr
- Repository: https://github.com/stevedylandev/bhvr

## Overview

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: [`server/src/index.ts`](https://github.com/stevedylandev/bhvr/blob/main/server/src/index.ts) (API entry), [`client/package.json`](https://github.com/stevedylandev/bhvr/blob/main/client/package.json) (Client pkg), [`client/src/App.tsx`](https://github.com/stevedylandev/bhvr/blob/main/client/src/App.tsx) (App shell), [`shared/src/types/index.ts`](https://github.com/stevedylandev/bhvr/blob/main/shared/src/types/index.ts) (Api types)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workspace["Workspace"]
  node_root["Monorepo<br/>workspace"]
  node_turbo["Turbo<br/>orchestrator<br/>[turbo.json]"]
  node_bun["Bun<br/>runtime/pkgmgr<br/>[bun.lock]"]
end

subgraph group_client["Client"]
  node_client_pkg["Client pkg<br/>[package.json]"]
  node_client_main["Main entry<br/>react entry<br/>[main.tsx]"]
  node_client_app["App shell<br/>react UI<br/>[App.tsx]"]
  node_vite["Vite<br/>frontend build<br/>[vite.config.ts]"]
end

subgraph group_server["Server"]
  node_server_pkg["Server pkg<br/>[package.json]"]
  node_server_main["API entry<br/>hono app<br/>[index.ts]"]
  node_hono["Hono<br/>web framework"]
end

subgraph group_shared["Shared"]
  node_shared_pkg["Shared pkg<br/>[package.json]"]
  node_shared_index["Contracts<br/>types module<br/>[index.ts]"]
  node_shared_types["Api types<br/>type defs<br/>[index.ts]"]
end

node_root -->|"orchestrates"| node_turbo
node_root -->|"uses"| node_bun
node_root -->|"contains"| node_client_pkg
node_root -->|"contains"| node_server_pkg
node_root -->|"contains"| node_shared_pkg
node_client_pkg -->|"builds with"| node_vite
node_client_pkg -->|"starts at"| node_client_main
node_client_main -->|"renders"| node_client_app
node_client_app -.->|"fetches API"| node_server_main
node_client_app -->|"types"| node_shared_types
node_server_pkg -->|"starts at"| node_server_main
node_server_main -->|"uses"| node_hono
node_server_main -->|"returns"| node_shared_types
node_shared_pkg -->|"exports"| node_shared_index
node_shared_index -->|"re-exports"| node_shared_types

click node_turbo "https://github.com/stevedylandev/bhvr/blob/main/turbo.json"
click node_bun "https://github.com/stevedylandev/bhvr/blob/main/bun.lock"
click node_client_pkg "https://github.com/stevedylandev/bhvr/blob/main/client/package.json"
click node_client_main "https://github.com/stevedylandev/bhvr/blob/main/client/src/main.tsx"
click node_client_app "https://github.com/stevedylandev/bhvr/blob/main/client/src/App.tsx"
click node_vite "https://github.com/stevedylandev/bhvr/blob/main/client/vite.config.ts"
click node_server_pkg "https://github.com/stevedylandev/bhvr/blob/main/server/package.json"
click node_server_main "https://github.com/stevedylandev/bhvr/blob/main/server/src/index.ts"
click node_shared_pkg "https://github.com/stevedylandev/bhvr/blob/main/shared/package.json"
click node_shared_index "https://github.com/stevedylandev/bhvr/blob/main/shared/src/index.ts"
click node_shared_types "https://github.com/stevedylandev/bhvr/blob/main/shared/src/types/index.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_root,node_turbo,node_bun toneBlue
class node_client_pkg,node_client_main,node_client_app,node_vite toneAmber
class node_server_pkg,node_server_main,node_hono toneMint
class node_shared_pkg,node_shared_index,node_shared_types toneRose
```

## Components

### Workspace

Monorepo orchestration and build tooling

- **Monorepo**: workspace · Workspace root and package coordination
- [Turbo](https://github.com/stevedylandev/bhvr/blob/main/turbo.json): orchestrator · Runs package tasks across the monorepo · `turbo.json`
- [Bun](https://github.com/stevedylandev/bhvr/blob/main/bun.lock): runtime/pkgmgr · Package manager and JavaScript runtime · `bun.lock`

### Client

Vite + React browser application

- [Client pkg](https://github.com/stevedylandev/bhvr/blob/main/client/package.json): package · Frontend workspace package · `client/package.json`
- [Main entry](https://github.com/stevedylandev/bhvr/blob/main/client/src/main.tsx): react entry · Browser app bootstrap · `client/src/main.tsx`
- [App shell](https://github.com/stevedylandev/bhvr/blob/main/client/src/App.tsx): react UI · Starter UI and API call flow · `client/src/App.tsx`
- [Vite](https://github.com/stevedylandev/bhvr/blob/main/client/vite.config.ts): frontend build · Dev server and bundler for the client · `client/vite.config.ts`

### Server

Hono HTTP API service

- [Server pkg](https://github.com/stevedylandev/bhvr/blob/main/server/package.json): package · Backend workspace package · `server/package.json`
- [API entry](https://github.com/stevedylandev/bhvr/blob/main/server/src/index.ts): hono app · HTTP app setup and middleware · `server/src/index.ts`
- **Hono**: web framework · Lightweight request routing layer

### Shared

Cross-package TypeScript contracts

- [Shared pkg](https://github.com/stevedylandev/bhvr/blob/main/shared/package.json): package · Cross-package contract workspace · `shared/package.json`
- [Contracts](https://github.com/stevedylandev/bhvr/blob/main/shared/src/index.ts): types module · Shared exports for client and server · `shared/src/index.ts`
- [Api types](https://github.com/stevedylandev/bhvr/blob/main/shared/src/types/index.ts): type defs · API response shapes and shared contracts · `shared/src/types/index.ts`

## Connections

- 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
