-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/hono rpc #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
597a475
feat: restructure app for rpc
timkalan 02aba82
feat: zod validation example
timkalan be387bf
feat: better auth
timkalan 916e546
feat: try to trace better auth
timkalan 083d33b
feat: disallow imports from `server` -> `web`
drobilc 19e0901
feat: add `hono-rpc-query`
drobilc d3cf93b
feat: streamline demo
timkalan fddbf3f
refactor: a bit nicer auth instrumentation
timkalan d703326
Merge pull request #2 from zerodays/fix/server-imports
zigapk 164223e
fix: remove pnpm
zigapk 07356a8
docs: update todos in readme
zigapk 3f422ca
feat: add dynamic ports
zigapk cb66a9f
feat: add agents.md
zigapk 90834ef
feat: middleware, server structure
timkalan 9d2e6b4
Merge branch 'master' into feat/hono-rpc
timkalan 1fbf847
fix: reorganize toplevel assets
drobilc 4b5d1d6
feat: testing setup
timkalan d187b0d
feat: db import script
timkalan 596f99f
fix: add env to test
timkalan 0d77dbf
chore: explain why we ignore `server.ts`
drobilc 6869a8b
fix: read cookie max age from env variable
drobilc eac53b2
fix: types
drobilc 9447027
fix: readme
drobilc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| # AGENTS.md | ||
|
|
||
| Guidelines for AI coding agents working in this repository. | ||
|
|
||
| ## Tech Stack | ||
|
|
||
| - **Runtime:** Bun | ||
| - **Frontend:** React 19 + Vite + TailwindCSS v4 | ||
| - **Backend:** Hono (running on Bun) | ||
| - **Database:** PostgreSQL + Drizzle ORM | ||
| - **Auth:** Better Auth | ||
| - **Validation:** Zod | ||
| - **Linting/Formatting:** Biome | ||
| - **i18n:** i18next | ||
|
|
||
| ## Commands | ||
|
|
||
| ```bash | ||
| # Development | ||
| bun dev # Start full dev environment (DB, Vite, Drizzle Studio) | ||
| bun run build # Production build | ||
| bun start # Run production server | ||
|
|
||
| # Code Quality | ||
| bun run lint # Fix lint issues (Biome + locale check) | ||
| bun run lint:check # Check only (CI) | ||
| bun run format # Fix formatting | ||
| bun run format:check # Check only (CI) | ||
| bun run typecheck # Type-check all projects | ||
| bun run all # Run format + lint + typecheck + build | ||
|
|
||
| # Database | ||
| bun run db:start # Start PostgreSQL container | ||
| bun run db:push # Sync schema to DB (dev only) | ||
| bun run db:generate # Generate migrations | ||
| bun run db:migrate # Apply migrations | ||
| bun run db:regenerate-auth # Regenerate Better Auth schema | ||
| ``` | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ``` | ||
| web/ # Frontend (React) | ||
| components/ui/ # Reusable UI components (shadcn pattern) | ||
| lib/api.ts # Type-safe Hono RPC client | ||
| lib/auth-client.ts # Better Auth client | ||
| i18n/locales/ # Translation files | ||
|
|
||
| server/ # Backend (Hono) | ||
| server.tsx # Entry point & route assembly | ||
| auth.ts # Better Auth config | ||
| logger.ts # Pino logger with trace context | ||
| middleware/ # Global middleware | ||
| features/ # Feature modules (one folder per feature) | ||
| {feature}/ | ||
| index.ts # Re-exports feature routes | ||
| routes/ # One file per route handler | ||
| database/ | ||
| schema/auth.ts # Better Auth tables (auto-generated) | ||
| schema/app.ts # Custom tables (add your tables here) | ||
|
|
||
| env.ts # Environment schema (Zod) | ||
| ``` | ||
|
|
||
| ## Code Style | ||
|
|
||
| ### Formatting (Biome) | ||
| - 2-space indentation, double quotes, imports auto-organized | ||
|
|
||
| ### TypeScript | ||
| - Strict mode enabled | ||
| - Use `type` imports: `import type { Foo } from "bar"` | ||
| - Path aliases: `@/*` (root), `~/*` (web/) | ||
|
|
||
| ### Naming | ||
| - Files: `kebab-case.ts` | ||
| - Components: `PascalCase` | ||
| - Variables/functions: `camelCase` | ||
| - Database tables: `snake_case` | ||
|
|
||
| ### React Components | ||
| - Use function declarations, not arrow functions for components | ||
| - Props type inline: `function Button({ ...props }: React.ComponentProps<"button">)` | ||
| - Use `cn()` from `~/lib/utils` for class merging | ||
|
|
||
| ### Hono Routes | ||
| - One route handler per file in `server/features/{feature}/routes/` | ||
| - Use Zod validation with `zValidator`: | ||
| ```typescript | ||
| import { zValidator } from "@hono/zod-validator"; | ||
| import { Hono } from "hono"; | ||
| import { z } from "zod"; | ||
|
|
||
| const schema = z.object({ name: z.string().min(1) }); | ||
|
|
||
| export const myRoute = new Hono().get( | ||
| "/", | ||
| zValidator("query", schema), | ||
| async (c) => { | ||
| const { name } = c.req.valid("query"); | ||
| return c.json({ message: `Hello, ${name}!` }); | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ### Database (Drizzle) | ||
| - Define tables in `server/database/schema/app.ts` | ||
| - Use `drizzle-orm/pg-core` for table definitions | ||
| - Reference auth tables from `./auth.ts` for foreign keys | ||
|
|
||
| ### Environment Variables | ||
| - Define in `env.ts` with Zod schemas | ||
| - Access via `import env from "@/env"` | ||
| - Never hardcode secrets | ||
|
|
||
| ### i18n | ||
| - Add translations to `web/i18n/locales/{lang}/common.ts` | ||
| - Use `useTranslation("common")` hook | ||
| - Run `bun run check-locale` to verify all keys exist in all locales | ||
|
|
||
| ### Error Handling | ||
| - Use Zod for input validation | ||
| - Wrap pages in `<ErrorBoundary>` | ||
| - Server errors logged via `logger` from `@/server/logger` | ||
|
|
||
| ### Logging (Server) | ||
| ```typescript | ||
| import { logger } from "@/server/logger"; | ||
| logger.info({ userId, action }, "User performed action"); | ||
| ``` | ||
| Logger auto-injects traceId, spanId, userId when available. | ||
|
|
||
| ### Tracing (OpenTelemetry) | ||
| - HTTP requests, DB queries, and fetch calls are auto-traced | ||
| - For custom spans: `import { withSpan } from "@/server/tracing"` | ||
|
|
||
| ## Adding New Features | ||
|
|
||
| **Backend Route:** Create `server/features/{feature}/routes/{route-name}.ts`, re-export in `index.ts`, mount in `server/server.tsx` | ||
|
|
||
| **Frontend Page:** Add route to `web/router.tsx`, create component in `web/components/` | ||
|
|
||
| **Database Table:** Add to `server/database/schema/app.ts`, run `bun run db:push` (dev) or `db:generate && db:migrate` (prod) | ||
|
|
||
| ## Better Auth | ||
|
|
||
| - Config: `server/auth.ts` | ||
| - Client: `web/lib/auth-client.ts` | ||
| - After adding plugins: `bun run db:regenerate-auth` | ||
| - Session in routes: `await auth.api.getSession({ headers: c.req.raw.headers })` | ||
|
|
||
| ## API Client (Frontend) | ||
|
|
||
| Use type-safe Hono RPC: | ||
| ```typescript | ||
| import { api } from "~/lib/api"; | ||
| import { useMutation } from "@tanstack/react-query"; | ||
|
|
||
| const mutation = useMutation(api["my-route"].$get.mutationOptions({})); | ||
| mutation.mutate({ query: { name: "World" } }); | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.