Skip to main content

18. Database-Backed Personas

Status: Accepted Date: 2025-07-06

Context

The Arcana application's character personas (e.g., "Sage," "Oracle") were originally implemented as hardcoded definitions within the application source code. This approach was rigid, requiring a developer to make code changes and redeploy the application simply to add or modify a persona's system prompt. This created a significant bottleneck for content updates and prevented user-level customization.

Decision

We will replace the hardcoded persona system with a database-backed model. All persona definitions, specifically their system prompts, will be stored in a PostgreSQL database. Users will be able to manage their own custom personas through a set of Telegram bot commands (e.g., /set_persona by replying to a message, /list_personas). The application will fetch the appropriate persona from the database for each user during a tarot reading session.

Consequences

Positive:

  • Flexibility & Customization: Users can create and manage their own unique personas, leading to a more personalized and engaging experience.
  • Maintainability: System prompts can be updated in the database without requiring a code change or application deployment, decoupling content from code.
  • Scalability: The system can support a virtually unlimited number of user-defined personas without impacting application performance.

Negative:

  • Increased Complexity: This introduces a dependency on the database for a core piece of application logic, adding another potential point of failure.
  • Data Management: Requires schema management for the new persona tables and logic to handle data access.
  • User Interface: Requires a new set of Telegram commands and a clear user interface to manage these custom personas.

Mitigation:

  • Robust Data Layer: Use our existing MikroORM setup to manage database schemas and migrations reliably. Implement a dedicated service to handle all persona-related database operations.
  • Clear Documentation: Provide clear, user-facing documentation on how to use the Telegram commands to manage custom personas.
  • Sensible Defaults: Ensure a set of well-defined default personas are always available for new users or for those who do not wish to create their own.