PrismaXpress is a backend starter template built using TypeScript, Express.js, Prisma ORM, and PostgreSQL. It follows a modular pattern and includes essential middleware and utility functions, providing a solid foundation for backend development.
- TypeScript for type safety
- Express.js for building RESTful APIs
- Prisma ORM for database interaction with PostgreSQL
- Modular project structure for easy scalability
- Essential middleware (CORS, rate limiting, security headers)
- Logging with Pino
- Environment variable management with dotenv
- TypeScript: Ensures strong typing and reduces runtime errors.
- Express.js: Lightweight and flexible web framework for building REST APIs.
- Prisma ORM: A modern ORM for Node.js and TypeScript to interact with PostgreSQL.
- PostgreSQL: Powerful open-source relational database.
- Pino: A fast and low-overhead logger for Node.js applications.
- Zod: A TypeScript-first schema validation library for validation and parsing.
- dotenv: Loads environment variables from a
.envfile to configure the app. - CORS: Middleware to allow or restrict resources to be accessed from different origins.
- express-rate-limit: Middleware to limit repeated requests to public APIs.
- helmet: Helps secure Express apps by setting various HTTP headers.
- morgan: HTTP request logger middleware for node.js.
- Node.js >= 20.x
- PostgreSQL (locally or via cloud service)
git clone https://github.com/fahimahammed/PrismaXpress.git
cd PrismaXpressyarn installRename .env.example to .env:
cp .env.example .envGenerate the Prisma client:
yarn prisma:generateRun Prisma migrations to set up your database schema:
yarn prisma:migrateTo start the development server with hot-reloading:
yarn devThis will start the server and watch for file changes using ts-node-dev.
To build the project for production:
yarn buildThen, start the built project:
yarn start./prisma/ # Prisma-related files
├── migrations/ # Database migration files
│ └── 20250210110837_init/ # Initial migration file
│ └── migration.sql # SQL statements for the initial migration
├── schema.prisma # Prisma schema file that defines the data model
└── migration_lock.toml # Lock file for Prisma migrations
./src/ # Source code for the application
├── app.ts # Main entry point for the Express app
├── config/ # Configuration files
│ ├── database.ts # Database connection setup
│ ├── env.ts # Environment variables management
│ └── logger.ts # Logger configuration (for Pino or similar)
├── errors/ # Custom error handling
│ ├── ApiError.ts # API error class for structured error responses
│ └── handleZodError.ts # Handle errors from Zod schema validation
├── modules/ # Core modules of the application
│ └── (your module files here) # Add your application modules (controllers, services, routes)
├── server.ts # Server setup and middleware configuration
├── types/ # Type definitions for the app
│ ├── index.d.ts # Global types and interfaces
│ └── response.interfaces.ts # Interface for structuring API responses
└── utils/ # Utility functions
├── catchAsync.ts # Utility to handle async functions and catch errors
└── sendResponse.ts # Utility for sending consistent API responses
dev: Runs the server in development mode withts-node-dev.build: Compiles the TypeScript code to JavaScript.start: Starts the server from thedistfolder after building.prisma:generate: Generates Prisma client based on your schema.prisma:migrate: Applies any pending migrations to your database.seed: Seeds your database with initial data (run viats-node prisma/seed.ts).
- CORS: Cross-Origin Resource Sharing configuration
- Rate Limiting: Using
express-rate-limitto limit API requests - Security Headers: Using
helmetto set security-related HTTP headers - Request Logging: Using
morganandpinofor logging requests