pickstack

Angular + PostgreSQL (Drizzle)

PostgreSQL with Drizzle ORM: a schema, migration commands, a todo example and a local docker-compose. This page shows exactly what pickstack adds to a Angular project for PostgreSQL (Drizzle): the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.

$ npm create pickstack@latest my-app -- --framework angular --modules express,drizzle --yes
Customize in the configurator

New files

docker-compose.yml
# Local PostgreSQL for development: docker compose up -d
services:
  postgres:
    image: postgres:18
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: my-app
    ports:
      - "5432:5432"
    volumes:
      - postgres-data:/var/lib/postgresql

volumes:
  postgres-data:
server/.env.example
PORT=3001
DATABASE_URL=postgres://postgres:postgres@localhost:5432/my-app
server/.gitignore
node_modules
dist
.env
server/drizzle.config.ts
import "dotenv/config";
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  out: "./drizzle",
  schema: "./src/db/schema.ts",
  dialect: "postgresql",
  dbCredentials: {
    url:
      process.env.DATABASE_URL ??
      "postgres://postgres:postgres@localhost:5432/my-app",
  },
});
server/package.json
{
  "name": "my-app-server",
  "private": true,
  "version": "0.1.0",
  "type": "module",
  "scripts": {
    "dev": "tsx watch --env-file-if-exists=.env src/index.ts",
    "build": "tsc",
    "start": "node --env-file-if-exists=.env dist/index.js",
    "typecheck": "tsc --noEmit",
    "db:push": "drizzle-kit push",
    "db:generate": "drizzle-kit generate",
    "db:migrate": "drizzle-kit migrate",
    "db:studio": "drizzle-kit studio"
  },
  "dependencies": {
    "drizzle-orm": "^0.45.4",
    "express": "^5.3.0",
    "pg": "^8.23.1"
  },
  "devDependencies": {
    "@types/express": "^5.0.6",
    "@types/node": "^24.19.2",
    "@types/pg": "^8.23.1",
    "dotenv": "^18.0.10",
    "drizzle-kit": "^0.31.11",
    "tsx": "^4.23.15",
    "typescript": "~6.0.3"
  },
  "engines": {
    "node": ">=22.12.0"
  }
}
server/README.md
# my-app-server

Express 5 API on port 3001, with PostgreSQL (Drizzle). Copy `.env.example` to `.env` to change settings.

```bash
npm install
npm run dev
```
server/src/app.ts
import { desc } from "drizzle-orm";
import express from "express";
import { db } from "./db/index.js";
import { todos } from "./db/schema.js";

export const app = express();

app.use(express.json());

app.get("/api/health", (_req, res) => {
  res.json({ ok: true });
});

app.get("/api/hello", (req, res) => {
  const name = typeof req.query.name === "string" ? req.query.name : "world";
  res.json({ message: `Hello, ${name}!` });
});

app.get("/api/todos", async (_req, res) => {
  const rows = await db
    .select()
    .from(todos)
    .orderBy(desc(todos.createdAt))
    .limit(100);
  res.json(rows);
});

app.post("/api/todos", async (req, res) => {
  const title =
    typeof req.body?.title === "string" ? req.body.title.trim() : "";
  if (!title) {
    res.status(400).json({ error: "title is required" });
    return;
  }
  const [todo] = await db
    .insert(todos)
    .values({ title: title.slice(0, 200) })
    .returning();
  res.status(201).json(todo);
});
server/src/db/index.ts
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";

// Connects lazily: the first query opens a connection.
const pool = new Pool({
  connectionString:
    process.env.DATABASE_URL ??
    "postgres://postgres:postgres@localhost:5432/my-app",
});
// An idle connection can drop (e.g. Postgres restarts); without a listener that crashes the process.
pool.on("error", (error) =>
  console.error("Postgres pool error:", error.message),
);

export const db = drizzle({ client: pool });
server/src/db/schema.ts
import {
  boolean,
  integer,
  pgTable,
  timestamp,
  varchar,
} from "drizzle-orm/pg-core";

export const todos = pgTable("todos", {
  id: integer().primaryKey().generatedAlwaysAsIdentity(),
  title: varchar({ length: 200 }).notNull(),
  done: boolean().notNull().default(false),
  createdAt: timestamp("created_at").notNull().defaultNow(),
});
server/src/index.ts
import process from "node:process";
import { app } from "./app.js";

const port = Number(process.env.PORT ?? 3001);

app.listen(port, () => {
  console.log(`API listening on http://localhost:${port}`);
});
server/tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "rootDir": "src",
    "outDir": "dist",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "verbatimModuleSyntax": true,
    "types": ["node"]
  },
  "include": ["src"]
}
web/.gitignore
node_modules
dist
.angular
.env
.env.local
.DS_Store
web/angular.json
{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "cli": {
    "packageManager": "npm",
    "analytics": false
  },
  "newProjectRoot": "projects",
  "projects": {
    "my-app": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular/build:application",
          "options": {
            "browser": "src/main.ts",
            "tsConfig": "tsconfig.app.json",
            "assets": [
              {
                "glob": "**/*",
                "input": "public"
              }
            ],
            "styles": ["src/styles.css"]
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kB",
                  "maximumError": "1MB"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "4kB",
                  "maximumError": "8kB"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "optimization": false,
              "extractLicenses": false,
              "sourceMap": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular/build:dev-server",
          "options": {
            "proxyConfig": "proxy.conf.json"
          },
          "configurations": {
            "production": {
              "buildTarget": "my-app:build:production"
            },
            "development": {
              "buildTarget": "my-app:build:development"
            }
          },
          "defaultConfiguration": "development"
        }
      }
    }
  }
}
web/package.json
{
  "name": "my-app",
  "private": true,
  "version": "0.1.0",
  "type": "module",
  "scripts": {
    "ng": "ng",
    "dev": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "typecheck": "ngc -p tsconfig.app.json --noEmit"
  },
  "dependencies": {
    "@angular/common": "^22.3.0",
    "@angular/compiler": "^22.3.0",
    "@angular/core": "^22.3.0",
    "@angular/forms": "^22.3.0",
    "@angular/platform-browser": "^22.3.0",
    "@angular/router": "^22.3.0",
    "rxjs": "~7.8.2",
    "tslib": "^2.9.1"
  },
  "devDependencies": {
    "@angular/build": "^22.3.0",
    "@angular/cli": "^22.3.0",
    "@angular/compiler-cli": "^22.3.0",
    "typescript": "~6.0.3"
  }
}
web/proxy.conf.json
{
  "/api": {
    "target": "http://localhost:3001",
    "secure": false
  }
}
web/public/robots.txt
User-agent: *
Disallow:
web/README.md
# my-app

Stack: Angular 22, TypeScript, Express, PostgreSQL, Drizzle ORM.

## Getting started

```bash
npm install
npm run dev
```

## Scripts

- `npm run ng`
- `npm run build`
- `npm run watch`
- `npm run typecheck`

## API

The API lives in `../server` (Express). Start it with `npm run dev` there; requests to `/api` from this app are proxied to it in development.

## Push to GitHub

Create an empty repository on GitHub, then:

```bash
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/<your-username>/my-app.git
git push -u origin main
```
web/src/app/app.config.ts
import {
  type ApplicationConfig,
  provideBrowserGlobalErrorListeners,
} from "@angular/core";
import { provideRouter } from "@angular/router";
import { routes } from "./app.routes";

export const appConfig: ApplicationConfig = {
  providers: [provideBrowserGlobalErrorListeners(), provideRouter(routes)],
};
web/src/app/app.html
<main class="app">
  <nav class="nav">
    <a class="link" routerLink="/">Home</a>
    <a class="link" routerLink="/about">About</a>
  </nav>
  <router-outlet />
</main>
web/src/app/app.routes.ts
import type { Routes } from "@angular/router";
import { Home } from "./pages/home/home";

export const routes: Routes = [
  { path: "", component: Home },
  {
    path: "about",
    loadComponent: () => import("./pages/about/about").then((m) => m.About),
  },
];
web/src/app/app.ts
import { Component } from "@angular/core";
import { RouterLink, RouterOutlet } from "@angular/router";

@Component({
  selector: "app-root",
  imports: [RouterLink, RouterOutlet],
  templateUrl: "./app.html",
})
export class App {}
web/src/app/components/api-greeting/api-greeting.ts
import { Component, signal } from "@angular/core";

@Component({
  selector: "app-api-greeting",
  template: `<p class="text">{{ message() }}</p>`,
})
export class ApiGreeting {
  protected readonly message = signal("Calling the API…");

  constructor() {
    fetch("/api/hello?name=my-app")
      .then((response) => {
        if (!response.ok) throw new Error(`HTTP ${response.status}`);
        return response.json();
      })
      .then((data) => this.message.set(data.message))
      .catch(() =>
        this.message.set("The API isn't running: start it in server/."),
      );
  }
}
web/src/app/components/counter/counter.html
<div class="card">
  <p class="count">{{ count() }}</p>
  <div class="row">
    <button type="button" class="btn" (click)="decrement()">-1</button>
    <button type="button" class="btn" (click)="increment()">+1</button>
  </div>
</div>
web/src/app/components/counter/counter.ts
import { Component, signal } from "@angular/core";

@Component({
  selector: "app-counter",
  templateUrl: "./counter.html",
})
export class Counter {
  protected readonly count = signal(0);

  protected increment(): void {
    this.count.update((value) => value + 1);
  }

  protected decrement(): void {
    this.count.update((value) => value - 1);
  }
}
web/src/app/pages/about/about.html
<section class="page">
  <h1 class="title">About</h1>
  <p class="text">
    Built with Angular 22, TypeScript, Express, PostgreSQL, Drizzle ORM.
  </p>
</section>
web/src/app/pages/about/about.ts
import { Component } from "@angular/core";

@Component({
  selector: "app-about",
  templateUrl: "./about.html",
})
export class About {}
web/src/app/pages/home/home.html
<section class="page">
  <h1 class="title">my-app</h1>
  <app-counter />
  <app-api-greeting />
</section>
web/src/app/pages/home/home.ts
import { Component } from "@angular/core";
import { ApiGreeting } from "../../components/api-greeting/api-greeting";
import { Counter } from "../../components/counter/counter";

@Component({
  selector: "app-home",
  imports: [Counter, ApiGreeting],
  templateUrl: "./home.html",
})
export class Home {}
web/src/index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>my-app</title>
    <base href="/" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
  </head>
  <body>
    <app-root></app-root>
  </body>
</html>
web/src/main.ts
import { bootstrapApplication } from "@angular/platform-browser";
import { App } from "./app/app";
import { appConfig } from "./app/app.config";

bootstrapApplication(App, appConfig).catch((err) => console.error(err));
web/src/styles.css
:root {
  font-family: system-ui, sans-serif;
  color: #0f172a;
  background: #f8fafc;
}

body {
  margin: 0;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 2rem;
  box-sizing: border-box;
}

.title {
  font-size: 1.875rem;
  margin: 0;
}

.nav {
  display: flex;
  gap: 1rem;
}

.link {
  color: #475569;
  text-decoration: none;
  font-weight: 500;
}

.link:hover {
  color: #0f172a;
}

.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.text {
  max-width: 28rem;
  text-align: center;
  color: #475569;
}

.card {
  background: #fff;
  padding: 2rem;
  border-radius: 1rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  text-align: center;
}

.count {
  font-size: 3rem;
  font-weight: 700;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.row {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
}

.btn {
  background: #0f172a;
  color: #fff;
  border: 0;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  font: inherit;
  cursor: pointer;
}

.btn:hover {
  background: #334155;
}
web/tsconfig.app.json
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "types": []
  },
  "include": ["src/**/*.ts"],
  "exclude": ["src/**/*.spec.ts"]
}
web/tsconfig.json
{
  "compileOnSave": false,
  "compilerOptions": {
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "skipLibCheck": true,
    "isolatedModules": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "ES2022",
    "module": "preserve"
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  },
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    }
  ]
}

Project files

Related templates