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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ NEXT_PUBLIC_AUTH_PROVIDER=local
# Okta: OIDC_ROLE_CLAIM=groups
# Azure AD: OIDC_ROLE_CLAIM=roles

# ============================================
# STORAGE PROVIDER (Optional)
# ============================================
# Controls where application data is persisted.
# "local" (default) = browser localStorage only (zero config, great for dev)
# "sqlite" = SQLite file on server (persistent, single-node)
# "postgres" = PostgreSQL database (persistent, multi-node, enterprise)
#
# Note: NOT prefixed with NEXT_PUBLIC_ — server-side only, discovered at runtime
# via GET /api/storage/config endpoint.
STORAGE_PROVIDER=local

# SQLite storage path (required when STORAGE_PROVIDER=sqlite)
# STORAGE_SQLITE_PATH=./data/libredb-storage.db

# PostgreSQL connection URL (required when STORAGE_PROVIDER=postgres)
# STORAGE_POSTGRES_URL=postgresql://user:pass@host:5432/libredb

# ===========================================
# LLM Configuration (Strategy Pattern)
# ===========================================
Expand Down
28 changes: 27 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

LibreDB Studio is a web-based SQL IDE for cloud-native teams. It supports PostgreSQL, MySQL, SQLite, Oracle, SQL Server, MongoDB, Redis, and a demo mode with AI-powered query assistance.

## Github
* Repository: https://github.com/libredb/libredb-studio
* Container Registry: https://github.com/libredb/libredb-studio/pkgs/container/libredb-studio
* Docker Image: ghcr.io/libredb/libredb-studio:latest

## Development Commands

```bash
Expand Down Expand Up @@ -58,6 +63,7 @@ The project uses ESLint 9 for linting and `bun:test` for testing with `@testing-
- **AI:** Multi-model support (Gemini, OpenAI, Ollama, Custom)
- **Databases:** PostgreSQL (`pg`), MySQL (`mysql2`), SQLite (`better-sqlite3`), Oracle (`oracledb`), SQL Server (`mssql`), MongoDB (`mongodb`), Redis (`ioredis`)
- **Auth:** JWT-based with `jose` library + OIDC SSO with `openid-client` (Auth0, Keycloak, Okta, Azure AD)
- **Storage:** Pluggable storage layer — localStorage (default), SQLite (`better-sqlite3`), or PostgreSQL (`pg`)

### Directory Structure

Expand All @@ -69,6 +75,7 @@ src/
│ │ │ └── oidc/ # OIDC login + callback routes (PKCE, code exchange)
│ │ ├── ai/ # AI endpoints (chat, nl2sql, explain, safety)
│ │ ├── db/ # Query, schema, health, maintenance, transactions
│ │ ├── storage/ # Storage sync API (config, CRUD, migrate)
│ │ └── admin/ # Fleet health, audit endpoints
│ ├── admin/ # Admin dashboard (RBAC protected)
│ └── login/ # Login page
Expand All @@ -83,6 +90,15 @@ src/
│ └── ui/ # Shadcn/UI primitives
├── hooks/ # Custom React hooks
└── lib/
├── storage/ # Storage abstraction layer
│ ├── index.ts # Barrel export
│ ├── types.ts # StorageData, ServerStorageProvider interfaces
│ ├── storage-facade.ts # Public sync API + CustomEvent dispatch
│ ├── local-storage.ts # Pure localStorage CRUD
│ ├── factory.ts # Env-based provider factory (singleton)
│ └── providers/
│ ├── sqlite.ts # better-sqlite3 backend
│ └── postgres.ts # pg backend
├── db/ # Database provider module (Strategy Pattern)
│ ├── providers/
│ │ ├── sql/ # SQL providers (postgres, mysql, sqlite, oracle, mssql)
Expand Down Expand Up @@ -133,7 +149,12 @@ e2e/ # Playwright E2E tests (browser)

4. **API Routes:** All backend logic in `src/app/api/`. Protected routes require valid JWT. Public routes: `/login`, `/api/auth`, `/api/db/health`

5. **Client State:** LocalStorage for connections, query history, and saved queries (`src/lib/storage.ts`)
5. **Storage Abstraction:** `src/lib/storage/` module provides pluggable persistence:
- **Local** (default): Browser localStorage, zero config
- **SQLite**: `better-sqlite3` file DB for single-node persistent storage
- **PostgreSQL**: `pg` for multi-node enterprise storage
- Write-through cache: localStorage always serves reads; `useStorageSync` hook pushes mutations to server (debounced)
- Controlled by `STORAGE_PROVIDER` env var (server-side only, discovered at runtime via `/api/storage/config`)

6. **Multi-Tab Workspace:** Each query tab has independent state (query, results, execution status)

Expand Down Expand Up @@ -164,6 +185,11 @@ LLM_PROVIDER=gemini # gemini, openai, ollama, custom
LLM_API_KEY=<key>
LLM_MODEL=gemini-2.5-flash
LLM_API_URL=<url> # For ollama/custom providers

# Optional storage config (server-side only, not NEXT_PUBLIC_)
STORAGE_PROVIDER=local # local (default) | sqlite | postgres
STORAGE_SQLITE_PATH=./data/libredb-storage.db # SQLite file path
STORAGE_POSTGRES_URL=postgresql://... # PostgreSQL connection URL
```

### Path Aliases
Expand Down
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ ENV NODE_OPTIONS="--max-old-space-size=384"

COPY --from=builder /usr/src/app/public ./public

# Set the correct permission for prerender cache
RUN mkdir -p .next
# Set the correct permission for prerender cache and storage
RUN mkdir -p .next data

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder /usr/src/app/.next/standalone ./
COPY --from=builder /usr/src/app/.next/static ./.next/static

# Copy better-sqlite3 native binding for server storage support
COPY --from=builder /usr/src/app/node_modules/better-sqlite3 ./node_modules/better-sqlite3
COPY --from=builder /usr/src/app/node_modules/bindings ./node_modules/bindings
COPY --from=builder /usr/src/app/node_modules/file-uri-to-path ./node_modules/file-uri-to-path
COPY --from=builder /usr/src/app/node_modules/prebuild-install ./node_modules/prebuild-install 2>/dev/null || true

# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs && \
Expand Down
Loading