Skip to content

yoosuf/docket

Repository files navigation

Docket

Document Generation Service

Generate DOCX/PDF from versioned templates and dynamic JSON data.
Convention-based template discovery — drop a file, it's live. No code changes.

Python 3.12+ FastAPI Docker MIT 36 tests


✨ Features

  • Zero-code document types — Drop {type}_v{version}.docx into templates/ and it's immediately available via the API
  • Legacy .doc support — Old Word templates auto-convert to .docx via LibreOffice
  • PDF output — Seamless DOCX→PDF via LibreOffice (baked into the Docker image)
  • Versioned templates — Multiple versions coexist; latest is used unless a specific version is requested
  • RESTful API — Clean resource model (documents, document-types) with OpenAPI docs
  • No database — Metadata is encoded in filenames; everything lives on disk (swap out for S3/Postgres when you're ready)
  • Docker-native — Single docker compose up with LibreOffice included

🚀 Quick start

git clone https://github.com/yoosuf/docket.git
cd docket
docker compose up --build

Open http://127.0.0.1:8000/docs — interactive API docs are ready.

📄 Usage

Try it in one command:

./scripts/try_document.sh                     # invoice, docx
./scripts/try_document.sh quote pdf           # quote, pdf
./scripts/try_document.sh purchase_order pdf  # purchase_order, pdf

Or via curl:

curl -X POST http://127.0.0.1:8000/api/v1/documents \
  -H "Content-Type: application/json" \
  -d @docs/examples/invoice.json

Adding a new document type:

  1. Create a template (docxtpl-compatible .docx with Jinja2 placeholders)
  2. Name it {type}_v{version}.docx and drop it into templates/
  3. That's it — no code, no config, no restart

📚 Documentation

Document What's inside
docs/architecture.md Module layout, component & sequence diagrams, extension points
docs/design-decisions.md ADR-style rationale for key architectural choices
docs/production-readiness.md Migration guide: local disk → S3, no DB → Postgres, sync → job queues
docs/examples.md Ready-to-run samples for all 5 shipped document types

🧪 Tests

pytest

36 tests exercising template resolution, service orchestration, REST endpoints, and rendering — no mocks on the DOCX layer.

🏗 Architecture

Modular monolith — one domain (documents) in one folder:

app/
├── main.py           # Composition root (FastAPI app)
├── core/             # Config, errors, middleware
└── modules/
    └── documents/    # Router, service, repository, models

Full architecture docs at docs/architecture.md.

📦 Shipped templates

Type Template Version
Invoice invoice_v1.docx 1
Quote quote_v1.docx 1
Purchase Order purchase_order_v1.docx 1
Contract contract_v1.docx 1
Memo memo_v1.doc (legacy) 1

🛠 Tech stack

FastAPI · docxtpl (Jinja2-in-DOCX) · LibreOffice (PDF conversion) · Docker · Pydantic · Uvicorn

📜 License

MIT © 2026 Yoosuf


Status: POC — no production dependencies (no DB, no S3, no auth, no queues). Ready to evolve into a full document service — see the production-readiness guide.

About

Generate DOCX/PDF documents from versioned templates and dynamic JSON data. Convention-based template discovery — drop a file, it's live. No code changes. Built with FastAPI.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors