106 lines
1.7 KiB
Markdown
106 lines
1.7 KiB
Markdown
# Playzer Monorepo
|
|
|
|
Este repositorio contiene:
|
|
|
|
- `apps/frontend`: React + Vite + TanStack Router/Query.
|
|
- `apps/backend`: Bun + Hono + Prisma + Better Auth.
|
|
- `packages/api-contract`: contratos Zod/tipos compartidos.
|
|
|
|
## Requisitos
|
|
|
|
- Bun reciente
|
|
- PostgreSQL disponible
|
|
|
|
## Setup rápido
|
|
|
|
1. Instalar dependencias:
|
|
|
|
```sh
|
|
bun install
|
|
```
|
|
|
|
2. Configurar backend:
|
|
|
|
```sh
|
|
cp apps/backend/.env.example apps/backend/.env
|
|
```
|
|
|
|
3. Configurar frontend:
|
|
|
|
```sh
|
|
cp apps/frontend/.env.example apps/frontend/.env
|
|
```
|
|
|
|
4. Ejecutar migraciones:
|
|
|
|
```sh
|
|
bun --filter backend prisma:migrate
|
|
```
|
|
|
|
## Variables de entorno
|
|
|
|
### Backend (`apps/backend/.env`)
|
|
|
|
- `DATABASE_URL`
|
|
- `BETTER_AUTH_SECRET`
|
|
- `BETTER_AUTH_URL`
|
|
- `APP_BASE_URL`
|
|
- `CORS_ORIGIN`
|
|
|
|
### Frontend (`apps/frontend/.env`)
|
|
|
|
- `VITE_API_BASE_URL`
|
|
|
|
## Desarrollo
|
|
|
|
Backend:
|
|
|
|
```sh
|
|
bun run dev:backend
|
|
```
|
|
|
|
Frontend:
|
|
|
|
```sh
|
|
bun run dev:frontend
|
|
```
|
|
|
|
Todo junto:
|
|
|
|
```sh
|
|
bun run dev
|
|
```
|
|
|
|
## Prisma
|
|
|
|
Regenerar cliente después de cambios de schema:
|
|
|
|
```sh
|
|
bun --filter backend prisma:generate
|
|
```
|
|
|
|
## Autenticación
|
|
|
|
El proyecto usa **Better Auth** con sesión por cookie.
|
|
|
|
- Backend: `c.get('user')` y `c.get('session')` en contexto Hono.
|
|
- Frontend: `authClient` con `fetchOptions.credentials = 'include'`.
|
|
- Frontend API: Axios con `withCredentials = true`.
|
|
- Backend CORS: `credentials: true`.
|
|
|
|
## Deploy (Docker)
|
|
|
|
- Build context: raíz del monorepo (`./`)
|
|
- Dockerfile: `./Dockerfile`
|
|
- Build args requeridos:
|
|
- `DATABASE_URL`
|
|
- `VITE_API_BASE_URL`
|
|
- `BETTER_AUTH_SECRET`
|
|
- `BETTER_AUTH_URL`
|
|
|
|
## Flujo recomendado de cambios de API
|
|
|
|
1. Actualizar contrato en `packages/api-contract`.
|
|
2. Implementar backend en `apps/backend`.
|
|
3. Consumir contrato desde frontend (`@repo/api-contract`).
|