---
title: "Deploy Textbook Generator"
description: "Textbook Generator Template"
category: "Other"
url: https://railway.com/deploy/textbook-generator
---

# Deploy Textbook Generator

Textbook Generator Template

**[Deploy Textbook Generator on Railway](https://railway.com/template/textbook-generator)**

- **Creator:** Medibuddy
- **Category:** Other

## Template content

### medibuddy-mla-builder

- **Source:** https://github.com/AG-Education/medibuddy-mla-builder
- **Public domain:** Yes

## Documentation

Ah — that's almost certainly the leading `---` I wrapped it in. A README parser reads a top-of-file `---` as the start of YAML front matter and swallows everything up to the next `---`, so all the headings between them vanish → "missing sections." Here's the same content **without** the horizontal rules, starting straight at the H1:

# Deploy and Host Textbook Generator on Railway

Textbook Generator is a web app and CLI that automates building MLA medical-curriculum textbook chapters. Pick a chapter or a whole textbook (body system) and it generates 12 structured sections — text, TL;DRs, and illustrations — with OpenAI, writes them back to Google Sheets, renders charts and citations, uploads a Google Doc, and produces import-ready CSV and image bundles.

## About Hosting Textbook Generator

Hosting Textbook Generator means running a single stateless Node.js (Express) server that gates a small web UI behind basic auth and orchestrates long-running generation jobs. Each chapter takes ~10–15 minutes and chains dozens of OpenAI calls, Google Sheets reads/writes, an external chart-renderer service, and Google Drive uploads — so the container must stay alive for the duration of a run and reach the OpenAI, Google, and renderer APIs. Authentication to Google uses a service account (no interactive browser flow in a container). There's no database: jobs are tracked in memory, and all durable output lands in Google Sheets and Drive. Run a single instance, since in-flight job state isn't shared across replicas.

## Common Use Cases

- **Generate a full textbook in one click** — batch-generate every ready chapter in a body system, with automatic retries and a "retry failed" pass.
- **Regenerate a single chapter** — refresh one chapter's AI content and produce an updated Google Doc for review.
- **Export for platform import** — download a per-textbook, import-ready CSV plus a zip of all the images that textbook references.

## Dependencies for Textbook Generator Hosting

- **Node.js 18+** (ESM) — Express, googleapis, and the OpenAI SDK.
- **OpenAI API key** — `gpt-5.2` for text and `gpt-image-2` for per-section illustrations.
- **Google Cloud service account** — with Editor access to the source Google Sheets and the destination Drive folder.
- **MLA chart-renderer service** — the companion Railway service that resolves charts, hover content, and references.
- **Google Sheets + Drive** — the content map sheet (chapters + file IDs), the data sheet (write target), and a Drive folder for images, Docs, and the library CSV.

### Deployment Dependencies

- [Railway](https://railway.app)
- [OpenAI Platform — API keys](https://platform.openai.com/api-keys)
- [Google Cloud — Service Accounts](https://cloud.google.com/iam/docs/service-accounts-create)
- [Google Sheets API](https://developers.google.com/sheets/api) · [Google Drive API](https://developers.google.com/drive/api)
- [googleapis (npm)](https://www.npmjs.com/package/googleapis)

### Implementation Details

**Start command:** `npm start` (runs `node src/server.js`). Railway supplies `PORT` automatically.

**Environment variables:**

| Variable | Required | Purpose |
| --- | --- | --- |
| `APP_PASSWORD` | **Yes** | Password gating the web UI (HTTP basic auth). Use a long random string. |
| `OPENAI_API_KEY` | Yes (for generation) | OpenAI key for text + image generation. |
| `GOOGLE_SERVICE_ACCOUNT_JSON` | **Yes on Railway** | Full service-account JSON key as a single-line string. Its `client_email` must have Editor on the Sheets and the Drive folder. (Without it, the app falls back to local OAuth, which can't open a browser in a container.) |
| `APP_USERNAME` | No | Basic-auth username (default `mla`). |
| `DRIVE_FOLDER_ID` | No | Override the destination Drive folder for images, Docs, and the library CSV. |
| `PORT` | No | Set automatically by Railway. |

> Note: generation runs are long (~10–15 min/chapter; a full textbook can run hours). Keep the service warm, and prefer a single instance — job progress lives in memory, though completed chapters always persist to Sheets and Drive.

## Why Deploy Textbook Generator on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Textbook Generator on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

That's all seven required sections (plus the optional Implementation Details) with no front-matter trap. Want me to drop this into the repo as `RAILWAY.md` (or merge it into `README.md`) and push it on a branch for a PR?

## Similar templates

- [Rocky Linux](https://railway.com/deploy/rocky-linux) — [Jul'26] Hosted Rocky Linux 9 workspace with SSH and persistent storage. 🚀
- [Foundry Virtual Tabletop](https://railway.com/deploy/X5tR6G) — A Self-Hosted & Modern Roleplaying Platform
- [Letta Code Remote](https://railway.com/deploy/letta-code-remote) — Run a Letta Code agent 24/7. No inbound ports, just deploy.

Open this page in a browser: https://railway.com/deploy/textbook-generator
