Let users upload videos, tag them with one or more entries, and watch them from a new Discovery Videos page. Backend: - Add Video and VideoEntry models and relations - Add video controller and /video routes - Add video thumbnail generation service (ffmpeg-static) - Add video upload storage location and config Frontend: - Add DiscoveryVideosPage with sidebar link and route - Add AddVideoDialog, VideoDropzone, EntryMultiSelect, VideoCard and VideoPlayerDialog components - Add discoveryVideos API client and useDiscoveryVideos hook - Add format helpers, video types and normalizers - Add skeleton for the page Docs: - Document the feature in docs-vault
3.6 KiB
3.6 KiB
title, tags
| title | tags | |||
|---|---|---|---|---|
| Backend |
|
Backend
Overview
Node.js + Express REST API serving the Frontend via JSON. Uses Sequelize ORM with a MySQL database named Showzy.
Entry Point — server.js
- Creates Express app with
body-parser(JSON + URL-encoded) - CORS: allows all origins (
*) - All API routes mounted under
/api/v1viaroutes/routes.js - Error handler middleware at the end (see Error Handling)
- Debug crash route at
/killer(outside/api/v1) - Sequelize sync:
sequelize.sync({ alter: doUpdate })wheredoUpdate = false - Calls
initializeData()after sync — seeds 27 TMDB genres if needed - Listens on port from
settings.json(default4000) - Process-level handlers for
unhandledRejectionanduncaughtException
Project Structure
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 (15 controllers)
├── services/ Business logic (16 services) → [[Services]]
├── models/ Sequelize models (19 models) → [[Models]]
├── routes/ Express routers (15 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
Middleware Pipeline
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 MySQLShowzyonlocalhost(root/password)config/relations.js— All model associations (see Database#Relationships)config/dataInitializer.js— Seeds genre table with 27 TMDB genresconfig/sequelizeHooks.js— Auto-managesorderfield on Collections
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 and Services 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
- Discovery Videos — Video upload/stream API