28f8e3b7b2
Includes nix develop shell (node, pg, vips), buildNpmPackage derivation, and a NixOS module for deploying as a systemd service with hardening, dedicated user, and configurable secrets via environmentFile. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
178 lines
3.8 KiB
Markdown
178 lines
3.8 KiB
Markdown
# buildfor_life_repair
|
|
|
|
Inventory and repair tracking system for vintage computers and audio equipment. Built with SvelteKit, PostgreSQL, and Tailwind CSS.
|
|
|
|
## Features
|
|
|
|
- **Device tracking** — computers, audio equipment, peripherals with full specs, images, documents
|
|
- **Component tracking** — individual parts (BlueSCSI, RAM, logic boards, etc.) linked to devices
|
|
- **Installation log** — full history of component installs/removals with timestamps
|
|
- **Operation/repair log** — per-device repair, inspection, cleaning, modification history
|
|
- **QR code labels** — printable labels for devices and components, scannable for quick lookup
|
|
- **Global search** — find devices/components by ID, name, or scanned QR code
|
|
- **Dark mode** — follows system preference or manual toggle
|
|
|
|
## Prerequisites
|
|
|
|
- [Node.js](https://nodejs.org/) 18+
|
|
- [PostgreSQL](https://www.postgresql.org/) 14+ (or Docker)
|
|
|
|
## Setup
|
|
|
|
### 1. Install dependencies
|
|
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
### 2. Set up the database
|
|
|
|
**Option A: Use your own PostgreSQL instance**
|
|
|
|
```sql
|
|
CREATE USER bflr WITH PASSWORD 'bflr_dev';
|
|
CREATE DATABASE buildfor_life_repair OWNER bflr;
|
|
\c buildfor_life_repair
|
|
GRANT ALL PRIVILEGES ON DATABASE buildfor_life_repair TO bflr;
|
|
GRANT ALL ON SCHEMA public TO bflr;
|
|
```
|
|
|
|
**Option B: Use Docker**
|
|
|
|
```bash
|
|
docker compose up -d
|
|
```
|
|
|
|
### 3. Configure environment
|
|
|
|
Copy the example env file and edit as needed:
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
```
|
|
|
|
Edit `.env` with your database connection string:
|
|
|
|
```
|
|
DATABASE_URL=postgresql://bflr:bflr_dev@localhost:5432/buildfor_life_repair
|
|
UPLOAD_DIR=static/uploads
|
|
BASE_URL=http://localhost:5173
|
|
```
|
|
|
|
### 4. Run database migrations
|
|
|
|
Push the schema to your database:
|
|
|
|
```bash
|
|
npm run db:push
|
|
```
|
|
|
|
Or generate and run migrations:
|
|
|
|
```bash
|
|
npm run db:generate
|
|
npm run db:migrate
|
|
```
|
|
|
|
### 5. Start the dev server
|
|
|
|
```bash
|
|
npm run dev
|
|
```
|
|
|
|
The app will be available at [http://localhost:5173](http://localhost:5173).
|
|
|
|
## Database commands
|
|
|
|
| Command | Description |
|
|
|---|---|
|
|
| `npm run db:push` | Push schema changes directly to the database |
|
|
| `npm run db:generate` | Generate SQL migration files from schema changes |
|
|
| `npm run db:migrate` | Run pending migrations |
|
|
| `npm run db:studio` | Open Drizzle Studio (visual database browser) |
|
|
|
|
## Build for production
|
|
|
|
```bash
|
|
npm run build
|
|
npm run preview
|
|
```
|
|
|
|
## NixOS
|
|
|
|
This project includes a Nix flake with a dev shell, package, and NixOS module.
|
|
|
|
### Development shell
|
|
|
|
```bash
|
|
nix develop
|
|
npm install
|
|
npm run dev
|
|
```
|
|
|
|
Or with direnv (`.envrc` is included):
|
|
|
|
```bash
|
|
direnv allow
|
|
npm install
|
|
npm run dev
|
|
```
|
|
|
|
### Build with Nix
|
|
|
|
```bash
|
|
nix build
|
|
```
|
|
|
|
### NixOS module (deploy as a service)
|
|
|
|
Add this flake to your NixOS configuration inputs, then:
|
|
|
|
```nix
|
|
# flake.nix
|
|
{
|
|
inputs.buildfor-life-repair.url = "git+https://git.b4l.co.th/B4L/buildfor_life_repair.git";
|
|
}
|
|
```
|
|
|
|
```nix
|
|
# configuration.nix
|
|
{ inputs, ... }:
|
|
{
|
|
imports = [ inputs.buildfor-life-repair.nixosModules.default ];
|
|
|
|
services.buildfor-life-repair = {
|
|
enable = true;
|
|
port = 3000;
|
|
databaseUrl = "postgresql://bflr:password@localhost:5432/buildfor_life_repair";
|
|
baseUrl = "https://repair.example.com";
|
|
openFirewall = true;
|
|
};
|
|
}
|
|
```
|
|
|
|
Or use an environment file for secrets:
|
|
|
|
```nix
|
|
services.buildfor-life-repair = {
|
|
enable = true;
|
|
port = 3000;
|
|
environmentFile = "/run/secrets/bflr-env"; # contains DATABASE_URL=...
|
|
baseUrl = "https://repair.example.com";
|
|
};
|
|
```
|
|
|
|
The module creates a systemd service with:
|
|
- Dedicated `bflr` user/group
|
|
- Upload directory at `/var/lib/buildfor-life-repair/uploads`
|
|
- Systemd hardening (NoNewPrivileges, ProtectSystem, PrivateTmp)
|
|
- Auto-restart on failure
|
|
- Optional firewall rule
|
|
|
|
## Tech stack
|
|
|
|
- **Frontend:** SvelteKit 5, Svelte 5 (runes), Tailwind CSS v4
|
|
- **Backend:** SvelteKit server, Drizzle ORM, PostgreSQL
|
|
- **Validation:** Zod
|
|
- **Other:** sharp (image thumbnails), qrcode (QR generation), date-fns
|