Rainty module: Content library (video, audio, documents, links)
Build v1 of the Content library in Rainty: staff upload videos (via the video provider, HLS streaming), audio files, PDF documents and links, organise them in folders and tags, replace files with new versions, and assign items to customers. You write library-service and the frontend module; who sees what is handled by the platform: rows carry the user and organisation from the token, and the data routes apply the permissions and approve every file access. The model must be ready for the customer portal.
Rainty module: Content library (video, audio, documents, links)
Rainty is one application for professionals who manage customers; each customer gets a different set of switchable modules. This challenge builds the Content library: the place where a coach or a teacher keeps the material they share with their customers (videos, audio files, PDF documents and links), organises it in folders and tags, replaces a file with a corrected version, and assigns items to customers. Fitness relies mostly on video; Education relies on PDFs and, for language teachers, on audio.
Customers cannot sign in to Rainty yet. In this version the library is used by the staff of the organisation: they upload, organise, preview and assign. Assignments are stored against the customer record, so that when the customer portal arrives the same assignments become what each customer sees, without changes to your model.
This brief has two parts: a backend service, library-service, and the frontend module libreria. Who sees what is not your problem: every item, folder, version and assignment is written with the user and the organisation taken from the token, and the platform's permission layer decides what each user gets back. The rules, the workflow and the common acceptance criteria of the module challenges are in the common brief and the documents it points to. They are part of the specification: read them first.
Repository and workflow
| Repository | https://github.com/vinovalab/rainty |
| Module key | libreria |
| Verticals | Fitness and Education first; the module works in all |
| Working branch | feature/libreria |
| Target branch (PR) | main |
| Service folder | services/library-service/ (rainty) |
| Module folder | frontend/modules/libreria/ (rainty) |
| Reference mockup | ~/riferimenti/MP002-libreria/mockup-b/ in your workspace (see below) |
You work from your personal dev-platform workspace (https://ws-<your-github-login>.vinovalab.ai, sign in with Cloudflare Access). Run ws-sync, then git checkout -b feature/libreria origin/main in rainty. Run the frontend dev server from frontend/apps/rainty-organizer against the development API, on port 5182, with the dev users the project coordinator enables for you (at least two users and one organisation admin of the same organisation, with a few customers already in the organisation). Push only your branch and open the Pull Request targeting main (gh pr create --base main).
The documents that govern the work
Read these before writing a line. Reviews cite their rule numbers.
- Rainty module challenges: common brief: the workflow, the six non-negotiable rules, the deliverables and the common acceptance criteria.
- Rainty modules contract: manifest, frontend, proposal, core, events, services, acceptance (§1–§10).
- Anatomy of a module: the thirteen pieces of a module, file by file, proposal included.
- Engineering guidelines: how code is written and reviewed here.
- The Conversation Context Service (
rainty/docs/conversation-context/PROPOSAL.mdandrainty/services/conversation-context-service/): the reference for a Rainty service that stores its data through the platform's data routes. Reuse its patterns; do not change it. - The
fotomodule (rainty/frontend/modules/foto/, in particularapi/documenti.ts): the reference for uploading a file to the platform's document service from a module and keeping only the document id. - The
compitimodule (rainty/frontend/modules/compiti/): a module with a tab in the customer record (schedaClientein the manifest), the same shape you need for "Material assigned to this customer".
Where the documents do not match what you find in the repositories or in the development API, report it in the PR. Those corrections are on us to fix and never move your delivery window.
The first version
Inside:
- four content types:
- video (mp4, mov, phone formats): uploaded straight from the browser with a resumable upload, transcoded by the video provider, played as HLS streaming, never downloadable;
- audio (mp3, m4a/aac, wav, ogg): stored as uploaded and played with a player that has seek and playback speed (0.75×, 1×, 1.25×);
- PDF documents: shown in an in-app viewer; downloadable only when the item's "allow download" switch is on (off by default);
- links (any http/https URL: YouTube, articles, external tools): title and preview image fetched once when the link is added; opened in a new tab;
- a library page with previews (video thumbnail, audio duration, PDF first page, link preview), nested folders, tags, an optional subject and level whose labels come from the vertical through the manifest (for example "Body area" in Fitness, "Subject" and "Level A1–C2" in Education), filters by type, folder, tag and subject, and search on title, description and the text inside PDFs;
- edit title, description, tags, folder, subject, level, allow-download; delete (soft, the item disappears from the library and from new assignments);
- versions: replacing the file of a video, audio or PDF creates a new version; the item shows its version history, and the current version is what new assignments and references get;
- assignments: assign an item to one or more customers of the organisation, with optional start and expiry dates; see and remove the assignments of an item; a tab in the customer record lists the material assigned to that customer;
- references with version pinning: an API other modules will use (homework, planned activities) to point to a library item; creating a reference records the version current at that moment, and reading it returns that version even after the item is replaced. You build and test the API; wiring it into those modules is ours;
- status of each item (uploading, processing, ready, failed) updated live in the library while a video is processed.
Outside (later challenges), and decided:
- images: not in this version;
- office files (docx, pptx, xlsx): PDF only in this version, no conversion;
- the customer side (customer list of assigned items, customer players, progress saved, "who watched and how far"): it arrives with the customer portal. Leave room in the model; build no customer interface;
- groups and classes as assignment targets, and assigning a whole folder: customers only, items only;
- audio processing (loudness normalisation, AAC, HLS audio, waveform) and audio transcription: audio is played as uploaded;
- indexing in rAInty (so the agent can answer on the documents and find a page): ours, later, from the text you store;
- quotas, usage metering and licence limits: ours, later;
- the in-house video transcoder (FFmpeg and object storage): a later challenge; your design must allow it without changes to the frontend;
- offline access, live streaming, subtitles and chapters, editing files inside the library, selling content.
Who uses it, and who sees what
- Member. A user of the organisation with the module active. Uploads and organises material, assigns it to customers.
- Organisation admin. Sees the whole library of the organisation.
You do not implement visibility. Every row is written with the user id and the organisation id taken from the authentication token, never from the request. Every read goes through the platform's data routes, which apply the permission rules (which items a member sees, what the admin sees, nobody gets anything of another organisation) and return each item with a puoModificare flag. Your service and your interface show what they receive and hide edit, replace, delete and assign when puoModificare is false; they never filter by user, organisation or role, and never check RAINTY_ADMIN.
Access to a file is decided the same way. Before issuing any playback, viewer or download URL, the service asks the data routes whether the calling user can open that item (and that version); it never decides it on its own. The same check will serve customers when the portal arrives.
Architecture
library-service (yours)
A new Node service in rainty/services/library-service/, built like the other Rainty services (Dockerfile, release.json, compose entry in the rainty compose files, /status/health with a healthcheck, structured logs, tests). It is reached by the frontend as /library-service/*; we add the proxy location in the frontend's nginx.
- Authentication on every request through auth-service, as the other services do. The service forwards the user's token to the data routes; it never sends a user id or an organisation id of its own.
- No direct database access. Every read and write of library data goes through the data routes
/rainty/libreria/*(below). This is a platform rule, not a preference. - One Library API owned by us and written by you as an OpenAPI contract in the first PR commit, with a small conformance test suite that runs against the service. Only Vinova ids leave the service: no provider ids, no provider URLs except the signed playback and thumbnail URLs, no storage paths.
- Files (audio, PDF, link preview images) go to the platform's document service (
docs-service, see thefotomodule), and only the document id is stored on the version. PDF text comes from the document service's text extraction; the service stores it on the version so that search can find a sentence inside a PDF. The document service holds uploads in memory up to 200 MB: refuse larger audio and PDF files with a clear message. - Video goes through the video provider (Cloudflare Stream, development account provided by us): the service creates a direct resumable (tus) upload and returns it to the browser, which sends the file straight to the provider; the provider's webhook reaches an internal route of the service, which updates status, duration and thumbnail. Put the provider behind an adapter with one implementation: the in-house transcoder will be a second implementation of the same adapter, and the frontend must never know which one serves a video. Provider credentials are configuration, never in the repository.
- Access URLs are signed and short-lived, issued only after the data routes allow the access: a signed HLS URL for video; for audio and PDF, a URL of the service itself, signed and expiring, that streams the file from the document service with HTTP Range support (seek in audio, page loading in the PDF viewer) and sets
Content-Disposition: attachmentonly when download is allowed. - Links: the one-time fetch of title and preview image is a server-side request to an address chosen by the user. Protect it: http/https only, no private, loopback or link-local addresses (checked after DNS resolution and on every redirect), short timeout, small size limit, no cookies or credentials forwarded. The preview image is stored in the document service, never hotlinked.
- Live status: item status changes reach the open library through the service's own authenticated stream (Server-Sent Events), or by polling the item: your choice, justified in the proposal. Do not use the existing
redis-ws-bridge: it fans every Redis channel out to every authenticated client, with no per-organisation or per-user filtering. - File names, file content and link URLs never appear in logs, error messages or URLs beyond what the access URL itself needs.
Data routes (ours, from your proposal)
The routes under /rainty/libreria/* in data-service are written by the core team, as for every Rainty module, from the list you put in the proposal: for each route, method, path, what it reads or writes, and the shape of the request and of the answer. They take user and organisation from the token, write them on every row, apply the permission rules on every read, and answer the access check ("can this user open this item and this version"). Until they are live on development, write against a small stub in your tests that follows the same contract.
Tables (proposed by you, created by us)
In schema rainty_libreria, shaped in the proposal. A starting point, not a constraint:
elementi: organisation, owner, type (video / audio / document / link), title, description, tags, folder, subject, level, status (uploading / processing / ready / failed / deleted), current version, allow download, created and updated at;versioni: item, version number, document id (audio, PDF, preview image), mime type, size, duration (audio, video), page count and extracted text (PDF), URL (links), provider and provider reference (video, internal only), rights declared at, created at;cartelle: organisation, parent, name;assegnazioni: item, target kind and target reference (today onlyclientewith the customer id; later groups and classes), version assigned (the current version when the assignment is made), assigned by, starts at, expires at;riferimenti: item, pinned version, source kind (homework / activity) and source id.
Customers are referenced as cliente_id of the platform's customer table, as the other modules do. You do not need columns or tables for permissions: those are ours. Views and progress of customers are not in this version; say in the proposal where they will go.
The module
The frontend lives in frontend/modules/libreria/ and follows the module contract (manifest, pages, components, hooks, API client, it/en catalogues, tests):
- a library page: folders on the side (a drawer on the phone), the items as a grid or list with preview, type, status and tags; filters and search;
- an add flow: upload a file (progress, resumable for video, rights declaration required) or paste a link;
- an item page: the player or viewer for its type (HLS video player, audio player with speed and seek, PDF viewer, link card), details, versions, assignments;
- assign to customers, with the platform's customer picker, and optional dates;
- the customer record tab "Material" with the items assigned to that customer;
- an item returned with
puoModificarefalse is shown read-only.
The frontend reads the service's base URL from configuration only; it contains no provider SDK, provider URL format or provider id (an HLS player library such as hls.js is fine).
Reference mockup
Where it is. In your workspace, read-only, at ~/riferimenti/MP002-libreria/mockup-b/ (outside ~/code, so ws-sync never touches it). Start from LEGGIMI.md, then look at the screenshots in immagini/, then open index.html (python3 -m http.server from that folder; views with ?v=libreria|dettaglio|carica|cliente|telefono, dark theme with #dark). If the page does not open, the screenshots are enough. Do not copy the CSS of the mockup: use the real --rainty-* tokens and .rainty-* classes. The data in the mockup are invented and are at most test fixtures.
What follows from it. The mockup ("Gallery") is a direction, not a pixel spec. LEGGIMI.md lists what is fixed (previews as the content with faceted filters and counts, the item opening in a large dialog with details, versions and assignments, upload by dropping files on the gallery with the rights declaration in the drop zone and a summary of uploads, the link panel with its card preview, item states visible where the item is listed, read-only items with actions hidden and a lock in lists, PDF download off by default, which version each customer has, the "Material" tab grouped into active, scheduled and expired, the phone layout) and what is free (card size and columns, facet order and collapsing, spacing, icons, wording, empty and error states beyond the ones shown, placeholder art, extra player controls, component structure).
Use the impeccable skill for every piece of frontend, and check the result in light and dark, on desktop and at 375 px. Say in the PR what you checked.
What the core gives you, and what it does not
Available in development today: authentication and the user's organisation, per-user module activation, the customer table and picker, the document service (upload, text extraction), @rainty/api, the design system, and the module shell. From your proposal: the tables, the data routes with the permission rules, the module's licence key, the nginx location and the Cloudflare Stream development credentials.
Not available, and not yours to build or wait for: the customer portal, groups and classes, object storage (R2), FFmpeg, office-to-PDF conversion. If you need something from the core that is not there, ask for it in the "what I use from the core" section of the proposal; do not wait for it.
The proposal
Your first commit, in the rainty PR, is frontend/modules/libreria/PROPOSTA.md, together with the OpenAPI contract of the Library API, and your PR is open as soon as they exist. Beyond the proposal model of the anatomy it says: the tables, the data routes you need (with their request and answer), the Library API and its errors, the video adapter and the provider webhook, how access URLs are signed and how long they live, and how the link fetch is protected. We answer within the next working day: tables and data routes on development, the nginx location, the provider credentials and your dev users enabled, or the corrections we ask for. Later changes follow the same path. Keep the first proposal small.
Expected deliverables
- One PR on rainty from
feature/libreria:services/library-service/with the OpenAPI contract, the conformance suite and the other tests, its compose entries, the module folder withPROPOSTA.mdaligned with the final code, the manifest (it/encatalogues complete, subject and level labels per vertical), pages, components, hooks, the API client, tests, and a shortREADME.mdsaying what surprised you, how you handled each mismatch with the documents, how a second video backend plugs into the adapter, and where you departed from the mockup.
Acceptance criteria
The common criteria of the common brief apply in full (green checks, switch on/off behaviour, PROPOSTA.md matching the code, desktop and phone in light and dark). In addition:
- a member uploads a video, sees it go from processing to ready with a thumbnail without reloading, and plays it; the upload resumes after a network interruption;
- an audio file plays with seek and the three playback speeds;
- a PDF opens in the viewer; it can be downloaded only when allow-download is on, and the switch is off for new items;
- a link is added with its title and preview image fetched automatically; a link to a private or loopback address, directly or through a redirect, is refused;
- search finds a PDF by a sentence inside its text;
- replacing a PDF creates version 2; a reference created before the replacement still returns version 1, a new one returns version 2;
- an item is assigned to two customers with an expiry date and appears in the "Material" tab of both customer records; after the file is replaced, each assignment still shows the version that customer has;
- the layout follows the reference mockup (direction B, "Gallery"); deviations are explained in the README;
- user and organisation are never sent by the service or the frontend: they come only from the token; the service and the module contain no filter by user, organisation or role;
- no access URL is issued before the data routes allow the access; access URLs stop working after they expire;
- an item returned with
puoModificarefalse is read-only in the interface and changes to it are rejected by the service; - no response contains a provider id, an unsigned file URL or a storage path; the frontend contains no provider reference; the conformance suite passes;
- audio and PDF files above 200 MB are refused with a clear message, before the upload starts;
- the service never connects to the database and never uses
redis-ws-bridge; - the assignment model holds a non-customer target kind without a schema change;
- nothing outside
services/library-service/, the service's compose entries,frontend/modules/libreria/and your line infrontend/modules/index.tschanged in rainty.
If the brief is wrong
If something here turns out to be impossible or absent (a route that does not exist, a component that is not where it should be, a rule that contradicts another) say so on the challenge before you start. A brief that is wrong is our problem, and the window pauses while you wait for an answer.