Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

11 changes: 9 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
.git
.data
.nuxt
.output
node_modules
db-data
dist
build
dist
docker
*.db
*.db-*
.env
6 changes: 0 additions & 6 deletions .env.sample

This file was deleted.

32 changes: 0 additions & 32 deletions .eslintrc.json

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on:
push:
branches: [master]
pull_request:

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm

# GitHub's Ubuntu runners ship Google Chrome; the PDF test uses it.
- run: echo "CHROME_BIN=$(command -v google-chrome)" >> "$GITHUB_ENV"

- run: npm ci
- run: npm run lint
- run: npx prettier --check .
- run: npm run typecheck
- run: npm test
- run: npm run build
23 changes: 19 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
db-data/
docker/
# Dependencies and build output
node_modules/
.vagrant
.env
.nuxt/
.output/
dist/
build/

# Local data
.data/
*.db
*.db-shm
*.db-wal
docker/

# Env
.env
.env.*
!example.env

# Misc
.DS_Store
.vagrant
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.12.1
24
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.nuxt
.output
.data
node_modules
server/db/migrations
package-lock.json
flake.lock
5 changes: 3 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"semi": true,
"singleQuote": true,
"bracketSpacing": true,
"arrowParens": "avoid"
}
"arrowParens": "avoid",
"trailingComma": "es5"
}
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

53 changes: 53 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project

Zeithub is an open source invoicing app for freelancers (clients, projects, bank accounts, addresses, line-item invoices with PDF export). It is a single Nuxt 4 app: a Vue 3.5 SPA in `app/` and a Nitro API in `server/`, backed by one SQLite file through Drizzle ORM.

## Commands

```bash
npm install # also runs `nuxt prepare` (generates .nuxt/ types)
npm run dev # http://localhost:3002, DB at .data/zeithub.db
npm run build && npm start # production build in .output/
npm test # Vitest: unit + e2e projects
npm run lint # ESLint (flat config from @nuxt/eslint)
npm run format # Prettier
npm run typecheck # nuxt typecheck (vue-tsc)
npm run db:generate -- --name my-change # migration from schema changes
```

- Run one project: `npx vitest run --project unit` (fast, no server) or `--project e2e` (builds the app, runs it against a temp SQLite file). Filter with `-t "isolation"`.
- The e2e PDF test needs Chrome/Chromium: it uses `CHROME_BIN`, or Google Chrome's default macOS path. It is skipped if neither exists.
- Env vars: `DATABASE_PATH`, `NUXT_APP_SECRET` (required in production, 32+ chars; generated in dev), `CHROME_BIN`, `NUXT_SESSION_COOKIE_SECURE`. See `example.env`.
- Node 24 (`.nvmrc`, `flake.nix`, Dockerfile).

## Architecture

**Layout.** `app/` is the client (pages, components, layouts, stores, middleware). `server/` is Nitro (`api/`, `utils/`, `plugins/`, `db/`). `shared/` is imported by both. Nuxt auto-imports `app/{components,composables,utils,stores}`, `server/utils`, `shared/utils` and `shared/types`. Other files (e.g. `shared/invoice/document.ts`, `server/db/schema.ts`) are imported explicitly (`#shared/...` or relative paths).

**Database.** `server/db/schema.ts` is the source of truth. Drizzle uses `casing: 'snake_case'`, so code is camelCase and columns are snake_case with no aliasing. Money is integer cents (`unitPriceCents`, `discountCents`); `taxRate` is a percent (real); invoice dates are ISO `YYYY-MM-DD` text. Foreign keys are enforced. `server/utils/db.ts` exposes one shared connection via `useDb()` (WAL mode). `server/plugins/database.ts` runs migrations from `server/db/migrations/` and seeds currencies on startup. The build copies migrations to `.output/server/migrations`. The driver is synchronous (better-sqlite3): use `.get()`, `.all()`, `.run()`, and `.sync()` on relational `db.query.*` calls. Transaction callbacks must be synchronous.

**API (`server/api`).** File-based routes, one handler per file named by method (`index.get.ts`, `[id].put.ts`, …). Each handler:

1. calls `requireUser(event)` → `userId`,
2. validates input with `readBodyAs(event, schema)` / `getIdParam(event)` / `getParamsAs(...)` (`server/utils/validate.ts`),
3. queries with Drizzle, always filtering with `eq(table.userId, userId)`.

When a body references other rows (clientId, bankAccountId, projectId…), call `assertReferencesOwned` (`server/utils/ownership.ts`) so users can't attach each other's data. Errors use `createError({ statusCode })`. 400 responses carry `data.issues: [{ path, message }]`. Responses are plain data, with no `{ success }` envelope. Deleting a client, address or bank account used by an invoice returns 409.

**Validation schemas.** `shared/utils/schemas.ts` holds the zod schemas for every request body. The API validates with them, and forms run the same schema client-side (`validationMessages`) before submitting, so messages match.

**Auth.** `nuxt-auth-utils`: a sealed, httpOnly cookie session holding `{ user: { id, name } }` (type in `shared/types/auth.d.ts`). Passwords are scrypt (`hashPassword`). Legacy bcrypt hashes (imported from MySQL) are verified with bcryptjs and rehashed on sign-in (`server/utils/users.ts`). Client side: `useUserSession()`; `app/middleware/auth.global.ts` guards pages; `app/plugins/unauthorized.client.ts` sends the user to `/signin` on any API 401. Nothing auth-related lives in localStorage.

**Client.** Pages use `<script setup>` with top-level `await` on Pinia setup stores in `app/stores/` (one per resource; stores own all API calls via `$fetch`). Annotate `$fetch<T>()` when assigning to a typed ref: inferring through Nitro's typed routes can hit TS2321 "excessive stack depth". `InvoiceForm.vue` is shared by the new and edit pages, and saves a localStorage draft for new invoices. API errors go through `errorMessages()` into `<FormErrors>`. Styling is Tailwind v4 via `@tailwindcss/vite`; shared component classes (`.btn`, `.input`, `.select`, `.label`…) are in `app/assets/css/main.css`. Icons: `<Icon name="fa6-solid:…" />` (bundled locally).

**Invoice rendering.** `shared/invoice/document.ts` is the one invoice layout, written with `h()` and its own CSS scoped under `.invoice-page`. The invoice page renders it on screen, and `server/api/invoices/[id]/pdf.get.ts` renders it with `vue/server-renderer` and prints it with puppeteer-core, using one shared Chromium (`server/utils/browser.ts`). Data comes from `loadInvoiceDocument()` in `server/utils/invoices.ts`, one relational query. Totals come from `computeInvoiceTotals()` (`shared/utils/invoice-totals.ts`): lines rounded to cents, flat discount, then tax. Avoid class names in the document that clash with the app's global classes.

**Import from MySQL.** `scripts/import-mysql.ts` (`npm run db:import-mysql`, needs `MYSQL_URL`) is a one-off migration from the pre-0.6 MariaDB schema. `mysql2` is a dev dependency used only there.

## Style

Prettier 3: single quotes, semicolons, 2-space indent, 80 cols, `arrowParens: avoid`, `trailingComma: es5`. ESLint via `@nuxt/eslint` + `eslint-config-prettier`; prefix intentionally unused variables with `_`.
72 changes: 38 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
FROM node:18.12.1-alpine
# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

# Installs latest Chromium package.
RUN apk add --no-cache \
chromium \
nss \
freetype \
freetype-dev \
harfbuzz \
ca-certificates \
ttf-freefont \
g++ \
gcc \
libgcc \
libstdc++ \
linux-headers \
make

RUN npm install --quiet node-gyp -g
RUN npm install

# Bundle app source
# syntax=docker/dockerfile:1

# --- Build ---
FROM node:24-slim AS build
WORKDIR /app

COPY . .
ENV CHROME_BIN="/usr/bin/chromium-browser"
RUN npm run build
RUN npm prune
# EXPOSE 3000
CMD ["npm", "start"]
# No install scripts needed: better-sqlite3 ships prebuilt binaries, and
# skipping scripts avoids its fallback node-gyp build (and a toolchain).
RUN npm ci --ignore-scripts && npm run build

# --- Run ---
FROM node:24-slim

# Chromium renders the invoice PDFs.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
chromium \
fonts-liberation \
fonts-dejavu-core \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

ENV NODE_ENV=production \
HOST=0.0.0.0 \
PORT=3000 \
DATABASE_PATH=/data/zeithub.db \
CHROME_BIN=/usr/bin/chromium

WORKDIR /app
COPY --from=build /app/.output ./.output

# The SQLite database lives in /data; mount a volume there.
RUN mkdir -p /data && chown node:node /data
USER node
VOLUME /data

EXPOSE 3000
CMD ["node", ".output/server/index.mjs"]
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

Loading
Loading