update
This commit is contained in:
@@ -1,21 +1,62 @@
|
||||
# shadcn/ui monorepo template
|
||||
# electro4ort
|
||||
|
||||
This is a TanStack Start monorepo template with shadcn/ui.
|
||||
A chat app: friends and direct messages, group chats, **realms** with **cauldrons** (communities and the rooms in them), files, reactions, and voice and video calls.
|
||||
|
||||
## Adding components
|
||||
| Where | What |
|
||||
| -------------------- | ---------------------------------------------------------------------------- |
|
||||
| `apps/api` | The API: NestJS, PostgreSQL through Drizzle, Better Auth, Socket.IO, LiveKit |
|
||||
| `apps/web` | The web app: TanStack Start, TanStack Query, React 19 |
|
||||
| `packages/contracts` | Request and response shapes shared by both, as Zod schemas |
|
||||
| `packages/ui` | The components (shadcn/ui on Base UI) |
|
||||
|
||||
To add components to your app, run the following command at the root of your `web` app:
|
||||
## Development
|
||||
|
||||
Needs Node 24, pnpm and Docker.
|
||||
|
||||
```bash
|
||||
pnpm dlx shadcn@latest add button -c apps/web
|
||||
docker compose -f docker-compose.local.yml up -d # PostgreSQL, Redis, LiveKit
|
||||
cp apps/api/.env.example apps/api/.env # then set BETTER_AUTH_SECRET
|
||||
cp apps/web/.env.example apps/web/.env
|
||||
pnpm install
|
||||
pnpm --filter api db:migrate
|
||||
pnpm dev # web on :3000, API on :3001
|
||||
```
|
||||
|
||||
This will place the ui components in the `packages/ui/src/components` directory.
|
||||
After changing the tables in `apps/api/src/db/schema`, run `pnpm db:generate --name <what-changed>` and `pnpm db:migrate` in `apps/api`.
|
||||
|
||||
## Using components
|
||||
To add a shadcn/ui component: `pnpm dlx shadcn@latest add button -c apps/web`. It lands in `packages/ui/src/components` and is imported as `@repo/ui/components/button`.
|
||||
|
||||
To use the components in your app, import them from the `ui` package.
|
||||
## Checks
|
||||
|
||||
```tsx
|
||||
import { Button } from "@workspace/ui/components/button";
|
||||
```bash
|
||||
pnpm turbo run lint typecheck build # everything
|
||||
pnpm turbo run test # unit tests
|
||||
pnpm --filter api test:e2e # API end to end; needs the containers above
|
||||
```
|
||||
|
||||
`.github/workflows/ci.yml` runs the same on every push and pull request, and builds both Docker images.
|
||||
|
||||
## Deploying
|
||||
|
||||
`docker-compose.yml` runs the whole app on one server: Caddy in front (HTTPS with certificates it fetches itself), the web app, the API, PostgreSQL, Redis and LiveKit.
|
||||
|
||||
1. Point three DNS names at the server: `example.com`, `api.example.com` and `livekit.example.com` (yours in place of `example.com`). The web app and the API must share a parent domain like this: the session cookie is only sent between pages of one site.
|
||||
2. Open the firewall for 80 and 443 (TCP), 443 (UDP), and for calls 7881 (TCP) and 7882 (UDP).
|
||||
3. On the server, in a checkout of this repository:
|
||||
|
||||
```bash
|
||||
cp .env.example .env # fill in the domain and the secrets; the file says how to make each
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
To update: `git pull`, then `docker compose up -d --build` again. Migrations are applied by the `migrate` service before the new API starts.
|
||||
|
||||
What to know before relying on it:
|
||||
|
||||
- **Back up** the `postgres-data` volume (`docker compose exec postgres pg_dump -U electro4ort electro4ort`) and, unless files go to S3, the `files` volume.
|
||||
- **Files** are kept on the server's disk by default. Set the `S3_*` variables in `.env` to keep them in a bucket instead, which is also what running more than one API instance needs.
|
||||
- **Calls** work for people whose network allows UDP or TCP to the two ports above. Networks that only let HTTPS out need a TURN server, which LiveKit can run itself: see [its deployment guide](https://docs.livekit.io/home/self-hosting/deployment/).
|
||||
- **Accounts** need no email confirmation and there is no password reset yet: both need an email provider.
|
||||
- The API trusts one proxy in front of it (`TRUST_PROXY=1`, Caddy). Behind another load balancer as well, raise it, or rate limits count the balancer instead of the caller.
|
||||
|
||||
To run the images elsewhere (Kubernetes, a platform): `docker build --target api .` and `docker build --target web --build-arg VITE_API_URL=https://api.example.com .`; the API's settings are listed in `apps/api/.env.example`, and its migrations run with `node dist/db/migrate.js` in the same image.
|
||||
|
||||
Reference in New Issue
Block a user