chore: Updated readme 76ce986a
Steve · 2025-04-29 14:41 1 file(s) · +147 −0
README.md +147 −0
30 30
└── package.json          # Root package.json with workspaces
31 31
```
32 32
33 +
### Server
34 +
35 +
bhvr uses Hono as a backend API for it's simplicity and massive ecosystem of plugins. If you have ever used Express then it might feel familiar. Declaring routes and returning data is easy.
36 +
37 +
```
38 +
server
39 +
├── bun.lock
40 +
├── package.json
41 +
├── README.md
42 +
├── src
43 +
│   └── index.ts
44 +
└── tsconfig.json
45 +
```
46 +
47 +
```typescript src/index.ts
48 +
import { Hono } from 'hono'
49 +
import { cors } from 'hono/cors'
50 +
import type { ApiResponse } from 'shared/dist'
51 +
52 +
const app = new Hono()
53 +
54 +
app.use(cors())
55 +
56 +
app.get('/', (c) => {
57 +
  return c.text('Hello Hono!')
58 +
})
59 +
60 +
app.get('/hello', async (c) => {
61 +
62 +
  const data: ApiResponse = {
63 +
    message: "Hello BHVR!",
64 +
    success: true
65 +
  }
66 +
67 +
  return c.json(data, { status: 200 })
68 +
})
69 +
70 +
export default app
71 +
```
72 +
73 +
If you wanted to add a database to Hono you can do so with a multitude of Typescript libraries like [Supabase](https://supabase.com), or ORMs like [Drizzle](https://orm.drizzle.team/docs/get-started) or [Prisma](https://www.prisma.io/orm)
74 +
75 +
### Client
76 +
77 +
bhvr uses Vite + React Typescript template, which means you can build your frontend just as you would with any other React app. This makes it flexible to add UI components like [shadcn/ui](https://ui.shadcn.com) or routing using [React Router](https://reactrouter.com/start/declarative/installation).
78 +
79 +
```
80 +
client
81 +
├── eslint.config.js
82 +
├── index.html
83 +
├── package.json
84 +
├── public
85 +
│   └── vite.svg
86 +
├── README.md
87 +
├── src
88 +
│   ├── App.css
89 +
│   ├── App.tsx
90 +
│   ├── assets
91 +
│   ├── index.css
92 +
│   ├── main.tsx
93 +
│   └── vite-env.d.ts
94 +
├── tsconfig.app.json
95 +
├── tsconfig.json
96 +
├── tsconfig.node.json
97 +
└── vite.config.ts
98 +
```
99 +
100 +
```typescript src/App.tsx
101 +
import { useState } from 'react'
102 +
import beaver from './assets/beaver.svg'
103 +
import { ApiResponse } from 'shared'
104 +
import './App.css'
105 +
106 +
const SERVER_URL = import.meta.env.VITE_SERVER_URL || "http://localhost:3000"
107 +
108 +
function App() {
109 +
  const [data, setData] = useState<ApiResponse | undefined>()
110 +
111 +
  async function sendRequest() {
112 +
    try {
113 +
      const req = await fetch(`${SERVER_URL}/hello`)
114 +
      const res: ApiResponse = await req.json()
115 +
      setData(res)
116 +
    } catch (error) {
117 +
      console.log(error)
118 +
    }
119 +
  }
120 +
121 +
  return (
122 +
    <>
123 +
      <div>
124 +
        <a href="https://github.com/stevedylandev/bhvr" target="_blank">
125 +
          <img src={beaver} className="logo" alt="beaver logo" />
126 +
        </a>
127 +
      </div>
128 +
      <h1>bhvr</h1>
129 +
      <h2>Bun + Hono + Vite + React</h2>
130 +
      <p>A typesafe fullstack monorepo</p>
131 +
      <div className="card">
132 +
        <button onClick={sendRequest}>
133 +
          Call API
134 +
        </button>
135 +
        {data && (
136 +
          <pre className='response'>
137 +
            <code>
138 +
            Message: {data.message} <br />
139 +
            Success: {data.success.toString()}
140 +
            </code>
141 +
          </pre>
142 +
        )}
143 +
      </div>
144 +
      <p className="read-the-docs">
145 +
        Click the beaver to learn more
146 +
      </p>
147 +
    </>
148 +
  )
149 +
}
150 +
151 +
export default App
152 +
```
153 +
154 +
### Shared
155 +
156 +
The Shared package is used for anything you want to share between the Server and Client. This could be types or libraries that you use in both the enviorments.
157 +
158 +
```
159 +
shared
160 +
├── package.json
161 +
├── src
162 +
│   ├── index.ts
163 +
│   └── types
164 +
│       └── index.ts
165 +
└── tsconfig.json
166 +
```
167 +
168 +
Inside the `src/index.ts` we export any of our code from the folders so it's usabe in other parts of the monorepo
169 +
170 +
```typescript
171 +
export * from "./types"
172 +
```
173 +
174 +
By running `bun run dev` or `bun run build` it will compile and export the packages from `shared` so it can be used in either `client` or `server`
175 +
176 +
```typescript
177 +
import { ApiResponse } from 'shared'
178 +
```
179 +
33 180
## Getting Started
34 181
35 182
### Quick Start