Complete Documentation
Nirik documentation
Everything needed to run, secure, and operate Nirik in one place.
Written for developers, operators, and whoever got paged last.
Table of Contents
Overview
Nirik is a self-hosted AI code review service for GitHub pull requests and GitLab merge requests. When PR/MR events arrive by webhook, Nirik fetches the diff, filters noisy files, and sends full hunk context (unchanged context, removed, and added lines) to the AI so reviews are accurate. It posts comments only on added lines. By default the AI outputs a summary and errors (and warnings); info/suggestion-level comments are included only when your project rules request them.
Think of it as a reviewer who never sleeps, never bikesheds variable names for 40 minutes, and never says "LGTM" without context.
Features
- Supports GitHub PR webhooks and GitLab MR webhooks.
- Single webhook endpoint for both providers.
- Uses Gemini or OpenAI for AI review generation.
- Sends full hunk context (context + removed + added lines) to the AI for accurate reviews; comments are posted only on added lines.
-
Default: summary and errors (and warnings) only; info/suggestions
when project rules request them (e.g. in
.nirik/rules.md). - Background processing with queue workers for fast webhook responses.
- Prometheus metrics endpoint with token protection.
- Works on Docker Compose or Node process deployment.
How It Works
-
GitHub/GitLab sends webhook to
POST /api/v1/webhooks/review-pr. - Nirik verifies request signature/token (if configured).
- Nirik validates event action and enqueues review job.
- Worker fetches diff using Git provider API.
- Review engine filters files and chunks full hunks (context + removed + added lines); comments are attached only to added lines.
- AI generates summary + line comments (default: summary and errors/warnings only unless rules request info/suggestions).
- Nirik posts comments/discussions back to PR/MR.
Prerequisites
- Node.js 20+ (for non-Docker runs).
- Redis service available for queue/worker runtime.
- At least one AI key: Gemini or OpenAI.
- At least one Git provider token: GitHub and/or GitLab.
Quick Start
Goal: first useful review in minutes, not by the next sprint planning meeting.
Option A: Docker Compose
git clone https://github.com/imabhinavdev/nirik.git
cd nirik
cp .env.example .env
# edit .env
docker compose up -d
Option B: Local Node
git clone https://github.com/imabhinavdev/nirik.git
cd nirik
pnpm install
cp .env.example .env
# edit .env
pnpm start
Self-Hosting
Production rule of thumb: if it can fail at 3 a.m., it eventually will. Set health checks and logs before it does.
- Run Nirik behind HTTPS using Nginx, Caddy, Traefik, or Cloudflare Tunnel.
-
Set
BASE_URLto your public domain in.env. -
Expose endpoint
/api/v1/webhooks/review-prpublicly. - Protect secrets and rotate provider tokens regularly.
- Keep logs/monitoring enabled for job and API health.
Configuration
Set values in .env before starting the app.
| Variable | Required | Description |
|---|---|---|
PORT |
No | HTTP server port. Default 3000. |
NODE_ENV |
No |
development, production, or
test.
|
BASE_URL |
No | Public URL used in startup logs for correct webhook URL display. |
GEMINI_API_KEY |
One AI key | Gemini API key. Preferred when both AI providers are set. |
GEMINI_MODEL |
No | Gemini model name. Default gemini-2.0-flash. |
OPENAI_API_KEY |
One AI key | OpenAI API key (used if Gemini key is not set). |
OPENAI_MODEL |
No | OpenAI model name. Default gpt-4o-mini. |
GITHUB_TOKEN |
For GitHub | GitHub PAT with repo scope. |
GITLAB_TOKEN |
For GitLab | GitLab PAT with api scope. |
GITLAB_URL |
No | GitLab base URL. Default https://gitlab.com. |
GITHUB_WEBHOOK_SECRET |
Recommended | Validates GitHub X-Hub-Signature-256. |
GITLAB_WEBHOOK_TOKEN |
Recommended | Validates GitLab X-Gitlab-Token. |
METRICS_TOKEN |
Yes | Required token for metrics endpoint authorization. |
LOG_LEVEL |
No |
fatal, error, warn,
info, debug, trace,
silent.
|
Webhook Setup
GitHub
- Repo Settings -> Webhooks -> Add webhook.
-
Payload URL:
https://your-domain.com/api/v1/webhooks/review-pr. - Content type:
application/json. - Events: Pull requests.
-
Set Secret and mirror it in
GITHUB_WEBHOOK_SECRET.
GitLab
- Project Settings -> Webhooks.
-
URL:
https://your-domain.com/api/v1/webhooks/review-pr. - Enable Merge request events.
-
Set Secret token and mirror it in
GITLAB_WEBHOOK_TOKEN. - For self-hosted GitLab, set
GITLAB_URL.
Webhook Security
- GitHub requests are validated using HMAC SHA-256 signature header.
- GitLab requests are validated using token header comparison.
- If secrets are not set, webhook verification is disabled and not production-safe.
Metrics Security
GET /metrics requires an authorization header.
Authorization: Bearer <METRICS_TOKEN>
Example request:
curl -H "Authorization: Bearer your_token" https://your-domain.com/metrics
If you expose metrics publicly without auth, the internet will benchmark your mistakes for free.
API Reference
| Method | Path | Description |
|---|---|---|
GET |
/ |
Health endpoint. Returns success JSON. |
POST |
/api/v1/webhooks/review-pr |
Webhook endpoint for GitHub/GitLab PR/MR events. Accepts review-eligible actions and enqueues jobs. |
GET |
/metrics |
Prometheus metrics endpoint. Requires bearer token auth. |
Project-Specific Rules
Add a .nirik/rules.md file in the target repository
branch to apply custom review instructions. If not present, default
prompt rules are used.
By default the AI outputs only a summary and error/warning findings. To receive info or suggestion-level comments, mention that in your rules (e.g. include words like "suggestions", "info", or "hints").
Operations
- Use process supervision for Node deployments (systemd/PM2).
- Monitor logs for provider API failures and queue backlogs.
- Scrape metrics securely with
METRICS_TOKEN. - Rotate API tokens and webhook secrets periodically.
Troubleshooting
-
Missing Git tokens: set
GITHUB_TOKENand/orGITLAB_TOKEN. -
Missing AI keys: set
GEMINI_API_KEYorOPENAI_API_KEY. - 401 on webhook: verify configured webhook secret/token matches provider settings exactly.
-
401 on metrics: send
Authorization: Bearer <METRICS_TOKEN>. - No review after 202: inspect logs for AI or provider API errors and queue worker activity.
Debugging sequence: logs, env, webhook delivery history, then coffee. In that order.
FAQ
Can I use both Gemini and OpenAI?
Yes. If both keys are set, Gemini is selected first.
Can I use self-hosted GitLab?
Yes. Set GITLAB_URL to your instance base URL.
Does it review every event?
No. It processes review-relevant open/update event actions only.
Can I run this without Docker?
Yes. Install dependencies and run the Node server directly.
Why only summary and errors by default?
To keep reviews focused. Info and suggestion-level comments are
enabled when your .nirik/rules.md asks for them (e.g. by
mentioning "suggestions" or "info").
Will this end code review debates forever?
No, but it will move debates from "did anyone review this?" to "should this be a utility function?" which is real progress.