PostgreSQL Setup
ArchVault uses PostgreSQL 18 as its primary database, accessed through Drizzle ORM. All schema definitions live in apps/web/src/lib/schema/ and are managed via generated migrations.
Getting Started
Section titled “Getting Started”The dev compose.yaml includes a pre-configured PostgreSQL service. This is the fastest way to get started.
-
Start the database container:
Terminal window pnpm docker:compose:up -
Copy the environment template:
Terminal window cp apps/web/.env.example apps/web/.envThe default
DATABASE_URLalready matches the Docker container:DATABASE_URL=postgres://c4user:c4pass@localhost:5432/c4platform -
Run migrations to create the schema:
Terminal window pnpm db:migrate -
Start the dev server:
Terminal window pnpm dev:web
The database container exposes port 5432 on localhost. Data is persisted in the pgdata Docker volume — it survives docker compose down but is removed with docker compose down -v.
If you prefer a locally installed PostgreSQL instead of Docker:
-
Install PostgreSQL 16+ via your package manager:
Terminal window # macOSbrew install postgresql@18# Debian / Ubuntusudo apt install postgresql-18# Fedorasudo dnf install postgresql18-server -
Create a user and database:
Terminal window createuser -s c4usercreatedb -O c4user c4platform -
Set the connection string in
apps/web/.env:DATABASE_URL=postgres://c4user@localhost:5432/c4platform -
Run migrations:
Terminal window pnpm db:migrate
Connection Configuration
Section titled “Connection Configuration”ArchVault connects to PostgreSQL via a single DATABASE_URL environment variable in standard connection string format:
postgres://USER:PASSWORD@HOST:PORT/DATABASEThe connection is initialized in apps/web/src/lib/database.ts:
import { drizzle } from "drizzle-orm/node-postgres";export const db = drizzle(process.env.DATABASE_URL!);Drizzle Studio
Section titled “Drizzle Studio”Drizzle Studio provides a visual interface to browse and edit your database:
pnpm db:studioThis opens a web UI where you can inspect tables, run queries, and view relationships. Useful for debugging during development.
Schema Overview
Section titled “Schema Overview”The database contains 27 tables organized by domain:
| Domain | Tables | Description |
|---|---|---|
| Authentication | 12 | Users, sessions, accounts, organizations, teams, members, invitations, 2FA, SSO, SCIM |
| Workspaces | 1 | Architecture projects scoped to an organization |
| Core Domain | 8 | Elements, connections, technologies, tags, links — the C4 model data |
| Diagrams | 4 | Visual layouts, element/connection placement, revision history |
| Platform | 1 | Global application settings (key-value store) |
Key design patterns used throughout:
- Soft deletes — workspaces, elements, connections, and diagrams use a
deletedAttimestamp - Audit trails —
createdBy,updatedBy,createdAt,updatedAton most domain tables - Multi-tenancy — all content is scoped to an organization via the workspace
- Cascade deletes — deleting a workspace removes all its elements, connections, tags, and diagrams
Stopping the Database
Section titled “Stopping the Database”# Stop containers (data preserved)pnpm docker:compose:down
# Stop and delete all datapnpm docker:compose:down:v