An open API service indexing awesome lists of open source software.

https://github.com/derek486/express-mysql-ts-starter

Express TypeScript Starter โ€“ A structured and scalable boilerplate for building REST APIs with Express.js and TypeScript, featuring modular architecture, database integration, DTOs, error handling, and environment configuration. ๐Ÿš€
https://github.com/derek486/express-mysql-ts-starter

express mysql sequelize typescript

Last synced: about 2 months ago
JSON representation

Express TypeScript Starter โ€“ A structured and scalable boilerplate for building REST APIs with Express.js and TypeScript, featuring modular architecture, database integration, DTOs, error handling, and environment configuration. ๐Ÿš€

Awesome Lists containing this project

README

          

# **Express + TypeScript + MySQL Starter ๐Ÿš€**

A scalable, clean-architecture boilerplate for building RESTful APIs using **Express.js**, **TypeScript**, and **MySQL**. This project is ideal for developers who want a strong foundation with clear separation of concerns and modern development practices.

---

## **โœจ Features**

โœ… **TypeScript + Express** โ€“ Fast, typed, and modern API development
โœ… **Clean Architecture** โ€“ Modular organization into HTTP, Infrastructure, Persistence, and Shared layers
โœ… **MySQL + Sequelize ORM** โ€“ Integrated with MySQL using Sequelize for models and migrations
โœ… **Centralized Middleware** โ€“ Auth, validation, and error-handling middlewares
โœ… **Environment-Based Config** โ€“ Easily configurable via `.env` files
โœ… **Zod Validation** โ€“ Lightweight schema validation for request bodies
โœ… **Preconfigured Scripts** โ€“ Dev and build/start scripts with migration support

---

## **๐Ÿ“‚ Project Structure**

```
express-mysql-ts-starter/
โ”‚
โ”œโ”€โ”€ .env # Environment variables
โ”œโ”€โ”€ .env.example # Sample env file
โ”œโ”€โ”€ .gitignore # Ignored files
โ”œโ”€โ”€ package.json # Dependencies and scripts
โ”œโ”€โ”€ tsconfig.json # TypeScript configuration
โ”‚
โ””โ”€โ”€โ”€src/
โ”œโ”€โ”€ app.ts # Express app configuration
โ”œโ”€โ”€ config.ts # Application-level config
โ”œโ”€โ”€ index.ts # App entry point
โ”œโ”€โ”€ migrate.ts # Manual migration runner
โ”‚
โ”œโ”€โ”€ http/ # HTTP layer
โ”‚ โ”œโ”€โ”€ controllers/ # Controllers for each route
โ”‚ โ”œโ”€โ”€ middlewares/ # Auth, validation, error middlewares
โ”‚ โ”œโ”€โ”€ request/ # Request-specific types/schemas
โ”‚ โ””โ”€โ”€ shared/ # Codes and type helpers
โ”‚
โ”œโ”€โ”€ infrastructure/ # Business logic and app services
โ”‚ โ”œโ”€โ”€ dto/ # Data Transfer Objects
โ”‚ โ”œโ”€โ”€ implementation/ # Service implementations
โ”‚ โ”œโ”€โ”€ mappers/ # Map entities <-> DTOs
โ”‚ โ”œโ”€โ”€ repository/ # Abstraction for data access
โ”‚ โ””โ”€โ”€ shared/ # Common logic for infrastructure
โ”‚
โ”œโ”€โ”€ persistence/ # Database layer
โ”‚ โ”œโ”€โ”€ migrations/ # Sequelize migration scripts
โ”‚ โ”œโ”€โ”€ models/ # Sequelize models
โ”‚ โ”œโ”€โ”€ connection.ts # DB connection setup
โ”‚ โ””โ”€โ”€ relations.ts # Table/model relationships
โ”‚
โ”œโ”€โ”€ routes/ # API route declarations
โ””โ”€โ”€ shared/ # App-wide utilities
```

---

## **๐Ÿš€ Getting Started**

### 1๏ธโƒฃ Install Dependencies

```bash
npm install
```

### 2๏ธโƒฃ Configure Environment Variables

Create a `.env` file (or copy from `.env.example`) and add your DB credentials:

```env
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=express_ts_db
```

### 3๏ธโƒฃ Run Migrations

Run Sequelize migrations manually:

```bash
npm run migrate
```

### 4๏ธโƒฃ Run the Development Server

```bash
npm run dev
```

### 5๏ธโƒฃ Build and Run in Production

```bash
npm run build
npm start
```

---

## **๐Ÿงช Scripts Overview**

| Script | Purpose |
| ----------------- | --------------------------------------- |
| `npm run dev` | Start development server with `ts-node` |
| `npm run build` | Compile TypeScript into `dist/` |
| `npm start` | Run compiled app (requires `build`) |
| `npm run migrate` | Run migrations for development |
| `migrate:test` | Run migrations in test environment |

---

## **๐Ÿง‘โ€๐Ÿ’ป Contributing**

Feel free to fork the repo and submit PRs or issues. Contributions are welcome! ๐Ÿ’ก

---

## **๐Ÿ“Œ Notes**

* Ensure MySQL is running and credentials in `.env` are valid.
* All requests are validated using `zod` in combination with `validator.middleware.ts`.
* The app uses JWT-based authentication (see `auth.middleware.ts`).
* Folder placeholders (`.gitkeep`) help keep the structure even if empty.

---

๐Ÿ”ฅ **Kickstart your next backend project with a scalable, modular architecture!** ๐Ÿš€