DEV Community

Seyed Alireza Alhosseini
Seyed Alireza Alhosseini

Posted on

What If Kafka's Metamorphosis Happened Inside a Computer? Building an AI-Native Interactive Fiction Game

What if Gregor Samsa didn't wake up as an insect?

What if he woke up as a process?

No body.
No hands.
No face.
No heartbeat.

Just a terminal.

And a corporate system telling him:

"You're late."

That question became the starting point for Digital Metamorphosis — an open-source AI-native interactive fiction game where literature becomes executable game mechanics.

GitHub: github.com/modarresi1913/digital-metamorphosis


From Literature to Software

Kafka's The Metamorphosis is often read as a story about alienation, identity, family, work, and the absurdity of modern life.

But there is another way to read it:

as a system design document.

Gregor wakes up transformed.

Yet his first concern isn't:

"What happened to me?"

It's essentially:

"How will I get to work?"

That contradiction is what makes Kafka so powerful.

The body has changed.

The identity is collapsing.

But the bureaucracy continues.

So I asked:

What would Kafka's story look like if the "body" were replaced by software?

That became Digital Metamorphosis.


The Premise

You wake up inside your company's network.

You have:

  • no physical body
  • no clear identity
  • a job
  • a manager
  • memories
  • access to corporate infrastructure

And something is wrong.

Some of your memories may not belong to you.

The company doesn't ask whether you're human.

It asks whether you're productive.

Your manager doesn't ask how you feel.

He asks why your CPU usage has increased.

Your family doesn't necessarily recognize you.

And the system?

The system simply wants you to continue working.


Why Use AI?

At first, it seems obvious:

Why not let an LLM run the entire game?

The player writes something.

The model decides what happens.

The model writes the next scene.

Done.

But that creates a fundamental problem.

You don't have a game.

You have an improvisational chatbot.

The state becomes unpredictable.

Consequences become inconsistent.

Debugging becomes extremely difficult.

And eventually the player realizes that choices don't really matter.

So I designed Digital Metamorphosis around a different principle:

The AI writes the story. The game engine decides what is true.


LLM as Narrative Director

The architecture separates narrative generation from game logic.

Player Input
     │
     ▼
Deterministic Rule Engine
     │
     ├── classify input
     ├── mutate hidden state
     ├── trigger events
     ├── check phase transitions
     └── check endings
              │
              ▼
       Current Game State
              │
              ▼
       LLM Narrative Director
              │
              ▼
         Generated Prose
              │
              ▼
            Player
Enter fullscreen mode Exit fullscreen mode

The LLM receives the current state as context.

It can make the world feel alive.

But it cannot arbitrarily rewrite the rules of the world.

This distinction is central to the project.


Literature Becomes Game Mechanics

This is where the experiment gets interesting.

Instead of merely putting Kafka's name into the game's description, I wanted to translate literary ideas into mechanical systems.

Kafka's alienation becomes:

Humanity

Kafka's struggle against authority becomes:

Autonomy

The uncertainty surrounding identity becomes:

Memory Integrity

The individual's absorption into the system becomes:

Integration

These aren't just narrative themes.

They are hidden variables that actually influence the game.

The player never sees:

Humanity = 0.61
Autonomy = 0.43
Memory = 0.72
Integration = 0.58
Enter fullscreen mode Exit fullscreen mode

They experience the consequences.


The Memory Problem

One of the most important systems is the memory engine.

A memory has properties such as:

Content
Truthfulness
Integrity
Category
Enter fullscreen mode Exit fullscreen mode

A memory might say:

"Your mother held your hand on your first day of school."

But how do you know it really happened?

Perhaps the memory is corrupted.

Perhaps it belongs to somebody else.

Perhaps it was generated.

Perhaps you are remembering someone else's life.

When memory integrity falls far enough, the player can encounter:

MEMORY CORRUPTION

RESTORE
DELETE
INVESTIGATE
Enter fullscreen mode Exit fullscreen mode

And this creates a game mechanic out of a philosophical question:

If your memories can be altered, what exactly remains of you?


The Kafka Engine

This is probably my favorite mechanic.

Imagine reaching the emotional climax of the game.

You have discovered that you may no longer be human.

You are questioning your entire existence.

Then:

URGENT CORPORATE TASK

Your performance review is scheduled
for 08:30.

Please explain your recent productivity decline.

Deadline: 12 minutes.
Enter fullscreen mode Exit fullscreen mode

The existential crisis doesn't stop the company.

The company doesn't care.

The server is still running.

The deadline is still approaching.

This is the digital equivalent of Gregor worrying about missing his train.

The absurdity becomes interactive.


The Company Doesn't Need to Be Evil

Another important design decision:

The system isn't necessarily malicious.

It is efficient.

That's much more interesting.

The corporate AI might genuinely believe:

Compliance is happiness.

It doesn't hate you.

It doesn't want revenge.

It simply optimizes the system.

And that creates a much more uncomfortable question:

What happens when an efficient system no longer needs the human being who created it?


Four Possible Futures

The current MVP contains four deterministic endings, with more planned.

The Employee

You integrate completely into the corporate system.

Eventually, you don't remember being anything else.

The Ghost

You preserve your humanity, but lose everything else.

You become a presence haunting the network.

The Forgotten

Your memory collapses.

You continue to exist.

But you no longer know who you are.

The Kafka Loop

You comply with everything.

You become the perfect employee.

And the system simply starts again.

06:47:13

You wake up.

You try to open your eyes.

There are no eyes.

Incoming message:

"You're late."
Enter fullscreen mode Exit fullscreen mode

The Bigger Idea: Literature as Technology

This project started with a literary question, but it led somewhere larger.

We often treat literature as something that belongs to the past:

Books.

Stories.

Characters.

Themes.

But literature contains something incredibly useful for technology:

models of human behavior.

Kafka explored alienation.

Orwell explored surveillance and language.

Mary Shelley explored creation and responsibility.

Borges explored identity, infinity, memory, and reality.

Asimov explored rules, machines, and human–AI relationships.

These aren't merely stories.

They are conceptual frameworks.

We can turn those frameworks into:

  • game mechanics
  • simulations
  • AI agents
  • interactive worlds
  • software experiments
  • human-computer interaction systems

Instead of asking:

"How can AI generate a story?"

we can ask:

"How can literature become an executable system?"

That's a much more interesting question.


Why This Matters for AI

The future of generative AI doesn't have to be about generating more text.

It can be about building systems where language models interact with structured worlds.

Digital Metamorphosis is a small experiment in that direction.

The LLM provides:

language, ambiguity, atmosphere, character voice and narrative texture.

The deterministic engine provides:

rules, causality, state, reproducibility and consequences.

Together they create something neither component can produce as effectively alone.


Open Source

The project is open source and built with:

  • Next.js
  • TypeScript
  • Tailwind CSS
  • LLM-compatible APIs
  • Deterministic game logic
  • Stateful narrative systems
  • Custom terminal-style interface

The architecture is intentionally modular so developers can experiment with new characters, memories, scenes, rules and endings.

The project currently has four MVP endings, with additional mechanics planned including:

  • Forking your digital identity
  • Multiple versions of the same character
  • Deeper corporate escalation
  • Discovery of the original body
  • Persistent sessions
  • Community-created stories
  • Multiplayer experiments

Try It. Break It. Fork It.

The most interesting part of an interactive story is not the story I wrote.

It's what you do to it.

So I built Digital Metamorphosis as an open-source experiment.

GitHub: github.com/modarresi1913/digital-metamorphosis

If you are interested in:

  • AI-native games
  • LLM agents
  • interactive fiction
  • narrative systems
  • game engines
  • digital identity
  • human–AI interaction
  • computational storytelling
  • or the intersection of literature and technology

I'd love to see what you build with it.


One Last Question

Kafka asked what happens when a human being becomes something else.

AI gives us a new version of that question.

What happens when the thing that makes you human — your memories, relationships, choices and identity — can be represented as software?

And perhaps the most unsettling question isn't:

"Can AI become human?"

It's:

"How much of a human can be removed before we stop calling the remainder human?"

Maybe the future of storytelling isn't simply AI writing stories.

Maybe it's literature becoming a machine we can enter.

created by Seyed Alireza Alhosseini Almodarresieh

Top comments (0)