Updated the Obsidian docs-vault
This commit is contained in:
1 parent
72fd77ee01
commit
260282a0e2
36 files changed
+3497
-144
No files matched your search
@@ -0,0 +1,143 @@
|
||||
---
|
||||
title: API Clients
|
||||
tags:
|
||||
- frontend
|
||||
- api
|
||||
- axios
|
||||
---
|
||||
|
||||
# API Clients
|
||||
|
||||
All in `react_frontend/src/api/`. Each module exports an object with methods that call the [[Backend]] REST API via Axios.
|
||||
|
||||
Base Axios instance in `lib/api.ts` — configured with base URL and interceptors.
|
||||
|
||||
---
|
||||
|
||||
## entries.ts
|
||||
|
||||
Entry CRUD and management.
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `getAll()` | GET | `/entries` |
|
||||
| `getById(id)` | GET | `/entries/:id` |
|
||||
| `create(data)` | POST | `/entries` |
|
||||
| `update(id, data)` | PUT | `/entries/:id` |
|
||||
| `updateRatings(id, data)` | PUT | `/entries/:id/ratings` |
|
||||
| `updateIds(id, data)` | PUT | `/entries/:id/ids` |
|
||||
| `delete(id)` | DELETE | `/entries/:id` |
|
||||
| `refresh(id)` | PUT | `/entries/:id/refresh` |
|
||||
| `fetchCollection(id)` | PUT | `/entries/:id/fetch-collection` |
|
||||
| `getSeasons(id)` | GET | `/entries/:id/seasons` |
|
||||
| `syncSeries()` | GET | `/entries/sync-series` |
|
||||
| `uploadMedia(id, formData)` | POST | `/entries/:id/media` |
|
||||
| `setMediaSelected(entryId, mediaId)` | PUT | `/entries/:entryId/media/:mediaId` |
|
||||
| `deleteMedia(entryId, mediaId)` | DELETE | `/entries/:entryId/media/:mediaId` |
|
||||
|
||||
## tmdb.ts
|
||||
|
||||
TMDB proxy endpoints (via backend).
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `getPopularMovies(page)` | GET | `/entries/tmdb/popular/movie` |
|
||||
| `getPopularTv(page)` | GET | `/entries/tmdb/popular/tv` |
|
||||
| `getTrendingMovies(page)` | GET | `/entries/tmdb/trending/movie` |
|
||||
| `getTrendingTv(page)` | GET | `/entries/tmdb/trending/tv` |
|
||||
| `getTopRatedMovies(page)` | GET | `/entries/tmdb/top-rated/movie` |
|
||||
| `getTopRatedTv(page)` | GET | `/entries/tmdb/top-rated/tv` |
|
||||
| `getUpcomingMovies(page)` | GET | `/entries/tmdb/upcoming/movie` |
|
||||
| `search(query, page)` | GET | `/entries/tmdb/search` |
|
||||
| `getPopularPeople()` | GET | `/people/tmdb/popular` |
|
||||
| `searchPeople(query)` | GET | `/people/tmdb/search` |
|
||||
|
||||
## collections.ts
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `getAll()` | GET | `/collections` |
|
||||
| `getById(id)` | GET | `/collections/:id` |
|
||||
| `create(data)` | POST | `/collections` |
|
||||
| `update(id, data)` | PUT | `/collections/:id` |
|
||||
| `updateWithMedia(id, formData)` | PUT | `/collections/:id` (multipart) |
|
||||
| `delete(id)` | DELETE | `/collections/:id` |
|
||||
| `getCollectionParts(id)` | PUT | `/collections/:id/parts` |
|
||||
| `addEntry(collectionId, entryId)` | POST | `/collections/:id/entries/:entryId` |
|
||||
| `removeEntry(collectionId, entryId)` | DELETE | `/collections/:id/entries/:entryId` |
|
||||
|
||||
## seasons.ts
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `getAll()` | GET | `/seasons` |
|
||||
| `getById(id)` | GET | `/seasons/:id` |
|
||||
| `getEpisodes(id)` | GET | `/seasons/:id/episodes` |
|
||||
| `create(data)` | POST | `/seasons` |
|
||||
| `update(id, data)` | PUT | `/seasons/:id` |
|
||||
| `delete(id)` | DELETE | `/seasons/:id` |
|
||||
|
||||
## episodes.ts
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `getByMonth(start, end)` | GET | `/episodes/month/:start/:end` |
|
||||
|
||||
## entry-seen.ts
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `getAll()` | GET | `/entry-seen` |
|
||||
| `getById(id)` | GET | `/entry-seen/:id` |
|
||||
| `getByEntry(entryId)` | GET | `/entry-seen/by-entry/:entryId` |
|
||||
| `create(data)` | POST | `/entry-seen` |
|
||||
| `update(id, data)` | PUT | `/entry-seen/:id` |
|
||||
| `delete(id)` | DELETE | `/entry-seen/:id` |
|
||||
|
||||
## episode-seen.ts
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `getAll()` | GET | `/episode-seen` |
|
||||
| `getById(id)` | GET | `/episode-seen/:id` |
|
||||
| `getByEpisode(episodeId)` | GET | `/episode-seen/by-episode/:episodeId` |
|
||||
| `create(data)` | POST | `/episode-seen` |
|
||||
| `update(id, data)` | PUT | `/episode-seen/:id` |
|
||||
| `delete(id)` | DELETE | `/episode-seen/:id` |
|
||||
|
||||
## people.ts
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `getAll()` | GET | `/people` |
|
||||
| `getById(id)` | GET | `/people/:id` |
|
||||
| `getCredits(id)` | GET | `/people/:id/credits` |
|
||||
| `getTmdbFilmography(id)` | GET | `/people/:id/tmdb-filmography` |
|
||||
| `fetchByTmdbId(tmdbId)` | POST | `/people/fetch` |
|
||||
|
||||
## statistics.ts
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `getAllTimeWatchTime()` | GET | `/statistics/watch-time` |
|
||||
| `getYearlyWatchTime(year)` | GET | `/statistics/watch-time/year/:year` |
|
||||
| `getYearlyWatchCount(year)` | GET | `/statistics/watch-count/year/:year` |
|
||||
| `getWatchdayDistribution()` | GET | `/statistics/watch-weekday` |
|
||||
|
||||
## settings.ts
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `get()` | GET | `/settings` |
|
||||
| `update(data)` | PUT | `/settings` |
|
||||
|
||||
## maintenance.ts
|
||||
|
||||
| Method | HTTP | Endpoint |
|
||||
|---|---|---|
|
||||
| `scanOrphanFiles()` | GET | `/maintenance/orphan-files` |
|
||||
| `deleteOrphanFiles()` | DELETE | `/maintenance/orphan-files` |
|
||||
| `scanOrphanMediaRecords()` | GET | `/maintenance/orphan-media-records` |
|
||||
| `deleteOrphanMediaRecords()` | DELETE | `/maintenance/orphan-media-records` |
|
||||
|
||||
Response type: `{ posters: number, logos: number, backdrops: number, stills: number }`
|
||||
@@ -0,0 +1,230 @@
|
||||
---
|
||||
title: API Reference
|
||||
tags:
|
||||
- backend
|
||||
- api
|
||||
- endpoints
|
||||
aliases:
|
||||
- Endpoints
|
||||
- REST API
|
||||
---
|
||||
|
||||
# API Reference
|
||||
|
||||
All endpoints are prefixed with `/api/v1`. See [[Backend]] for server setup.
|
||||
|
||||
---
|
||||
|
||||
## Entries
|
||||
|
||||
> [!info] File: `routes/entry.routes.js` → `controllers/entryController.js`
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/entries` | Get all library entries (with IDs, ratings, genres, networks, media, seens, seasons) |
|
||||
| `GET` | `/entries/:id` | Get entry by ID — triggers [[Services#Lazy Refresh\|lazy refresh]] if stale |
|
||||
| `POST` | `/entries` | Add entry from TMDB: `{ tmdb_id, is_tvserie }` |
|
||||
| `PUT` | `/entries/:id` | Update entry fields: `{ entryData }` |
|
||||
| `PUT` | `/entries/:id/ratings` | Update ratings: `{ entryRatings }` |
|
||||
| `PUT` | `/entries/:id/ids` | Update external IDs |
|
||||
| `DELETE` | `/entries/:id` | Delete entry and all related data |
|
||||
| `GET` | `/entries/:id/seasons` | Get all seasons for a TV entry |
|
||||
| `PUT` | `/entries/:id/refresh` | Force refresh from TMDB |
|
||||
| `PUT` | `/entries/:id/fetch-collection` | Fetch/create TMDB collection for entry |
|
||||
| `GET` | `/entries/sync-series` | Batch refresh all non-ended TV series |
|
||||
| `POST` | `/entries/:id/media` | Upload media (multipart — poster/backdrop/logo) |
|
||||
| `PUT` | `/entries/:entryId/media/:mediaId` | Set media as selected |
|
||||
|
||||
### TMDB Proxy
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/entries/tmdb/trending/:type` | Trending movies/tv |
|
||||
| `GET` | `/entries/tmdb/popular/:type` | Popular movies/tv |
|
||||
| `GET` | `/entries/tmdb/top-rated/:type` | Top-rated movies/tv |
|
||||
| `GET` | `/entries/tmdb/upcoming/movie` | Upcoming movies |
|
||||
| `GET` | `/entries/tmdb/search?query=&page=` | Multi-search |
|
||||
|
||||
---
|
||||
|
||||
## Collections
|
||||
|
||||
> [!info] File: `routes/collection.routes.js` → `controllers/collectionController.js`
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/collections` | All collections |
|
||||
| `GET` | `/collections/:id` | Collection by ID with entries |
|
||||
| `POST` | `/collections` | Create user collection |
|
||||
| `PUT` | `/collections/:id` | Update (multipart — poster/backdrop) |
|
||||
| `PUT` | `/collections/:id/refresh` | Refresh from TMDB |
|
||||
| `PUT` | `/collections/:id/parts` | Fetch missing parts from TMDB |
|
||||
| `DELETE` | `/collections/:id` | Delete collection |
|
||||
| `POST` | `/collections/:collectionId/entries/:entryId` | Add entry to collection |
|
||||
| `PATCH` | `/collections/:collectionId/entries/:entryId` | Update entry order |
|
||||
| `DELETE` | `/collections/:collectionId/entries/:entryId` | Remove entry from collection |
|
||||
| `POST` | `/collections/collection-with-entry` | Create collection + add first entry |
|
||||
|
||||
---
|
||||
|
||||
## Entry Seen (Movie Watch Records)
|
||||
|
||||
> [!info] File: `routes/entry-seen.routes.js` → `controllers/entrySeenController.js`
|
||||
|
||||
See [[Watch Tracking]] for the accuracy system.
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/entry-seen` | All entry seens |
|
||||
| `GET` | `/entry-seen/by-entry/:entryId` | Watch records for an entry |
|
||||
| `GET` | `/entry-seen/:id` | Single record by ID |
|
||||
| `POST` | `/entry-seen` | Create: `{ entry_id, date_seen, seen_with, accuracy }` |
|
||||
| `PUT` | `/entry-seen/:id` | Update record |
|
||||
| `DELETE` | `/entry-seen/:id` | Delete record |
|
||||
|
||||
---
|
||||
|
||||
## Episode Seen (Episode Watch Records)
|
||||
|
||||
> [!info] File: `routes/episode-seen.routes.js` → `controllers/episodeSeenController.js`
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/episode-seen` | All episode seens |
|
||||
| `GET` | `/episode-seen/by-episode/:episodeId` | Watch records for an episode |
|
||||
| `GET` | `/episode-seen/by-entry/:entryId` | All episode seens for an entry |
|
||||
| `GET` | `/episode-seen/:id` | Single record by ID |
|
||||
| `POST` | `/episode-seen` | Create: `{ entry_id, episode_id, date_seen, seen_with, accuracy }` |
|
||||
| `PUT` | `/episode-seen/:id` | Update record |
|
||||
| `DELETE` | `/episode-seen/:id` | Delete record |
|
||||
|
||||
---
|
||||
|
||||
## Seasons
|
||||
|
||||
> [!info] File: `routes/season.routes.js` → `controllers/seasonController.js`
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/seasons` | All seasons |
|
||||
| `GET` | `/seasons/:id` | Season by ID (includes episodes with episodeSeens) |
|
||||
| `GET` | `/seasons/:id/episodes` | Season episodes only |
|
||||
| `POST` | `/seasons` | Create season |
|
||||
| `PUT` | `/seasons/:id` | Update season |
|
||||
| `DELETE` | `/seasons/:id` | Delete season |
|
||||
|
||||
---
|
||||
|
||||
## Episodes
|
||||
|
||||
> [!info] File: `routes/episode.routes.js` → `controllers/episodeController.js`
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/episodes/month/:startDate/:endDate` | Episodes airing between dates (for [[Calendar]]) |
|
||||
|
||||
---
|
||||
|
||||
## Media
|
||||
|
||||
> [!info] File: `routes/media.routes.js` → `controllers/mediaController.js`
|
||||
|
||||
See [[Media System]] for details.
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/media` | All custom media records |
|
||||
| `GET` | `/media/:category/:type/:size/:fileName` | Serve media file |
|
||||
|
||||
**URL pattern:** `/media/{entries|collections|seasons|episodes|peoples}/{posters|backdrops|logos|stills|profiles}/{preview|full}/{filename}`
|
||||
|
||||
---
|
||||
|
||||
## People
|
||||
|
||||
> [!info] File: `routes/people.routes.js` → `controllers/peopleController.js`
|
||||
|
||||
See [[People]] for the lazy-fetch pattern.
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/people` | All people |
|
||||
| `GET` | `/people/popular?limit=` | Popular people (local DB) |
|
||||
| `GET` | `/people/search?query=` | Search people (local DB) |
|
||||
| `GET` | `/people/:id` | Person by ID (lazy-fetch from TMDB if needed) |
|
||||
| `GET` | `/people/:id/credits` | Person's credits |
|
||||
| `GET` | `/people/:id/tmdb-filmography` | Full TMDB filmography |
|
||||
| `POST` | `/people` | Create person |
|
||||
| `POST` | `/people/fetch` | Fetch by TMDB ID: `{ tmdb_id }` |
|
||||
| `PUT` | `/people/:id` | Update person |
|
||||
| `PUT` | `/people/:id/refresh` | Refresh from TMDB |
|
||||
| `DELETE` | `/people/:id` | Delete person |
|
||||
| `POST` | `/people/:id/media` | Upload profile picture |
|
||||
| `GET` | `/people/tmdb/popular` | TMDB popular people |
|
||||
| `GET` | `/people/tmdb/search?query=` | TMDB people search |
|
||||
|
||||
---
|
||||
|
||||
## Statistics
|
||||
|
||||
> [!info] File: `routes/statistics.routes.js` → `controllers/statisticsController.js`
|
||||
|
||||
See [[Statistics]] for chart details.
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/statistics/watch-time` | All-time watch time (series + movies, in minutes) |
|
||||
| `GET` | `/statistics/watch-time/year/:year` | Yearly watch time by month |
|
||||
| `GET` | `/statistics/watch-count/year/:year` | Yearly watch count by month |
|
||||
| `GET` | `/statistics/watch-weekday` | Watch-day distribution (EXACT accuracy only) |
|
||||
|
||||
---
|
||||
|
||||
## Settings
|
||||
|
||||
> [!info] File: `routes/settings.routes.js` → `controllers/settingsController.js`
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/settings` | Get all settings |
|
||||
| `PUT` | `/settings` | Update settings |
|
||||
|
||||
---
|
||||
|
||||
## Maintenance
|
||||
|
||||
> [!info] File: `routes/maintenance.routes.js` → `controllers/maintenanceController.js`
|
||||
|
||||
See [[Settings Page#Cleanup]] for the UI.
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/maintenance/orphan-files` | Dry scan — files on disk without DB records |
|
||||
| `DELETE` | `/maintenance/orphan-files` | Delete orphan files |
|
||||
| `GET` | `/maintenance/orphan-media-records` | Dry scan — DB records without files on disk |
|
||||
| `DELETE` | `/maintenance/orphan-media-records` | Delete orphan DB records |
|
||||
|
||||
**Response:** `{ posters: number, logos: number, backdrops: number, stills: number }`
|
||||
|
||||
---
|
||||
|
||||
## Import
|
||||
|
||||
> [!info] File: `routes/import.routes.js` → `controllers/importController.js`
|
||||
|
||||
See [[Import System]] for details.
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `POST` | `/import/movies` | Bulk import movies |
|
||||
| `POST` | `/import/tmdb` | Bulk import by TMDB IDs |
|
||||
| `POST` | `/import/episodes-watch-history` | Bulk import episode watch history |
|
||||
|
||||
---
|
||||
|
||||
## Utility
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `GET` | `/ping` | Health check → `{ message: 'pong' }` |
|
||||
| `GET/POST` | `/killer` | Debug: crash backend (outside `/api/v1`) |
|
||||
+110
-14
@@ -1,23 +1,119 @@
|
||||
---
|
||||
title: Architecture
|
||||
tags:
|
||||
- architecture
|
||||
- overview
|
||||
---
|
||||
|
||||
# Architecture
|
||||
|
||||
## Overview
|
||||
|
||||
Showy is a media tracking application with three main layers:
|
||||
Showy is a **single-user** media tracking application with three deployment layers:
|
||||
|
||||
- **[[Backend]]** — Node.js + Express REST API with Sequelize ORM and MySQL
|
||||
- **[[Frontend]]** — React 18 + TypeScript SPA (Vite, TanStack Query, Zustand, shadcn/ui)
|
||||
- **[[Electron]]** — Desktop wrapper using Electron
|
||||
| Layer | Technology | Role |
|
||||
|---|---|---|
|
||||
| [[Backend]] | Node.js + Express + Sequelize + MySQL | REST API, data persistence, TMDB proxy |
|
||||
| [[Frontend]] | React 19 + TypeScript + Vite | SPA with shadcn/ui components |
|
||||
| [[Electron]] | Electron 34 | Desktop wrapper, spawns backend as child process |
|
||||
|
||||
## Key Flows
|
||||
See [[Tech Stack]] for complete version inventory.
|
||||
|
||||
- Library data is fetched on app load into a Zustand store (`useLibraryStore`)
|
||||
- Pages use TanStack Query hooks for server state (seasons, episodes, statistics)
|
||||
- Dashboard charts consume statistics endpoints and library store data
|
||||
- Maintenance/cleanup operations use dedicated backend endpoints
|
||||
## System Diagram
|
||||
|
||||
## Important Files
|
||||
```mermaid
|
||||
graph TD
|
||||
subgraph Desktop["Electron (Desktop)"]
|
||||
E[Main Process] --> B
|
||||
E --> FE
|
||||
end
|
||||
|
||||
- `backend/server.js` — Express app entry point
|
||||
- `react_frontend/src/App.tsx` — React app entry + router
|
||||
- `react_frontend/src/stores/useLibraryStore.ts` — Global library state
|
||||
- `electron/main.js` — Electron main process
|
||||
subgraph FE["React Frontend"]
|
||||
Pages[Pages] --> Hooks
|
||||
Hooks --> APIClients[API Clients]
|
||||
Hooks --> LibStore[Zustand Library Store]
|
||||
APIClients --> |Axios| API
|
||||
end
|
||||
|
||||
subgraph B["Backend"]
|
||||
API[Express Routes] --> Controllers
|
||||
Controllers --> Services
|
||||
Services --> Models[Sequelize Models]
|
||||
Services --> TMDB[TMDB API]
|
||||
Models --> DB[(MySQL - Showzy)]
|
||||
end
|
||||
```
|
||||
|
||||
## Data Flow
|
||||
|
||||
### Library Loading
|
||||
|
||||
1. App mounts → `useLibrary()` hook fires `GET /api/v1/entries`
|
||||
2. Backend returns all entries with IDs, ratings, genres, networks, media, seasons, seens
|
||||
3. Response normalized by [[Normalizers]] (`normalizeEntry`)
|
||||
4. Entries loaded into [[Stores|useLibraryStore]] as `Map<number, Entry>` for O(1) lookup
|
||||
5. `isLoaded` flag set → pages render
|
||||
|
||||
### Adding an Entry
|
||||
|
||||
1. User searches TMDB → selects result → `POST /api/v1/entries` with `{tmdb_id, is_tvserie}`
|
||||
2. [[Services|EntryManager]] orchestrates the full pipeline:
|
||||
- Fetch from TMDB → save entry + IDs + ratings + genres + networks
|
||||
- If TV: fetch all seasons/episodes
|
||||
- Fetch credits (cast/crew)
|
||||
- Download media (posters, backdrops, logos) → generate previews
|
||||
- Fetch collection if applicable
|
||||
3. Response added to Zustand store → UI updates
|
||||
|
||||
### Lazy Refresh
|
||||
|
||||
- `getEntryById` checks `last_fetch` — if null or >24h old (and series not ended), triggers TMDB refresh
|
||||
- Same pattern for [[People]] via `getUpdatedPerson`
|
||||
|
||||
### Media Serving
|
||||
|
||||
1. Frontend requests `/api/v1/media/:category/:type/:size/:fileName`
|
||||
2. Backend reads from `{userDataPath}/images/...` directory
|
||||
3. Preview files: `{uuid}_preview.jpg` — full files: `{uuid}.ext`
|
||||
|
||||
## File Structure
|
||||
|
||||
```
|
||||
Showy/
|
||||
├── backend/ → [[Backend]]
|
||||
│ ├── server.js → Express entry point
|
||||
│ ├── config/ → DB, relations, hooks, initializer
|
||||
│ ├── controllers/ → Route handlers
|
||||
│ ├── services/ → Business logic
|
||||
│ ├── models/ → Sequelize models → [[Models]]
|
||||
│ ├── routes/ → Express routers → [[API Reference]]
|
||||
│ ├── errors/ → Custom errors → [[Error Handling]]
|
||||
│ ├── middleware/ → Error handler
|
||||
│ ├── mappers/ → Entry mapper
|
||||
│ └── utils/ → asyncWrapper, moment
|
||||
├── react_frontend/ → [[Frontend]]
|
||||
│ └── src/
|
||||
│ ├── api/ → Axios clients → [[API Clients]]
|
||||
│ ├── components/ → UI components → [[Components]]
|
||||
│ ├── hooks/ → TanStack Query hooks → [[Hooks]]
|
||||
│ ├── lib/ → Utilities, normalizers
|
||||
│ ├── pages/ → Route pages → [[Pages]]
|
||||
│ ├── stores/ → Zustand stores → [[Stores]]
|
||||
│ └── types/ → TypeScript types → [[Types]]
|
||||
├── electron/ → [[Electron]]
|
||||
├── frontend/ → Legacy Angular app (unused)
|
||||
├── docs-vault/ → This documentation
|
||||
└── docker-compose.yml → [[Deployment]]
|
||||
```
|
||||
|
||||
## Security Model
|
||||
|
||||
> [!warning] No Authentication
|
||||
> Showy is designed as a single-user local application. There is **no authentication or authorization**. CORS is set to `*`. The TMDB API key is stored server-side in `settings.json`.
|
||||
|
||||
## See Also
|
||||
|
||||
- [[Backend]] — Server-side details
|
||||
- [[Frontend]] — Client-side details
|
||||
- [[Database]] — Data layer
|
||||
- [[Deployment]] — Docker setup
|
||||
+88
-16
@@ -1,26 +1,98 @@
|
||||
---
|
||||
title: Backend
|
||||
tags:
|
||||
- backend
|
||||
- express
|
||||
- node
|
||||
---
|
||||
|
||||
# Backend
|
||||
|
||||
## Overview
|
||||
|
||||
Node.js + Express REST API with Sequelize ORM and MySQL database.
|
||||
Node.js + Express REST API serving the [[Frontend]] via JSON. Uses Sequelize ORM with a MySQL database named **Showzy**.
|
||||
|
||||
## Key Endpoints
|
||||
## Entry Point — `server.js`
|
||||
|
||||
- `GET/PUT /settings` — App settings
|
||||
- `GET/DELETE /maintenance/orphan-files` — Orphan file scan/cleanup
|
||||
- `GET/DELETE /maintenance/orphan-media-records` — Orphan DB record scan/cleanup
|
||||
- `GET /statistics/watch-weekday` — Watchday distribution (filtered to EXACT accuracy)
|
||||
- CRUD endpoints for entries, seasons, episodes, collections, people
|
||||
1. Creates Express app with `body-parser` (JSON + URL-encoded)
|
||||
2. CORS: allows all origins (`*`)
|
||||
3. All API routes mounted under `/api/v1` via `routes/routes.js`
|
||||
4. Error handler middleware at the end (see [[Error Handling]])
|
||||
5. Debug crash route at `/killer` (outside `/api/v1`)
|
||||
6. Sequelize sync: `sequelize.sync({ alter: doUpdate })` where `doUpdate = false`
|
||||
7. Calls `initializeData()` after sync — seeds 27 TMDB genres if needed
|
||||
8. Listens on port from `settings.json` (default `4000`)
|
||||
9. Process-level handlers for `unhandledRejection` and `uncaughtException`
|
||||
|
||||
## Important Files
|
||||
## Project Structure
|
||||
|
||||
- `server.js` — Express app setup
|
||||
- `config/database.js` — Sequelize/MySQL connection
|
||||
- `config/relations.js` — Model associations
|
||||
- `controllers/` — Route handlers
|
||||
- `services/` — Business logic
|
||||
- `models/` — Sequelize models
|
||||
```
|
||||
backend/
|
||||
├── server.js Entry point
|
||||
├── package.json Dependencies
|
||||
├── nodemon.json Dev config (watches .js, .json)
|
||||
├── settings.json Runtime config (see [[Env]])
|
||||
├── config/
|
||||
│ ├── database.js Sequelize instance → MySQL "Showzy"
|
||||
│ ├── relations.js All model associations → [[Database#Relationships]]
|
||||
│ ├── dataInitializer.js Genre seeding (27 TMDB genres)
|
||||
│ └── sequelizeHooks.js UserCollectionEntry hooks (order management)
|
||||
├── controllers/ Route handlers (14 controllers)
|
||||
├── services/ Business logic (16 services) → [[Services]]
|
||||
├── models/ Sequelize models (17 models) → [[Models]]
|
||||
├── routes/ Express routers (14 route files) → [[API Reference]]
|
||||
├── errors/ Custom error classes → [[Error Handling]]
|
||||
├── middleware/
|
||||
│ └── errorHandler.js Central error catching
|
||||
├── mappers/
|
||||
│ └── entryMapper.js Entry response mapping
|
||||
└── utils/
|
||||
├── asyncWrapper.js Async route error wrapper
|
||||
└── moment.js Bundled Moment.js 2.29.0
|
||||
```
|
||||
|
||||
## Known Issues
|
||||
## Middleware Pipeline
|
||||
|
||||
- Maintenance service `deleteOrphanFiles` uses synchronous `fs.existsSync` in a loop
|
||||
```
|
||||
Request → body-parser → CORS → /api/v1/routes → Controller → Service → Response
|
||||
↓ (on error)
|
||||
errorHandler middleware
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Backend reads `settings.json` at startup. See [[Env]] for all fields.
|
||||
|
||||
Key config files:
|
||||
|
||||
- `config/database.js` — Sequelize connection to MySQL `Showzy` on `localhost` (root/password)
|
||||
- `config/relations.js` — All model associations (see [[Database#Relationships]])
|
||||
- `config/dataInitializer.js` — Seeds genre table with 27 TMDB genres
|
||||
- `config/sequelizeHooks.js` — Auto-manages `order` field on [[Collections|UserCollectionEntry]]
|
||||
|
||||
## Key Patterns
|
||||
|
||||
### Async Wrapper
|
||||
|
||||
All route handlers are wrapped with `asyncWrapper()` which catches rejected promises and forwards to `next(err)` → [[Error Handling]].
|
||||
|
||||
### Singleton Services
|
||||
|
||||
All services use the singleton pattern — `if (!Class.instance) Class.instance = this`.
|
||||
|
||||
### Lazy Refresh
|
||||
|
||||
[[Services|EntryManager]] and [[Services|PeopleManager]] implement lazy refresh: data is only re-fetched from TMDB if `last_fetch` is null or older than 24 hours.
|
||||
|
||||
### Media Pipeline
|
||||
|
||||
See [[Media System]] for the complete download → optimize → serve flow.
|
||||
|
||||
## See Also
|
||||
|
||||
- [[API Reference]] — All endpoints
|
||||
- [[Database]] — Schema and models
|
||||
- [[Services]] — Business logic
|
||||
- [[Error Handling]] — Error classes and middleware
|
||||
- [[TMDB Integration]] — External API
|
||||
- [[Media System]] — Image handling
|
||||
@@ -0,0 +1,41 @@
|
||||
---
|
||||
title: Calendar
|
||||
tags:
|
||||
- feature
|
||||
- calendar
|
||||
- episodes
|
||||
---
|
||||
|
||||
# Calendar
|
||||
|
||||
## Overview
|
||||
|
||||
Monthly calendar view showing upcoming TV episode air dates. Helps users track when new episodes of their shows are airing.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. [[Pages#CalendarPage|CalendarPage]] renders a monthly grid
|
||||
2. Calls `episodesApi.getByMonth(startDate, endDate)` for the visible month range
|
||||
3. Backend `episodeService.getEpisodesBetweenDates()` queries episodes with:
|
||||
- `air_date` between start and end dates
|
||||
- Entry has `showInCalendar = true`
|
||||
4. Episodes displayed on their air date cells
|
||||
|
||||
## Data Flow
|
||||
|
||||
```
|
||||
CalendarPage → useEpisodesByMonth(start, end) → GET /episodes/month/:start/:end
|
||||
↓
|
||||
episodeService.getEpisodesBetweenDates()
|
||||
↓
|
||||
Episodes with air_date in range + showInCalendar
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Each entry has a `showInCalendar` flag (default `true`). Users can toggle this in the [[Components#Dialogs|EntrySettingsDialog]] to hide a show's episodes from the calendar.
|
||||
|
||||
## See Also
|
||||
|
||||
- [[API Reference#Episodes]] — Calendar endpoint
|
||||
- [[Library]] — `showInCalendar` flag
|
||||
+20
-7
@@ -1,16 +1,29 @@
|
||||
---
|
||||
title: Changelog
|
||||
tags:
|
||||
- changelog
|
||||
- milestones
|
||||
---
|
||||
|
||||
# Changelog
|
||||
|
||||
All project milestones. See also `changes.md` in project root.
|
||||
|
||||
---
|
||||
|
||||
## Milestone 001
|
||||
|
||||
### Backend
|
||||
- Added accuracy filter (`WHERE accuracy = 'EXACT'`) to [[Statistics]] watchday distribution queries
|
||||
|
||||
- Added accuracy filter (`WHERE accuracy = 'EXACT'`) to [[Statistics]] watchday distribution queries in `statisticsController.js`
|
||||
|
||||
### Frontend
|
||||
- Replaced Calendar popover with native date input in [[EntrySeenDialog]] and [[EpisodeSeenEditDialog]]
|
||||
|
||||
- Replaced Calendar popover with native `<input type="date">` in [[Watch Tracking|EntrySeenDialog]] and [[Watch Tracking|EpisodeSeenEditDialog]] for easier year selection
|
||||
- Merged date + accuracy into a single row in both seen dialogs
|
||||
- [[LibraryGrowthChart]]: uses `createdAt` only, includes all entries (watchlist + library)
|
||||
- [[SeasonPage]] and [[EpisodePage]]: added `max-w-4xl` width constraint
|
||||
- Breadcrumbs now show "Title / Season x / Episode x" instead of generic labels — see [[Navigation]]
|
||||
- Fixed EpisodePage using `seasonId` (DB id) instead of `season.season_number`
|
||||
- [[Statistics|LibraryGrowthChart]]: uses `createdAt` only (removed `date_first_seen`), includes all entries (watchlist + library)
|
||||
- [[Pages|SeasonPage]] and [[Pages|EpisodePage]]: added `max-w-4xl` width constraint
|
||||
- [[Navigation|Breadcrumbs]] now show "Title / Season x / Episode x" instead of generic labels
|
||||
- Fixed EpisodePage using `seasonId` (DB id) instead of `season.season_number` for display
|
||||
- Added cleanup section to [[Settings Page]] for orphan files/media records
|
||||
- Created `api/maintenance.ts` API client
|
||||
- Created [[API Clients|maintenance.ts]] API client
|
||||
@@ -0,0 +1,54 @@
|
||||
---
|
||||
title: Collections
|
||||
tags:
|
||||
- feature
|
||||
- collections
|
||||
---
|
||||
|
||||
# Collections
|
||||
|
||||
## Overview
|
||||
|
||||
Collections group related entries together. Two types:
|
||||
|
||||
| Type | Source | `isUserCollection` |
|
||||
|---|---|---|
|
||||
| TMDB Collections | Auto-fetched from TMDB (e.g., "The Dark Knight Trilogy") | `false` |
|
||||
| User Collections | Manually created by the user | `true` |
|
||||
|
||||
## Data Model
|
||||
|
||||
See [[Models#Collection]] and [[Models#UserCollectionEntry]].
|
||||
|
||||
- Collections linked to entries via `UserCollectionEntry` join table
|
||||
- Join table has `order` field — auto-managed by Sequelize hooks
|
||||
- Hooks in `sequelizeHooks.js` maintain order on create/update/destroy
|
||||
|
||||
## TMDB Collections
|
||||
|
||||
When an entry is added that belongs to a TMDB collection:
|
||||
|
||||
1. [[Services#EntryManager]] detects `collection_id` on the entry
|
||||
2. Calls [[Services#CollectionManager]] `.fetchAndSaveCollection(tmdbId)`
|
||||
3. Collection created with poster/backdrop from TMDB
|
||||
4. Missing parts can be fetched via "Fetch Parts" action
|
||||
|
||||
## User Collections
|
||||
|
||||
Users can create custom collections:
|
||||
|
||||
- Name, description
|
||||
- Poster and backdrop (upload via multipart)
|
||||
- Add/remove entries, reorder
|
||||
|
||||
## API Endpoints
|
||||
|
||||
See [[API Reference#Collections]].
|
||||
|
||||
## Frontend
|
||||
|
||||
- [[Pages#CollectionsPage|CollectionsPage]] — Grid of all collections
|
||||
- [[Pages#CollectionDetailsPage|CollectionDetailsPage]] — Collection detail with entries
|
||||
- [[Components#Dialogs|CollectionEditDialog]] — Create/edit dialog
|
||||
- [[Components#Dialogs|AddEntryToCollectionDialog]] — Add entry picker
|
||||
- [[Hooks#useCollections]] — Query and mutation hooks
|
||||
@@ -0,0 +1,82 @@
|
||||
---
|
||||
title: Components
|
||||
tags:
|
||||
- frontend
|
||||
- components
|
||||
- react
|
||||
---
|
||||
|
||||
# Components
|
||||
|
||||
All in `react_frontend/src/components/`. Organized by domain.
|
||||
|
||||
---
|
||||
|
||||
## Layout
|
||||
|
||||
| Component | File | Description |
|
||||
|---|---|---|
|
||||
| `AppLayout` | `layout/AppLayout.tsx` | Root layout with Sidebar + main area |
|
||||
| `Sidebar` | `layout/Sidebar.tsx` | Left navigation sidebar |
|
||||
|
||||
## Entry Components
|
||||
|
||||
| Component | File | Description |
|
||||
|---|---|---|
|
||||
| `EntryCard` | `entries/EntryCard.tsx` | Entry poster card (grid item) |
|
||||
| `EntryLibraryGrid` | `entries/EntryLibraryGrid.tsx` | Grid layout for entry cards |
|
||||
| `TrendingSlider` | `entries/TrendingSlider.tsx` | Horizontal slider for trending entries |
|
||||
| `TrendingGrid` | `entries/TrendingGrid.tsx` | Grid for trending/popular TMDB entries |
|
||||
| `SeasonsContainer` | `entries/SeasonsContainer.tsx` | Seasons list for TV entry details |
|
||||
| `EpisodeWatchHistory` | `entries/EpisodeWatchHistory.tsx` | Watch history list for an episode |
|
||||
| `CastList` | `entries/CastList.tsx` | Horizontal cast/crew list |
|
||||
|
||||
## Collection Components
|
||||
|
||||
| Component | File | Description |
|
||||
|---|---|---|
|
||||
| `CollectionsGrid` | `collections/CollectionsGrid.tsx` | Grid of collection cards |
|
||||
|
||||
## Dashboard Charts
|
||||
|
||||
See [[Statistics]] for data details.
|
||||
|
||||
| Component | File | Description |
|
||||
|---|---|---|
|
||||
| `WatchActivityChart` | `dashboard/WatchActivityChart.tsx` | Monthly watch activity (area chart) |
|
||||
| `WatchTimeChart` | `dashboard/WatchTimeChart.tsx` | Monthly watch time (area chart) |
|
||||
| `CouchDayChart` | `dashboard/CouchDayChart.tsx` | Day-of-week distribution (bar chart) |
|
||||
| `LibraryGrowthChart` | `dashboard/LibraryGrowthChart.tsx` | Library growth over time (area chart) |
|
||||
| `MediaTypeChart` | `dashboard/MediaTypeChart.tsx` | Movies vs TV breakdown |
|
||||
| `TopGenresChart` | `dashboard/TopGenresChart.tsx` | Top genres by count |
|
||||
| `RatingsChart` | `dashboard/RatingsChart.tsx` | Ratings distribution |
|
||||
|
||||
## Dialogs
|
||||
|
||||
| Component | File | Description |
|
||||
|---|---|---|
|
||||
| `EntrySeenDialog` | `dialogs/EntrySeenDialog.tsx` | Mark movie/episode as watched. Uses react-hook-form + zod. See [[Watch Tracking]] |
|
||||
| `EpisodeSeenEditDialog` | `dialogs/EpisodeSeenEditDialog.tsx` | Create/edit episode watch record |
|
||||
| `EntryMediaDialog` | `dialogs/EntryMediaDialog.tsx` | Media gallery for entry |
|
||||
| `EntrySettingsDialog` | `dialogs/EntrySettingsDialog.tsx` | Entry settings (calendar, sync, hidden) |
|
||||
| `MovieWatchHistoryDialog` | `dialogs/MovieWatchHistoryDialog.tsx` | Full movie watch history |
|
||||
| `RatingDialog` | `dialogs/RatingDialog.tsx` | Rate entry (supports half-stars) |
|
||||
| `ConfirmDialog` | `dialogs/ConfirmDialog.tsx` | Generic confirmation dialog |
|
||||
| `AddEntryToCollectionDialog` | `dialogs/AddEntryToCollectionDialog.tsx` | Add entry to collection picker |
|
||||
| `CollectionEditDialog` | `dialogs/CollectionEditDialog.tsx` | Create/edit collection |
|
||||
|
||||
## Skeletons
|
||||
|
||||
> [!info] File: `components/skeletons/PageSkeletons.tsx`
|
||||
|
||||
14 named skeleton exports used as `<Suspense>` fallbacks for lazy-loaded pages:
|
||||
|
||||
`HomeSkeleton`, `LibrarySkeleton`, `WatchlistSkeleton`, `DashboardSkeleton`, `CollectionsSkeleton`, `CollectionDetailsSkeleton`, `MediaSkeleton`, `CalendarSkeleton`, `EntryDetailsSkeleton`, `SeasonSkeleton`, `EpisodeSkeleton`, `PeopleSkeleton`, `PersonDetailsSkeleton`, `SettingsSkeleton`
|
||||
|
||||
## UI Primitives (shadcn/ui)
|
||||
|
||||
Base components from shadcn/ui in `components/ui/`:
|
||||
|
||||
`badge`, `avatar`, `button`, `calendar`, `card`, `checkbox`, `dialog`, `dropdown-menu`, `input`, `label`, `popover`, `progress`, `scroll-area`, `select`, `separator`, `sheet`, `skeleton`, `sonner`, `switch`, `tabs`, `textarea`, `tooltip`
|
||||
|
||||
Theme: **base-nova** style.
|
||||
+102
-11
@@ -1,21 +1,112 @@
|
||||
---
|
||||
title: Database
|
||||
tags:
|
||||
- backend
|
||||
- database
|
||||
- mysql
|
||||
- sequelize
|
||||
---
|
||||
|
||||
# Database
|
||||
|
||||
## Overview
|
||||
|
||||
MySQL database named "Showzy", managed by Sequelize ORM. Schema sync uses `{ alter: doUpdate }` where `doUpdate = false` by default.
|
||||
MySQL database named **Showzy**, managed by Sequelize 6 ORM.
|
||||
|
||||
## Key Models
|
||||
- Connection: `localhost`, user `root`, password `password`
|
||||
- Sync mode: `sequelize.sync({ alter: false })` — no auto-alter in production
|
||||
- Logging: writes SQL to `sequelize.log`
|
||||
- Genre seeding: 27 TMDB genres auto-seeded on startup
|
||||
|
||||
- `Entry` — Movies and TV series
|
||||
- `Season` — TV seasons (belongs to Entry)
|
||||
- `Episode` — TV episodes (belongs to Season)
|
||||
- `EntrySeen` — Movie watch records (has `accuracy` field: EXACT, ESTIMATED, UNKNOWN)
|
||||
- `EpisodeSeen` — Episode watch records (has `accuracy` field: EXACT, ESTIMATED, UNKNOWN)
|
||||
- `Media` — Image file references (posters, logos, backdrops, stills)
|
||||
- `Collection`, `Genre`, `Network`, `People`, `Credit`, `Franchise`
|
||||
## Entity Relationship Diagram
|
||||
|
||||
```mermaid
|
||||
erDiagram
|
||||
Entry ||--o| EntryId : has
|
||||
Entry ||--o| EntryRating : has
|
||||
Entry ||--o{ EntrySeen : has
|
||||
Entry ||--o{ Season : has
|
||||
Entry ||--o{ Credit : has
|
||||
Entry }o--o{ Genre : tagged
|
||||
Entry }o--o{ Network : airs-on
|
||||
Entry }o--o{ Collection : belongs-to
|
||||
|
||||
Season ||--o{ Episode : contains
|
||||
Episode ||--o{ EpisodeSeen : has
|
||||
|
||||
Credit }o--|| People : references
|
||||
|
||||
Media ||--|| Entry : polymorphic
|
||||
Media ||--|| Season : polymorphic
|
||||
Media ||--|| Episode : polymorphic
|
||||
Media ||--|| Collection : polymorphic
|
||||
Media ||--|| People : polymorphic
|
||||
```
|
||||
|
||||
## Relationships
|
||||
|
||||
Defined in `backend/config/relations.js`:
|
||||
|
||||
| Source | Target | Type | Through | On Delete |
|
||||
|---|---|---|---|---|
|
||||
| Entry | EntryId | `hasOne` | — | CASCADE |
|
||||
| Entry | EntryRating | `hasOne` | — | CASCADE |
|
||||
| Entry | EntrySeen | `hasMany` | — | CASCADE |
|
||||
| Entry | Season | `hasMany` | — | CASCADE |
|
||||
| Entry | Credit | `hasMany` | — | — |
|
||||
| Entry | Genre | `belongsToMany` | EntryGenre | — |
|
||||
| Entry | Network | `belongsToMany` | EntryNetwork | — |
|
||||
| Entry | Collection | `belongsToMany` | UserCollectionEntry | — |
|
||||
| Season | Episode | `hasMany` | — | CASCADE |
|
||||
| Episode | EpisodeSeen | `hasMany` | — | — |
|
||||
| Credit | People | `belongsTo` | — | — |
|
||||
| Credit | Entry | `belongsTo` | — | — |
|
||||
| People | Credit | `hasMany` (as 'roles') | — | — |
|
||||
| Media | * | Polymorphic scopes | `mediaable` + `mediaableId` | — |
|
||||
|
||||
### Polymorphic Media Scopes
|
||||
|
||||
Media uses `mediaable` (string: 'entry', 'people', 'collection', 'season', 'episode') and `mediaableId` to associate with any entity.
|
||||
|
||||
## Hooks
|
||||
|
||||
Defined in `backend/config/sequelizeHooks.js`:
|
||||
|
||||
- **UserCollectionEntry.afterCreate** — Updates collection `updatedAt`, auto-assigns `order`
|
||||
- **UserCollectionEntry.afterUpdate** — Updates collection `updatedAt`, re-orders other entries
|
||||
- **UserCollectionEntry.afterDestroy** — Updates collection `updatedAt`, cleanup
|
||||
|
||||
## All Models
|
||||
|
||||
See [[Models]] for detailed field definitions of every model.
|
||||
|
||||
### Quick Reference
|
||||
|
||||
| Model | Purpose | Timestamps |
|
||||
|---|---|---|
|
||||
| [[Models#Entry\|Entry]] | Movies and TV series | Yes |
|
||||
| [[Models#Season\|Season]] | TV seasons | Yes |
|
||||
| [[Models#Episode\|Episode]] | TV episodes | Yes |
|
||||
| [[Models#EntrySeen\|EntrySeen]] | Movie watch records | No |
|
||||
| [[Models#EpisodeSeen\|EpisodeSeen]] | Episode watch records | Yes |
|
||||
| [[Models#Media\|Media]] | Polymorphic image records | Yes |
|
||||
| [[Models#Collection\|Collection]] | TMDB + user collections | Yes |
|
||||
| [[Models#UserCollectionEntry\|UserCollectionEntry]] | Collection ↔ Entry join | No |
|
||||
| [[Models#Credit\|Credit]] | Cast/crew credits | Yes |
|
||||
| [[Models#People\|People]] | Person profiles | Yes |
|
||||
| [[Models#EntryId\|EntryId]] | External IDs (TMDB, IMDB, TVDB) | No |
|
||||
| [[Models#EntryRating\|EntryRating]] | Multi-source ratings | No |
|
||||
| [[Models#EntryGenre\|EntryGenre]] | Entry ↔ Genre join | No |
|
||||
| [[Models#EntryNetwork\|EntryNetwork]] | Entry ↔ Network join | No |
|
||||
| [[Models#Genre\|Genre]] | Genres (seeded from TMDB) | No |
|
||||
| [[Models#Network\|Network]] | TV networks | No |
|
||||
| [[Models#Franchise\|Franchise]] | Franchise grouping (unused) | No |
|
||||
|
||||
## Important Files
|
||||
|
||||
- `backend/config/database.js` — Connection config
|
||||
- `backend/config/relations.js` — Model associations
|
||||
- `backend/config/database.js` — Sequelize connection
|
||||
- `backend/config/relations.js` — All associations
|
||||
- `backend/config/dataInitializer.js` — Genre seeding
|
||||
- `backend/config/sequelizeHooks.js` — Collection order hooks
|
||||
- `backend/models/` — All model definitions
|
||||
- `backend/models/` — All Sequelize model definitions
|
||||
@@ -1,12 +1,88 @@
|
||||
---
|
||||
title: Deployment
|
||||
tags:
|
||||
- deployment
|
||||
- docker
|
||||
- infrastructure
|
||||
---
|
||||
|
||||
# Deployment
|
||||
|
||||
## Overview
|
||||
|
||||
Docker-based deployment using `docker-compose.yml` at project root.
|
||||
Showy can be deployed via Docker Compose (server) or as an Electron desktop app (local). See [[Electron]] for desktop deployment.
|
||||
|
||||
## Docker Compose
|
||||
|
||||
> [!info] File: `docker-compose.yml` (v3.9)
|
||||
|
||||
### Services
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
FE[Frontend :3000] --> BE[Backend :4000]
|
||||
BE --> DB[(MySQL :3306)]
|
||||
```
|
||||
|
||||
#### Frontend
|
||||
|
||||
- **Build:** Root Dockerfile
|
||||
- **Args:** `API_URL`, `TMDB_API_KEY`
|
||||
- **Port:** `3000:80`
|
||||
- **Depends on:** backend
|
||||
- Uses Nginx to serve static files (`frontend/nginx.conf`)
|
||||
|
||||
#### Backend
|
||||
|
||||
- **Build:** `backend/Dockerfile`
|
||||
- **Port:** `4000:4000`
|
||||
- **Depends on:** mysql
|
||||
- **Environment:**
|
||||
- `MYSQL_HOST=mysql`
|
||||
- `MYSQL_DB=Showzy`
|
||||
- `MYSQL_USER=root`
|
||||
- `MYSQL_PASSWORD=password`
|
||||
|
||||
#### MySQL
|
||||
|
||||
- **Image:** `mysql:8.0`
|
||||
- **Port:** `3306:3306`
|
||||
- **Environment:**
|
||||
- `MYSQL_ROOT_PASSWORD=rootpassword`
|
||||
- `MYSQL_DATABASE=mydatabase`
|
||||
- **Volume:** `db_data:/var/lib/mysql` (persistent)
|
||||
|
||||
### Build & Run
|
||||
|
||||
```bash
|
||||
docker-compose up -d --build
|
||||
```
|
||||
|
||||
## Backend Dockerfile
|
||||
|
||||
| Step | Action |
|
||||
|---|---|
|
||||
| Base | `node:18` (or similar) |
|
||||
| Copy | `package.json`, `pnpm-lock.yaml` |
|
||||
| Install | `pnpm install` |
|
||||
| Copy | All source files |
|
||||
| Expose | Port 4000 |
|
||||
| CMD | `node server.js` |
|
||||
|
||||
## Important Files
|
||||
|
||||
- `docker-compose.yml` — Compose orchestration
|
||||
- `backend/Dockerfile` — Backend container
|
||||
- `frontend/Dockerfile` — Angular frontend container (legacy)
|
||||
- `frontend/nginx.conf` — Nginx config for frontend serving
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `docker-compose.yml` | Multi-container orchestration |
|
||||
| `backend/Dockerfile` | Backend container build |
|
||||
| `frontend/Dockerfile` | Legacy Angular frontend container |
|
||||
| `frontend/nginx.conf` | Nginx static file config |
|
||||
|
||||
> [!note] Legacy Frontend
|
||||
> The Docker setup currently uses the Angular frontend (`/frontend`). The React frontend (`/react_frontend`) is the active development target but may not yet be containerized.
|
||||
|
||||
## See Also
|
||||
|
||||
- [[Env]] — Environment variables
|
||||
- [[Electron]] — Desktop deployment alternative
|
||||
- [[Architecture]] — System overview
|
||||
+68
-4
@@ -1,11 +1,75 @@
|
||||
---
|
||||
title: Electron
|
||||
tags:
|
||||
- electron
|
||||
- desktop
|
||||
---
|
||||
|
||||
# Electron
|
||||
|
||||
## Overview
|
||||
|
||||
Desktop wrapper using Electron. Entry point: `electron/main.js`.
|
||||
Electron 34 wraps the Showy backend + frontend into a standalone desktop application for Windows.
|
||||
|
||||
## Architecture
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
E[Electron Main Process] --> |child_process.spawn| B[Node.js Backend]
|
||||
E --> |BrowserWindow.loadFile| FE[Frontend Build]
|
||||
FE --> |HTTP requests| B
|
||||
E --> |IPC: backend-ready| FE
|
||||
```
|
||||
|
||||
## Main Process — `electron/main.js`
|
||||
|
||||
1. Spawns backend as a **child process**: `node backend/server.js`
|
||||
2. Sets `PARENT_PROCESS` env var pointing to Electron user data path
|
||||
3. Backend auto-restarts if it crashes
|
||||
4. Creates `BrowserWindow` (1200×720) loading `frontend_build/browser/index.html`
|
||||
5. Sends `backend-ready` IPC event when backend starts listening
|
||||
6. On window close → kills backend child process
|
||||
|
||||
### Window Configuration
|
||||
|
||||
| Setting | Value |
|
||||
|---|---|
|
||||
| Width | 1200 |
|
||||
| Height | 720 |
|
||||
| Context Isolation | `true` |
|
||||
| Sandbox | `true` |
|
||||
| Node Integration | `true` |
|
||||
|
||||
## Preload Script — `electron/preload.js`
|
||||
|
||||
Exposes `electron.ipcRenderer` to the renderer process via `contextBridge.exposeInMainWorld`:
|
||||
|
||||
- `send(channel, data)` — send to main
|
||||
- `on(channel, callback)` — listen from main
|
||||
|
||||
## Build Configuration
|
||||
|
||||
| Field | Value |
|
||||
|---|---|
|
||||
| `appId` | `x4lo.showy` |
|
||||
| Target | Windows x64 directory output |
|
||||
| Icon | From Angular frontend assets |
|
||||
|
||||
## Package Dependencies
|
||||
|
||||
- `electron` 34
|
||||
- `electron-builder` 25
|
||||
- All backend dependencies (bundled)
|
||||
|
||||
## Important Files
|
||||
|
||||
- `electron/main.js` — Main process
|
||||
- `electron/preload.js` — Preload script
|
||||
- `electron/package.json` — Electron dependencies
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `electron/main.js` | Main process entry |
|
||||
| `electron/preload.js` | Context bridge for IPC |
|
||||
| `electron/package.json` | Electron + backend deps |
|
||||
|
||||
## See Also
|
||||
|
||||
- [[Architecture]] — System overview
|
||||
- [[Deployment]] — Docker alternative
|
||||
+116
-9
@@ -1,16 +1,123 @@
|
||||
# Environment Variables
|
||||
---
|
||||
title: Environment & Configuration
|
||||
tags:
|
||||
- configuration
|
||||
- environment
|
||||
- settings
|
||||
aliases:
|
||||
- Environment Variables
|
||||
- Configuration
|
||||
---
|
||||
|
||||
## Overview
|
||||
# Environment & Configuration
|
||||
|
||||
Configuration is managed via `backend/settings.json` (see `settings.json.example`).
|
||||
## Backend — `settings.json`
|
||||
|
||||
## Key Settings
|
||||
The primary configuration file. Located at `backend/settings.json`. See `settings.json.example` for template.
|
||||
|
||||
- `tmdbApiKey` — TMDB API key for metadata fetching
|
||||
- `backPort` — Backend server port
|
||||
- Database connection configured in `backend/config/database.js`
|
||||
| Field | Type | Default | Description |
|
||||
|---|---|---|---|
|
||||
| `userDataPath` | string | `C:\Users\{user}\Documents\Showy Data` | Root path for [[Media System\|media storage]] |
|
||||
| `tmdbApiUrl` | string | `https://api.themoviedb.org/3` | [[TMDB Integration]] base URL |
|
||||
| `tmdbApiKey` | string | — | TMDB API key (**required**) |
|
||||
| `backPort` | number | `4000` | Backend server port |
|
||||
| `frontPort` | string | `8000` | Frontend port (reference only) |
|
||||
| `portableMode` | string | `""` | Portable mode path (empty = disabled) |
|
||||
| `libraryViewMode` | string | `"grid"` | Library page view mode |
|
||||
| `watchlistViewMode` | string | `"grid"` | Watchlist page view mode |
|
||||
|
||||
### Example
|
||||
|
||||
```json
|
||||
{
|
||||
"userDataPath": "C:\\Users\\username\\Documents\\Showy Data",
|
||||
"tmdbApiUrl": "https://api.themoviedb.org/3",
|
||||
"tmdbApiKey": "your_tmdb_api_key_here",
|
||||
"frontPort": "8000",
|
||||
"backPort": 4000,
|
||||
"portableMode": "",
|
||||
"libraryViewMode": "grid",
|
||||
"watchlistViewMode": "grid"
|
||||
}
|
||||
```
|
||||
|
||||
## Database Configuration
|
||||
|
||||
> [!info] File: `backend/config/database.js`
|
||||
|
||||
| Setting | Value |
|
||||
|---|---|
|
||||
| Dialect | MySQL |
|
||||
| Database | `Showzy` |
|
||||
| Host | `localhost` |
|
||||
| Username | `root` |
|
||||
| Password | `password` |
|
||||
| Logging | `sequelize.log` file |
|
||||
|
||||
## Docker Environment Variables
|
||||
|
||||
Used in `docker-compose.yml` — override database connection:
|
||||
|
||||
| Variable | Default | Description |
|
||||
|---|---|---|
|
||||
| `MYSQL_HOST` | `mysql` | MySQL host (Docker service name) |
|
||||
| `MYSQL_DB` | `Showzy` | Database name |
|
||||
| `MYSQL_USER` | `root` | Database user |
|
||||
| `MYSQL_PASSWORD` | `password` | Database password |
|
||||
| `MYSQL_ROOT_PASSWORD` | `rootpassword` | MySQL root password (init) |
|
||||
|
||||
## Frontend Environment
|
||||
|
||||
| Variable | Source | Description |
|
||||
|---|---|---|
|
||||
| `VITE_API_URL` | `.env` or build arg | API base URL override |
|
||||
|
||||
Vite dev proxy: `/api` → `http://showyback.coolguy.space` (configured in `vite.config.ts`)
|
||||
|
||||
## Electron Environment
|
||||
|
||||
| Variable | Set By | Description |
|
||||
|---|---|---|
|
||||
| `PARENT_PROCESS` | Electron main process | Electron user data path — signals backend it's running inside Electron |
|
||||
|
||||
## Media Folder Structure
|
||||
|
||||
Created automatically by `configService` on startup at `{userDataPath}`:
|
||||
|
||||
```
|
||||
{userDataPath}/
|
||||
├── images/
|
||||
│ ├── entries/
|
||||
│ │ ├── posters/
|
||||
│ │ ├── backdrops/
|
||||
│ │ └── logos/
|
||||
│ ├── collections/
|
||||
│ │ ├── posters/
|
||||
│ │ └── backdrops/
|
||||
│ ├── seasons/
|
||||
│ │ └── posters/
|
||||
│ ├── episodes/
|
||||
│ │ └── stills/
|
||||
│ └── peoples/
|
||||
│ └── profiles/
|
||||
└── showy.log
|
||||
```
|
||||
|
||||
## Important Files
|
||||
|
||||
- `backend/settings.json.example` — Template
|
||||
- `backend/config/database.js` — DB connection config
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `backend/settings.json` | Runtime configuration |
|
||||
| `backend/settings.json.example` | Template |
|
||||
| `backend/config/database.js` | Database connection |
|
||||
| `backend/services/configService.js` | Config reader/writer |
|
||||
| `docker-compose.yml` | Docker env vars |
|
||||
| `react_frontend/vite.config.ts` | Frontend dev proxy |
|
||||
|
||||
## See Also
|
||||
|
||||
- [[Backend]] — Server setup
|
||||
- [[Deployment]] — Docker configuration
|
||||
- [[TMDB Integration]] — API key usage
|
||||
- [[Media System]] — Storage paths
|
||||
- [[Settings Page]] — UI for editing settings
|
||||
@@ -0,0 +1,70 @@
|
||||
---
|
||||
title: Error Handling
|
||||
tags:
|
||||
- backend
|
||||
- errors
|
||||
- middleware
|
||||
---
|
||||
|
||||
# Error Handling
|
||||
|
||||
## Overview
|
||||
|
||||
All errors flow through a central error handler middleware at the end of the Express pipeline. Custom error classes extend a base `CustomError` for consistent API responses.
|
||||
|
||||
## Error Classes
|
||||
|
||||
All in `backend/errors/`:
|
||||
|
||||
| Class | HTTP Status | File |
|
||||
|---|---|---|
|
||||
| `CustomError` | 500 | `CustomError.js` (base class) |
|
||||
| `BadRequestError` | 400 | `BadRequestError.js` |
|
||||
| `ValidationError` | 400 | `ValidationError.js` |
|
||||
| `NotFoundError` | 404 | `NotFoundError.js` |
|
||||
| `ConflictError` | 409 | `ConflictError.js` |
|
||||
| `ForbiddenError` | 403 | `ForbiddenError.js` |
|
||||
| `UnauthorizedError` | 401 | `UnauthorizedError.js` |
|
||||
| `InternalServerError` | 500 | `InternalServerError.js` |
|
||||
|
||||
All extend `CustomError` which extends `Error`. Each sets `this.statusCode` and `this.name`.
|
||||
|
||||
## Error Handler Middleware
|
||||
|
||||
> [!info] File: `backend/middleware/errorHandler.js`
|
||||
|
||||
Catches and normalizes all errors:
|
||||
|
||||
1. **CustomError subclasses** → `{ error: name, message, statusCode }`
|
||||
2. **Sequelize `ValidationError`** → 400 with field-level messages
|
||||
3. **`SequelizeUniqueConstraintError`** → 409 Conflict
|
||||
4. **`SequelizeForeignKeyConstraintError`** → 400 Bad Request
|
||||
5. **Generic errors** → 500 Internal Server Error
|
||||
|
||||
All errors are logged via `logService.logToFile()`.
|
||||
|
||||
## Async Wrapper
|
||||
|
||||
> [!info] File: `backend/utils/asyncWrapper.js`
|
||||
|
||||
Wraps async route handlers to catch rejected promises:
|
||||
|
||||
```js
|
||||
const asyncWrapper = (fn) => (req, res, next) => {
|
||||
fn(req, res, next).catch(next);
|
||||
};
|
||||
```
|
||||
|
||||
All controller methods are wrapped with this before being passed to Express routes.
|
||||
|
||||
## Response Format
|
||||
|
||||
Error responses follow this structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"error": "NotFoundError",
|
||||
"message": "Entry not found",
|
||||
"statusCode": 404
|
||||
}
|
||||
```
|
||||
+116
-19
@@ -1,32 +1,129 @@
|
||||
---
|
||||
title: Frontend
|
||||
tags:
|
||||
- frontend
|
||||
- react
|
||||
- typescript
|
||||
---
|
||||
|
||||
# Frontend
|
||||
|
||||
## Overview
|
||||
|
||||
React 18 + TypeScript SPA built with Vite. Uses shadcn/ui for components, TanStack Query for server state, Zustand for client state, and Recharts for charts.
|
||||
React 19 + TypeScript SPA built with Vite 8. Located in `react_frontend/`.
|
||||
|
||||
| Concern | Solution |
|
||||
|---|---|
|
||||
| UI Components | shadcn/ui (base-nova theme) + Tailwind CSS 4 |
|
||||
| Server State | TanStack Query 5 (react-query) |
|
||||
| Client State | Zustand 5 → [[Stores]] |
|
||||
| Routing | React Router 7 → [[Routing]] |
|
||||
| Forms | react-hook-form 7 + Zod 4 |
|
||||
| Charts | Recharts 3 → [[Statistics]] |
|
||||
| Toasts | Sonner |
|
||||
| Icons | Lucide |
|
||||
| Dates | date-fns |
|
||||
| HTTP | Axios |
|
||||
|
||||
## Entry Point
|
||||
|
||||
```
|
||||
main.tsx → App.tsx → QueryClientProvider → TooltipProvider → RouterProvider → Toaster
|
||||
```
|
||||
|
||||
**QueryClient config:**
|
||||
- `retry: 1`
|
||||
- `refetchOnWindowFocus: false`
|
||||
- `staleTime: 2 minutes`
|
||||
|
||||
## Architecture
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
subgraph UI["UI Layer"]
|
||||
Pages --> Components
|
||||
Components --> ShadcnUI[shadcn/ui]
|
||||
end
|
||||
|
||||
subgraph State["State Layer"]
|
||||
Pages --> Hooks
|
||||
Hooks --> TQ[TanStack Query]
|
||||
Hooks --> Store[Zustand Store]
|
||||
TQ --> APIClients[API Clients]
|
||||
end
|
||||
|
||||
APIClients --> |Axios| Backend[Backend REST API]
|
||||
```
|
||||
|
||||
### Data Flow
|
||||
|
||||
1. App mounts → `useLibrary()` fetches all entries → [[Stores|useLibraryStore]] loaded
|
||||
2. Pages use [[Hooks]] wrapping TanStack Query for server data
|
||||
3. Mutations update Zustand optimistically → invalidate Query caches
|
||||
4. [[Normalizers]] transform backend responses to frontend [[Types]]
|
||||
|
||||
## Project Structure
|
||||
|
||||
```
|
||||
react_frontend/src/
|
||||
├── api/ → [[API Clients]] (11 Axios modules)
|
||||
├── components/ → [[Components]] (by category)
|
||||
│ ├── dashboard/ → Chart components
|
||||
│ ├── dialogs/ → Modal dialogs
|
||||
│ ├── entries/ → Entry-related components
|
||||
│ ├── layout/ → AppLayout, Sidebar
|
||||
│ ├── skeletons/ → Loading skeletons
|
||||
│ └── ui/ → shadcn/ui primitives
|
||||
├── hooks/ → [[Hooks]] (10 hook files)
|
||||
├── lib/ → Utilities
|
||||
│ ├── api.ts → Axios instance
|
||||
│ ├── media-utils.ts → [[Media Utilities]]
|
||||
│ ├── normalizers.ts → [[Normalizers]]
|
||||
│ └── utils.ts → cn() helper
|
||||
├── pages/ → [[Pages]] (17 route pages)
|
||||
├── stores/ → [[Stores]] (2 Zustand stores)
|
||||
└── types/ → [[Types]] (TypeScript interfaces)
|
||||
```
|
||||
|
||||
## Vite Configuration
|
||||
|
||||
- React plugin + Tailwind CSS plugin
|
||||
- Path alias: `@/` → `src/`
|
||||
- Dev proxy: `/api` → `http://showyback.coolguy.space`
|
||||
|
||||
## Key Patterns
|
||||
|
||||
- **State Management**: `useLibraryStore` (Zustand) holds all entries; TanStack Query for server data
|
||||
- **Forms**: react-hook-form + zod for validation
|
||||
- **Routing**: React Router v6 with nested routes
|
||||
- **Styling**: Tailwind CSS + shadcn/ui components
|
||||
### Library-First Architecture
|
||||
|
||||
## Important Pages
|
||||
The entire entry library is loaded into a Zustand `Map<number, Entry>` on startup. This enables:
|
||||
|
||||
- **Dashboard** — [[Statistics]] charts (CouchDayChart, LibraryGrowthChart)
|
||||
- **Entry Details** — Entry info, seasons list, watch history
|
||||
- **[[SeasonPage]]** — Season episodes with watch progress
|
||||
- **[[EpisodePage]]** — Episode details with prev/next navigation
|
||||
- **[[Settings Page]]** — App config + maintenance cleanup
|
||||
- O(1) entry lookup by ID
|
||||
- TMDB entries checked against library by TMDB ID → if present, local version displayed
|
||||
- Optimistic UI updates
|
||||
|
||||
## Navigation
|
||||
### Lazy Page Loading
|
||||
|
||||
See [[Navigation]] for breadcrumb patterns.
|
||||
All 17 pages use `React.lazy()` with custom skeleton fallbacks via `<Suspense>`. See [[Routing]].
|
||||
|
||||
## API Clients
|
||||
### Form Pattern
|
||||
|
||||
Located in `react_frontend/src/api/`:
|
||||
- `settings.ts` — Settings CRUD
|
||||
- `maintenance.ts` — Orphan file/record scan and cleanup
|
||||
- `seasons.ts` — Season and episode data
|
||||
- `entries.ts` — Entry CRUD
|
||||
Forms use `react-hook-form` with `zodResolver`:
|
||||
|
||||
```
|
||||
useForm({ resolver: zodResolver(schema), values }) → handleSubmit → mutation.mutate
|
||||
```
|
||||
|
||||
### Toast Notifications
|
||||
|
||||
All mutation success/error feedback via Sonner toasts.
|
||||
|
||||
## See Also
|
||||
|
||||
- [[Routing]] — All 17 routes
|
||||
- [[Pages]] — Every page component
|
||||
- [[Components]] — UI components by category
|
||||
- [[Hooks]] — Custom hooks
|
||||
- [[Stores]] — State management
|
||||
- [[API Clients]] — Backend communication
|
||||
- [[Types]] — TypeScript types
|
||||
- [[Navigation]] — Breadcrumbs
|
||||
@@ -0,0 +1,134 @@
|
||||
---
|
||||
title: Hooks
|
||||
tags:
|
||||
- frontend
|
||||
- hooks
|
||||
- react-query
|
||||
---
|
||||
|
||||
# Hooks
|
||||
|
||||
Custom hooks in `react_frontend/src/hooks/`. All query hooks wrap TanStack Query. All mutation hooks invalidate relevant caches and update [[Stores|Zustand store]] when applicable.
|
||||
|
||||
---
|
||||
|
||||
## useEntries
|
||||
|
||||
> [!info] File: `hooks/useEntries.ts`
|
||||
|
||||
The main library hooks. Mutations update [[Stores|useLibraryStore]] optimistically.
|
||||
|
||||
| Hook | Type | Description |
|
||||
|---|---|---|
|
||||
| `useLibrary()` | Query | Fetch all entries → loads into Zustand store. Runs once on mount. |
|
||||
| `useEntry(id)` | Query | Single entry by ID (triggers lazy refresh on backend) |
|
||||
| `useEntrySeasons(id)` | Query | Seasons for an entry |
|
||||
| `useCreateEntry()` | Mutation | `POST /entries` → adds to Zustand store |
|
||||
| `useUpdateEntry()` | Mutation | `PUT /entries/:id` → updates Zustand store |
|
||||
| `useDeleteEntry()` | Mutation | `DELETE /entries/:id` → removes from Zustand store |
|
||||
| `useRefreshEntry()` | Mutation | `PUT /entries/:id/refresh` |
|
||||
| `useUpdateEntryRatings()` | Mutation | `PUT /entries/:id/ratings` |
|
||||
| `useUploadMedia()` | Mutation | `POST /entries/:id/media` |
|
||||
|
||||
## useCollections
|
||||
|
||||
> [!info] File: `hooks/useCollections.ts`
|
||||
|
||||
| Hook | Type | Description |
|
||||
|---|---|---|
|
||||
| `useCollections()` | Query | All collections |
|
||||
| `useCollection(id)` | Query | Single collection with entries |
|
||||
| `useCreateCollection()` | Mutation | Create user collection |
|
||||
| `useUpdateCollection()` | Mutation | Update collection (with media) |
|
||||
| `useDeleteCollection()` | Mutation | Delete collection |
|
||||
| `useAddEntryToCollection()` | Mutation | Add entry to collection |
|
||||
| `useRemoveEntryFromCollection()` | Mutation | Remove entry from collection |
|
||||
|
||||
## useSeasons
|
||||
|
||||
> [!info] File: `hooks/useSeasons.ts`
|
||||
|
||||
| Hook | Type | Description |
|
||||
|---|---|---|
|
||||
| `useSeason(id)` | Query | Season by ID (includes episodes) |
|
||||
| `useSeasonEpisodes(id)` | Query | Episodes for a season |
|
||||
|
||||
## useEntrySeen
|
||||
|
||||
> [!info] File: `hooks/useEntrySeen.ts`
|
||||
|
||||
See [[Watch Tracking]].
|
||||
|
||||
| Hook | Type | Description |
|
||||
|---|---|---|
|
||||
| `useEntrySeenByEntry(entryId)` | Query | Watch records for an entry |
|
||||
| `useCreateEntrySeen()` | Mutation | Create watch record |
|
||||
| `useUpdateEntrySeen()` | Mutation | Update watch record |
|
||||
| `useDeleteEntrySeen()` | Mutation | Delete watch record |
|
||||
|
||||
## useEpisodeSeen
|
||||
|
||||
> [!info] File: `hooks/useEpisodeSeen.ts`
|
||||
|
||||
See [[Watch Tracking]].
|
||||
|
||||
| Hook | Type | Description |
|
||||
|---|---|---|
|
||||
| `useEpisodeSeenByEpisode(episodeId)` | Query | Watch records for an episode |
|
||||
| `useCreateEpisodeSeen()` | Mutation | Create episode watch record |
|
||||
| `useUpdateEpisodeSeen()` | Mutation | Update episode watch record |
|
||||
| `useDeleteEpisodeSeen()` | Mutation | Delete episode watch record |
|
||||
|
||||
## usePeople
|
||||
|
||||
> [!info] File: `hooks/usePeople.ts`
|
||||
|
||||
| Hook | Type | Description |
|
||||
|---|---|---|
|
||||
| `usePerson(id)` | Query | Person by ID (lazy-fetch from TMDB) |
|
||||
| `usePersonCredits(id)` | Query | Person's credits |
|
||||
| `usePopularPeople(limit)` | Query | Popular people (local) |
|
||||
| `useSearchPeople(query)` | Query | Search people (local) |
|
||||
|
||||
## useTmdb
|
||||
|
||||
> [!info] File: `hooks/useTmdb.ts`
|
||||
|
||||
Infinite queries for TMDB browse/search pages. All return paginated results.
|
||||
|
||||
| Hook | Type | Description |
|
||||
|---|---|---|
|
||||
| `useTmdbTrending(type)` | Infinite Query | Trending movies/tv |
|
||||
| `useTmdbPopular(type)` | Infinite Query | Popular movies/tv |
|
||||
| `useTmdbTopRated(type)` | Infinite Query | Top-rated movies/tv |
|
||||
| `useTmdbUpcoming()` | Infinite Query | Upcoming movies |
|
||||
| `useTmdbSearch(query)` | Infinite Query | Multi-search |
|
||||
| `useTmdbPopularPeople()` | Infinite Query | Popular people |
|
||||
| `useTmdbSearchPeople(query)` | Infinite Query | People search |
|
||||
|
||||
## useStatistics
|
||||
|
||||
> [!info] File: `hooks/useStatistics.ts`
|
||||
|
||||
See [[Statistics]].
|
||||
|
||||
| Hook | Type | Description |
|
||||
|---|---|---|
|
||||
| `useAllTimeWatchTime()` | Query | Total watch time (all time) |
|
||||
| `useYearlyWatchTime(year)` | Query | Watch time by month |
|
||||
| `useYearlyWatchCount(year)` | Query | Watch count by month |
|
||||
| `useWatchdayDistribution()` | Query | Day-of-week distribution |
|
||||
|
||||
## useEpisodes
|
||||
|
||||
> [!info] File: `hooks/useEpisodes.ts`
|
||||
|
||||
| Hook | Type | Description |
|
||||
|---|---|---|
|
||||
| `useEpisodesByMonth(start, end)` | Query | Episodes airing in date range (for [[Calendar]]) |
|
||||
|
||||
## useDebounce
|
||||
|
||||
> [!info] File: `hooks/useDebounce.ts`
|
||||
|
||||
Utility hook: `useDebounce(value, delay)` — returns debounced value. Used by search inputs.
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
title: Import System
|
||||
tags:
|
||||
- backend
|
||||
- import
|
||||
- bulk
|
||||
---
|
||||
|
||||
# Import System
|
||||
|
||||
## Overview
|
||||
|
||||
Bulk import functionality for migrating data into Showy. Self-throttling to respect TMDB rate limits.
|
||||
|
||||
> [!info] File: `backend/services/importerService.js`
|
||||
|
||||
## Endpoints
|
||||
|
||||
See [[API Reference#Import]].
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `POST` | `/api/v1/import/movies` | Bulk import movies |
|
||||
| `POST` | `/api/v1/import/tmdb` | Import by TMDB IDs |
|
||||
| `POST` | `/api/v1/import/episodes-watch-history` | Import episode watch history |
|
||||
|
||||
## Rate Limiting
|
||||
|
||||
The importer self-throttles to stay under TMDB API limits:
|
||||
|
||||
- **Max 35 requests per 10 seconds**
|
||||
- **500ms delay** between each individual request
|
||||
- Each import triggers the full [[Services#EntryManager]] pipeline (TMDB fetch → save → media download)
|
||||
|
||||
## Flows
|
||||
|
||||
### Movie Import
|
||||
|
||||
1. Receives array of movie data
|
||||
2. For each: calls `EntryManager.fetchAndSaveNewEntry(tmdbId, false)`
|
||||
3. Throttled execution with progress tracking
|
||||
|
||||
### TMDB ID Import
|
||||
|
||||
1. Receives array of TMDB IDs + type flags
|
||||
2. For each: calls `EntryManager.fetchAndSaveNewEntry(tmdbId, isTvSeries)`
|
||||
3. Same throttled execution
|
||||
|
||||
### Episode Watch History Import
|
||||
|
||||
1. Receives array of episode watch records
|
||||
2. Creates `EpisodeSeen` records in bulk
|
||||
3. Updates `date_first_seen`/`date_last_seen` on episodes and entries
|
||||
+62
-14
@@ -1,20 +1,68 @@
|
||||
# Showy Documentation Vault
|
||||
---
|
||||
title: Showy Documentation
|
||||
tags:
|
||||
- index
|
||||
- entry-point
|
||||
aliases:
|
||||
- Home
|
||||
- MOC
|
||||
---
|
||||
|
||||
Welcome to the Showy project documentation. Use the links below to navigate.
|
||||
# Showy — Project Documentation
|
||||
|
||||
## Core Documentation
|
||||
> [!info] What is Showy?
|
||||
> A single-user movie and TV series library tracker. Browse TMDB content, add entries, track watch history, manage collections, view upcoming episodes on a calendar, and see statistics.
|
||||
|
||||
- [[Architecture]]
|
||||
- [[Frontend]]
|
||||
- [[Backend]]
|
||||
- [[Electron]]
|
||||
- [[Database]]
|
||||
- [[Deployment]]
|
||||
- [[Env]]
|
||||
- [[Changelog]]
|
||||
**Author:** Mohammed Abad (X4Lo) — [GitHub](https://github.com/X4Lo/showy)
|
||||
|
||||
## Quick Links
|
||||
---
|
||||
|
||||
## Architecture & Infrastructure
|
||||
|
||||
- [[Architecture]] — System overview, tech stack, data flow
|
||||
- [[Tech Stack]] — All technologies and versions
|
||||
- [[Deployment]] — Docker Compose setup
|
||||
- [[Env]] — Environment variables and configuration
|
||||
- [[Electron]] — Desktop wrapper details
|
||||
|
||||
## Backend
|
||||
|
||||
- [[Backend]] — Express server, middleware, project structure
|
||||
- [[API Reference]] — Complete REST API endpoint reference
|
||||
- [[Database]] — MySQL schema, Sequelize models, relationships
|
||||
- [[Models]] — All Sequelize model definitions
|
||||
- [[Services]] — Business logic layer (managers + services)
|
||||
- [[Error Handling]] — Custom error classes and middleware
|
||||
- [[TMDB Integration]] — External API proxy and data fetching
|
||||
- [[Media System]] — Image storage, download, optimization, previews
|
||||
- [[Import System]] — Bulk import flows
|
||||
|
||||
## Frontend
|
||||
|
||||
- [[Frontend]] — React app structure, patterns, conventions
|
||||
- [[Routing]] — All 17 routes with lazy loading
|
||||
- [[Pages]] — Every page component
|
||||
- [[Components]] — All UI components by category
|
||||
- [[Hooks]] — Custom hooks (queries, mutations, utilities)
|
||||
- [[Stores]] — Zustand state management
|
||||
- [[API Clients]] — Frontend Axios API modules
|
||||
- [[Types]] — TypeScript type definitions
|
||||
- [[Normalizers]] — Backend → Frontend data transformation
|
||||
- [[Media Utilities]] — Image URL resolution and formatting
|
||||
|
||||
## Feature Documentation
|
||||
|
||||
- [[Library]] — Entry management, watchlist, favorites
|
||||
- [[Collections]] — TMDB and user collections
|
||||
- [[Watch Tracking]] — EntrySeen, EpisodeSeen, accuracy system
|
||||
- [[Calendar]] — Upcoming episodes view
|
||||
- [[Statistics]] — Dashboard charts and data
|
||||
- [[People]] — Cast, crew, filmography
|
||||
- [[Settings Page]] — App settings and maintenance cleanup
|
||||
- [[Statistics]] — Dashboard charts and data queries
|
||||
- [[Navigation]] — Breadcrumb and page navigation patterns
|
||||
- [[Search]] — TMDB search and local search
|
||||
- [[Navigation]] — Breadcrumbs, routing patterns
|
||||
|
||||
## Project Management
|
||||
|
||||
- [[Changelog]] — Milestone history
|
||||
- [[Known Issues]] — Tracked bugs and technical debt
|
||||
@@ -0,0 +1,95 @@
|
||||
---
|
||||
title: Known Issues
|
||||
tags:
|
||||
- issues
|
||||
- technical-debt
|
||||
- bugs
|
||||
---
|
||||
|
||||
# Known Issues
|
||||
|
||||
Tracked bugs and technical debt items.
|
||||
|
||||
---
|
||||
|
||||
## Backend
|
||||
|
||||
### Synchronous File Checks in Maintenance
|
||||
|
||||
- **File:** `backend/services/maintenanceService.js`
|
||||
- **Issue:** `deleteOrphanMediaRecords` uses `fs.existsSync()` in a loop, which is synchronous and blocks the event loop
|
||||
- **Impact:** Slow for large media libraries
|
||||
- **Fix:** Replace with `fs.promises.access()` or batch with `Promise.all()`
|
||||
|
||||
### Hardcoded Database Credentials
|
||||
|
||||
- **File:** `backend/config/database.js`
|
||||
- **Issue:** MySQL credentials hardcoded as `root` / `password`
|
||||
- **Impact:** Security concern for non-local deployments
|
||||
- **Fix:** Read from environment variables or `settings.json`
|
||||
|
||||
### CORS Allows All Origins
|
||||
|
||||
- **File:** `backend/server.js`
|
||||
- **Issue:** CORS set to `*` (all origins)
|
||||
- **Impact:** Acceptable for single-user local app, problematic if exposed to network
|
||||
- **Fix:** Configure allowed origins in settings
|
||||
|
||||
### Bundled Moment.js
|
||||
|
||||
- **File:** `backend/utils/moment.js`
|
||||
- **Issue:** Full Moment.js 2.29.0 is bundled directly in source code instead of as npm dependency
|
||||
- **Impact:** Outdated version, harder to update
|
||||
- **Fix:** Replace with `date-fns` or install via npm
|
||||
|
||||
### Killer Route in Production
|
||||
|
||||
- **File:** `backend/server.js`
|
||||
- **Issue:** `GET /killer` crashes the backend — useful for debug only
|
||||
- **Impact:** DoS risk if backend is exposed
|
||||
- **Fix:** Gate behind dev-mode check
|
||||
|
||||
## Frontend
|
||||
|
||||
### Implicit `any` Types in SeasonPage
|
||||
|
||||
- **File:** `react_frontend/src/pages/SeasonPage.tsx`
|
||||
- **Issue:** Several callback parameters have implicit `any` type
|
||||
- **Impact:** TypeScript strict mode violations
|
||||
- **Fix:** Add explicit type annotations
|
||||
|
||||
### Unused Imports in EntrySeenDialog
|
||||
|
||||
- **File:** `react_frontend/src/components/dialogs/EntrySeenDialog.tsx`
|
||||
- **Issue:** Some imports from old Calendar implementation may still exist
|
||||
- **Impact:** Bundle size (minor)
|
||||
- **Fix:** Clean up unused imports
|
||||
|
||||
### Normalizer Inconsistency
|
||||
|
||||
- **Issue:** Backend returns mixed camelCase/snake_case fields depending on query type
|
||||
- **Impact:** [[Normalizers]] layer exists to handle this, but it's fragile
|
||||
- **Fix:** Standardize backend response format (ideally all snake_case)
|
||||
|
||||
## Database
|
||||
|
||||
### Franchise Model Unused
|
||||
|
||||
- **File:** `backend/models/Franchise.js`
|
||||
- **Issue:** Model defined but not used anywhere in the application
|
||||
- **Impact:** Dead code
|
||||
- **Fix:** Implement franchise feature or remove model
|
||||
|
||||
### No Database Migrations
|
||||
|
||||
- **Issue:** Schema changes rely on `sequelize.sync({ alter })` which is disabled (`doUpdate = false`)
|
||||
- **Impact:** Manual schema management required for changes
|
||||
- **Fix:** Implement proper Sequelize migrations
|
||||
|
||||
## Docker
|
||||
|
||||
### Legacy Frontend in Docker
|
||||
|
||||
- **Issue:** Docker Compose uses the Angular frontend (`/frontend`), not the React frontend (`/react_frontend`)
|
||||
- **Impact:** Docker deployment serves outdated UI
|
||||
- **Fix:** Create Dockerfile for React frontend, update Compose
|
||||
@@ -0,0 +1,62 @@
|
||||
---
|
||||
title: Library
|
||||
tags:
|
||||
- feature
|
||||
- library
|
||||
- entries
|
||||
---
|
||||
|
||||
# Library
|
||||
|
||||
## Overview
|
||||
|
||||
The library is the core of Showy — a personal collection of movies and TV series. Entries can be in the **library** (watched/watching) or the **watchlist** (planning to watch).
|
||||
|
||||
## Entry Lifecycle
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
TMDB[TMDB Search] --> |Add| Watchlist
|
||||
Watchlist --> |Mark Watched| Library
|
||||
TMDB --> |Add to Library| Library
|
||||
Library --> |Toggle| Watchlist
|
||||
Library --> |Delete| Gone[Deleted]
|
||||
```
|
||||
|
||||
## Entry States
|
||||
|
||||
| Flag | Meaning |
|
||||
|---|---|
|
||||
| `watchlist = false` | In library (default) |
|
||||
| `watchlist = true` | In watchlist |
|
||||
| `favorit = true` | Favorited |
|
||||
| `hidden = true` | Hidden from library view |
|
||||
| `showInCalendar = true` | Episodes appear in [[Calendar]] |
|
||||
| `autoSync = true` | Auto-refreshed by `SyncSeriesData()` |
|
||||
|
||||
## Adding Entries
|
||||
|
||||
1. User searches TMDB via [[Search]]
|
||||
2. Selects a result → `POST /api/v1/entries` with `{ tmdb_id, is_tvserie }`
|
||||
3. [[Services#EntryManager]] runs the full pipeline:
|
||||
- TMDB fetch → save entry + IDs + ratings + genres + networks
|
||||
- TV series: fetch all seasons → all episodes
|
||||
- Fetch credits → save cast/crew + [[People]] records
|
||||
- Download media → generate previews
|
||||
- Fetch collection if applicable
|
||||
|
||||
## Library Store
|
||||
|
||||
All entries are held in [[Stores|useLibraryStore]] as a `Map<number, Entry>` for O(1) lookups. The store is populated on app startup and kept in sync via optimistic updates on mutations.
|
||||
|
||||
## Pages
|
||||
|
||||
- [[Pages#LibraryPage|LibraryPage]] — Grid of all library entries
|
||||
- [[Pages#WatchlistPage|WatchlistPage]] — Grid of watchlist entries
|
||||
- [[Pages#EntryDetailsPage|EntryDetailsPage]] — Entry detail view
|
||||
|
||||
## Related
|
||||
|
||||
- [[Watch Tracking]] — Marking entries as watched
|
||||
- [[Collections]] — Grouping entries
|
||||
- [[Statistics]] — Library analytics
|
||||
@@ -0,0 +1,104 @@
|
||||
---
|
||||
title: Media System
|
||||
tags:
|
||||
- backend
|
||||
- media
|
||||
- images
|
||||
---
|
||||
|
||||
# Media System
|
||||
|
||||
## Overview
|
||||
|
||||
Showy downloads images from TMDB and stores them locally. Each image gets a UUID filename and a low-res preview. The [[Models#Media|Media model]] is polymorphic — it can associate with entries, seasons, episodes, collections, or people.
|
||||
|
||||
## Pipeline
|
||||
|
||||
```mermaid
|
||||
graph LR
|
||||
TMDB[TMDB Image API] --> DL[mediaDownloaderService]
|
||||
DL --> |UUID filename| FS[Local Filesystem]
|
||||
DL --> OPT[mediaOptimizerService]
|
||||
OPT --> |_preview suffix| FS
|
||||
DL --> DB[Media.create]
|
||||
DB --> MySQL[(MySQL)]
|
||||
```
|
||||
|
||||
### Step by Step
|
||||
|
||||
1. **Download** — `mediaDownloaderService` fetches image from TMDB, saves with UUID filename
|
||||
2. **Optimize** — `mediaOptimizerService` generates a `_preview` version using `sharp`
|
||||
- JPEG for photos (posters, backdrops, stills, profiles)
|
||||
- PNG for logos (transparency)
|
||||
3. **Record** — `mediaService` creates a `Media` DB record with polymorphic association
|
||||
4. **Serve** — Express serves files via `/api/v1/media/:category/:type/:size/:fileName`
|
||||
|
||||
## Storage Structure
|
||||
|
||||
```
|
||||
{userDataPath}/images/
|
||||
├── entries/
|
||||
│ ├── posters/ {uuid}.jpg + {uuid}_preview.jpg
|
||||
│ ├── backdrops/ {uuid}.jpg + {uuid}_preview.jpg
|
||||
│ └── logos/ {uuid}.png + {uuid}_preview.png
|
||||
├── collections/
|
||||
│ ├── posters/
|
||||
│ └── backdrops/
|
||||
├── seasons/
|
||||
│ └── posters/
|
||||
├── episodes/
|
||||
│ └── stills/
|
||||
└── peoples/
|
||||
└── profiles/
|
||||
```
|
||||
|
||||
`{userDataPath}` defaults to `C:\Users\{user}\Documents\Showy Data` — configurable in [[Env|settings.json]].
|
||||
|
||||
## Media Model Fields
|
||||
|
||||
See [[Models#Media]] for full schema.
|
||||
|
||||
Key fields:
|
||||
|
||||
- `mediaable` — entity type: `'entry'`, `'people'`, `'collection'`, `'season'`, `'episode'`
|
||||
- `mediaableId` — polymorphic FK
|
||||
- `type` — image type: `'poster'`, `'backdrop'`, `'logo'`, `'still'`, `'profile'`
|
||||
- `path` — UUID filename on disk
|
||||
- `isSelected` — the "active" image displayed in UI
|
||||
- `isCustom` — user-uploaded (vs TMDB-downloaded)
|
||||
|
||||
## Serving URLs
|
||||
|
||||
API pattern: `GET /api/v1/media/:category/:type/:size/:fileName`
|
||||
|
||||
| Parameter | Values |
|
||||
|---|---|
|
||||
| `category` | `entries`, `collections`, `seasons`, `episodes`, `peoples` |
|
||||
| `type` | `posters`, `backdrops`, `logos`, `stills`, `profiles` |
|
||||
| `size` | `preview`, `full` |
|
||||
| `fileName` | UUID filename with extension |
|
||||
|
||||
Example: `/api/v1/media/entries/posters/preview/abc123_preview.jpg`
|
||||
|
||||
## User Uploads
|
||||
|
||||
Users can upload custom media via:
|
||||
|
||||
- `POST /entries/:id/media` (Multer, supports poster/backdrop/logo)
|
||||
- `POST /people/:id/media` (profile pictures)
|
||||
- `PUT /collections/:id` (multipart with poster/backdrop)
|
||||
|
||||
Upload config: `mutlerStorageLocations.js` — UUID filenames, stored in same directory structure.
|
||||
|
||||
## Frontend URL Resolution
|
||||
|
||||
See [[Media Utilities]] for how the frontend resolves which image to display:
|
||||
|
||||
1. Local selected media → 2. TMDB fallback → 3. Default placeholder
|
||||
|
||||
## Maintenance
|
||||
|
||||
See [[Settings Page#Cleanup]] for orphan file/record detection and removal.
|
||||
|
||||
- **Orphan files** = files on disk with no DB record
|
||||
- **Orphan media records** = DB records pointing to missing files
|
||||
@@ -0,0 +1,69 @@
|
||||
---
|
||||
title: Media Utilities
|
||||
tags:
|
||||
- frontend
|
||||
- media
|
||||
- utilities
|
||||
---
|
||||
|
||||
# Media Utilities
|
||||
|
||||
> [!info] File: `react_frontend/src/lib/media-utils.ts`
|
||||
|
||||
Frontend utility functions for resolving image URLs and formatting display data.
|
||||
|
||||
## Image URL Resolution
|
||||
|
||||
The resolution priority for all image functions:
|
||||
|
||||
1. **Local selected media** — `isSelected = true` in Media records
|
||||
2. **TMDB fallback** — entry's `poster_path` / `banner_path` from TMDB
|
||||
3. **Default placeholder** — fallback image
|
||||
|
||||
### `getPosterUrl(entry)`
|
||||
|
||||
Returns the best poster URL for an entry.
|
||||
|
||||
### `getBackdropUrl(entry)`
|
||||
|
||||
Returns the best backdrop URL for an entry.
|
||||
|
||||
### `getCollectionPosterUrl(collection)`
|
||||
|
||||
### `getCollectionBackdropUrl(collection)`
|
||||
|
||||
Same pattern for [[Collections]].
|
||||
|
||||
### `getProfileUrl(profilePath)`
|
||||
|
||||
TMDB profile image at `w185` size. Used for [[People]] cards.
|
||||
|
||||
### `getTmdbPosterUrl(path, size?)`
|
||||
|
||||
Direct TMDB image URL construction. Default size: `w500`.
|
||||
|
||||
## Formatting
|
||||
|
||||
### `formatRuntime(minutes)`
|
||||
|
||||
Converts minutes to human-readable: `142` → `2h 22m`
|
||||
|
||||
### `formatDate(dateString)`
|
||||
|
||||
Formats date strings for display.
|
||||
|
||||
## TMDB Image Sizes
|
||||
|
||||
| Type | Sizes Used |
|
||||
|---|---|
|
||||
| Posters | `w342`, `w500`, `w780` |
|
||||
| Backdrops | `w780`, `w1280` |
|
||||
| Stills | `w300`, `w1280` |
|
||||
| Profiles | `w185` |
|
||||
|
||||
Base URL: `https://image.tmdb.org/t/p/`
|
||||
|
||||
## See Also
|
||||
|
||||
- [[Media System]] — Backend image storage and serving
|
||||
- [[TMDB Integration]] — External image API
|
||||
@@ -0,0 +1,355 @@
|
||||
---
|
||||
title: Models
|
||||
tags:
|
||||
- backend
|
||||
- database
|
||||
- models
|
||||
- sequelize
|
||||
aliases:
|
||||
- Sequelize Models
|
||||
---
|
||||
|
||||
# Models
|
||||
|
||||
Complete field reference for every Sequelize model. See [[Database]] for relationships.
|
||||
|
||||
All models in `backend/models/`.
|
||||
|
||||
---
|
||||
|
||||
## Entry
|
||||
|
||||
> [!info] File: `backend/models/Entry.js`
|
||||
|
||||
The core model — represents a movie or TV series.
|
||||
|
||||
| Field | Type | Default/Notes |
|
||||
|---|---|---|
|
||||
| `id` | INTEGER PK AUTO | |
|
||||
| `title` | STRING(500) | |
|
||||
| `original_title` | STRING(100) | |
|
||||
| `release_date` | DATE | |
|
||||
| `release_status` | STRING(50) | |
|
||||
| `runtime` | INTEGER | Minutes |
|
||||
| `tagline` | STRING(200) | |
|
||||
| `storyline` | STRING(3000) | |
|
||||
| `country` | STRING(30) | |
|
||||
| `certification` | INTEGER | |
|
||||
| `network_studio` | STRING(40) | |
|
||||
| `collection_id` | INTEGER | TMDB collection ID |
|
||||
| `max_cast` | INTEGER | Default `10` |
|
||||
| `credit_fetched` | BOOLEAN | Default `false` |
|
||||
| `watchlist` | BOOLEAN | Default `false` |
|
||||
| `favorit` | BOOLEAN | Default `false` |
|
||||
| `hidden` | BOOLEAN | Default `false` |
|
||||
| `showInCalendar` | BOOLEAN | Default `true` |
|
||||
| `autoSync` | BOOLEAN | Default `true` |
|
||||
| `note` | STRING(2000) | User notes |
|
||||
| `is_tvseries` | BOOLEAN | `true` = TV, `false` = movie |
|
||||
| `status` | STRING(20) | e.g. "Ended", "Returning Series" |
|
||||
| `poster_path` | STRING(200) | TMDB poster path |
|
||||
| `banner_path` | STRING(200) | TMDB backdrop path |
|
||||
| `date_first_seen` | DATEONLY | |
|
||||
| `date_last_seen` | DATEONLY | |
|
||||
| `last_fetch` | DATEONLY | Used by [[Services#Lazy Refresh\|lazy refresh]] |
|
||||
|
||||
**Has:** [[#EntryId]] (1:1), [[#EntryRating]] (1:1), [[#EntrySeen]] (1:N), [[#Season]] (1:N), [[#Credit]] (1:N), Genres (M:N), Networks (M:N), Collections (M:N), Media (polymorphic)
|
||||
|
||||
---
|
||||
|
||||
## Season
|
||||
|
||||
> [!info] File: `backend/models/Season.js`
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | INTEGER PK AUTO | |
|
||||
| `tmdb_id` | STRING(30) | |
|
||||
| `imdb_id` | STRING(30) | |
|
||||
| `entry_id` | INTEGER FK | → Entry |
|
||||
| `name` | STRING(500) | |
|
||||
| `overview` | STRING(3000) | |
|
||||
| `season_number` | INTEGER | Display number (not DB id) |
|
||||
| `episode_count` | INTEGER | |
|
||||
| `air_date` | DATE | |
|
||||
| `user_rating` | FLOAT | |
|
||||
| `tmdb_rating` | FLOAT | |
|
||||
| `imdb_rating` | FLOAT | |
|
||||
| `poster_path` | STRING(200) | |
|
||||
| `banner_path` | STRING(200) | |
|
||||
|
||||
**Has:** [[#Episode]] (1:N), Media (polymorphic)
|
||||
|
||||
> [!warning] Important
|
||||
> `season_number` is the display number (0 = Specials, 1 = Season 1, etc.). `id` is the database primary key. Frontend pages should use `season_number` for display, not `id`.
|
||||
|
||||
---
|
||||
|
||||
## Episode
|
||||
|
||||
> [!info] File: `backend/models/Episode.js`
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | INTEGER PK AUTO | |
|
||||
| `tmdb_id` | STRING(30) | |
|
||||
| `imdb_id` | STRING(30) | |
|
||||
| `tvdb_id` | STRING(30) | |
|
||||
| `season_id` | INTEGER FK | → Season |
|
||||
| `name` | STRING(500) | |
|
||||
| `overview` | STRING(3000) | |
|
||||
| `episode_number` | INTEGER | |
|
||||
| `episode_type` | STRING(60) | |
|
||||
| `runtime` | INTEGER | Minutes |
|
||||
| `air_date` | DATE | |
|
||||
| `user_rating` | FLOAT | |
|
||||
| `tmdb_rating` | FLOAT | |
|
||||
| `still_path` | STRING(200) | |
|
||||
| `date_first_seen` | DATEONLY | |
|
||||
| `date_last_seen` | DATEONLY | |
|
||||
|
||||
**Has:** [[#EpisodeSeen]] (1:N), Media (polymorphic)
|
||||
|
||||
---
|
||||
|
||||
## EntrySeen
|
||||
|
||||
> [!info] File: `backend/models/EntrySeen.js`
|
||||
|
||||
Movie watch record. See [[Watch Tracking]].
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | INTEGER PK AUTO | |
|
||||
| `entry_id` | INTEGER FK | → Entry |
|
||||
| `date_seen` | DATE | |
|
||||
| `seen_with` | STRING(50) | |
|
||||
| `accuracy` | ENUM | `'EXACT'`, `'ESTIMATED'`, `'UNKNOWN'`. Default `'EXACT'` |
|
||||
|
||||
**No timestamps.**
|
||||
|
||||
---
|
||||
|
||||
## EpisodeSeen
|
||||
|
||||
> [!info] File: `backend/models/EpisodeSeen.js`
|
||||
|
||||
Episode watch record. See [[Watch Tracking]].
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | INTEGER PK AUTO | |
|
||||
| `entry_id` | INTEGER FK | → Entry |
|
||||
| `episode_id` | INTEGER FK | → Episode |
|
||||
| `date_seen` | DATE | |
|
||||
| `seen_with` | STRING(50) | |
|
||||
| `accuracy` | ENUM | `'EXACT'`, `'ESTIMATED'`, `'UNKNOWN'`. Default `'EXACT'` |
|
||||
|
||||
**Has timestamps.**
|
||||
|
||||
---
|
||||
|
||||
## Media
|
||||
|
||||
> [!info] File: `backend/models/Media.js`
|
||||
|
||||
Polymorphic image record. See [[Media System]].
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | INTEGER PK AUTO | |
|
||||
| `mediaable` | STRING | `'entry'`, `'people'`, `'collection'`, `'season'`, `'episode'` |
|
||||
| `mediaableId` | INTEGER | Polymorphic FK |
|
||||
| `type` | STRING(50) | `'poster'`, `'backdrop'`, `'logo'`, `'still'`, `'profile'` |
|
||||
| `path` | STRING(200) | UUID filename on disk |
|
||||
| `isLocal` | BOOLEAN | |
|
||||
| `isSelected` | BOOLEAN | Default `false` — the "active" media |
|
||||
| `isCustom` | BOOLEAN | Default `false` — user-uploaded |
|
||||
| `isFavorit` | BOOLEAN | Default `false` |
|
||||
|
||||
---
|
||||
|
||||
## Collection
|
||||
|
||||
> [!info] File: `backend/models/Collection.js`
|
||||
|
||||
See [[Collections]].
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | INTEGER PK AUTO | |
|
||||
| `tmdbId` | STRING(30) | |
|
||||
| `imdbId` | STRING(30) | |
|
||||
| `tvdbId` | STRING(30) | |
|
||||
| `name` | STRING(150) | |
|
||||
| `description` | STRING(3000) | |
|
||||
| `isUserCollection` | BOOLEAN | Default `false` — `true` = created by user |
|
||||
| `userRating` | FLOAT | |
|
||||
| `posterPath` | STRING(200) | |
|
||||
| `backdropPath` | STRING(200) | |
|
||||
| `isLocal` | BOOLEAN | Default `false` |
|
||||
|
||||
**Associated entries via [[#UserCollectionEntry]] join table.**
|
||||
|
||||
---
|
||||
|
||||
## UserCollectionEntry
|
||||
|
||||
> [!info] File: `backend/models/UserCollectionEntry.js`
|
||||
|
||||
Join table for Collection ↔ Entry (M:N). Managed by hooks in `sequelizeHooks.js`.
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `user_collection_id` | INTEGER PK, FK | → Collection |
|
||||
| `entry_id` | INTEGER PK, FK | → Entry |
|
||||
| `order` | INTEGER | Display order (auto-managed by hooks) |
|
||||
|
||||
**No timestamps.**
|
||||
|
||||
---
|
||||
|
||||
## Credit
|
||||
|
||||
> [!info] File: `backend/models/Credit.js`
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | INTEGER PK AUTO | |
|
||||
| `tmdb_credit_id` | STRING(100) | |
|
||||
| `adult` | BOOLEAN | Default `false` |
|
||||
| `profile_path` | STRING(200) | TMDB profile image |
|
||||
| `character` | STRING(100) | Role name (for cast) |
|
||||
| `order` | INTEGER | Display order |
|
||||
| `cast_type` | ENUM | `'cast'`, `'crew'`. Default `'cast'` |
|
||||
| `department` | STRING(100) | For crew |
|
||||
| `job` | STRING(100) | For crew |
|
||||
| `entry_id` | INTEGER FK | → Entry |
|
||||
| `people_id` | INTEGER FK | → People |
|
||||
|
||||
---
|
||||
|
||||
## People
|
||||
|
||||
> [!info] File: `backend/models/People.js`
|
||||
|
||||
See [[People]].
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | INTEGER PK AUTO | |
|
||||
| `tmdb_id` | STRING(100) | |
|
||||
| `name` | STRING(100) | |
|
||||
| `birthday` | DATEONLY | |
|
||||
| `deathday` | DATEONLY | Nullable |
|
||||
| `gender` | INTEGER | TMDB gender codes |
|
||||
| `biography` | TEXT | |
|
||||
| `place_of_birth` | STRING(100) | |
|
||||
| `adult` | BOOLEAN | Default `false` |
|
||||
| `popularity` | FLOAT | |
|
||||
| `known_for_department` | STRING(50) | |
|
||||
| `homepage` | STRING(200) | Nullable |
|
||||
| `imdb_id` | STRING(20) | |
|
||||
| `profile_path` | STRING(200) | |
|
||||
| `last_fetch` | DATEONLY | For lazy-fetch |
|
||||
| `profile_update` | DATEONLY | |
|
||||
| `fully_fetched` | BOOLEAN | Default `false` — triggers TMDB fetch when `false` |
|
||||
|
||||
---
|
||||
|
||||
## EntryId
|
||||
|
||||
> [!info] File: `backend/models/EntryId.js`
|
||||
|
||||
External ID storage (1:1 with Entry).
|
||||
|
||||
| Field | Type |
|
||||
|---|---|
|
||||
| `id` | INTEGER PK AUTO |
|
||||
| `entry_id` | INTEGER FK → Entry |
|
||||
| `tmdb_id` | STRING(30) |
|
||||
| `imdb_id` | STRING(30) |
|
||||
| `tvdb_id` | STRING(30) |
|
||||
|
||||
**No timestamps.**
|
||||
|
||||
---
|
||||
|
||||
## EntryRating
|
||||
|
||||
> [!info] File: `backend/models/EntryRating.js`
|
||||
|
||||
Multi-source ratings (1:1 with Entry).
|
||||
|
||||
| Field | Type |
|
||||
|---|---|
|
||||
| `id` | INTEGER PK AUTO |
|
||||
| `entry_id` | INTEGER FK → Entry |
|
||||
| `user_rating` | FLOAT |
|
||||
| `tmdb_rating` | FLOAT |
|
||||
| `imdb_rating` | FLOAT |
|
||||
| `rotten_tomatoes_rating` | FLOAT |
|
||||
|
||||
**No timestamps.**
|
||||
|
||||
---
|
||||
|
||||
## EntryGenre
|
||||
|
||||
> [!info] File: `backend/models/EntryGenre.js`
|
||||
|
||||
Join table: Entry ↔ Genre. Composite PK: `(genre_id, entry_id)`. No timestamps.
|
||||
|
||||
---
|
||||
|
||||
## EntryNetwork
|
||||
|
||||
> [!info] File: `backend/models/EntryNetwork.js`
|
||||
|
||||
Join table: Entry ↔ Network. Composite PK: `(network_id, entry_id)`. Has `order` field. No timestamps.
|
||||
|
||||
---
|
||||
|
||||
## Genre
|
||||
|
||||
> [!info] File: `backend/models/Genre.js`
|
||||
|
||||
| Field | Type | Notes |
|
||||
|---|---|---|
|
||||
| `id` | INTEGER PK | TMDB genre ID (not auto-increment) |
|
||||
| `name` | STRING(30) | |
|
||||
|
||||
**No timestamps.** Seeded with 27 TMDB genres on startup.
|
||||
|
||||
---
|
||||
|
||||
## Network
|
||||
|
||||
> [!info] File: `backend/models/Network.js`
|
||||
|
||||
| Field | Type |
|
||||
|---|---|
|
||||
| `id` | INTEGER PK (TMDB ID) |
|
||||
| `name` | STRING(30) |
|
||||
| `originCountry` | STRING(100) |
|
||||
| `homepage` | STRING(100) |
|
||||
| `logoPath` | STRING(200) |
|
||||
| `posterPath` | STRING(200) |
|
||||
| `backdropPath` | STRING(200) |
|
||||
|
||||
**No timestamps.**
|
||||
|
||||
---
|
||||
|
||||
## Franchise
|
||||
|
||||
> [!info] File: `backend/models/Franchise.js`
|
||||
|
||||
| Field | Type |
|
||||
|---|---|
|
||||
| `id` | INTEGER PK AUTO |
|
||||
| `title` | STRING(50) |
|
||||
| `overview` | STRING(300) |
|
||||
| `user_rating` | FLOAT |
|
||||
|
||||
**No timestamps. Currently unused — reserved for future franchise grouping.**
|
||||
+69
-14
@@ -1,25 +1,80 @@
|
||||
---
|
||||
title: Navigation
|
||||
tags:
|
||||
- frontend
|
||||
- navigation
|
||||
- breadcrumbs
|
||||
- ux
|
||||
---
|
||||
|
||||
# Navigation
|
||||
|
||||
## Overview
|
||||
## Sidebar
|
||||
|
||||
Breadcrumb-style navigation for detail pages. Pages use linked text segments separated by `/`.
|
||||
The `Sidebar` component provides the main navigation:
|
||||
|
||||
## Patterns
|
||||
| Link | Page |
|
||||
|---|---|
|
||||
| Home | `/` |
|
||||
| Search | `/search` |
|
||||
| Library | `/library` |
|
||||
| Watchlist | `/watchlist` |
|
||||
| Collections | `/collections` |
|
||||
| Calendar | `/calendar` |
|
||||
| People | `/people` |
|
||||
| Media | `/media` |
|
||||
| Dashboard | `/dashboard` |
|
||||
| Settings | `/settings` |
|
||||
|
||||
## Breadcrumb Patterns
|
||||
|
||||
Detail pages use breadcrumb-style navigation with linked text segments separated by `/`.
|
||||
|
||||
### SeasonPage
|
||||
`Title / Season x`
|
||||
- "Title" links to `/entry/:entryId`
|
||||
- "Season x" is the current page (non-linked, bold)
|
||||
- Entry title fetched from `useLibraryStore`
|
||||
|
||||
```
|
||||
Title / Season x
|
||||
```
|
||||
|
||||
- **Title** → links to `/entry/:entryId`
|
||||
- **Season x** → current page (non-linked, bold, `text-foreground font-medium`)
|
||||
- Entry title from `useLibraryStore((s) => s.entries.get(entryId)?.title)`
|
||||
- Season number from `season.season_number`
|
||||
|
||||
### EpisodePage
|
||||
`Title / Season x / Episode x`
|
||||
- "Title" links to `/entry/:entryId`
|
||||
- "Season x" links to `/entry/:entryId/season/:seasonId`
|
||||
- "Episode x" is the current page (non-linked, bold)
|
||||
- Uses `useSeason()` hook to get `season_number` (not the DB `seasonId`)
|
||||
- Entry title fetched from `useLibraryStore`
|
||||
|
||||
```
|
||||
Title / Season x / Episode x
|
||||
```
|
||||
|
||||
- **Title** → links to `/entry/:entryId`
|
||||
- **Season x** → links to `/entry/:entryId/season/:seasonId`
|
||||
- **Episode x** → current page (non-linked, bold)
|
||||
- Entry title from [[Stores|useLibraryStore]]
|
||||
- Season number from `useSeason()` hook → `season.season_number`
|
||||
|
||||
> [!warning] Season Number vs Season ID
|
||||
> Always use `season.season_number` for display (0 = Specials, 1 = Season 1, etc.). The `seasonId` URL parameter is the **database ID**, not the display number. The `S##E##` badge on EpisodePage uses `season.season_number` padded to 2 digits.
|
||||
|
||||
## Width Constraints
|
||||
|
||||
Detail pages (EntryDetailsPage, [[SeasonPage]], [[EpisodePage]]) use `mx-auto max-w-4xl` for consistent max width.
|
||||
Detail pages use `mx-auto max-w-4xl` for consistent max width:
|
||||
|
||||
- `EntryDetailsPage`
|
||||
- `SeasonPage`
|
||||
- `EpisodePage`
|
||||
|
||||
## Entry Details Hierarchy
|
||||
|
||||
```
|
||||
/entry/:id → EntryDetailsPage (entry detail)
|
||||
↓ Season card click
|
||||
/entry/:id/season/:seasonId → SeasonPage (episode list)
|
||||
↓ Episode click
|
||||
/entry/:id/season/:seasonId/episode/:episodeId → EpisodePage (episode detail)
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
- [[Routing]] — All routes
|
||||
- [[Pages]] — Page components
|
||||
@@ -0,0 +1,63 @@
|
||||
---
|
||||
title: Normalizers
|
||||
tags:
|
||||
- frontend
|
||||
- data-transformation
|
||||
---
|
||||
|
||||
# Normalizers
|
||||
|
||||
> [!info] File: `react_frontend/src/lib/normalizers.ts`
|
||||
|
||||
## Overview
|
||||
|
||||
The backend returns Sequelize model instances serialized as JSON. Field naming is inconsistent (mix of camelCase from model definitions and snake_case from raw SQL). Normalizers transform backend responses into consistent frontend [[Types]].
|
||||
|
||||
## Functions
|
||||
|
||||
### `normalizeMedia(media)`
|
||||
|
||||
Handles field aliases:
|
||||
|
||||
- `isLocal` / `is_local` → `isLocal`
|
||||
- `isSelected` / `is_selected` → `isSelected`
|
||||
- `isCustom` / `is_custom` → `isCustom`
|
||||
- `isFavorit` / `is_favorit` → `isFavorit`
|
||||
|
||||
### `normalizeCredit(credit)`
|
||||
|
||||
Handles the `person` / `people` alias from Sequelize:
|
||||
|
||||
- Backend may return `credit.person` or `credit.people`
|
||||
- Normalizes to `credit.people`
|
||||
|
||||
### `normalizeGenres(genres)`
|
||||
|
||||
Handles two formats:
|
||||
|
||||
- Array of strings (`["Action", "Drama"]`)
|
||||
- Array of objects (`[{ id: 28, name: "Action" }]`)
|
||||
- Normalizes to array of `Genre` objects
|
||||
|
||||
### `normalizeEntry(entry)`
|
||||
|
||||
Full entry normalization — the main transformer:
|
||||
|
||||
- Coerces TMDB IDs to numbers
|
||||
- Normalizes nested `entry_ids`, `entry_ratings`, `genres`, `networks`
|
||||
- Normalizes all `medias` via `normalizeMedia`
|
||||
- Normalizes all `entry_seens`
|
||||
- Normalizes all `seasons`
|
||||
|
||||
### `normalizeCollection(collection)`
|
||||
|
||||
Handles field aliases:
|
||||
|
||||
- `tmdbId` / `tmdb_id` → `tmdb_id`
|
||||
- `posterPath` / `poster_path` → `poster_path`
|
||||
- `backdropPath` / `backdrop_path` → `backdrop_path`
|
||||
- `isUserCollection` / `is_user_collection` → `isUserCollection`
|
||||
|
||||
## Why This Exists
|
||||
|
||||
Sequelize model definitions use camelCase (`isLocal`, `tmdbId`) but some queries return snake_case. The frontend expects consistent snake_case for most fields. The normalizer layer ensures the frontend [[Types]] are always consistent regardless of backend response format.
|
||||
@@ -0,0 +1,110 @@
|
||||
---
|
||||
title: Pages
|
||||
tags:
|
||||
- frontend
|
||||
- pages
|
||||
- react
|
||||
---
|
||||
|
||||
# Pages
|
||||
|
||||
All pages in `react_frontend/src/pages/`. Lazy-loaded via `React.lazy()`. See [[Routing]] for URL mapping.
|
||||
|
||||
---
|
||||
|
||||
## HomePage
|
||||
|
||||
Browse trending and popular movies/TV shows from TMDB. Uses infinite scrolling via `useTmdb` hooks.
|
||||
|
||||
## SearchPage
|
||||
|
||||
TMDB multi-search with debounced input. Results checked against [[Stores|library store]] — local entries displayed if already in library.
|
||||
|
||||
## DashboardPage
|
||||
|
||||
Statistics dashboard with 7 chart components. See [[Statistics]].
|
||||
|
||||
Charts: `WatchActivityChart`, `WatchTimeChart`, `CouchDayChart`, `LibraryGrowthChart`, `MediaTypeChart`, `TopGenresChart`, `RatingsChart`
|
||||
|
||||
## LibraryPage
|
||||
|
||||
Entry grid showing all non-watchlist, non-hidden entries from [[Stores|library store]]. See [[Library]].
|
||||
|
||||
## DiscoverPage
|
||||
|
||||
TMDB browse by category: popular, trending, top-rated, upcoming. Uses `useTmdb` infinite queries.
|
||||
|
||||
Route: `/discover/:category` where category = `popular-movies`, `trending-movies`, `popular-tv`, etc.
|
||||
|
||||
## WatchlistPage
|
||||
|
||||
Grid of entries where `watchlist = true`. Similar to LibraryPage.
|
||||
|
||||
## CollectionsPage
|
||||
|
||||
Grid of all [[Collections]]. Both TMDB collections and user-created collections.
|
||||
|
||||
## CollectionDetailsPage
|
||||
|
||||
Single collection with entry list, metadata, poster/backdrop. Edit/delete/refresh actions.
|
||||
|
||||
## MediaPage
|
||||
|
||||
Browse and manage all media (images) across all entries.
|
||||
|
||||
## CalendarPage
|
||||
|
||||
Monthly [[Calendar]] view showing upcoming episode air dates. Uses `episodesApi.getByMonth()`.
|
||||
|
||||
## EntryDetailsPage
|
||||
|
||||
The main entry detail view. Width constrained to `max-w-4xl`.
|
||||
|
||||
Sections:
|
||||
|
||||
- Backdrop + poster + title + metadata
|
||||
- Actions: watchlist, favorite, refresh, settings, rating
|
||||
- Watch history (movies) → [[Watch Tracking]]
|
||||
- Seasons list (TV) → links to SeasonPage
|
||||
- Cast list → links to PersonDetailsPage
|
||||
- Media gallery → [[Media System]]
|
||||
|
||||
## SeasonPage
|
||||
|
||||
Season detail with episode list. Width: `max-w-4xl`.
|
||||
|
||||
- Breadcrumb: `Title / Season x` (see [[Navigation]])
|
||||
- Episode progress bar
|
||||
- Mark-all-as-seen action
|
||||
- Episode list with watch status
|
||||
- Links to EpisodePage
|
||||
|
||||
## EpisodePage
|
||||
|
||||
Episode detail with watch history. Width: `max-w-4xl`.
|
||||
|
||||
- Breadcrumb: `Title / Season x / Episode x` (see [[Navigation]])
|
||||
- Episode thumbnail (TMDB still)
|
||||
- `S##E##` display using `season.season_number` (not DB id)
|
||||
- Prev/next episode navigation
|
||||
- Watch history management
|
||||
- Cast list
|
||||
|
||||
## PeoplePage
|
||||
|
||||
Browse and search people (actors, directors). Both local DB and TMDB search.
|
||||
|
||||
## PersonDetailsPage
|
||||
|
||||
Person profile with biography, filmography. Uses lazy-fetch via [[Services#PeopleManager]].
|
||||
|
||||
## PersonTmdbRedirectPage
|
||||
|
||||
Takes a TMDB person ID, fetches/creates the local person record, redirects to `PersonDetailsPage`.
|
||||
|
||||
## SettingsPage
|
||||
|
||||
App configuration + maintenance. See [[Settings Page]].
|
||||
|
||||
- General settings (TMDB API key, backend port)
|
||||
- Cleanup section (orphan files, orphan media records)
|
||||
@@ -0,0 +1,62 @@
|
||||
---
|
||||
title: People
|
||||
tags:
|
||||
- feature
|
||||
- people
|
||||
- cast
|
||||
- crew
|
||||
---
|
||||
|
||||
# People
|
||||
|
||||
## Overview
|
||||
|
||||
Showy tracks actors, directors, and other crew members. People are linked to entries via [[Models#Credit|Credit]] records.
|
||||
|
||||
## Lazy-Fetch Pattern
|
||||
|
||||
People profiles are **lazily fetched** from TMDB:
|
||||
|
||||
1. When credits are fetched for an entry, basic `People` records are created with `fully_fetched = false`
|
||||
2. When a user views a person's detail page, `GET /people/:id` triggers [[Services#PeopleManager|PeopleManager.getUpdatedPerson]]
|
||||
3. If `fully_fetched = false`, full profile is fetched from TMDB:
|
||||
- Biography, birthday, place of birth, etc.
|
||||
- Profile picture downloaded and previewed
|
||||
- `fully_fetched` set to `true`
|
||||
4. Subsequent views skip the TMDB call
|
||||
|
||||
## Data Model
|
||||
|
||||
See [[Models#People]] and [[Models#Credit]].
|
||||
|
||||
### Credit Types
|
||||
|
||||
| `cast_type` | Fields Used |
|
||||
|---|---|
|
||||
| `cast` | `character`, `order` |
|
||||
| `crew` | `department`, `job` |
|
||||
|
||||
## Pages
|
||||
|
||||
- [[Pages#PeoplePage|PeoplePage]] — Browse and search people
|
||||
- [[Pages#PersonDetailsPage|PersonDetailsPage]] — Full profile + filmography
|
||||
- [[Pages#PersonTmdbRedirectPage|PersonTmdbRedirectPage]] — TMDB ID → local redirect
|
||||
|
||||
## API Endpoints
|
||||
|
||||
See [[API Reference#People]].
|
||||
|
||||
## Hooks
|
||||
|
||||
See [[Hooks#usePeople]].
|
||||
|
||||
## TMDB Data
|
||||
|
||||
People data from TMDB includes:
|
||||
|
||||
- Full biography
|
||||
- Birth/death dates and location
|
||||
- Profile images
|
||||
- Combined credits (all movies + TV shows)
|
||||
|
||||
See [[TMDB Integration]] for API details.
|
||||
@@ -0,0 +1,64 @@
|
||||
---
|
||||
title: Routing
|
||||
tags:
|
||||
- frontend
|
||||
- routing
|
||||
- pages
|
||||
---
|
||||
|
||||
# Routing
|
||||
|
||||
## Overview
|
||||
|
||||
React Router 7 with lazy-loaded pages. All routes defined in `react_frontend/src/App.tsx`.
|
||||
|
||||
Every page uses `React.lazy()` with a custom `<Suspense>` skeleton fallback.
|
||||
|
||||
## Route Table
|
||||
|
||||
| Path | Page Component | Skeleton | Description |
|
||||
|---|---|---|---|
|
||||
| `/` | `HomePage` | `HomeSkeleton` | Landing page with trending/popular |
|
||||
| `/search` | `SearchPage` | `HomeSkeleton` | TMDB multi-search |
|
||||
| `/dashboard` | `DashboardPage` | `DashboardSkeleton` | [[Statistics]] charts |
|
||||
| `/library` | `LibraryPage` | `LibrarySkeleton` | [[Library]] grid/list |
|
||||
| `/discover/:category` | `DiscoverPage` | `HomeSkeleton` | TMDB browse (popular, trending, top-rated, upcoming) |
|
||||
| `/watchlist` | `WatchlistPage` | `WatchlistSkeleton` | Watchlist entries |
|
||||
| `/collections` | `CollectionsPage` | `CollectionsSkeleton` | [[Collections]] overview |
|
||||
| `/collections/:id` | `CollectionDetailsPage` | `CollectionDetailsSkeleton` | Collection with entries |
|
||||
| `/media` | `MediaPage` | `MediaSkeleton` | Media management |
|
||||
| `/calendar` | `CalendarPage` | `CalendarSkeleton` | [[Calendar]] upcoming episodes |
|
||||
| `/entry/:id` | `EntryDetailsPage` | `EntryDetailsSkeleton` | Entry details, seasons, cast |
|
||||
| `/entry/:entryId/season/:seasonId` | `SeasonPage` | `SeasonSkeleton` | Season episodes |
|
||||
| `/entry/:entryId/season/:seasonId/episode/:episodeId` | `EpisodePage` | `EpisodeSkeleton` | Episode details |
|
||||
| `/people` | `PeoplePage` | `PeopleSkeleton` | [[People]] browse |
|
||||
| `/people/:id` | `PersonDetailsPage` | `PersonDetailsSkeleton` | Person profile + filmography |
|
||||
| `/people/tmdb/:tmdbId` | `PersonTmdbRedirectPage` | `PersonDetailsSkeleton` | TMDB person → local redirect |
|
||||
| `/settings` | `SettingsPage` | `SettingsSkeleton` | [[Settings Page]] |
|
||||
|
||||
## Layout
|
||||
|
||||
All routes are wrapped in `AppLayout` which provides:
|
||||
|
||||
- `Sidebar` — left-side navigation
|
||||
- Main content area
|
||||
|
||||
## URL Patterns
|
||||
|
||||
### Entry Details Hierarchy
|
||||
|
||||
```
|
||||
/entry/:id → EntryDetailsPage
|
||||
/entry/:entryId/season/:seasonId → SeasonPage
|
||||
/entry/:entryId/season/:seasonId/episode/:episodeId → EpisodePage
|
||||
```
|
||||
|
||||
### Breadcrumbs
|
||||
|
||||
See [[Navigation]] for breadcrumb patterns on nested pages.
|
||||
|
||||
## See Also
|
||||
|
||||
- [[Pages]] — Detailed page documentation
|
||||
- [[Navigation]] — Breadcrumb patterns
|
||||
- [[Frontend]] — App-level setup
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
title: Search
|
||||
tags:
|
||||
- feature
|
||||
- search
|
||||
- tmdb
|
||||
---
|
||||
|
||||
# Search
|
||||
|
||||
## Overview
|
||||
|
||||
Showy provides TMDB multi-search for discovering new content to add to the library.
|
||||
|
||||
## How It Works
|
||||
|
||||
1. User types a query in the [[Pages#SearchPage|SearchPage]]
|
||||
2. Input is debounced via [[Hooks#useDebounce|useDebounce]]
|
||||
3. `GET /entries/tmdb/search?query=&page=` called via [[API Clients|tmdb.ts]]
|
||||
4. Backend proxies to TMDB `/search/multi` via [[TMDB Integration|tmdbService.searchMulti]]
|
||||
5. Results returned as `TmdbPaginatedResponse<TmdbEntry>`
|
||||
6. Each result checked against [[Stores|library store]] — if already in library, the local entry card is shown instead
|
||||
|
||||
## Library Cross-Reference
|
||||
|
||||
When search results are displayed, the frontend checks each TMDB result's ID against entries in the Zustand store. If a match is found (`entry.entry_ids.tmdb_id === result.id`), the local `EntryCard` is rendered with library actions instead of the "Add" button.
|
||||
|
||||
## People Search
|
||||
|
||||
People search is also available on the [[Pages#PeoplePage|PeoplePage]]:
|
||||
|
||||
- `GET /people/tmdb/search?query=` → TMDB person search
|
||||
- Local DB search via `GET /people/search?query=`
|
||||
|
||||
## Discover Pages
|
||||
|
||||
Browse TMDB by category on [[Pages#DiscoverPage|DiscoverPage]]:
|
||||
|
||||
- Popular movies/TV
|
||||
- Trending movies/TV
|
||||
- Top-rated movies/TV
|
||||
- Upcoming movies
|
||||
|
||||
All use infinite scrolling via [[Hooks#useTmdb|useTmdb]] hooks.
|
||||
@@ -0,0 +1,237 @@
|
||||
---
|
||||
title: Services
|
||||
tags:
|
||||
- backend
|
||||
- services
|
||||
- business-logic
|
||||
---
|
||||
|
||||
# Services
|
||||
|
||||
All services use the **singleton pattern** and are in `backend/services/`. Services are the business logic layer between [[Backend|controllers]] and [[Models]].
|
||||
|
||||
## Architecture
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
Controllers --> Managers
|
||||
Controllers --> Services
|
||||
Managers --> Services
|
||||
Managers --> TMDB[tmdbService]
|
||||
Services --> Models[Sequelize Models]
|
||||
|
||||
subgraph Managers["Manager Services (Orchestrators)"]
|
||||
EM[EntryManager]
|
||||
CM[CollectionManager]
|
||||
PM[PeopleManager]
|
||||
MM[MediaManager]
|
||||
end
|
||||
|
||||
subgraph Services["Data Services"]
|
||||
ES[entryService]
|
||||
CS[collectionService]
|
||||
PS[peopleService]
|
||||
NS[networkService]
|
||||
EPS[episodeService]
|
||||
MS[mediaService]
|
||||
MDS[mediaDownloaderService]
|
||||
MOS[mediaOptimizerService]
|
||||
SS[storageService]
|
||||
IS[importerService]
|
||||
MNT[maintenanceService]
|
||||
CFG[configService]
|
||||
LOG[logService]
|
||||
end
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Manager Services (Orchestrators)
|
||||
|
||||
Managers orchestrate complex multi-step operations that span multiple services.
|
||||
|
||||
### EntryManager
|
||||
|
||||
> [!info] File: `backend/services/entryManager.js`
|
||||
|
||||
The main orchestrator for entry lifecycle.
|
||||
|
||||
#### `fetchAndSaveNewEntry(tmdbId, isTvSeries)`
|
||||
|
||||
Full pipeline for adding a new entry from TMDB:
|
||||
|
||||
1. Fetch entry data from TMDB (`tmdbService.fetchEntryData`)
|
||||
2. Save entry + EntryId + EntryRating + genres + networks
|
||||
3. If TV: fetch all seasons → fetch all episodes per season
|
||||
4. Fetch credits (cast/crew) → save with People records
|
||||
5. Download media (posters, backdrops, logos) → generate previews
|
||||
6. Fetch TMDB collection if entry has `collection_id`
|
||||
|
||||
#### `refrechEntryById(id)`
|
||||
|
||||
Force-refresh: compare local vs TMDB data, update fields, genres, networks, seasons/episodes, credits, media.
|
||||
|
||||
#### `getUpdatedEntry(id)` ^lazy-refresh
|
||||
|
||||
**Lazy refresh pattern:** If `last_fetch` is null or older than 24 hours (and series is not "Ended"), triggers `refrechEntryById`. Otherwise returns cached data.
|
||||
|
||||
#### `SyncSeriesData()`
|
||||
|
||||
Batch refresh all TV series where `autoSync = true` and `status != 'Ended'`.
|
||||
|
||||
### CollectionManager
|
||||
|
||||
> [!info] File: `backend/services/collectionManager.js`
|
||||
|
||||
#### `fetchAndSaveCollection(tmdbId)`
|
||||
|
||||
TMDB fetch → create/update collection → link entries → download media → generate previews.
|
||||
|
||||
#### `fetchCollectionByEntryId(entryId)`
|
||||
|
||||
Find TMDB collection for an entry and create it.
|
||||
|
||||
#### `getCollectionParts(collectionId)`
|
||||
|
||||
Fetch missing collection parts from TMDB, auto-import them as entries.
|
||||
|
||||
### PeopleManager
|
||||
|
||||
> [!info] File: `backend/services/peopleManager.js`
|
||||
|
||||
#### `getUpdatedPerson(id)`
|
||||
|
||||
**Lazy-fetch pattern:** If `fully_fetched` is `false`, fetches full profile from TMDB → updates DB → downloads media → generates previews. Otherwise returns cached data.
|
||||
|
||||
### MediaManager
|
||||
|
||||
> [!info] File: `backend/services/mediaManager.js`
|
||||
|
||||
See [[Media System]] for the complete flow.
|
||||
|
||||
#### `getEntryMedia(tmdbId, isTv, includes)`
|
||||
|
||||
Downloads posters, backdrops, and logos from TMDB for an entry.
|
||||
|
||||
#### `getSeasonMedia(season)`
|
||||
|
||||
Downloads season poster from TMDB.
|
||||
|
||||
#### `getEpisodenMedia(episode)`
|
||||
|
||||
Downloads episode still from TMDB.
|
||||
|
||||
---
|
||||
|
||||
## Data Services
|
||||
|
||||
### entryService
|
||||
|
||||
> [!info] File: `backend/services/entryService.js`
|
||||
|
||||
- `getAllEntries()` — Returns all entries with full includes (IDs, ratings, genres, networks, media, seens, seasons)
|
||||
- `getEntryById(id)` — Single entry with full includes
|
||||
- `createEntry(data)` — Full creation pipeline
|
||||
- `updateEntry(id, data)` — Partial update
|
||||
- `deleteEntry(id)` — Cascade delete
|
||||
|
||||
### collectionService
|
||||
|
||||
> [!info] File: `backend/services/collectionService.js`
|
||||
|
||||
CRUD for [[Collections]]. Handles `UserCollectionEntry` join records.
|
||||
|
||||
### episodeService
|
||||
|
||||
> [!info] File: `backend/services/episodeService.js`
|
||||
|
||||
- `getEpisodesBetweenDates(start, end)` — For [[Calendar]]. Respects `showInCalendar` flag on entries.
|
||||
|
||||
### peopleService
|
||||
|
||||
> [!info] File: `backend/services/peopleService.js`
|
||||
|
||||
- `getPersonById(id)` — Returns person with roles + entries + media
|
||||
- `fetchAndSavePersonByTmdbId(tmdbId)` — Create from TMDB data
|
||||
|
||||
### networkService
|
||||
|
||||
> [!info] File: `backend/services/networkService.js`
|
||||
|
||||
- `createOrUpdateNetwork(data)` — Upsert for TV networks
|
||||
|
||||
### mediaService
|
||||
|
||||
> [!info] File: `backend/services/mediaService.js`
|
||||
|
||||
- `Media.create()` wrapper
|
||||
|
||||
### tmdbService
|
||||
|
||||
> [!info] File: `backend/services/tmdbService.js`
|
||||
|
||||
See [[TMDB Integration]].
|
||||
|
||||
14 methods wrapping TMDB API v3 calls:
|
||||
|
||||
`fetchEntryData`, `fetchSeasonData`, `fetchEntryMedia`, `fetchCollectionData`, `fetchEntryCredits`, `fetchPersonDetails`, `fetchPersonCombinedCredits`, `fetchTrending`, `fetchPopular`, `fetchTopRated`, `fetchUpcoming`, `searchMulti`, `searchPeople`, `fetchPopularPeople`
|
||||
|
||||
### configService
|
||||
|
||||
> [!info] File: `backend/services/configService.js`
|
||||
|
||||
- Reads/writes `settings.json`
|
||||
- Creates media folder structure on startup
|
||||
- Provides TMDB credentials to other services
|
||||
- `getMediaFolder()` — returns `userDataPath` for media storage
|
||||
|
||||
### mediaDownloaderService
|
||||
|
||||
> [!info] File: `backend/services/mediaDownloaderService.js`
|
||||
|
||||
Downloads images from TMDB to local filesystem. Uses UUID naming. See [[Media System]].
|
||||
|
||||
### mediaOptimizerService
|
||||
|
||||
> [!info] File: `backend/services/mediaOptimizerService.js`
|
||||
|
||||
Generates low-resolution preview images using `sharp`. JPEG for photos, PNG for logos. Preview files named `{uuid}_preview.{ext}`. See [[Media System]].
|
||||
|
||||
### storageService
|
||||
|
||||
> [!info] File: `backend/services/storageService.js`
|
||||
|
||||
Low-level file write via Node.js streams.
|
||||
|
||||
### importerService
|
||||
|
||||
> [!info] File: `backend/services/importerService.js`
|
||||
|
||||
See [[Import System]].
|
||||
|
||||
- `bulkImportMovies(data)` — Import movies
|
||||
- `bulkImportTmdb(ids)` — Import by TMDB IDs
|
||||
- `bulkImportEpisodes(data)` — Import episode watch history
|
||||
- Self-throttling: 35 requests per 10s, 500ms delay between each
|
||||
|
||||
### maintenanceService
|
||||
|
||||
> [!info] File: `backend/services/maintenanceService.js`
|
||||
|
||||
See [[Settings Page#Cleanup]].
|
||||
|
||||
- `deleteOrphanFiles(dry)` — Files on disk without DB records
|
||||
- `deleteOrphanMediaRecords(dry)` — DB records without files on disk
|
||||
- Both return `{ posters, logos, backdrops, stills }` counts
|
||||
|
||||
### logService
|
||||
|
||||
> [!info] File: `backend/services/logService.js`
|
||||
|
||||
- `logToFile(message)` — Writes timestamped line to `showy.log`
|
||||
|
||||
### mutlerStorageLocations
|
||||
|
||||
> [!info] File: `backend/services/mutlerStorageLocations.js`
|
||||
|
||||
Multer upload configs for entry, collection, and people images. UUID filenames.
|
||||
+66
-18
@@ -1,32 +1,80 @@
|
||||
---
|
||||
title: Settings Page
|
||||
tags:
|
||||
- feature
|
||||
- settings
|
||||
- maintenance
|
||||
---
|
||||
|
||||
# Settings Page
|
||||
|
||||
## Overview
|
||||
|
||||
App configuration and maintenance tools at `/settings`.
|
||||
App configuration and maintenance tools at `/settings`. Contains two card sections.
|
||||
|
||||
## Sections
|
||||
## General Settings
|
||||
|
||||
### General Settings
|
||||
- **TMDB API Key** — Required for media metadata lookups
|
||||
- **Backend Port** — Port the backend server runs on
|
||||
Form using react-hook-form + zod validation.
|
||||
|
||||
### Cleanup
|
||||
Added in Milestone 001. Uses [[Backend]] maintenance endpoints.
|
||||
| Field | Type | Description |
|
||||
|---|---|---|
|
||||
| TMDB API Key | Password input | Required for [[TMDB Integration]] |
|
||||
| Backend Port | Number input | Port the backend server runs on (default 4000) |
|
||||
|
||||
#### Orphan Files
|
||||
- **Scan** (`GET /maintenance/orphan-files`) — Dry run, returns counts of orphan files by type
|
||||
- **Delete** (`DELETE /maintenance/orphan-files`) — Removes orphan files from disk
|
||||
Saved via `PUT /api/v1/settings`.
|
||||
|
||||
#### Orphan Media Records
|
||||
- **Scan** (`GET /maintenance/orphan-media-records`) — Dry run, returns counts of DB records with no file
|
||||
- **Delete** (`DELETE /maintenance/orphan-media-records`) — Removes orphan records from database
|
||||
## Cleanup
|
||||
|
||||
Maintenance tools for cleaning up orphaned data. Uses backend maintenance endpoints.
|
||||
|
||||
### Orphan Files
|
||||
|
||||
Files that exist on disk but have **no matching database record**.
|
||||
|
||||
| Action | Button | Endpoint | Effect |
|
||||
|---|---|---|---|
|
||||
| Scan | `Scan` (outline) | `GET /maintenance/orphan-files` | Dry run — counts only |
|
||||
| Delete | `Delete` (destructive) | `DELETE /maintenance/orphan-files` | Removes files from disk |
|
||||
|
||||
The Delete button only appears when the scan finds orphans.
|
||||
|
||||
### Orphan Media Records
|
||||
|
||||
Database records that point to **files that no longer exist on disk**.
|
||||
|
||||
| Action | Button | Endpoint | Effect |
|
||||
|---|---|---|---|
|
||||
| Scan | `Scan` (outline) | `GET /maintenance/orphan-media-records` | Dry run — counts only |
|
||||
| Delete | `Delete` (destructive) | `DELETE /maintenance/orphan-media-records` | Removes DB records |
|
||||
|
||||
### Response Format
|
||||
Both endpoints return: `{ posters: number, logos: number, backdrops: number, stills: number }`
|
||||
|
||||
Both scan and delete return:
|
||||
|
||||
```json
|
||||
{ "posters": 0, "logos": 0, "backdrops": 0, "stills": 0 }
|
||||
```
|
||||
|
||||
Displayed as: "3 poster(s), 1 backdrop(s)" or "None found".
|
||||
|
||||
## Implementation Details
|
||||
|
||||
- State: `useState` for scan results (`OrphanResult | null`)
|
||||
- Mutations: `useMutation` for scan and delete operations
|
||||
- Loading: `Loader2` spinner on buttons during operations
|
||||
- Conditional rendering: Delete button only shown when `hasOrphans(result) === true`
|
||||
|
||||
## Important Files
|
||||
|
||||
- `react_frontend/src/pages/SettingsPage.tsx`
|
||||
- `react_frontend/src/api/maintenance.ts`
|
||||
- `backend/controllers/maintenanceController.js`
|
||||
- `backend/services/maintenanceService.js`
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `react_frontend/src/pages/SettingsPage.tsx` | Page component |
|
||||
| `react_frontend/src/api/maintenance.ts` | API client |
|
||||
| `backend/controllers/maintenanceController.js` | Route handlers |
|
||||
| `backend/services/maintenanceService.js` | Business logic |
|
||||
|
||||
## See Also
|
||||
|
||||
- [[API Reference#Maintenance]] — Endpoint details
|
||||
- [[Media System]] — How media files are stored
|
||||
- [[Env]] — Settings configuration
|
||||
+85
-13
@@ -1,26 +1,98 @@
|
||||
---
|
||||
title: Statistics
|
||||
tags:
|
||||
- feature
|
||||
- statistics
|
||||
- dashboard
|
||||
- charts
|
||||
---
|
||||
|
||||
# Statistics
|
||||
|
||||
## Overview
|
||||
|
||||
Dashboard charts powered by [[Backend]] statistics endpoints and the library store.
|
||||
The Dashboard page shows 7 chart components, combining backend statistics endpoints with client-side library store computations.
|
||||
|
||||
## Charts
|
||||
|
||||
### WatchActivityChart
|
||||
|
||||
- **Type:** Area chart (Recharts)
|
||||
- **Data:** Monthly watch count for a selected year
|
||||
- **Source:** `GET /statistics/watch-count/year/:year` → [[Hooks#useStatistics|useYearlyWatchCount]]
|
||||
- **File:** `components/dashboard/WatchActivityChart.tsx`
|
||||
|
||||
### WatchTimeChart
|
||||
|
||||
- **Type:** Area chart
|
||||
- **Data:** Monthly watch time (hours) for a selected year
|
||||
- **Source:** `GET /statistics/watch-time/year/:year` → [[Hooks#useStatistics|useYearlyWatchTime]]
|
||||
- **File:** `components/dashboard/WatchTimeChart.tsx`
|
||||
|
||||
### CouchDayChart
|
||||
- Shows watch distribution by day of week (bar chart)
|
||||
- Endpoint: `GET /statistics/watch-weekday`
|
||||
- **Only counts records with `accuracy = 'EXACT'`** (Milestone 001)
|
||||
- Queries both `EpisodeSeen` and `EntrySeen` tables
|
||||
|
||||
- **Type:** Bar chart
|
||||
- **Data:** Watch distribution by day of week
|
||||
- **Source:** `GET /statistics/watch-weekday` → [[Hooks#useStatistics|useWatchdayDistribution]]
|
||||
- **File:** `components/dashboard/CouchDayChart.tsx`
|
||||
|
||||
> [!important] Accuracy Filter
|
||||
> Only counts records where `accuracy = 'EXACT'`. Estimated and unknown dates are excluded to prevent skewing day-of-week patterns. See [[Watch Tracking#Accuracy System]].
|
||||
|
||||
**Backend query** (`statisticsController.js`):
|
||||
- Queries both `EpisodeSeen` and `EntrySeen` with `WHERE accuracy = 'EXACT'`
|
||||
- Groups by `DAYOFWEEK(date_seen)` (1=Sunday → 7=Saturday)
|
||||
- Sums counts from both tables
|
||||
|
||||
### LibraryGrowthChart
|
||||
- Shows cumulative library growth over time (area chart)
|
||||
- Data source: Library store entries (client-side computation)
|
||||
- Uses `createdAt` field as the entry date (Milestone 001)
|
||||
- Includes all entries (library + watchlist)
|
||||
- Supports year filter with "All" option
|
||||
|
||||
- **Type:** Area chart
|
||||
- **Data:** Cumulative library growth over time
|
||||
- **Source:** Client-side computation from [[Stores|library store]]
|
||||
- **File:** `components/dashboard/LibraryGrowthChart.tsx`
|
||||
|
||||
Details:
|
||||
|
||||
- Uses `createdAt` field as entry date (when it was added to Showy)
|
||||
- Includes **all entries** (library + watchlist)
|
||||
- Supports year filter dropdown + "All" option
|
||||
- "All" mode: monthly data across all years
|
||||
- Year mode: monthly data for selected year, with cumulative count starting from entries before that year
|
||||
|
||||
### MediaTypeChart
|
||||
|
||||
- **Type:** Chart showing movies vs TV breakdown
|
||||
- **Source:** Client-side from library store
|
||||
- **File:** `components/dashboard/MediaTypeChart.tsx`
|
||||
|
||||
### TopGenresChart
|
||||
|
||||
- **Type:** Chart showing top genres by count
|
||||
- **Source:** Client-side from library store
|
||||
- **File:** `components/dashboard/TopGenresChart.tsx`
|
||||
|
||||
### RatingsChart
|
||||
|
||||
- **Type:** Chart showing ratings distribution
|
||||
- **Source:** Client-side from library store
|
||||
- **File:** `components/dashboard/RatingsChart.tsx`
|
||||
|
||||
## Backend Endpoints
|
||||
|
||||
See [[API Reference#Statistics]].
|
||||
|
||||
| Endpoint | Returns |
|
||||
|---|---|
|
||||
| `GET /statistics/watch-time` | All-time total minutes (series + movies) |
|
||||
| `GET /statistics/watch-time/year/:year` | Monthly watch minutes for year |
|
||||
| `GET /statistics/watch-count/year/:year` | Monthly watch counts for year |
|
||||
| `GET /statistics/watch-weekday` | Day-of-week distribution (EXACT only) |
|
||||
|
||||
## Important Files
|
||||
|
||||
- `react_frontend/src/components/dashboard/CouchDayChart.tsx`
|
||||
- `react_frontend/src/components/dashboard/LibraryGrowthChart.tsx`
|
||||
- `backend/controllers/statisticsController.js` — `getWatchdayDistribution` method
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `backend/controllers/statisticsController.js` | Backend queries |
|
||||
| `react_frontend/src/components/dashboard/` | All 7 chart components |
|
||||
| `react_frontend/src/hooks/useStatistics.ts` | Query hooks |
|
||||
| `react_frontend/src/api/statistics.ts` | API client |
|
||||
@@ -0,0 +1,98 @@
|
||||
---
|
||||
title: Stores
|
||||
tags:
|
||||
- frontend
|
||||
- zustand
|
||||
- state-management
|
||||
aliases:
|
||||
- State Management
|
||||
- Zustand
|
||||
---
|
||||
|
||||
# Stores
|
||||
|
||||
Zustand stores in `react_frontend/src/stores/`. Two stores managing client-side state.
|
||||
|
||||
---
|
||||
|
||||
## useLibraryStore
|
||||
|
||||
> [!info] File: `stores/useLibraryStore.ts`
|
||||
|
||||
The core application store. Holds **all library entries** in a `Map<number, Entry>` for O(1) lookups.
|
||||
|
||||
### State
|
||||
|
||||
| Field | Type | Description |
|
||||
|---|---|---|
|
||||
| `entries` | `Map<number, Entry>` | All entries keyed by ID |
|
||||
| `isLoaded` | `boolean` | True after initial fetch completes |
|
||||
|
||||
### Actions
|
||||
|
||||
| Action | Signature | Description |
|
||||
|---|---|---|
|
||||
| `setEntries` | `(entries: Entry[]) => void` | Bulk load entries (clears + rebuilds map) |
|
||||
| `addEntry` | `(entry: Entry) => void` | Add single entry |
|
||||
| `updateEntry` | `(id: number, data: Partial<Entry>) => void` | Partial update |
|
||||
| `removeEntry` | `(id: number) => void` | Delete entry from store |
|
||||
|
||||
### Helper Hook
|
||||
|
||||
```typescript
|
||||
export function useLibraryEntries(): Entry[] {
|
||||
return Array.from(useLibraryStore((s) => s.entries).values());
|
||||
}
|
||||
```
|
||||
|
||||
Returns all entries as an array. Used by [[Statistics|LibraryGrowthChart]], [[Pages|LibraryPage]], etc.
|
||||
|
||||
### Usage Pattern
|
||||
|
||||
```typescript
|
||||
// Read single entry
|
||||
const entry = useLibraryStore((s) => s.entries.get(entryId));
|
||||
|
||||
// Read title (used in breadcrumbs)
|
||||
const title = useLibraryStore((s) => s.entries.get(id)?.title);
|
||||
|
||||
// Check if library is loaded
|
||||
const isLoaded = useLibraryStore((s) => s.isLoaded);
|
||||
```
|
||||
|
||||
### Population Flow
|
||||
|
||||
1. `App.tsx` renders → `useLibrary()` hook fires
|
||||
2. `GET /api/v1/entries` → backend returns all entries with relations
|
||||
3. Each entry passed through `normalizeEntry()` → [[Normalizers]]
|
||||
4. `setEntries(normalized)` → map populated, `isLoaded = true`
|
||||
5. Mutations call `addEntry`/`updateEntry`/`removeEntry` for optimistic updates
|
||||
|
||||
---
|
||||
|
||||
## useThemeStore
|
||||
|
||||
> [!info] File: `stores/useThemeStore.ts`
|
||||
|
||||
Theme toggle with localStorage persistence.
|
||||
|
||||
### State
|
||||
|
||||
| Field | Type | Description |
|
||||
|---|---|---|
|
||||
| `theme` | `'dark' \| 'light'` | Current theme |
|
||||
|
||||
### Actions
|
||||
|
||||
| Action | Description |
|
||||
|---|---|
|
||||
| `toggleTheme()` | Switches between dark/light |
|
||||
| `setTheme(theme)` | Set specific theme |
|
||||
|
||||
### Persistence
|
||||
|
||||
Uses Zustand `persist` middleware:
|
||||
|
||||
- Storage key: `showy-theme`
|
||||
- Stored in `localStorage`
|
||||
- On change: toggles `dark`/`light` class on `document.documentElement`
|
||||
@@ -0,0 +1,91 @@
|
||||
---
|
||||
title: TMDB Integration
|
||||
tags:
|
||||
- backend
|
||||
- tmdb
|
||||
- external-api
|
||||
---
|
||||
|
||||
# TMDB Integration
|
||||
|
||||
## Overview
|
||||
|
||||
Showy uses **TMDB API v3** as its primary source for movie and TV metadata. All TMDB calls are proxied through the backend — the frontend never contacts TMDB directly.
|
||||
|
||||
## Configuration
|
||||
|
||||
- API base URL: `https://api.themoviedb.org/3`
|
||||
- API key stored in `settings.json` → `tmdbApiKey`
|
||||
- Managed by `configService`
|
||||
|
||||
## tmdbService
|
||||
|
||||
> [!info] File: `backend/services/tmdbService.js`
|
||||
|
||||
### Entry Data
|
||||
|
||||
| Method | TMDB Endpoint | Returns |
|
||||
|---|---|---|
|
||||
| `fetchEntryData(tmdbId, isTV)` | `/movie/{id}` or `/tv/{id}` | Full entry metadata |
|
||||
| `fetchSeasonData(tmdbId, seasonNum)` | `/tv/{id}/season/{num}` | Season with episodes |
|
||||
| `fetchEntryMedia(tmdbId, isTV)` | `/movie/{id}/images` or `/tv/{id}/images` | Posters, backdrops, logos |
|
||||
| `fetchEntryCredits(tmdbId, isTV)` | `/movie/{id}/credits` or `/tv/{id}/credits` | Cast and crew |
|
||||
| `fetchCollectionData(collectionId)` | `/collection/{id}` | Collection with parts |
|
||||
|
||||
### Person Data
|
||||
|
||||
| Method | TMDB Endpoint |
|
||||
|---|---|
|
||||
| `fetchPersonDetails(tmdbId)` | `/person/{id}` |
|
||||
| `fetchPersonCombinedCredits(tmdbId)` | `/person/{id}/combined_credits` |
|
||||
|
||||
### Browse & Search
|
||||
|
||||
| Method | TMDB Endpoint |
|
||||
|---|---|
|
||||
| `fetchTrending(type)` | `/trending/{type}/week` |
|
||||
| `fetchPopular(type)` | `/{type}/popular` |
|
||||
| `fetchTopRated(type)` | `/{type}/top_rated` |
|
||||
| `fetchUpcoming()` | `/movie/upcoming` |
|
||||
| `searchMulti(query, page)` | `/search/multi` |
|
||||
| `searchPeople(query)` | `/search/person` |
|
||||
| `fetchPopularPeople()` | `/person/popular` |
|
||||
|
||||
## Frontend TMDB Proxy
|
||||
|
||||
The frontend accesses TMDB data through backend proxy endpoints (see [[API Reference#TMDB Proxy]]):
|
||||
|
||||
```
|
||||
Frontend → /api/v1/entries/tmdb/trending/movie → Backend → TMDB API → Response
|
||||
```
|
||||
|
||||
This keeps the API key server-side.
|
||||
|
||||
## Image URLs
|
||||
|
||||
TMDB image base URL: `https://image.tmdb.org/t/p/`
|
||||
|
||||
Common sizes used:
|
||||
|
||||
- Posters: `w342`, `w500`, `w780`
|
||||
- Backdrops: `w780`, `w1280`
|
||||
- Stills: `w300`, `w1280`
|
||||
- Profiles: `w185`
|
||||
|
||||
See [[Media Utilities]] for frontend URL resolution and [[Media System]] for local image caching.
|
||||
|
||||
## Lazy Refresh Pattern
|
||||
|
||||
Used by [[Services#EntryManager]] and [[Services#PeopleManager]]:
|
||||
|
||||
1. Check `last_fetch` or `fully_fetched` field
|
||||
2. If stale (>24h) or never fetched → call TMDB
|
||||
3. Update local data + set `last_fetch` to today
|
||||
4. TV series with `status = "Ended"` skip refresh
|
||||
|
||||
## Rate Limiting
|
||||
|
||||
The [[Import System]] self-throttles to stay under TMDB limits:
|
||||
|
||||
- Max 35 requests per 10 seconds
|
||||
- 500ms delay between individual requests
|
||||
@@ -0,0 +1,72 @@
|
||||
---
|
||||
title: Tech Stack
|
||||
tags:
|
||||
- architecture
|
||||
- tech-stack
|
||||
---
|
||||
|
||||
# Tech Stack
|
||||
|
||||
Complete technology inventory for Showy.
|
||||
|
||||
## Backend
|
||||
|
||||
| Technology | Version | Purpose |
|
||||
|---|---|---|
|
||||
| Node.js | — | Runtime |
|
||||
| Express | 4.x | HTTP framework |
|
||||
| Sequelize | 6.x | ORM |
|
||||
| MySQL | 8.0 | Database |
|
||||
| Axios | — | HTTP client (TMDB API) |
|
||||
| Sharp | — | Image processing (previews) |
|
||||
| Multer | — | File upload handling |
|
||||
| UUID | — | Unique filename generation |
|
||||
| body-parser | — | Request body parsing |
|
||||
| Nodemon | — | Dev auto-restart |
|
||||
|
||||
## React Frontend
|
||||
|
||||
| Technology | Version | Purpose |
|
||||
| --------------- | ------- | ----------------------------------- |
|
||||
| React | 19 | UI framework |
|
||||
| TypeScript | — | Type safety |
|
||||
| Vite | 8 | Build tool + dev server |
|
||||
| TanStack Query | 5 | Server state management |
|
||||
| Zustand | 5 | Client state management |
|
||||
| React Router | 7 | Client-side routing |
|
||||
| react-hook-form | 7 | Form handling |
|
||||
| Zod | 4 | Schema validation |
|
||||
| shadcn/ui | — | Component library (base-nova theme) |
|
||||
| Tailwind CSS | 4 | Utility-first CSS |
|
||||
| Recharts | 3 | Charts (dashboard) |
|
||||
| Sonner | — | Toast notifications |
|
||||
| Lucide | — | Icon library |
|
||||
| date-fns | — | Date formatting |
|
||||
| Axios | — | HTTP client |
|
||||
|
||||
## Desktop
|
||||
|
||||
| Technology | Version | Purpose |
|
||||
|---|---|---|
|
||||
| Electron | 34 | Desktop wrapper |
|
||||
| electron-builder | 25 | Packaging/distribution |
|
||||
|
||||
## Infrastructure
|
||||
|
||||
| Technology | Purpose |
|
||||
|---|---|
|
||||
| Docker | Containerization |
|
||||
| Docker Compose | Multi-container orchestration |
|
||||
| Nginx | Frontend static file serving (Docker) |
|
||||
|
||||
## External APIs
|
||||
|
||||
| API | Usage |
|
||||
|---|---|
|
||||
| TMDB API v3 | Movie/TV metadata, images, search, trending |
|
||||
|
||||
## See Also
|
||||
|
||||
- [[Architecture]] — How these fit together
|
||||
- [[Deployment]] — Docker setup
|
||||
- [[Env]] — Configuration
|
||||
@@ -0,0 +1,107 @@
|
||||
---
|
||||
title: Types
|
||||
tags:
|
||||
- frontend
|
||||
- typescript
|
||||
- types
|
||||
---
|
||||
|
||||
# Types
|
||||
|
||||
All TypeScript interfaces in `react_frontend/src/types/index.ts`.
|
||||
|
||||
---
|
||||
|
||||
## Core Entity Types
|
||||
|
||||
### Entry
|
||||
|
||||
The main entity — movie or TV series.
|
||||
|
||||
Key fields: `id`, `title`, `original_title`, `release_date`, `runtime`, `storyline`, `is_tvseries`, `watchlist`, `favorit`, `hidden`, `status`, `poster_path`, `banner_path`, `date_first_seen`, `date_last_seen`, `createdAt`
|
||||
|
||||
Relations: `entry_ids` ([[#EntryIds]]), `entry_ratings` ([[#EntryRatings]]), `genres` ([[#Genre]][]), `networks` ([[#Network]][]), `medias` ([[#Media]][]), `entry_seens` ([[#EntrySeen]][]), `seasons` ([[#Season]][])
|
||||
|
||||
### Season
|
||||
|
||||
TV season. Key fields: `id`, `entry_id`, `name`, `season_number`, `episode_count`, `air_date`, `poster_path`
|
||||
|
||||
### Episode
|
||||
|
||||
TV episode. Key fields: `id`, `season_id`, `name`, `episode_number`, `runtime`, `air_date`, `still_path`, `date_first_seen`, `date_last_seen`
|
||||
|
||||
### EntrySeen
|
||||
|
||||
Movie watch record. Fields: `id`, `entry_id`, `date_seen`, `seen_with`, `accuracy`
|
||||
|
||||
### EpisodeSeen
|
||||
|
||||
Episode watch record. Fields: `id`, `entry_id`, `episode_id`, `date_seen`, `seen_with`, `accuracy`
|
||||
|
||||
### SeenAccuracy
|
||||
|
||||
Type alias: `'EXACT' | 'ESTIMATED' | 'UNKNOWN'`
|
||||
|
||||
Used by both EntrySeen and EpisodeSeen. See [[Watch Tracking]].
|
||||
|
||||
---
|
||||
|
||||
## Supporting Types
|
||||
|
||||
### EntryIds
|
||||
|
||||
External IDs: `tmdb_id`, `imdb_id`, `tvdb_id`
|
||||
|
||||
### EntryRatings
|
||||
|
||||
Multi-source ratings: `user_rating`, `tmdb_rating`, `imdb_rating`, `rotten_tomatoes_rating`
|
||||
|
||||
### Media
|
||||
|
||||
Image record: `id`, `mediaable`, `mediaableId`, `type`, `path`, `isLocal`, `isSelected`, `isCustom`, `isFavorit`
|
||||
|
||||
### Collection
|
||||
|
||||
Fields: `id`, `tmdb_id`, `imdb_id`, `name`, `description`, `isUserCollection`, `userRating`, `poster_path`, `backdrop_path`, `entries`
|
||||
|
||||
### People
|
||||
|
||||
Person profile: `id`, `tmdb_id`, `name`, `birthday`, `deathday`, `gender`, `biography`, `profile_path`, `fully_fetched`
|
||||
|
||||
### Credit
|
||||
|
||||
Cast/crew: `id`, `character`, `order`, `cast_type`, `department`, `job`, `people` (nested People)
|
||||
|
||||
### Genre
|
||||
|
||||
`id`, `name`
|
||||
|
||||
### Network
|
||||
|
||||
`id`, `name`
|
||||
|
||||
### Settings
|
||||
|
||||
`tmdbApiKey`, `backPort`, `frontPort`, `userDataPath`, `libraryViewMode`, `watchlistViewMode`
|
||||
|
||||
---
|
||||
|
||||
## TMDB Types
|
||||
|
||||
### TmdbEntry
|
||||
|
||||
TMDB search/browse result: `id`, `title`/`name`, `overview`, `poster_path`, `backdrop_path`, `media_type`, `release_date`/`first_air_date`, `vote_average`
|
||||
|
||||
### TmdbPerson
|
||||
|
||||
TMDB person result: `id`, `name`, `profile_path`, `known_for_department`, `known_for`
|
||||
|
||||
### TmdbPaginatedResponse
|
||||
|
||||
Generic paginated TMDB response: `page`, `total_pages`, `total_results`, `results`
|
||||
|
||||
---
|
||||
|
||||
## Type Normalization
|
||||
|
||||
Backend Sequelize responses use a mix of camelCase and snake_case. The [[Normalizers]] layer transforms them into consistent frontend types. See [[Normalizers]].
|
||||
@@ -0,0 +1,74 @@
|
||||
---
|
||||
title: Watch Tracking
|
||||
tags:
|
||||
- feature
|
||||
- watch-tracking
|
||||
- seen
|
||||
---
|
||||
|
||||
# Watch Tracking
|
||||
|
||||
## Overview
|
||||
|
||||
Showy tracks when users watch movies and episodes. Two models handle this:
|
||||
|
||||
| Model | For | Key Fields |
|
||||
|---|---|---|
|
||||
| [[Models#EntrySeen\|EntrySeen]] | Movies | `entry_id`, `date_seen`, `seen_with`, `accuracy` |
|
||||
| [[Models#EpisodeSeen\|EpisodeSeen]] | Episodes | `entry_id`, `episode_id`, `date_seen`, `seen_with`, `accuracy` |
|
||||
|
||||
## Accuracy System
|
||||
|
||||
Every watch record has an `accuracy` field indicating how precise the `date_seen` is:
|
||||
|
||||
| Value | Meaning | Used in Statistics |
|
||||
|---|---|---|
|
||||
| `EXACT` | User knows the exact date | Yes — [[Statistics#CouchDayChart]] |
|
||||
| `ESTIMATED` | Approximate date | No — excluded from day-of-week charts |
|
||||
| `UNKNOWN` | No date information | No |
|
||||
|
||||
> [!tip] Why Accuracy Matters
|
||||
> When importing historical watch data, exact dates are often unknown. The accuracy field prevents estimated dates from skewing [[Statistics]] charts that rely on day-of-week patterns.
|
||||
|
||||
## Frontend Dialogs
|
||||
|
||||
### EntrySeenDialog
|
||||
|
||||
- File: `components/dialogs/EntrySeenDialog.tsx`
|
||||
- Used for: Movies (create/edit watch records) and TV episodes (mark season episodes as seen)
|
||||
- Form: react-hook-form + zod validation
|
||||
- Date input: Native `<input type="date">` (allows easy year selection)
|
||||
- Date + accuracy displayed in same row
|
||||
|
||||
### EpisodeSeenEditDialog
|
||||
|
||||
- File: `components/dialogs/EpisodeSeenEditDialog.tsx`
|
||||
- Used for: Creating/editing individual episode watch records
|
||||
- Date + accuracy in same row
|
||||
- Includes "seen with" field
|
||||
|
||||
## API Endpoints
|
||||
|
||||
See [[API Reference#Entry Seen (Movie Watch Records)]] and [[API Reference#Episode Seen (Episode Watch Records)]].
|
||||
|
||||
## Hooks
|
||||
|
||||
- [[Hooks#useEntrySeen]] — Movie watch record CRUD
|
||||
- [[Hooks#useEpisodeSeen]] — Episode watch record CRUD
|
||||
|
||||
## Batch Operations
|
||||
|
||||
### Mark All Seen (Season)
|
||||
|
||||
The [[Pages#SeasonPage|SeasonPage]] has a "Mark All as Seen" action that:
|
||||
|
||||
1. Filters unwatched episodes
|
||||
2. Creates an `EpisodeSeen` for each
|
||||
3. Uses the selected date and accuracy
|
||||
|
||||
## Side Effects
|
||||
|
||||
When watch records are created/updated/deleted:
|
||||
|
||||
- `date_first_seen` and `date_last_seen` are updated on the Entry/Episode
|
||||
- Statistics queries are affected (if accuracy = EXACT)
|
||||
Reference in new issue
Block a user