Database Architecture

Document: 16-database-architecture.md
Version: 1.0.0


Purpose

This document defines the database architecture and data modelling standards used across all Rundown projects.

The database is responsible for storing structured business data in a consistent, reliable, and scalable manner. It serves as the foundation for application logic, content relationships, and transactional operations.

This document establishes how data should be modelled, organized, and maintained throughout the lifecycle of a project.


Database Philosophy

The database should represent the business domain rather than the user interface.

Tables, relationships, and schemas should model real-world entities and processes instead of pages, components, or frontend layouts.

A well-designed database should remain stable even if the frontend is completely redesigned.


Standard Database

Rundown standardizes on:

PostgreSQL

Reasons include:


Responsibilities

The database owns:


Non-Responsibilities

The database should not own:

Binary assets belong in Cloudflare R2.


Data Modelling

Every table should represent a meaningful business entity.

Examples:

Avoid creating tables that exist solely to support a specific page or UI component.


Relationships

Relationships should accurately reflect business rules.

Examples:

Category
    │
    ├── Product
    │
    ├── Product
    │
    └── Product
Author
    │
    ├── Post
    │
    ├── Post
    │
    └── Post

Relationships should minimize duplication while maintaining clarity.


Normalization

Data should be normalized where appropriate.

Benefits include:

Denormalization should only be introduced when supported by measurable performance requirements.


Naming Standards

Database objects should follow the naming conventions defined in:

09-naming-conventions.md

Examples:

Tables:

products

order_items

blog_posts

Columns:

created_at

updated_at

product_name

user_id

Primary Keys

Every table should include a primary key.

Primary keys should:


Foreign Keys

Relationships between tables should use foreign keys to maintain referential integrity.

Avoid storing duplicate relationship data.


Timestamps

Every business table should include:

created_at

updated_at

Additional timestamps may be introduced when required.

Examples:


Soft Deletes

Soft deletes should be used only when business requirements justify retaining deleted records.

Examples:

Temporary or non-critical data may be permanently deleted when appropriate.


Indexing

Indexes should be added for:

Indexes improve performance but should be introduced deliberately to avoid unnecessary overhead.


Transactions

Database transactions should be used whenever multiple operations must succeed or fail together.

Examples:

Partial writes should be avoided.


Migrations

All schema changes must be version-controlled through migrations.

Direct manual changes to production databases are prohibited.

Migrations should be:


Backup Strategy

Every production database must be backed up regularly.

Backups should be:

A backup that cannot be restored should not be considered valid.


Performance

Database performance should prioritize:

Application performance issues should not automatically be solved by adding more database complexity.


Security

The database should:

Production credentials must never be exposed within application code.


Engineering Decision

Business-Oriented Data Model

Status: Accepted

Decision

Database schemas should model business entities rather than frontend implementation details.

Reasoning

This approach:


Database Checklist

Before introducing a new table or relationship, verify:


Summary

The database serves as the structured foundation of every Rundown application.

By modelling business concepts rather than frontend implementation, the database remains stable, scalable, and maintainable as applications evolve.