Skip to content

cocoatype/barc-generator

Repository files navigation

Barc Generator

Swift Platform License Docker

A quick barcode generation tool built with Swift, for the web on both server and client.

Check out the live version at https://generator.getbarc.app/

🏗️ Architecture

Barc Generator is a modular monorepo with four separate pieces:

┌─────────────────────────────────────────┐
│     Frontend (Preact + TypeScript)      │
│   Web interface with WASM integration   │
└─────────────────────────────────────────┘
                    │
          ┌─────────┴──────────┐
          │                    │
   ┌──────▼──────┐    ┌────────▼──────┐
   │ WebAssembly │    │    Server     │
   │ (SwiftWasm) │    │ (Hummingbird) │
   └──────┬──────┘    └────────┬──────┘
          │                    │
          └────────┬───────────┘
                   │
    ┌──────────────▼──────────────┐
    │    Core Swift Modules       │
    │  Reusable barcode libraries │
    └─────────────────────────────┘

📁 Framework Modules

This is a set of Swift frameworks, largely taken directly from the Barc iOS app and built to compile on Swift for Linux and Swift Embedded (for SwiftWasm).

  • Barcodes: Standard barcode models, defining supported formats
  • BarcodeEncoding: Encodes barcode values into a representation suitable for rendering
  • BarcodeImageRendering: Renders encoded barcodes to SVG and PNG formats
  • BarcodeFormats: Helper models for communicating between SwiftWasm and server-side Swift
  • Geometry and Base64: Replacement libraries for functionality missing in Embedded Swift

🕸️ WebAssembly

A WASM bundle for running Swift code in the browser. It provides a small shim between user input and the framework modules. WASM code doesn't naturally have ways to send data like strings between JavaScript and non-JavaScript code (like our Swift code), so this project handles that conversion.

⚙️ Server

A server-side Swift application built with the Hummingbird framework. It's responsible for hosting the frontend, as well as producing exported SVG and PNG files for download.

🪟 Frontend

The SwiftWasm code is only used to calculate and render the barcode displayed to the user. All of the rest of the user-facing UI is done in this project, built with Preact and Vite.

📦 Hosting

This project is built and hosted as a Docker image. Building is done in multiple stages:

  • build-backend: Builds the Hummingbird server
  • build-wasm: Builds the WASM bundle and runs the Binaryen optimizer to optimize bundle size
  • build-frontend: Builds the Vite project, including the output of build-wasm
  • Final: Creates a minimal runtime image for the server with necessary dependencies

📄 License

This project is licensed under the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later).

See LICENSE for the full license text.

About

A web-based barcode generator, built with SwiftWasm and Preact

Resources

License

Stars

Watchers

Forks

Packages