Erstes lauffähiges Grundgerüst: Monorepo, Fastify-API, React-Startseite, Docker

This commit is contained in:
2026-07-19 01:14:29 +02:00
parent 657496fe49
commit 7b8723729b
39 changed files with 4388 additions and 15 deletions

View File

@@ -0,0 +1,70 @@
import { existsSync, mkdirSync } from "node:fs";
import { dirname } from "node:path";
import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import * as schema from "./schema.js";
const databasePath = process.env.DATABASE_PATH ?? "./data/launchpad.db";
// Stellt sicher, dass das Verzeichnis für die SQLite-Datei existiert
// (relevant im Docker-Volume /data).
const dir = dirname(databasePath);
if (dir !== "." && !existsSync(dir)) {
mkdirSync(dir, { recursive: true });
}
const sqlite = new Database(databasePath);
sqlite.pragma("journal_mode = WAL");
sqlite.pragma("foreign_keys = ON");
export const db = drizzle(sqlite, { schema });
/**
* Legt die Tabellen an, falls sie noch nicht existieren.
* Für den ersten Commit reicht ein einfaches "CREATE TABLE IF NOT EXISTS",
* spätere Commits ersetzen dies durch echte Drizzle-Migrationen (drizzle-kit).
*/
export function ensureSchema(): void {
sqlite.exec(`
CREATE TABLE IF NOT EXISTS devices (
id TEXT PRIMARY KEY,
hostname TEXT NOT NULL,
ip TEXT NOT NULL,
mac TEXT,
manufacturer TEXT,
model TEXT,
online INTEGER NOT NULL DEFAULT 0,
source TEXT NOT NULL,
last_scan TEXT,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS services (
id TEXT PRIMARY KEY,
device_id TEXT NOT NULL REFERENCES devices(id) ON DELETE CASCADE,
display_name TEXT NOT NULL,
category TEXT,
favorite INTEGER NOT NULL DEFAULT 0,
"order" REAL NOT NULL DEFAULT 0,
alias TEXT NOT NULL DEFAULT '[]',
icon TEXT,
hostname TEXT NOT NULL,
url TEXT NOT NULL,
https INTEGER NOT NULL DEFAULT 0,
port INTEGER NOT NULL,
favicon TEXT,
description TEXT,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS categories (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
"order" REAL NOT NULL DEFAULT 0,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL
);
`);
}

View File

@@ -0,0 +1,60 @@
import { sqliteTable, text, integer, real } from "drizzle-orm/sqlite-core";
/**
* Ein physisches/logisches Gerät im Netzwerk (z. B. per FritzBox-Scan gefunden).
*/
export const devices = sqliteTable("devices", {
id: text("id").primaryKey(),
hostname: text("hostname").notNull(),
ip: text("ip").notNull(),
mac: text("mac"),
manufacturer: text("manufacturer"),
model: text("model"),
online: integer("online", { mode: "boolean" }).notNull().default(false),
source: text("source").notNull(), // fritzbox | dns | http | https | portscan | manual
lastScan: text("last_scan"), // ISO-8601
createdAt: text("created_at").notNull(),
updatedAt: text("updated_at").notNull(),
});
/**
* Ein Dienst, der auf einem Gerät läuft (z. B. Frigate, Portainer, Gitea ...).
* Benutzeränderungen (displayName, category, favorite, order, alias, icon)
* dürfen von Scans NIEMALS überschrieben werden siehe README/Spezifikation.
*/
export const services = sqliteTable("services", {
id: text("id").primaryKey(),
deviceId: text("device_id")
.notNull()
.references(() => devices.id, { onDelete: "cascade" }),
// vom Benutzer gepflegt, wird von Scans nicht überschrieben
displayName: text("display_name").notNull(),
category: text("category"),
favorite: integer("favorite", { mode: "boolean" }).notNull().default(false),
order: real("order").notNull().default(0),
alias: text("alias").notNull().default("[]"), // JSON-Array als String
icon: text("icon"),
// von Scans aktualisierbar
hostname: text("hostname").notNull(),
url: text("url").notNull(),
https: integer("https", { mode: "boolean" }).notNull().default(false),
port: integer("port").notNull(),
favicon: text("favicon"),
description: text("description"),
createdAt: text("created_at").notNull(),
updatedAt: text("updated_at").notNull(),
});
/**
* Frei definierbare Kategorien (Erstellen/Löschen/Umbenennen/Sortieren per Drag & Drop).
*/
export const categories = sqliteTable("categories", {
id: text("id").primaryKey(),
name: text("name").notNull(),
order: real("order").notNull().default(0),
createdAt: text("created_at").notNull(),
updatedAt: text("updated_at").notNull(),
});