120 lines
4.1 KiB
Markdown
120 lines
4.1 KiB
Markdown
---
|
|
title: Architecture
|
|
tags:
|
|
- architecture
|
|
- overview
|
|
---
|
|
|
|
# Architecture
|
|
|
|
## Overview
|
|
|
|
Showy is a **single-user** media tracking application with three deployment layers:
|
|
|
|
| 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 |
|
|
|
|
See [[Tech Stack]] for complete version inventory.
|
|
|
|
## System Diagram
|
|
|
|
```mermaid
|
|
graph TD
|
|
subgraph Desktop["Electron (Desktop)"]
|
|
E[Main Process] --> B
|
|
E --> FE
|
|
end
|
|
|
|
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
|