Martijn BendersFabylon →
Chapter 2

Inside the Machine

Martijn Benders delves into the technical foundations of Fabylon Bookmaker, revealing the architectural choices that power this unique tool for poets.

Q

Martijn, thank you for taking the time to speak with us. We've discussed the vision behind Fabylon Bookmaker, and now I'd love to peek "inside the machine." Can you give us a high-level overview of how the application is architected?

Martijn

Of course. At its core, Fabylon Bookmaker is designed as a modular system. I knew from the start that I wanted to avoid a monolithic structure. The entire process of turning a manuscript into a publishable book, especially with the nuances of poetry, involves distinct stages. It felt natural to separate these stages into their own software modules. This separation of concerns is key. We have a module for text ingestion and cleaning, another for the core stanza detection, one for formatting and layout, and a final one for generating the e-book files, specifically for Amazon's KDP platform. This modularity means I can work on improving one part of the system without worrying about breaking everything else. It also opens up the possibility of swapping out modules in the future if better technologies or algorithms emerge.

The communication between these modules is handled through a central orchestration pipeline. I think of it as a conveyor belt in a factory. The raw manuscript gets on at one end, and each module performs its specific task as it moves along. The data that passes between them is strictly defined using typed dataclasses. This is a concept from Python that I find incredibly important. It’s like having a very specific, non-negotiable blueprint for the information. Every piece of data—a line of text, a stanza, a page break—has to conform to a predefined structure. This eliminates a huge category of potential bugs and makes the entire system more robust and predictable. You know exactly what kind of data you're receiving at each step, and what you're expected to pass on.

Q

That’s a fascinating analogy. You mentioned typed dataclasses. For our readers who might not be developers, could you elaborate on why that’s so crucial for a project like this? It sounds like it adds a layer of rigidity, which some might see as counterintuitive for a creative tool.

Martijn

It’s a fair question. It might seem rigid, but it’s the kind of rigidity that fosters creativity by providing a stable foundation. When you’re building a house, you want the foundation to be absolutely solid and unchanging. It’s the same with software. The dataclasses define the "shape" of the information. For instance, a `Line` dataclass might have attributes for the text itself, its line number, and whether it’s part of a stanza. A `Stanza` dataclass would then be a collection of these `Line` objects. By enforcing this structure, I don’t have to constantly check if the data is in the right format. I can trust that a `Stanza` object will always contain `Line` objects, and not, say, a random string of text or a number.

This "trust" is the important part. It frees me up to focus on the creative and complex parts of the problem, like the stanza detection algorithm itself. I’m not bogged down in defensive programming, writing endless checks to handle malformed data. The structure becomes an implicit contract within the software. It makes the code cleaner, easier to read, and, most importantly, easier to reason about. For a solo developer working on a complex project, that clarity is priceless. It’s a bit like poetic form, actually. The constraints of a sonnet or a villanelle don’t stifle creativity; they channel it, forcing you to be more inventive within a defined space. The typed dataclasses are my software sonnets.

Q

I love that comparison. You also mentioned Python and PyQt5 as your technologies of choice. Python is renowned for its readability, but what led you to choose it and PyQt5 specifically for the graphical user interface?

Martijn

Python was a natural choice for me. As a poet, I’m drawn to clarity and expressiveness, and Python’s syntax has that quality. It reads almost like plain English, which aligns with my belief that code should be as understandable as possible. But beyond its elegance, Python has a vast and mature ecosystem of libraries. For a project like Fabylon, which touches on natural language processing, file manipulation, and data structuring, having access to powerful, well-tested libraries is a massive advantage. It allows me to stand on the shoulders of giants, so to speak.

As for the user interface, the choice of PyQt5 was more deliberate. I needed to build a desktop application, not a web app. The process of book formatting is intensive and requires a lot of local file interaction, which is much better handled by a native application. PyQt is a set of bindings for the Qt application framework, which is a very powerful, cross-platform toolkit for creating graphical user interfaces. It’s robust and has been used to build all sorts of complex applications. While it has a steeper learning curve than some other GUI toolkits, it gives me a fine-grained level of control over the user experience. I wanted the interface to be clean, functional, and unobtrusive, allowing the writer’s work to take center stage. PyQt5 provides the tools to build that kind of professional-grade, responsive interface that doesn’t get in the way of the creative process.

Q

It sounds like every technical decision was deeply intertwined with the overall philosophy of the tool. Looking at the orchestration pipeline, could you walk us through how it handles a typical manuscript, from initial import to the final EPUB file?

Martijn

Certainly. Let’s say a poet has finished their manuscript in a Word document. The first step is ingestion. The user points the application to the file, and the first module gets to work. Its job is to extract the raw text, and this is often trickier than it sounds. It has to deal with different encodings, special characters, and the "cruft" that word processors often insert. The goal is to get a clean, plain text representation of the work. This clean text is then passed to the next stage as a series of `Line` objects.

This is where the magic happens: the stanza detection module. This is the heart of Fabylon. It iterates through the lines, applying a set of heuristics and algorithms I’ve developed to identify the breaks between stanzas. It looks for patterns in line spacing, indentation, and other subtle cues that poets use to structure their work. It’s not just looking for a double-space. It’s a more nuanced analysis. Once it identifies a stanza, it groups the corresponding `Line` objects into a `Stanza` object. The output of this module is a structured representation of the entire poem, a list of `Stanza` objects.

This structured data then moves to the formatting and layout module. This module takes the abstract `Stanza` objects and translates them into a concrete layout for the book page. It considers things like font size, line spacing, and how to handle stanzas that break across pages. Finally, the layout information is passed to the EPUB generation module. This module takes the formatted content and packages it into a valid EPUB file, complete with the necessary metadata, table of contents, and all the other bits and pieces that Amazon KDP requires. The end result is a file that can be uploaded directly to KDP, ready for publishing. Each step is a transformation, taking unstructured data and progressively adding structure and meaning until you have a finished product.