Lightweight, fast, and easy-to-use backend app template for Node.js, based on NestJS. Uses Prisma.io and PostgreSQL as a base for data storage, Redis for caching/queues, and OIDC for authentication.
Start a new project based on LiteEnd in seconds. This command downloads the template (without git history), sets up the environment file, and installs dependencies.
Replace my-app with your project name:
npx degit uxname/liteend my-app && cd my-app && git init && cp .env.example .env && npm install- Database: Update
.envwith your credentials and rundocker-compose up -d. - Migrations: Run
npm run db:migrations:apply. - Run:
npm run start:dev.
- Table of Contents
- Features
- Tech Stack
- Prerequisites
- Installation
- Usage
- Docker
- Database Workflow (Prisma)
- Code Quality
- Configuration
- Internationalization (i18n)
- Contributing
- Show Your Support
- License
- NestJS Framework: Robust and scalable backend structure.
- Prisma ORM: Type-safe database access with PostgreSQL.
- Redis Integration: Support for caching and background jobs using Bull queues.
- Docker Support: Easy setup and deployment with Docker and Docker Compose (App, PostgreSQL, Redis, Admin UIs, Backup).
- Code Quality Tools: Integrated Biome (linting/formatting) and Vitest (testing).
- Authentication: Secure OIDC (OpenID Connect) integration (Logto, Auth0, etc.) with lazy user registration.
- Database Migrations: Managed schema changes with Prisma Migrate.
- Configuration Management: Environment-based configuration using
.envfiles. - Logging: High-performance structured logging with Pino (file rotation included).
- API Documentation: Basic Swagger UI setup.
- WebSockets: Support for real-time communication.
- Task Queues: Bull module integration.
- Email: Mailer module integration.
- GraphQL: Apollo server integration.
- Health Checks: Endpoint for monitoring application status.
- Automated DB Backups: Scheduled database backups via a dedicated Docker service.
- Internationalization (i18n): Support for multiple languages.
- Language: TypeScript
- Framework: NestJS
- ORM: Prisma
- Database: PostgreSQL
- Caching/Queues: Redis
- Containerization: Docker, Docker Compose
- Package Manager: npm
- Linting/Formatting: BiomeJS
- Testing: Vitest, Pactum
- Logging: Pino
- Admin Tools (via Docker): pgAdmin 4, Redis Commander
- Node.js: Use a recent LTS version (e.g., 18.x, 20.x). Check project specifics if needed.
- npm: Usually comes with Node.js.
- Git: For cloning the repository.
- Docker & Docker Compose: (Recommended) For easy environment setup and running PostgreSQL/Redis.
-
Clone the repository:
git clone https://github.com/uxname/liteend.git cd liteend -
(Optional) Change Git remote URL:
git remote set-url origin <YOUR_NEW_GIT_REPOSITORY_URL>
-
Set up environment variables: Copy the example environment file and customize it.
cp .env.example .env # Edit .env file with your specific configuration (database credentials, ports, Redis details, etc.) # See the 'Configuration' section below for key variables.
-
Install dependencies:
npm install
-
(If using Docker - Recommended) Start external services (Database & Redis): Ensure Docker Desktop or Docker Engine/Compose is running.
docker-compose up -d db redis # Wait a few seconds for the database and Redis to initialize.Note: If you are not using Docker, ensure PostgreSQL and Redis are installed, running, and accessible according to your
.envconfiguration. -
Apply database migrations: This command applies existing migrations to set up the database schema.
npm run db:migrations:apply
-
(Optional) Seed the database: If seed data is available, populate the database:
npm run db:seed
-
Run in watch mode: The application will restart automatically on file changes. Requires database and Redis to be running.
npm run start:dev
-
Run in debug mode: Starts the application with the Node.js inspector enabled.
npm run start:debug
-
Build the application: This compiles TypeScript to JavaScript and performs checks.
npm run build
-
Run the production build: Starts the application from the compiled code in the
distfolder. EnsureNODE_ENVis set toproduction. Requires database and Redis to be running.npm run start:prod
Note: The
prestart:prodscript automatically runsnpm run db:migrations:applybefore starting.
Once the application is running (e.g., via npm run start:dev), the Swagger UI for API documentation is available at:
http://localhost:<PORT>/swagger
Replace <PORT> with the application port specified in your .env file (default is 4000).
The application provides built-in endpoints for monitoring and administration:
/health: Returns the application status. Used by Docker healthcheck. Example response:{"status":"ok",...}
/logs/: View recent logs (requires credentials from.env)./logs/all: View all logs./logs/error: View error logs.- (See
src/common/logger-serve/logger-serve.controller.tsfor more)
/studio: Access Prisma Studio for database browsing and manipulation (runs alongside the NestJS app). Requires credentials from.env.
/board: Access the Bull Board UI to monitor background job queues (e.g., email sending). Requires credentials from.env.
- Query:
debug: A GraphQL query available in the main GraphQL endpoint (/graphql) that returns system information like application version, uptime, and the last git commit.
The docker-compose.yml file defines the following services for a complete development/testing environment:
app: The main NestJS application container.db: PostgreSQL database container.redis: Redis container (for Bull queues, caching).db_admin: pgAdmin 4 container, a web UI for managing PostgreSQL.redis_admin: Redis Commander container, a web UI for managing Redis.db_backup: A dedicated container that performs scheduled backups of the PostgreSQL database.
-
Start all services: Launches the app, database, Redis, and admin UIs in detached mode.
docker-compose up -d
-
Start only specific services (e.g., DB and Redis): Useful during initial setup or if running the app locally.
docker-compose up -d db redis
-
Stop all services:
docker-compose down
-
Rebuild and start services: If you've made changes to
Dockerfileor need to rebuild images:docker-compose up -d --build
- Application:
http://localhost:<PORT>(SeePORTin.env) - pgAdmin (DB Admin):
http://localhost:<DB_ADMIN_PORT>(SeeDB_ADMIN_PORT,DB_ADMIN_EMAIL,DB_ADMIN_PASSWORDin.envfor login) - Redis Commander (Redis Admin):
http://localhost:<REDIS_ADMIN_PORT>(SeeREDIS_ADMIN_PORT,REDIS_ADMIN_USER,REDIS_ADMIN_PASSWORDin.envfor login) - Prisma Studio (DB Admin via App):
http://localhost:<PORT>/studio(SeePORT,PRISMA_STUDIO_LOGIN,PRISMA_STUDIO_PASSWORDin.envfor login) - Bull Board (Task Queues):
http://localhost:<PORT>/board(SeePORT,BULL_BOARD_LOGIN,BULL_BOARD_PASSWORDin.envfor login)
-
The
db_backupservice automatically creates compressed PostgreSQL backups. -
Configuration: Schedule (
BACKUP_INTERVAL), rotation (BACKUP_ROTATION), format, etc., are defined indocker-compose.ymlfor thedb_backupservice. -
Location: Backups are stored in the volume mapped to
./data/database_backupson the host machine. -
Manual Restore Example:
# Ensure the backup file exists in ./data/database_backups/ # Replace '...' with the actual backup filename docker compose exec db_backup sh -c "npx tsx restore.ts postgres_YYYY-MM-DDTHH-MM-SS-MSZ.sql.gz"
(Refer to
db-backup-tool/restore.tsor related scripts for details)
You can view logs for individual services:
docker-compose logs app
docker-compose logs db
docker-compose logs redis
# Use '-f' to follow logs in real-time
docker-compose logs -f appManage your database schema and migrations using Prisma CLI commands wrapped in npm scripts.
- Edit Schema: Modify
prisma/schema.prisma. - Format Schema:
npm run db:schema:format - Create Migration:
npm run db:migrations:create(Provide a descriptive name when prompted). Review the generated SQL inprisma/migrations. - Apply Migrations:
npm run db:migrations:apply - Generate Prisma Client:
npm run db:gen(Often run automatically). - Reset Database (Caution!):
npm run db:reset - Push Schema (Dev Only!):
npm run db:push(Directly syncs schema, bypasses migrations).
Note: For a typical development workflow, you will mostly use
npm run db:migrations:createandnpm run db:migrations:apply.For more details, visit the Prisma Documentation.
TL;DR: Run
npm run check(linter + type-check) before every commit.
A Lefthook pre-commit hook is configured (lefthook.yml) to run checks automatically.
- Check code (BiomeJS):
npm run lint - Fix code (BiomeJS):
npm run lint:fix - Check TypeScript types:
npm run ts:check - Run all checks:
npm run check
- Run unit tests:
npm run test - Run unit tests (watch mode):
npm run test:watch - Run e2e tests:
npm run test:e2e(Requires running app/db) - Generate coverage report:
npm run test:cov
Configuration is managed via environment variables loaded by @nestjs/config from a .env file.
- Copy
.env.exampleto.env. - Fill in your specific values in
.env.
These are some of the most important variables in .env.example to configure:
NODE_ENV: Set todevelopmentorproduction.PORT: The port the NestJS application will listen on.OIDC_ISSUER: The URL of the OIDC provider (e.g., Logto).OIDC_AUDIENCE: The API identifier defined in the OIDC provider.OIDC_JWKS_URI: The URL to the JSON Web Key Set (JWKS) of the provider.DATABASE_URL: The full connection string for PostgreSQL.DATABASE_HOST,DATABASE_PORT,DATABASE_USER,DATABASE_PASSWORD,DATABASE_NAME: Individual database connection parameters.REDIS_HOST,REDIS_PORT,REDIS_PASSWORD: Redis connection details.MAILER_...: Email sending configuration (SMTP details).DB_ADMIN_PORT,DB_ADMIN_EMAIL,DB_ADMIN_PASSWORD: pgAdmin access details.REDIS_ADMIN_PORT,REDIS_ADMIN_USER,REDIS_ADMIN_PASSWORD: Redis Commander access details.PRISMA_STUDIO_LOGIN,PRISMA_STUDIO_PASSWORD: Credentials for the Prisma Studio web UI (/studio).BULL_BOARD_LOGIN,BULL_BOARD_PASSWORD: Credentials for the Bull Board web UI (/board).LOGS_ADMIN_PANEL_USER,LOGS_ADMIN_PANEL_PASSWORD: Credentials for the protected log viewer (/logs).
(Refer to .env.example for the full list and src/config/ for validation schemas).
The project uses nestjs-i18n for handling multiple languages.
- Language files (JSON format) are located in
src/i18n/. - Add new language directories (e.g.,
src/i18n/de/) and translation files as needed.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
Give a ⭐️ if this project helped you!
