Database Schema
This section provides detailed information about the ToDoWrite Models database schema.
Schema Overview
The ToDoWrite Models implementation uses:
33 Total Tables: 12 model tables + 21 association tables
Integer Primary Keys: Auto-incrementing IDs (1, 2, 3, …)
Proper Foreign Keys: Referential integrity across all relationships
Database Support: SQLite and PostgreSQL
Schema Files
The complete database schema is available in the following files:
SQL Schema
The SQL schema file contains complete table definitions for SQLite:
lib_package/src/todowrite/core/schemas/todowrite_models_schema.sql
-- ToDoWrite Models Schema
-- Generated on: 2025-11-18T21:16:05.919141
-- Total tables: 33 (12 model tables + 21 association tables)
-- Database support: SQLite3 (this schema) + PostgreSQL
-- Note: All id fields are PRIMARY KEY, NOT NULL, and autoincrementing
-- - SQLite: INTEGER PRIMARY KEY AUTOINCREMENT
-- - PostgreSQL: id SERIAL PRIMARY KEY (recommended)
-- Generates: integer NOT NULL PRIMARY KEY DEFAULT nextval('table_name_id_seq'::regclass)
-- Modern alternative: id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
-- Strict alternative: id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY
--
-- Foreign Key Constraints Pattern:
-- All association tables follow these conventions:
-- Table names: model1_model2 (alphabetical order, singular)
-- Column names: model_name_id (referencing model's id field)
-- Foreign keys: model_name_id INTEGER REFERENCES model_name(id)
-- Example: goals_phases (goal_id INTEGER REFERENCES goals(id), phase_id INTEGER REFERENCES phases(id))
-- This ensures referential integrity across all relationships in the ToDoWrite hierarchy.
CREATE TABLE acceptance_criteria (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR NOT NULL,
description TEXT,
status VARCHAR NOT NULL,
progress INTEGER,
started_date VARCHAR,
completion_date VARCHAR,
owner VARCHAR,
severity VARCHAR,
work_type VARCHAR,
assignee VARCHAR,
extra_data TEXT,
created_at VARCHAR NOT NULL,
updated_at VARCHAR NOT NULL
);
CREATE TABLE acceptance_criteria_interface_contracts (
acceptance_criteria_id INTEGER REFERENCES acceptance_criteria(id),
interface_contract_id INTEGER REFERENCES interface_contracts(id)
);
CREATE TABLE acceptance_criteria_labels (
acceptance_criteria_id INTEGER REFERENCES acceptance_criteria(id),
label_id INTEGER REFERENCES labels(id)
);
CREATE TABLE commands (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title VARCHAR NOT NULL,
description TEXT,
JSON Schema
The JSON schema provides detailed model definitions for validation:
lib_package/src/todowrite/core/schemas/todowrite_models.schema.json
{
"title": "ToDoWrite Models Schema",
"description": "JSON Schema for ToDoWrite 12-layer hierarchy",
"version": "1.0.0",
"models": {
"Goal": {
"table_name": "goals",
"columns": {
"id": {
"type": "INTEGER",
"nullable": false,
"primary_key": true,
"autoincrement": true
},
"title": {
"type": "VARCHAR",
"nullable": false,
"primary_key": false,
"autoincrement": "auto"
},
"description": {
"type": "TEXT",
"nullable": true,
"primary_key": false,
"autoincrement": "auto"
},
"status": {
"type": "VARCHAR",
"nullable": false,
"primary_key": false,
Model Tables
Each of the 12 ToDoWrite Models has its own table:
goals - Project objectives
concepts - Abstract ideas
contexts - Background information
constraints - Technical/business constraints
requirements - Functional requirements
acceptance_criteria - Definition of done criteria
interface_contracts - API contracts
phases - Project phases
steps - Individual steps
tasks - Specific tasks
sub_tasks - Task breakdowns
commands - Executable commands
labels - Tagging system
Association Tables
Many-to-many relationships are handled through join tables following the pattern:
-- Example: goals and tasks relationship
CREATE TABLE goals_tasks (
goal_id INTEGER NOT NULL,
task_id INTEGER NOT NULL,
FOREIGN KEY (goal_id) REFERENCES goals(id),
FOREIGN KEY (task_id) REFERENCES tasks(id),
PRIMARY KEY (goal_id, task_id)
);
Common association tables include:
goals_tasks- Goals ↔ Taskstasks_labels- Tasks ↔ Labelscommands_labels- Commands ↔ Labelsphases_steps- Phases ↔ Stepssteps_tasks- Steps ↔ Taskstasks_sub_tasks- Tasks ↔ SubTasks
And many more to support the complete hierarchy.
Foreign Key Constraints
All association tables maintain referential integrity:
Parent-Child: Direct hierarchy relationships
Many-to-Many: Cross-layer associations
Cascading: Proper cascade rules for data consistency
Schema Validation
The schema is validated using:
JSON Schema: Data structure validation
SQLAlchemy ORM: Model definition validation
Database Constraints: Referential integrity checks
For programmatic schema validation, see ToDoWrite Models API Reference.