The Cosmere API database is designed to represent the complex relationships within Brandon Sanderson's Cosmere universe. The schema supports books, characters, worlds, magic systems, and their interconnections.
Worlds (1) ←→ (N) Series
Worlds (1) ←→ (N) Books
Worlds (1) ←→ (N) Characters
Worlds (1) ←→ (N) Magic Systems
Series (1) ←→ (N) Books
Books (N) ←→ (N) Characters (via BookCharacter)
Characters (N) ←→ (N) Characters (via CharacterRelationship)
Characters (N) ←→ (N) Magic Systems (via CharacterMagicSystem)
Shards (1) ←→ (N) ShardVessels
Represents the various planets and locations in the Cosmere.
Fields:
id(String, PK): Unique identifiername(String): World namedescription(Text): World descriptionsystem(String): Planetary systemis_habitable(Boolean): Whether the world is habitablemagic_systems_description(Text): Description of magic systemsnotable_features(Text): Notable features of the worldcreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestamp
Relationships:
- Has many Series
- Has many Books
- Has many Characters
- Has many Magic Systems
Represents book series within the Cosmere.
Fields:
id(String, PK): Unique identifiername(String): Series namedescription(Text): Series descriptionworld_id(String, FK): Reference to Worldplanned_books(Integer): Number of planned bookscurrent_books(Integer): Number of published booksstatus(Enum): ongoing, complete, planned, on_hiatusreading_order(Text): JSON string for reading ordercreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestamp
Relationships:
- Belongs to World
- Has many Books
Represents individual books in the Cosmere.
Fields:
id(String, PK): Unique identifiertitle(String): Book titleseries_id(String, FK): Reference to Seriesworld_id(String, FK): Reference to Worldpublication_date(Date): Publication datesummary(Text): Book summarypage_count(Integer): Number of pagesis_standalone(Boolean): Whether it's a standalone bookreading_order(Integer): Order within seriescreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestamp
Relationships:
- Belongs to Series
- Belongs to World
- Has many Characters (via BookCharacter)
Represents characters in the Cosmere.
Fields:
id(String, PK): Unique identifiername(String): Character namealiases(Array[String]): Array of alias namesworld_of_origin_id(String, FK): Reference to Worldspecies(String): Character speciesstatus(Enum): alive, dead, unknown, immortalbiography(Text): Character biographyappearance(Text): Physical appearancepersonality(Text): Personality descriptionabilities(Text): Character abilitiescreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestamp
Relationships:
- Belongs to World
- Has many Books (via BookCharacter)
- Has many Relationships (via CharacterRelationship)
- Has many Magic Systems (via CharacterMagicSystem)
Represents magic systems in the Cosmere.
Fields:
id(String, PK): Unique identifiername(String): Magic system nameworld_id(String, FK): Reference to Worlddescription(Text): System descriptionmechanics(Text): How the magic worksrequirements(Text): Requirements to uselimitations(Text): System limitationsis_investiture_based(Boolean): Whether it's investiture-basedrelated_systems(Text): JSON string of related systemscreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestamp
Relationships:
- Belongs to World
- Has many Characters (via CharacterMagicSystem)
Represents Shards of Adonalsium.
Fields:
id(String, PK): Unique identifiername(String): Shard nameintent(String): The Shard's intentstatus(Enum): whole, splintered, conjoined, unknowncurrent_vessel(String): Current vessel nameoriginal_vessel(String): Original vessel namedescription(Text): Shard descriptionperpendicularity(Text): Location of perpendicularitymagic_systems(Text): Associated magic systemsresidence(Text): Where the Shard residesis_combined(Boolean): Is this a combination of Shardscreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestamp
Relationships:
- Has many ShardVessels
Many-to-many relationship between Books and Characters.
Fields:
id(String, PK): Unique identifierbook_id(String, FK): Reference to Bookcharacter_id(String, FK): Reference to Characterrole(String): Character role in bookis_pov_character(Boolean): Is this a POV characterfirst_appearance(Boolean): Is this their first appearancenotes(Text): Additional notescreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestamp
Many-to-many relationship between Characters.
Fields:
id(String, PK): Unique identifiercharacter_id(String, FK): Reference to Characterrelated_character_id(String, FK): Reference to related Characterrelationship_type(Enum): family, romantic, friendship, enemy, mentor, student, ally, rival, otherdescription(Text): Relationship descriptionis_reciprocal(Boolean): Is this relationship mutualstrength(String): Relationship strengthnotes(Text): Additional notescreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestamp
Many-to-many relationship between Characters and Magic Systems.
Fields:
id(String, PK): Unique identifiercharacter_id(String, FK): Reference to Charactermagic_system_id(String, FK): Reference to Magic Systemuser_type(Enum): practitioner, student, former, potential, unknownproficiency_level(String): Skill levelis_active(Boolean): Is currently using this magicnotes(Text): Additional notescreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestamp
Represents vessels of Shards.
Fields:
id(String, PK): Unique identifiershard_id(String, FK): Reference to Shardvessel_name(String): Vessel namevessel_type(String): original, current, formerstart_date(String): When they became vesselend_date(String): When they stopped being vesseldescription(Text): Vessel descriptioncreated_at(DateTime): Creation timestampupdated_at(DateTime): Last update timestamp
The following indexes are created for performance:
- Primary keys on all tables
- Foreign key indexes on all relationship fields
- Name indexes on searchable fields (World.name, Character.name, etc.)
- Status indexes on enum fields
- Composite indexes for common query patterns
- All foreign key relationships are properly constrained
- Cascade delete rules are applied where appropriate
- Nullable foreign keys for optional relationships
- Enum values are validated at the database level
- Boolean fields have proper constraints
- String length limits are enforced
- Unique constraints on business keys where appropriate
- Composite unique constraints for junction tables
-
Get all characters in a book:
SELECT c.* FROM characters c JOIN book_characters bc ON c.id = bc.character_id WHERE bc.book_id = ?
-
Get all books in a series:
SELECT * FROM books WHERE series_id = ? ORDER BY reading_order
-
Get character relationships:
SELECT cr.*, c1.name as character_name, c2.name as related_name FROM character_relationships cr JOIN characters c1 ON cr.character_id = c1.id JOIN characters c2 ON cr.related_character_id = c2.id WHERE cr.character_id = ?
-
Get magic system users:
SELECT c.* FROM characters c JOIN character_magic_systems cms ON c.id = cms.character_id WHERE cms.magic_system_id = ? AND cms.is_active = true
- Initial Migration: Creates all tables with proper relationships
- Data Migration: Imports data from JSON files
- Index Optimization: Adds performance indexes
- Constraint Validation: Ensures data integrity
- Full-text Search: Consider adding full-text search capabilities
- Audit Trail: Add audit tables for tracking changes
- Soft Deletes: Implement soft delete functionality
- Caching: Add caching layer for frequently accessed data
- Partitioning: Consider table partitioning for large datasets