This project hosts the backend implementation of the main Tapestry application. It consist of two main parts - a Node.js server implementing the REST API described in shared and a background worker that executes asynchronous jobs.
This server requires the following infrastructure components:
- A PostgreSQL database for storing Tapestry data.
- An AWS S3 bucket for storing Tapestry binary assets.
- A Redis server instance for caching and scheduling background jobs.
- (optional) A HashiCorp Vault for storing user secrets such as AI API keys.
These services can be configured manually, started via docker-compose, or orchestrated using the included OpenTofu configuration.
Take a look at .env.example or config.ts for a list of configuration variables. To configure the server for local execution, copy .env.example to .env, and fill in the blanks.
This project uses Prisma ORM which generates database-related types dynamically. In order for the application to compile correctly, the Prisma types must first be generated from the schema.prisma file. This can be done by running:
npm run prisma:generateAdditionally, in order to set up the database, the DB migrations also need to be applied:
npm run prisma:migrateNote that these two commands must also be run every time there is a change in the schema.prisma file.
To run the server locally, all necessary infrastructure needs to be available, configuration must be provided in a .env file, the Prisma types must be generated, and DB migrations executed. The server can then be started by running:
npm startAnd the background worker can be started using:
npm run start:workerThe Tapestry Project also includes Dockerfiles for some components. They are used internally when running the project using docker compose or OpenTofu. However, Dockerfile.server is a good place to see all external dependencies the server project has. Note for example, that the worker part of the Docker image requires chromium (used by puppeteer for making screenshots when generating item or tapestry thumbnails), ffmpeg and imagemagick (again, for generating item thumbnails for videos, PDFs, etc.).
As mentioned above, the project contains two main parts - REST API and background tasks.
The src/resources directory contains implementations of all REST resources described in the shared project. The main request handling flow is described in resources/base-resource.ts. It includes parsing the request parameters, invoking the appropriate access control handlers, executing the main endpoint logic, serializing the result, and sending it back to the client. The specific access policies along with implementation of resource endpoints are provided in separate files, one per REST resource.
The application uses BullMQ for executing background jobs. The entrypoint for background workers is tasks/worker.ts. All of the supported tasks that background workers can execute are also implemented in the tasks/ directory. Currently these include generating item or tapestry thumbnails, as well as importing or forking tapestries.