A comprehensive, modular, and production-ready NestJS backend starter template.
- Modular Structure: Organized by feature modules for scalability.
- TypeORM Integration: PostgreSQL support with migration scripts.
- Authentication: JWT-based authentication with Passport strategies.
- User Management: User module with roles and status enums.
- Validation: DTOs and global validation pipes.
- Swagger: Auto-generated API docs with JWT bearer support.
- Logging: Winston logger integration.
- Caching: Redis cache module.
- Docker Ready: Dockerfile and docker-compose for easy setup.
- Environment Config:
.envsupport for all configuration.
git clone https://github.com/yourusername/nestjs-backend-starter.git
cd nestjs-backend-starterpnpm install
# or
npm installCopy .env-example to .env and update values as needed:
cp .env-example .envdocker compose up -dThis will start both the backend and a PostgreSQL database.
Make sure PostgreSQL and Redis are running and .env is configured.
pnpm start:dev
# or
npm run start:devGenerate a migration after changing entities:
pnpm migration:generateRun migrations:
pnpm migration:runVisit http://localhost:3000/docs for Swagger UI.
src/
common/ # Shared decorators, enums, guards, etc.
config/ # Configuration files
database/ # Base entities, migrations
modules/ # Feature modules (auth, users, etc.)
shared/ # Shared modules (logger, cache)
main.ts # App entry point
app.module.ts # Root module
| Command | Description |
|---|---|
pnpm start:dev |
Start in watch mode |
pnpm build |
Build the project |
pnpm migration:generate |
Generate a new migration |
pnpm migration:run |
Run pending migrations |
pnpm test |
Run unit tests |
docker compose up |
Start app and DB with Docker |
- Fork the repo
- Create your feature branch (
git checkout -b feature/foo) - Commit your changes
- Push to the branch (
git push origin feature/foo) - Create a new Pull Request
MIT
Happy coding!