# 🚀 Express TypeScript Drizzle (PostgreSQL) Server

Bootstrapped with [**nhb-express**](https://www.npmjs.com/package/nhb-express)

---

## 📦 Features

- ✅ **TypeScript** with `ts-node` and `nodemon` for development and pre-configured `tsconfig.json`
- ✅ **Express.js** pre‑configured with custom middlewares
- ✅ **Zod** for schema validation
- ✅ **Drizzle** for PostgreSQL integration
- ✅ **Stylog** from [`nhb-toolbox`](https://toolbox.nazmul-nhb.dev/docs/utilities/misc/stylog) for colorful logging
- ✅ **[nhb-scripts](https://www.npmjs.com/package/nhb-scripts)** for easy build, commit, module scaffolding, formatting, linting, and more. [see below](#️-scripts)
- ✅ **Scaffolding via CLI** – choose package manager, DB, etc.
- ✅ Pre‑set configs for ESLint, Prettier, and `nhb-scripts`

---

## 🚀 Development

Install dependencies (already done by `nhb-express` scaffold)

Run in development mode:

```bash
pnpm dev     # or npm run dev / yarn dev
# Runs on port: 4242 by default
```

---

## 📁 Structure

```ini
📁 <your-project-name>/
 ├─ 📁 .github/
 │   └─ 📁 workflows/
 │       └─ ⚙️ publish.yml     # GitHub Actions workflow for CI/CD (vercel deployment) 
 │
 ├─ 📁 .vscode/
 │   ├─ 📄 extensions.json     # Recommended Extensions for VS Code
 │   └─ 📄 settings.json       # VS Code Settings for better formatting
 │
 ├─ 📁 migrations/             # Migration files (will be) generated by drizzle-kit 
 │
 ├─ 📁 public/                 # Folder contains static files
 |   └─ 🖼️ favicon.png         # Favicon to show in client application(s) if supported, e.g. Browsers
 │
 ├─ 📁 scripts/                # Helper scripts for development purpose
 │
 ├─ 📁 src/                    # All source (*.ts) files
 │   ├─ 📁 app/                # Application logic and internal configs
 │   |   ├─ 📁 configs/        # App configurations (CORS, ENV etc.)
 │   |   ├─ 📁 constants/      # Constant values
 │   |   ├─ 📁 errors/         # Custom error Class/processors/handlers
 │   |   ├─ 📁 middlewares/    # Custom Express middlewares
 │   |   ├─ 📁 modules/        # Feature modules (controllers, services, etc.)
 │   |   ├─ 📁 routes/         # Route configuration
 │   |   ├─ 📁 types/          # Types for the App
 │   |   └─ 📁 utilities/      # Helper functions
 │   |
 │   ├─ 📁 drizzle/            # Drizzle schema and initialization
 │   |   ├─ 📁 schema/         # Contains drizzle schemas
 │   |   └─ 📄 index.ts        # Drizzle initialization with all schemas
 │   |
 │   ├─ 📄 app.ts              # Express app setup
 │   ├─ 📄 index.d.ts          # Global type declarations
 │   └─ 📄 server.ts           # Server bootstrap
 │
 ├─ 🔒 .env                    # Environment variables
 ├─ 🚫 .gitignore              # Ignore files/folders from being pushed/committed
 ├─ 🚫 .prettierignore         # Ignore files/folders from being formatted with prettier (used if Prettier is selected as formatter)
 ├─ ⚙️ .prettierrc.json        # Prettier config (used if Prettier is selected as formatter)
 ├─ ⚙️ biome.json              # Biome config (used if Biome is selected as formatter)
 ├─ ⚙️ eslint.config.mjs       # ESLint config (used if Prettier + ESLint is selected: flat config, ready for TS)
 ├─ ⚙️ nhb.scripts.config.mjs  # Config for nhb-scripts
 ├─ ⚙️ nodemon.json            # Nodemon config
 ├─ ⚙️ package.json            # Auto-generated `package.json`
 ├─ 📃 README.md               # This file
 ├─ ⚙️ tsconfig.json           # Ready to use tsconfig
 └─ ⚙️ vercel.json             # Deployment config for Vercel
```

---

## 🛠️ Scripts

- `pnpm/npm/yarn run dev` – Start in dev mode with `nodemon` and `ts-node`
- `pnpm/npm/yarn run start` – Run the built server
- `pnpm/npm/yarn run deploy` – Build the project and deploy to Vercel (`nhb-build && vercel --prod`)
- `pnpm/npm/yarn run build` – Build the project for production (`nhb-build`)
- `pnpm/npm/yarn run build:gen` - Run `drizzle-kit generate` and build the project
- `pnpm/npm/yarn run gen` - Run `drizzle-kit generate` with other arguments
- `pnpm/npm/yarn run migrate` - Run `drizzle-kit migrate` with other arguments
- `pnpm/npm/yarn run drop` - Run `drizzle-kit drop` with other arguments
- `pnpm/npm/yarn run push` - Run `drizzle-kit push` with other arguments
- `pnpm/npm/yarn run pull` - Run `drizzle-kit pull` with other arguments
- `pnpm/npm/yarn run export` - Run `drizzle-kit export` with other arguments
- `pnpm/npm/yarn run check` - Run `drizzle-kit check` with other arguments
- `pnpm/npm/yarn run drizzle:up` - Run `drizzle-kit up` with other arguments
- `pnpm/npm/yarn run studio` - Run `drizzle-kit studio` to open Drizzle Studio in Browser
- `pnpm/npm/yarn run schema` - Create a drizzle schema from template using `nhb-module`
- `pnpm/npm/yarn run module` - Scaffold new module (service, controller, routes, schema etc.) from template using `nhb-module`
- `pnpm/npm/yarn run format` – Format the codebase
- `pnpm/npm/yarn run lint` – Lint the code
- `pnpm/npm/yarn run fix` – Auto‑fix lint issues
- `pnpm/npm/yarn run commit` – Guided commit workflow (`nhb-commit`)
- `pnpm/npm/yarn run count` – Count exports (`nhb-count`)
- `pnpm/npm/yarn run delete` – Delete any file/folder from the CLI (`nhb-delete`)
- `pnpm/npm/yarn run secret` – Generate secrets for jwt (using crypto module)
- `pnpm/npm/yarn run typecheck` → runs TypeScript type checking

---

## ⚙️ CI/CD Workflow

A ready‑to‑use **GitHub Actions workflow** is included in:

```ini
.github/workflows/publish.yml
```

✅ **What it does:**

- Runs on push to your main branch
- Builds your project
- Deploys automatically to **Vercel** (configured via `vercel.json`)

✅ **How to use:**

1. Push your project to a GitHub repository.
2. Add your Vercel tokens/secrets as GitHub repository secrets:
    Go to `Settings >> Secrets and variables >> Actions >> Repository secrets` and add these variables:
    - `VERCEL_ORG_ID`
    - `VERCEL_PROJECT_ID`
    - `VERCEL_TOKEN`
3. Every time you push to `main` and _version is updated_, GitHub Actions will trigger and deploy your server to Vercel.

You can customize the workflow to fit your own CI/CD needs (e.g., change branches, add tests, deploy elsewhere).

---

Made with ❤️ by [Nazmul Hassan](https://github.com/nazmul-nhb)

**Powered by `nhb-express`** 🚀
