9.7 KiB
Rewindarr
Self-hosted Next.js 16 app (App Router, React 19, Tailwind 4, TypeScript) that shows Plex and Jellyfin statistics from Tautulli or Tracearr (Jellyfin only through Tracearr). It ships as a Docker image (ghcr.io/raunot/rewindarr, raunoot/rewindarr, also published under the old plex-rewind names) that listens on port 8383.
Contributor setup is in CONTRIBUTING.md. Use pnpm (pinned in package.json) and Node 26.
Commands
pnpm dev: dev server with Turbopack athttp://localhost:3000..env.local(from.env.example) is optional; withoutNEXTAUTH_SECRETa secret is created inconfig/auth-secret.pnpm lint:all: oxlint,tsc --noEmit(TypeScript 7), Stylelint and an oxfmt check.pnpm lint:all:fixfixes what it can.pnpm test: Vitest unit tests, kept next to the code they test as*.test.ts.pnpm build:next buildfollowed byserwist build, which generates the service worker inpublic/sw.js.pnpm commit: guided Conventional Commits prompt (commitizen).
Run pnpm lint:all and pnpm test before every PR. CI also runs pnpm build.
Checking UI changes
- A git worktree starts without
.env.localand the files inconfig/. Copy them from the main checkout, or the proxy redirects to the setup pages. Copyingconfig/play-history.json.gztoo saves reading the whole play history again. - Run
pnpm devand check the change in a browser at phone (about 390px) and desktop widths. When port 3000 is taken, Next uses the next free port. - Plex login returns to
NEXT_PUBLIC_SITE_URL, or without it to the address it was started from. Cookies are not scoped by port, so with the same secret (NEXTAUTH_SECRETorconfig/auth-secret) a login on 3000 also works on the other ports. - Loading skeletons copy the layout of what they stand in for, so nothing moves once the data arrives:
DashboardLoader.tsx,HistorySkeleton.tsx,ActivitiesSkeleton.tsx,OverviewSkeletoninOverview.tsxand theloading.tsxfiles. When a change moves, adds or removes anything in a card, row or page that has a skeleton, update the skeleton in the same change and compare the two at phone and desktop widths. To see a skeleton, throttle the network in the browser, or open a page with nothing to show (such as/history?q=zzzz, a search that matches nothing), whereSkeletonSizedkeeps an invisible copy you can unhide. That copy is cut tomax-h-96, so remove the class too to see all of a long list. - Take before and after screenshots of what changed, with the same URL, width and state, at phone and desktop widths where the layout differs. Take the before ones before you edit, or from a
developworktree on another port. - When the change moves or needs interaction (animations, transitions, gestures, multi-step flows), also record a short video, MP4 or WebM under 10 MB. Record the before too when the difference is in the motion.
- Save the media outside the repository. Show it in your final message with the file paths, and point out any real names or watch history in it, as PR media is public.
- End with how to check the change: the URL paths to open, what to click and any settings it needs.
Branches, commits and PRs
- Open PRs against
develop, nevermain. - Commits and PR titles follow Conventional Commits:
type(scope): description. Types are enforced bycommitlint.config.ts:feat,fix,ui(custom, for UI changes),perf,docs,revert,chore,refactor,build,ci,style,test. - Branch names follow
type(scope)/short-description, for examplefeat(dashboard)/new-widgetorfix/null-pointer. - PR descriptions follow
.github/pull_request_template.md: a summary, a test plan with the URL paths to check, and for UI changes a before/after table.ghcan't upload files, so name each file in the table's cells; the user drags them in on GitHub. - Releases are automated by semantic-release: pre-releases from
develop, releases frommain, with a backmerge frommaintodevelop.featbumps minor;fix,ui,perf,build,ci,revertandrefactorbump patch;docs,chore,styleandtestdo not release. Never edit versions or changelogs by hand. - Husky runs lint-staged on commit and commitlint on the message. Do not skip the hooks.
Architecture
src/app: routes ((home),dashboard,rewind,activity,history,settings,api). Components and server actions sit next to their route in_componentsand_actions; shared ones are insrc/componentsandsrc/hooks.src/proxy.ts: the Next 16 proxy (formerly middleware), wrapped in next-auth'swithAuth. It sets the Content Security Policy with a script nonce (src/utils/csp.ts) and redirects to the setup pages while required settings (REQUIRED_SETTINGSinsrc/utils/helpers.ts) are missing.- Settings live in
config/settings.json, read and written bysrc/utils/getSettings.ts. The file is created fromDEFAULT_SETTINGSinsrc/utils/constants.tsand merged with it when read. Types are insrc/types/settings.d.ts.config/also holds the saved play history, the source snapshot, uploaded Rewind music and the music previews found for Rewind. In Docker it is a volume at/app/config. - Statistics source:
settings.connection.statisticsSourceistautulliortracearr. Both implement theStatsSourceinterface insrc/types/statsSource.d.ts: Tautulli intautulliSource.ts(HTTP clientfetchTautulli.ts), Tracearr intracearrSource.ts(HTTP clientfetchTracearr.ts), which maps Tracearr data onto the shared types instatsSource.d.ts(ItemRow,Library,Activityand the rest, which keep Tautulli's field names). Types for one source's own API stay insrc/types/tautulli.d.tsandsrc/types/tracearr.d.ts.getStatsSource()insrc/utils/statsSource.tspicks one; the data utils and pages call it instead of branching on the source. A new statistic goes into the interface and both implementations. The media server issettings.connection.mediaServerType(plexorjellyfin); Tautulli only tracks Plex, and Tracearr's is the type of the server picked in the connection settings. Plex IDs are numbers in the shared types and Jellyfin IDs are hex strings, so compare IDs as strings. - Play history: most statistics are computed from the source's play history.
playHistory.tsreads it page by page from server start (src/instrumentation.ts), keeps it topped up and saves it toconfig/play-history.json.gzthroughplayHistoryFile.ts(raise itsVERSIONwhen saved plays gain a field, so older files are read again).playStats.tscomputes the statistics, and pages wait for the read withgetHistoryProgress().sourceSnapshot.tssaves the source's other answers, such as libraries and users, so pages still work while the source is down. - Other data utils:
getDashboard.ts,getRewind.ts,getHistory.ts,getUsersTop.ts,fetchSeerr.ts,fetchTmdb.ts. - Rewind music: a story plays the first of its sources that loads (
useStoryMusic.ts), ending with the admin's own track. A show plays the library's theme song (plexAudio.ts), then Plex's own by TVDB ID; a movie the library's; a song its file from Plex. What those can't play falls back to a 30-second preview from Deezer or iTunes:musicPreview.tsfinds a movie's or show's soundtrack by its TMDB ID, or a song by its artist and title (musicPreviewSources.ts, matched inmusicPreviewMatch.ts), saves which track it is toconfig/music-previews.jsonand streams it through/api/rewind/preview. - Translations:
messages/*.json(en-GB,en-US,et,fr,de,it,es), loaded bysrc/i18n/request.ts. The locale list isLOCALESinsrc/utils/constants.ts.en-GBis the reference anden-USonly changes the spelling.messages/messages.test.tschecks that every locale has the same keys and placeholders, andreact/jsx-no-literalsflags hardcoded strings in JSX, so use next-intl. - PWA: the service worker source is
src/lib/sw.ts, with a static offline fallback inpublic/offline.html;public/manifest.jsonis the web manifest.next.config.tsusesoutput: 'standalone', which theDockerfilerelies on. docker-compose.ymlis for local development: it builds the image, maps3000:8383and reads.env.local.
Code style
oxfmt (no semicolons, single quotes, sorted imports and Tailwind classes, .oxfmtrc.json) and oxlint (.oxlintrc.json) decide formatting; oxlint also requires blank lines around return, if and variable declarations, through @stylistic/eslint-plugin loaded as a JS plugin. Disable a rule for one line with // oxlint-disable-next-line <rule>. oxlint does not remove unused imports, it reports them. CSS classes are kebab-case. Run pnpm lint:all:fix instead of formatting by hand.
Rules
- Never commit secrets or user data:
.env*.local, the files inconfig/, API keys, tokens orNEXTAUTH_SECRET. Do not paste them into issues, logs or PR text either. - Do not add AI attribution to commits or PRs: no
Co-Authored-Bytrailers and no "generated with" lines. - Keep commit messages, PR descriptions and docs plain and concise.
- Do not hand-edit
pnpm-lock.yaml.
This is NOT the Next.js you know
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in node_modules/next/dist/docs/ (resolved from this file's directory; in monorepos the next package may not be visible from the repo root) before writing any code. Heed deprecation notices.
This block is written and re-added by next dev — verify at node_modules/next/dist/server/lib/generate-agent-files.js. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.