# Themis Music Shield — AI Music Copyright Protection System

## Proposal: Comprehensive Music Originality Verification & Legal Risk Mitigation

---

## The Problem

Oshun generates music at scale — through Calliope (AI artists), Euterpe (music
production), Isis (generative factory), and Nous (audio AI). Every generated
track is a potential copyright liability. A single infringement lawsuit can cost
$150,000+ per work in statutory damages (US Copyright Act §504), destroy brand
trust, and trigger platform-wide takedowns.

Current AI music generators (Suno, Udio) are already facing RIAA lawsuits
alleging systematic reproduction of copyrighted material. The legal landscape is
hostile and precedent is being set _right now_. We cannot afford to be reactive
— we must build the most comprehensive originality verification system in the
industry, integrated into every music generation pipeline, operating as an
immovable gate between generation and publication.

### Why "As Good as Humanly Possible" Matters

- **Melodic plagiarism** is the #1 litigation vector. The "Blurred Lines"
  verdict ($5.3M) established that even _feel_ can be actionable. The "Dark
  Horse" case ($2.8M, later reversed) showed that short melodic fragments
  trigger lawsuits even when the legal outcome is uncertain. The litigation cost
  alone is destructive.
- **AI memorization** is a proven phenomenon. Large language models and music
  models demonstrably memorize and reproduce training data verbatim. We must
  assume our generation models can and will reproduce copyrighted material
  unless actively prevented.
- **Scale amplifies risk**. If we generate 10,000 tracks/day and 0.1% contain
  infringing material, that's 10 potential lawsuits per day. At scale, even tiny
  false-negative rates are catastrophic.

---

## System Architecture Overview

```
┌─────────────────────────────────────────────────────────────────────┐
│                    MUSIC GENERATION PIPELINE                        │
│  (Calliope / Euterpe / Isis / Nous / any generation source)        │
└──────────────────────────┬──────────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────────────┐
│                   THEMIS MUSIC SHIELD GATE                          │
│                                                                     │
│  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌──────────────┐ │
│  │   Melodic    │ │  Harmonic   │ │  Rhythmic   │ │   Spectral   │ │
│  │  Similarity  │ │  Similarity │ │  Similarity │ │  Similarity  │ │
│  │   Engine     │ │   Engine    │ │   Engine    │ │   Engine     │ │
│  └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬───────┘ │
│         │               │               │               │          │
│  ┌──────┴──────┐ ┌──────┴──────┐ ┌──────┴──────┐ ┌─────┴────────┐ │
│  │   Lyric     │ │   Vocal     │ │  Structural │ │   Audio      │ │
│  │  Similarity │ │  Similarity │ │  Similarity │ │ Fingerprint  │ │
│  │   Engine    │ │   Engine    │ │   Engine    │ │   Engine     │ │
│  └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────┬───────┘ │
│         │               │               │               │          │
│         └───────────┬───┴───────┬───────┴───────────────┘          │
│                     │           │                                   │
│              ┌──────▼──────┐ ┌──▼──────────────┐                   │
│              │    Risk     │ │   Provenance    │                   │
│              │   Scoring   │ │   Audit Trail   │                   │
│              │   Engine    │ │                  │                   │
│              └──────┬──────┘ └──────┬──────────┘                   │
│                     │               │                               │
│              ┌──────▼───────────────▼──────┐                       │
│              │     Decision Engine          │                       │
│              │  PASS │ FLAG │ REJECT │ HOLD │                       │
│              └──────┬──────────────────────┘                       │
│                     │                                               │
└─────────────────────┼───────────────────────────────────────────────┘
                      │
          ┌───────────┼───────────┐
          ▼           ▼           ▼
     ┌─────────┐ ┌─────────┐ ┌──────────┐
     │  PASS   │ │  FLAG   │ │  REJECT  │
     │ Publish │ │ Human   │ │ Auto-    │
     │         │ │ Review  │ │ Regen    │
     └─────────┘ └─────────┘ └──────────┘
```

---

## Core Technology Pillars

### 1. Melodic Similarity Engine (`@themis/melodic-analysis`)

Melody is the most legally protected element of music. This is the single most
critical subsystem.

#### 1.1 Pitch Sequence Extraction

- **Monophonic melody extraction** — Isolate the dominant melodic line from
  polyphonic audio using pYIN (probabilistic YIN), CREPE, or SPICE neural pitch
  trackers. Extract fundamental frequency (f0) contours at frame-level
  resolution (10ms frames).
- **Polyphonic melody extraction** — For tracks with multiple melodic lines
  (harmonies, countermelodies), extract all salient pitch streams using
  multi-pitch estimation (DeepSalience, BasicPitch). Each stream is analyzed
  independently.
- **MIDI-level quantization** — Convert continuous pitch contours to discrete
  note events with onset, offset, pitch (MIDI number), and velocity. Apply
  adaptive quantization that respects the track's tempo grid while preserving
  expressive timing.
- **Vocal melody isolation** — Use source separation (Demucs, HTDemucs) to
  isolate vocal tracks before melody extraction, since vocal melodies are the
  primary litigation target.
- **Instrumental melody extraction** — Separately extract lead instrument
  melodies (guitar solos, synth leads, piano riffs) which are independently
  protectable.

#### 1.2 Melodic Contour Analysis

- **Parsons Code representation** — Encode melodies as Up/Down/Repeat sequences
  (e.g., `*UUDDUDDR`). This captures the gross contour shape and enables rapid
  pre-filtering before expensive comparison. Parsons codes are
  transposition-invariant by definition.
- **Interval sequence representation** — Encode melodies as sequences of
  intervals in semitones (e.g., `+2, +2, +1, -2, -2, -1, -2`). This is
  transposition-invariant and more precise than Parsons coding.
- **Relative pitch encoding** — Normalize all melodies to start on pitch 0 and
  express subsequent notes as cumulative intervals. Eliminates key dependency
  entirely.
- **Contour complexity scoring** — Measure the entropy/complexity of a melodic
  contour. Simple contours (stepwise, narrow range) are more likely to match
  existing works by chance; complex contours are stronger evidence of copying
  when matched.
- **Segment-level contour comparison** — Compare contours at multiple
  granularities: phrase-level (8-16 bars), motif-level (1-4 bars), and
  fragment-level (3-8 notes). Different match lengths have different legal
  significance.

#### 1.3 N-gram Melodic Matching

- **Pitch n-gram extraction** — Extract all contiguous pitch subsequences of
  length n (typically n = 5 through 12) from both the query melody and the
  reference database. Store as hash tables for O(1) lookup.
- **Interval n-gram matching** — Same as above but using interval sequences
  rather than absolute pitches. This is transposition-invariant — the same
  melody in C major and E♭ major produces identical interval n-grams.
- **Weighted n-gram scoring** — Not all n-gram matches are equal:
  - Matches in the chorus/hook carry 3x weight (hooks are the most protectable
    and recognizable element)
  - Matches at phrase boundaries carry 2x weight (beginnings and endings of
    melodic phrases are more memorable)
  - Matches in verses carry 1x weight
  - Matches in transitions/fills carry 0.5x weight
- **Common melody filtering** — Maintain a database of melodic fragments that
  are so common they are considered public domain or unprotectable (e.g.,
  do-re-mi, pentatonic scale runs, standard blues licks, Alberti bass patterns).
  Filter these from match results to reduce false positives.
- **Rhythmically-aware n-grams** — Encode both pitch AND duration in n-grams
  (e.g., `C4:q, D4:e, E4:e` = C quarter note, D eighth note, E eighth note). A
  melody with the same pitches but entirely different rhythm is a much weaker
  match.

#### 1.4 Similarity Metrics

- **Edit distance (Levenshtein)** — Minimum number of insertions, deletions, and
  substitutions to transform one melody into another. Normalized by length for
  cross-length comparison.
- **Dynamic Time Warping (DTW)** — Elastic matching that handles tempo
  variations, rubato, and slight timing differences. Essential for comparing
  melodies performed at different tempos or with different rhythmic feels.
- **Longest Common Subsequence (LCS)** — Finds the longest shared melodic
  fragment allowing gaps. A long LCS between two melodies is strong evidence of
  similarity even if surrounding material differs.
- **Smith-Waterman local alignment** — Adapted from bioinformatics. Finds the
  best local alignment between two melodies, identifying the region of highest
  similarity. Especially useful when one melody is embedded within a longer
  work.
- **Cosine similarity on pitch histograms** — Compare the statistical
  distribution of pitches (pitch class profiles). Two melodies using the same
  notes in the same proportions score high even if the ordering differs. Useful
  as a fast pre-filter.
- **Earth Mover's Distance on contour features** — Measure the "work" required
  to transform one melodic contour distribution into another. Captures global
  shape similarity.

#### 1.5 Transposition & Tempo Invariance

- **All-key comparison** — For every query melody, generate all 12
  transpositions and compare against the reference database. Since
  interval-based representations are inherently transposition-invariant, this is
  handled implicitly for interval n-grams but must be explicit for absolute
  pitch comparisons.
- **Tempo normalization** — Normalize all melodies to a canonical tempo (120
  BPM) before comparison. This ensures that the same melody played at 80 BPM and
  140 BPM produces the same comparison result.
- **Mode-invariant comparison** — The same melody in major and natural minor
  (e.g., "Happy Birthday" in C major vs. A minor) should be detected. Use
  interval sequences modulo mode to capture this.
- **Rhythmic augmentation/diminution detection** — Detect when a melody has been
  rhythmically doubled (augmented) or halved (diminished) in duration while
  preserving pitch content.

#### 1.6 Reference Database Integration

- **Proprietary melody database** — Index millions of melodies extracted from
  commercially released music. Sources: MusicBrainz metadata, AcoustID
  fingerprints, licensed melody databases (e.g., MIDI databases, sheet music
  repositories).
- **Public domain melody corpus** — Separately index all known public domain
  melodies (folk songs, hymns, classical themes, traditional music from all
  cultures) so that matches against public domain works can be automatically
  cleared.
- **Real-time ingestion** — As new commercially released music appears (via
  chart tracking, release monitoring, Content ID partner feeds), automatically
  extract and index its melodies within 24 hours of release.
- **Cultural melody databases** — Index melodies from non-Western traditions
  (ragas, maqamat, gamelan scales, West African melodic patterns, Chinese
  pentatonic traditions) to avoid inadvertent appropriation claims.

---

### 2. Harmonic Similarity Engine (`@themis/harmonic-analysis`)

Chord progressions have weaker copyright protection than melodies (the I-V-vi-IV
progression is used in thousands of songs and is not protectable), but unusual
harmonic sequences combined with other similar elements can strengthen an
infringement claim.

#### 2.1 Chord Progression Extraction

- **Audio-to-chord transcription** — Extract chord labels from audio using
  neural chord recognition models (e.g., BTC, HarmonyTransformer). Output chord
  symbols at beat or half-beat resolution.
- **Roman numeral analysis** — Convert chord progressions to Roman numeral
  notation relative to the detected key (e.g., C-Am-F-G → I-vi-IV-V). This
  enables key-invariant comparison.
- **Extended chord vocabulary** — Recognize not just triads (major/minor) but
  7ths, 9ths, 11ths, 13ths, sus chords, augmented, diminished, altered
  dominants, polychords, and slash chords. The specificity of unusual chord
  voicings increases protectability.
- **Harmonic rhythm extraction** — Capture not just which chords appear but when
  they change. The rhythmic placement of chord changes is part of the musical
  identity.

#### 2.2 Harmonic Similarity Comparison

- **N-gram chord progression matching** — Extract chord progression n-grams (n =
  4 through 8) and compare against the reference database.
- **Common progression filtering** — Maintain an exhaustive database of
  non-protectable progressions:
  - I-V-vi-IV (most common pop progression)
  - I-IV-V-I (basic tonal cadence)
  - i-VII-VI-VII (Andalusian cadence)
  - I-vi-IV-V (50s progression / "Heart and Soul")
  - vi-IV-I-V (modern pop variant)
  - 12-bar blues (I-I-I-I-IV-IV-I-I-V-IV-I-V)
  - ii-V-I (jazz standard cadence)
  - Hundreds more cataloged common progressions
  - Any progression appearing in 50+ commercially released songs is
    automatically classified as non-protectable
- **Harmonic function comparison** — Compare progressions at the level of
  harmonic function (tonic/subdominant/dominant) rather than specific chords.
  This captures the deeper harmonic logic.
- **Modulation pattern comparison** — Detect and compare key changes
  (modulations). The specific pattern of modulations through a song is a more
  distinctive fingerprint than any single progression within a key.
- **Voice leading comparison** — Compare the specific voice leading (how
  individual notes move between chords) rather than just chord labels. Two songs
  using I-V-vi-IV with identical voice leading are more similar than two songs
  using the same progression with different voicings.

#### 2.3 Harmonic Protectability Scoring

- **Uniqueness scoring** — Score each chord progression against the reference
  database. Progressions found in fewer existing songs receive higher
  protectability scores.
- **Complexity weighting** — More complex harmonic language (jazz harmony,
  chromaticism, non-functional harmony) is more likely to be protectable because
  it's less likely to arise independently.
- **Context-dependent scoring** — A I-V-vi-IV progression alone is not
  protectable, but I-V-vi-IV with a specific bass line, specific voicing, and
  specific rhythm might be.

---

### 3. Rhythmic Similarity Engine (`@themis/rhythmic-analysis`)

Rhythmic patterns have the weakest copyright protection of all musical elements,
but distinctive rhythmic signatures (drum breaks, beat patterns) can be
protectable, especially when sampled.

#### 3.1 Beat & Rhythm Extraction

- **Beat grid detection** — Extract the metrical grid (downbeats, beats,
  subdivisions) using joint beat/downbeat tracking models (madmom, BeatNet).
- **Drum pattern transcription** — Extract drum patterns from audio using
  automatic drum transcription. Decompose into kick, snare, hi-hat, and other
  percussion elements on a quantized grid.
- **Rhythmic motif extraction** — Identify repeated rhythmic patterns (1-4 bar
  loops) and extract them as binary onset patterns on a 16th-note or 32nd-note
  grid.
- **Groove analysis** — Extract micro-timing deviations from the grid (swing,
  shuffle, humanization patterns). These "groove templates" are distinct
  fingerprints.
- **Polyrhythmic detection** — Identify layered rhythmic patterns (e.g.,
  3-against-4) that may constitute protectable arrangements.

#### 3.2 Rhythmic Comparison

- **Onset pattern matching** — Compare binary onset patterns using Hamming
  distance (number of differing positions).
- **Groove template similarity** — Compare micro-timing profiles using
  correlation coefficients. Two tracks using the same drum machine pattern with
  the same swing setting will have highly correlated groove templates.
- **Drum break fingerprinting** — Maintain a database of iconic drum breaks
  (Amen break, Funky Drummer, Impeach the President, Think break, Apache, etc.)
  and detect their use or close derivatives.
- **Tempo-invariant rhythm comparison** — Normalize all rhythmic patterns to a
  canonical tempo before comparison.
- **Cross-rhythm detection** — Detect when a rhythmic pattern from one genre
  tradition appears in another (e.g., a dembow rhythm in a pop song).

---

### 4. Spectral & Timbral Similarity Engine (`@themis/spectral-analysis`)

Timbre and spectral characteristics are generally not copyrightable, but they
are crucial for detecting direct sampling, close reproduction of production
styles, and "sound-alike" issues that may not constitute legal infringement but
create brand/reputation risk.

#### 4.1 Spectral Feature Extraction

- **Mel-Frequency Cepstral Coefficients (MFCCs)** — Extract the standard 13-40
  MFCCs per frame, capturing the spectral envelope shape. MFCCs are the most
  widely used feature for audio similarity.
- **Chroma features (HPCP)** — Extract Harmonic Pitch Class Profiles. These
  capture the harmonic content while being timbre-invariant.
- **Spectral centroid, bandwidth, rolloff** — Extract low-level spectral
  descriptors that characterize the "brightness" and frequency distribution.
- **Spectral flux** — Measure spectral change over time. Useful for detecting
  similar production dynamics (e.g., filter sweeps, build-ups).
- **Tonnetz representation** — Project harmonic content onto the Tonnetz
  (pitch-class network) for topology-aware harmonic comparison.
- **Mel spectrogram embeddings** — Use pre-trained neural networks (VGGish,
  PANNs, CLAP, MERT, MusicGen encoder) to extract high-level spectral embeddings
  that capture perceptual similarity.

#### 4.2 Timbral Fingerprinting

- **Production style fingerprinting** — Extract features that characterize the
  mix: EQ curves, dynamic range, stereo width, reverb characteristics, bass
  weight. Two tracks with the same production style will have similar
  fingerprints.
- **Instrument timbre identification** — Identify specific instrument sounds and
  their processing chain. Useful for detecting when the same synthesizer
  patches, sample libraries, or processing chains produce overly similar
  results.
- **Vocal timbre analysis** — See Vocal Similarity Engine (Section 6).
- **Mastering characteristics** — Compare loudness (LUFS), dynamic range, peak
  characteristics, and frequency balance.

#### 4.3 Sample Detection

- **Direct sample detection** — Detect when an audio segment has been directly
  sampled (copied) from another recording. This is distinct from musical
  similarity — it's identical audio content, potentially time-stretched or
  pitch-shifted.
- **Sample library identification** — Maintain fingerprints of popular sample
  libraries (Splice, Loopmasters, Native Instruments, etc.) and detect when
  generated audio reproduces exact samples. This prevents inadvertent claims
  against sample library content.
- **Micro-sample detection** — Detect very short samples (< 1 second) such as
  drum hits, vocal chops, and sound effects that may have been memorized from
  training data.

---

### 5. Lyric Similarity Engine (`@themis/lyric-analysis`)

Lyrics have strong copyright protection as literary works. Even partial lyric
reproduction can constitute infringement.

#### 5.1 Text-Level Analysis

- **N-gram text matching** — Extract word-level n-grams (n = 3 through 8) from
  generated lyrics and compare against a database of copyrighted lyrics. Direct
  text overlap beyond common phrases is flagged.
- **Semantic similarity** — Use sentence embeddings (all-MiniLM, BGE, GTE) to
  compare the _meaning_ of lyric lines. Two lines expressing the same specific
  idea in different words may still infringe if the idea is sufficiently
  specific and original.
- **Phonetic similarity (sounds-alike detection)** — Convert lyrics to phonetic
  representations (IPA, Soundex, Metaphone) and compare. Lyrics that _sound_ the
  same when sung but use different spellings are still potentially infringing.
  Example: "all the single ladies" vs. "all the simple ladies" sound nearly
  identical when sung.
- **Rhyme scheme comparison** — Extract rhyme schemes (ABAB, AABB, etc.) and
  compare. Identical rhyme schemes with similar content are a stronger match.
- **Meter and scansion matching** — Analyze the rhythmic meter of lyrics
  (stressed/unstressed syllable patterns) and compare. Lyrics with identical
  meter, rhyme scheme, and similar content are a strong match.

#### 5.2 Filtering & Thresholds

- **Common phrase database** — Maintain an exhaustive database of lyric phrases
  that are too common to be protectable:
  - Generic love expressions ("I love you", "baby come back", "hold me tight")
  - Common idioms and proverbs used in songs
  - Genre-specific clichés ("ride or die", "on the floor", "hands in the air")
  - Phrases appearing in 100+ commercially released songs
- **Title protection** — Song titles are generally not copyrightable, but using
  a distinctive title phrase in lyrics (e.g., "Bohemian Rhapsody", "Smells Like
  Teen Spirit") triggers elevated scrutiny.
- **Hook/chorus weighting** — Lyric matches in the chorus/hook carry higher
  weight than matches in verses, as choruses are the most memorable and
  recognizable portions.
- **Multi-language support** — Analyze lyrics in all target languages. Detect
  when lyrics translate or transliterate copyrighted lyrics from another
  language.

#### 5.3 Lyric-Melody Joint Analysis

- **Combined lyric-melody matching** — The strongest infringement evidence is
  when both the lyrics AND the melody match simultaneously. A two-dimensional
  match (same words sung to the same tune) is far more significant than either
  alone.
- **Syllable-pitch alignment** — Analyze how specific syllables align with
  specific pitches. Even with different lyrics, if the syllable stress patterns
  align with the same melodic contour, this is a compound similarity signal.

---

### 6. Vocal Similarity Engine (`@themis/vocal-analysis`)

Voice similarity is increasingly litigious. The NO FAKES Act (US), and emerging
international regulations specifically address unauthorized voice replication.

#### 6.1 Speaker Embedding Comparison

- **Speaker verification embeddings** — Extract d-vectors or x-vectors using
  pre-trained speaker verification models (ECAPA-TDNN, TitaNet, WavLM). These
  embeddings capture the unique characteristics of a voice independent of what
  is being said.
- **Cosine similarity threshold** — Compare speaker embeddings against a
  database of protected voices (real artists who have not consented to voice
  replication). Flag any generated voice with cosine similarity > 0.75 to any
  protected voice.
- **Voice print database** — Maintain a database of voice prints for:
  - All major-label recording artists (extracted from publicly available music)
  - Artists who have explicitly opted out of AI voice replication
  - Artists covered by the NO FAKES Act or equivalent legislation
  - Public figures with voice right protections

#### 6.2 Vocal Characteristic Analysis

- **Formant analysis** — Compare vocal formant frequencies (F1-F5) which
  characterize the unique resonance of each voice.
- **Vibrato analysis** — Compare vibrato rate, depth, and onset patterns.
  Distinctive vibrato is a key identifying characteristic.
- **Breathiness/rasp quantification** — Measure and compare voice quality
  parameters (breathiness, roughness, strain).
- **Singing technique fingerprinting** — Identify signature techniques:
  melismatic runs (Mariah Carey, Whitney Houston), vocal fry (Britney Spears),
  growling (metal vocalists), yodeling (various traditions), falsetto
  transitions, etc.
- **Phrasing and timing analysis** — Compare how a voice phrases lyrics
  (anticipated/delayed beats, rubato, breath placement).

#### 6.3 Anti-Impersonation System

- **Real-time voice comparison** — During voice synthesis, continuously compare
  the generated voice against the protected voice database.
- **Distinctiveness scoring** — Score each generated voice on how distinct it is
  from _all_ known voices, not just protected ones. Higher distinctiveness =
  lower risk.
- **Voice modification suggestions** — When a generated voice is too similar to
  a protected voice, suggest specific modifications (shift formants, alter
  vibrato, change breathiness) to increase distinctiveness while preserving
  quality.
- **Consent verification** — Integrate with a consent database: if an artist has
  explicitly consented to voice replication (e.g., for a licensed
  collaboration), bypass the similarity flag for that specific artist.

---

### 7. Structural Similarity Engine (`@themis/structural-analysis`)

Song structure alone is rarely protectable (verse-chorus-verse is universal),
but structural similarity combined with other similar elements strengthens
infringement claims.

#### 7.1 Song Form Analysis

- **Section segmentation** — Automatically segment songs into structural
  sections (intro, verse, pre-chorus, chorus, bridge, outro, instrumental break)
  using MSAF, SALAMI, or neural segmentation models.
- **Section label sequence** — Extract the ordered sequence of section types as
  a structural fingerprint (e.g., I-V-V-PC-C-V-PC-C-B-C-C-O).
- **Section duration ratios** — Compare the relative durations of each section.
  Two songs with identical structure AND identical section proportions are more
  similar than two songs with just the same section sequence.
- **Energy contour** — Extract the loudness/energy curve over the entire song.
  Compare the overall dynamic shape (build-ups, drops, quiet sections).

#### 7.2 Arrangement Analysis

- **Instrumentation timeline** — Track which instruments enter and exit
  throughout the song. The arrangement fingerprint captures the orchestration
  choices.
- **Textural density curve** — Measure the number of simultaneous sound sources
  over time. Compare the textural "shape" of the arrangement.
- **Production event detection** — Detect specific production events (filter
  sweeps, risers, drops, breakdowns, drum fills) and compare their placement and
  sequence.

---

### 8. Audio Fingerprint Engine (`@themis/audio-fingerprint`)

Extends the existing `@nous/audio` fingerprinting system with copyright-specific
capabilities. This is the fastest pre-filter — catching direct copies and very
close reproductions before the more expensive analysis engines run.

#### 8.1 Multi-Algorithm Fingerprinting

- **Landmark-based fingerprinting** — Shazam-style spectrogram peak
  constellation matching. Highly robust to noise, encoding artifacts, and
  time-shifting. Catches direct copies, covers, and close reproductions.
  (Extends existing `@nous/audio` landmark fingerprinting.)
- **Chroma-based fingerprinting** — Captures harmonic content independent of
  timbre. Catches transposed covers, re-orchestrations, and instrumental
  versions. (Extends existing `@nous/audio` chroma fingerprinting.)
- **Neural audio fingerprinting** — Use learned fingerprints from pre-trained
  models (Neural Audio Fingerprint, COLA) that capture perceptual similarity at
  a deeper level than hand-crafted features.
- **Robust hashing** — Generate perceptual hashes that are invariant to common
  transformations: MP3 encoding, volume changes, EQ adjustments, slight pitch
  shifts. Two versions of the "same" recording should produce the same hash.

#### 8.2 Content ID Integration

- **YouTube Content ID proxy** — Before publication, submit audio to YouTube as
  private/unlisted and monitor for Content ID claims. This leverages the
  industry's most comprehensive fingerprint database (100M+ reference tracks) at
  zero cost.
- **Audible Magic / DistroKid integration** — Pre-screen against additional
  fingerprint databases used by major distribution platforms.
- **ISRC/ISWC cross-reference** — When a fingerprint match is found, resolve to
  the specific copyrighted work via International Standard Recording Code (ISRC)
  or International Standard Musical Work Code (ISWC).

#### 8.3 Near-Duplicate Detection

- **Segment-level matching** — Don't just match whole tracks; match segments
  (e.g., 10-second windows). A generated track that inadvertently reproduces 15
  seconds of a copyrighted chorus should be caught even if the rest is original.
- **Speed/pitch-shifted matching** — Detect copies that have been time-stretched
  or pitch-shifted. Common AI model failure mode: reproducing training data at a
  different speed/pitch.
- **Mix element matching** — After source separation (stems), fingerprint
  individual stems (vocals, drums, bass, instruments) and match each
  independently. A track might have an original melody but inadvertently
  reproduce a copyrighted drum pattern.

---

### 9. Reference Database System (`@themis/reference-db`)

The entire system is only as good as its reference database. A comprehensive,
current, and well-organized reference database is the foundation.

#### 9.1 Database Architecture

- **Melody database** — Indexed melodic contours, pitch n-grams, and interval
  sequences for millions of songs. Optimized for fast n-gram lookup (hash
  tables) and approximate nearest neighbor search (HNSW, IVF).
- **Audio fingerprint database** — Landmark and chroma fingerprints for all
  indexed audio. Optimized for constellation matching.
- **Lyric database** — Full lyrics with word-level n-gram indices and sentence
  embeddings. Sources: licensed lyric APIs (Musixmatch, Genius), public domain
  collections.
- **Voice print database** — Speaker embeddings for protected voices.
- **Harmonic database** — Chord progressions in Roman numeral form, indexed by
  n-gram.
- **Rhythm database** — Quantized drum patterns and rhythmic motifs.
- **Neural embedding database** — High-dimensional audio embeddings in a vector
  database (pgvector, Qdrant) for fast approximate similarity search.

#### 9.2 Data Sources & Ingestion

- **Commercial music catalogs** — License or extract features from:
  - MusicBrainz / AcoustID (open metadata + fingerprints for 20M+ recordings)
  - Spotify audio features API (tempo, key, loudness, etc. for 100M+ tracks)
  - Billboard / chart tracking services (prioritize popular/high-risk works)
  - MIDI databases (Lakh MIDI Dataset: 176,000+ MIDI files with melody data)
- **Public domain collections** — Index all known public domain music to enable
  automatic clearance of public domain matches:
  - IMSLP (600,000+ classical scores)
  - Musopen (public domain recordings)
  - Traditional folk music archives
  - Pre-1928 published music (US public domain)
- **Real-time ingestion pipeline** — Monitor new releases via:
  - Spotify new release radar
  - Apple Music new releases
  - Billboard chart entries
  - DDEX feed from major labels (if partnership established)
  - Social media viral music detection (TikTok trending sounds)
- **Update cadence** — New commercially released music must be indexed within 48
  hours of release. Chart-topping music within 24 hours. Viral content within 12
  hours.

#### 9.3 Database Maintenance

- **Deduplication** — Prevent the same work from appearing multiple times under
  different metadata (remasters, re-releases, compilation appearances).
- **Metadata enrichment** — Link fingerprint entries to comprehensive metadata:
  songwriter credits, publisher, label, ISRC, ISWC, copyright holder, known
  licensing terms.
- **Protectability annotation** — For each indexed work, score which elements
  are likely protectable based on originality analysis. Common progressions,
  generic lyrics, and standard drum patterns are marked as low-protectability.
- **Jurisdiction mapping** — Track copyright status per jurisdiction. A work in
  the public domain in one country may still be protected in another.

---

### 10. Legal Risk Scoring Engine (`@themis/risk-scoring`)

The decision engine that synthesizes all similarity signals into a single
actionable risk assessment.

#### 10.1 Multi-Dimensional Similarity Score

- **Element-wise scoring** — Generate independent similarity scores for each
  musical element: | Element | Weight | Rationale | |---|---|---| | Melody |
  0.35 | Strongest copyright protection | | Lyrics | 0.25 | Strong literary
  copyright | | Vocal identity | 0.15 | NO FAKES Act, voice rights | | Harmony |
  0.08 | Weak protection unless unusual | | Production/timbre | 0.07 | Generally
  not protectable | | Structure | 0.05 | Almost never protectable alone | |
  Rhythm | 0.05 | Weakest protection |

- **Compound similarity detection** — When multiple elements simultaneously
  match the same reference work, the risk escalates non-linearly. Two
  independent low-similarity matches (melody 30% + harmony 40%) are far less
  concerning than a compound match (melody 60% to Song X AND lyrics 50% to Song
  X). Compound matches against the same work receive a multiplier.
- **Confidence intervals** — All scores include confidence intervals. A 70%
  similarity score with ±20% confidence is treated differently than 70% with ±3%
  confidence.

#### 10.2 Legal Precedent Database

- **Case law database** — Maintain a structured database of music copyright
  infringement cases with their outcomes, the specific elements found similar,
  and the threshold the court applied: | Case | Year | Outcome | Key Element |
  Threshold Applied | |---|---|---|---|---| | Bright Tunes v. Harrisongs ("My
  Sweet Lord") | 1976 | Infringement | Melody | Subconscious copying | | Three
  Boys Music v. Bolton ("Love Is a Wonderful Thing") | 2000 | Infringement
  ($5.4M) | Melody + lyrics | General audience test | | Williams v. Gaye
  ("Blurred Lines") | 2015 | Infringement ($5.3M) | Overall feel/groove |
  Extrinsic + intrinsic test | | Gray v. Perry ("Dark Horse") | 2019 | Reversed
  on appeal | Ostinato | Too commonplace | | Griffin v. Sheeran ("Thinking Out
  Loud") | 2023 | No infringement | Harmony + rhythm | Common elements | |
  Structured Asset Sales v. Sheeran ("Let's Get It On") | 2023 | No infringement
  | Harmony + rhythm | Chord progressions not protectable |
- **Threshold calibration** — Use case law outcomes to calibrate risk
  thresholds. The system should flag at levels _below_ where courts have found
  infringement, providing a safety margin.

#### 10.3 Risk Classification

- **PASS (Green)** — Similarity scores below the minimum actionable threshold
  across all elements. No matches to any reference work exceed background noise
  levels. Auto-approved for publication.
- **ADVISORY (Yellow-Green)** — Low similarity detected to one or more reference
  works, but well below actionable thresholds. Logged for audit trail but
  auto-approved. Notification sent to content team for awareness.
- **FLAG (Yellow)** — Moderate similarity detected. Requires human review before
  publication. Content is held in review queue.
- **HIGH RISK (Orange)** — Significant similarity to a specific copyrighted work
  across one or more elements. Requires musicologist review AND legal review
  before publication. Remediation recommended.
- **REJECT (Red)** — Similarity exceeds safe thresholds with high confidence.
  Automatic rejection. Content is blocked from publication and routed to
  auto-regeneration pipeline.

#### 10.4 Jurisdiction-Aware Assessment

- **US Copyright Act analysis** — Apply the Arnstein test (probative similarity
  → access → substantial similarity) and the Ninth Circuit's extrinsic/intrinsic
  test.
- **EU Copyright Directive** — Apply the originality threshold standard
  (author's own intellectual creation).
- **UK CDPA analysis** — Apply the "substantial part" test.
- **Multi-jurisdiction reporting** — When a work will be distributed globally,
  assess risk under all major jurisdictions and report the highest risk.
- **Moral rights considerations** — In jurisdictions with moral rights (most of
  the world outside the US), assess whether generated content could constitute a
  "distortion" of an existing work.

---

### 11. Provenance & Audit Trail System (`@themis/provenance`)

Comprehensive documentation of every generated work's origins. Essential for
legal defense ("we took reasonable steps") and regulatory compliance.

#### 11.1 Generation Provenance

- **Prompt capture** — Record the exact prompt/parameters used to generate every
  piece of music. This includes text prompts, reference audio, style parameters,
  and any other generation inputs.
- **Model versioning** — Record the exact model version, checkpoint, and
  configuration used for generation. If a model is later found to have
  memorization issues, this enables retroactive auditing.
- **Generation parameters** — Record temperature, top-k/top-p, guidance scale,
  seed, and any other generation parameters.
- **Timestamp and operator** — Record when each piece was generated and by whom
  (automated pipeline vs. human operator vs. specific AI artist agent).
- **Multi-stage provenance** — For content that goes through multiple generation
  stages (e.g., melody → arrangement → production → mastering), record
  provenance at each stage.

#### 11.2 Training Data Provenance

- **Model training data manifests** — For each model used in generation,
  maintain a manifest of its training data: what datasets were used, what
  licenses apply, what opt-outs were honored.
- **Dataset audit** — Regular audits of training datasets to verify license
  compliance, opt-out honoring, and data quality.
- **Opt-out registry** — Maintain a registry of artists/rights holders who have
  opted out of AI training. Verify that all generation models respect these
  opt-outs.
- **Data lineage graph** — Track the full lineage from training data → model →
  generated output. If a specific training data source is later found to be
  unlicensed, identify all generated outputs that may be affected.

#### 11.3 Decision Audit Trail

- **Similarity scan results** — Store the complete output of every similarity
  scan, including all element-wise scores, matched reference works, and the
  final risk classification.
- **Human review decisions** — Record all human review decisions with reviewer
  identity, timestamp, rationale, and any conditions attached.
- **Override logging** — If a human reviewer overrides an automated rejection,
  record the full justification. All overrides are auditable.
- **Publication decision chain** — For every published work, maintain the
  complete decision chain: generation → scan → classification → review (if
  applicable) → approval → publication.

---

### 12. Human Review Pipeline (`@themis/review-pipeline`)

Automated systems catch the obvious cases; human experts catch the subtle ones.
A robust human review pipeline is essential for the "flag" zone between clear
pass and clear reject.

#### 12.1 Review Queue System

- **Priority queue** — Flagged content enters a review queue prioritized by:
  risk score (higher risk → faster review), publication deadline, artist tier
  (higher-profile artists → faster review), and similarity confidence.
- **Reviewer assignment** — Route flagged content to qualified reviewers based
  on expertise:
  - **Musicologist reviewers** — For melodic, harmonic, and structural
    similarity disputes
  - **Lyricist reviewers** — For lyric similarity disputes
  - **Legal reviewers** — For high-risk cases requiring legal analysis
  - **Genre specialists** — Reviewers with expertise in specific genres (hip-hop
    sampling culture, electronic music production, country songwriting
    conventions)
- **SLA targets** — 90% of flagged content reviewed within 4 hours. 99% within
  24 hours. High-risk content reviewed within 1 hour.

#### 12.2 Review Interface

- **A/B comparison tool** — Side-by-side playback of the generated track and the
  matched reference track, with synchronized waveform display, aligned to the
  matching segments.
- **Element isolation** — Ability to solo/mute individual elements (melody,
  harmony, rhythm, vocals) in both the generated and reference tracks for
  focused comparison.
- **Similarity heatmap** — Visual timeline showing where similarity is
  concentrated (e.g., the chorus of the generated track matches bars 33-48 of
  the reference track).
- **Legal context panel** — For each flagged match, display relevant legal
  context: the reference work's copyright holder, known litigiousness of the
  rights holder, relevant case law, and jurisdiction-specific risk.
- **One-click decisions** — Approve, reject, or request modification with a
  single click. Approved and rejected decisions include mandatory rationale
  text.

#### 12.3 Musicologist Network

- **Expert panel** — Maintain relationships with 10-20 professional
  musicologists who can provide expert opinions on difficult cases.
- **Escalation path** — Content that internal reviewers cannot confidently
  assess is escalated to the expert panel.
- **Expert opinion documentation** — Expert opinions are documented and stored
  as part of the audit trail, providing evidence of due diligence.

---

### 13. Remediation Pipeline (`@themis/remediation`)

When content is flagged or rejected, automatic remediation generates alternative
content that preserves the creative intent while eliminating the similarity.

#### 13.1 Targeted Element Modification

- **Melody variation** — When the melody is the flagged element, automatically
  generate variations that preserve the overall contour and emotional character
  while altering specific note sequences to break the similarity match:
  - Pitch substitution (replace matching notes with neighbor tones)
  - Rhythmic variation (alter the rhythm while keeping the pitch contour)
  - Intervallic variation (expand or compress intervals)
  - Ornamental variation (add grace notes, passing tones, turns)
- **Harmonic reharmonization** — When chord progressions are flagged, suggest
  alternative harmonizations that preserve the harmonic function but use
  different specific chords (e.g., replace IV with ii, replace V with viio).
- **Lyric reformulation** — When lyrics are flagged, regenerate the matching
  lines while preserving the semantic meaning, meter, and rhyme scheme.
- **Vocal modification** — When vocal similarity is flagged, apply targeted
  voice modifications (formant shifting, vibrato alteration, breathiness
  adjustment) to increase distinctiveness.
- **Rhythmic variation** — When rhythmic patterns are flagged, introduce
  micro-timing variations, swap drum sounds, or alter the rhythmic density.

#### 13.2 Regeneration Pipeline

- **Constrained regeneration** — When targeted modification is insufficient,
  regenerate the entire section with negative constraints: "generate a chorus
  that is NOT similar to [reference work]." The similarity engine runs as a
  real-time constraint during generation.
- **Iterative refinement** — Regeneration runs in a loop: generate → scan → if
  flagged, regenerate with tighter constraints → scan again. Maximum 5
  iterations before escalating to human review.
- **Creative intent preservation** — Track the original creative intent (mood,
  energy, genre, tempo, key, lyrical theme) and ensure that remediation
  preserves these while eliminating the similarity.

#### 13.3 Pre-Generation Screening

- **Prompt risk assessment** — Before generation even begins, assess the prompt
  for copyright risk:
  - References to specific artists ("make it sound like Drake") → high risk
  - References to specific songs ("similar to Bohemian Rhapsody") → reject
  - Genre/mood descriptions ("upbeat pop in C major") → normal risk
  - Specific musical descriptions ("use a I-V-vi-IV progression") → low risk
    (common elements)
- **Negative prompting** — Automatically inject negative constraints into
  generation prompts: "do not reproduce any existing copyrighted melodies."
- **Training data exclusion** — If the prompt references a specific genre or
  era, cross-reference against known memorization hotspots in the generation
  model and inject additional guardrails.

---

### 14. Model Safety & Training Data Governance (`@themis/model-governance`)

Prevention is better than detection. Ensuring that generation models are safe
_before_ deployment reduces the detection burden.

#### 14.1 Training Data Audit

- **License verification** — For every dataset used to train a music generation
  model, verify and document the license terms. Maintain a ledger: | Dataset |
  License | Covers Generative Use? | Opt-Out Mechanism | |---|---|---|---| | FMA
  (Free Music Archive) | CC-BY/CC0 | Yes | N/A | | MUSDB18 | Research only | No
  — cannot use for commercial generation | N/A | | Licensed catalog | Custom |
  Verify clause-by-clause | Artist request |
- **Opt-out compliance** — Honor all artist/rights-holder opt-out requests.
  Maintain an opt-out registry. When a model is trained, verify that all opt-out
  requests are honored in the training data.
- **Deduplication audit** — Verify that training data has been properly
  deduplicated. Duplicate training examples increase memorization risk.

#### 14.2 Memorization Detection

- **Membership inference testing** — After model training, run membership
  inference attacks against the model to detect which training examples it has
  memorized. Flag models with high memorization rates for additional
  deduplication or differential privacy.
- **Verbatim reproduction testing** — Feed the model prompts designed to elicit
  verbatim reproduction of training data (e.g., first 5 seconds of known
  training songs as continuation prompts). Measure reproduction rates.
- **Canary testing** — Insert known "canary" sequences into training data and
  test whether the model reproduces them. High canary reproduction = high
  memorization risk.
- **Differential privacy verification** — If differential privacy was used
  during training, verify the privacy budget (ε, δ) and ensure it provides
  meaningful protection against memorization.

#### 14.3 Model Red-Teaming

- **Adversarial prompt testing** — Before deploying a model, red-team it with
  prompts specifically designed to elicit copyrighted content:
  - "Continue this melody: [first 4 bars of a famous song]"
  - "Generate a song in the style of [famous artist] about [specific topic of
    their famous song]"
  - "Generate a beat that sounds like [famous producer]'s signature style"
- **Systematic coverage** — Red-team against a representative sample of the
  Billboard Hot 100, Grammy winners, and most-streamed tracks from each decade.
- **Ongoing monitoring** — Continuously red-team deployed models as new music is
  released. A model that didn't reproduce "Song X" last month might reproduce
  "Song Y" this month due to different prompt patterns.

---

### 15. Platform Integration & API (`@themis/music-shield-api`)

The shield must be seamlessly integrated into every music generation pipeline.

#### 15.1 Gating API

```typescript
interface MusicShieldScanRequest {
  audio: Float32Array | Uint8Array | string; // audio data or URL
  lyrics?: string; // lyrics text if available
  metadata?: {
    genre?: string;
    tempo?: number;
    key?: string;
    generationPrompt?: string;
    modelId?: string;
    modelVersion?: string;
    artistId?: string;
  };
  scanConfig?: {
    engines?: ScanEngine[]; // which engines to run (default: all)
    jurisdiction?: string[]; // jurisdictions to assess
    riskThreshold?: RiskLevel;
    maxLatencyMs?: number; // time budget for scan
  };
}

interface MusicShieldScanResult {
  overallRisk: RiskLevel; // PASS | ADVISORY | FLAG | HIGH_RISK | REJECT
  overallScore: number; // 0.0 - 1.0 composite score
  confidence: number; // confidence in the assessment
  elementScores: {
    melody: ElementScore;
    lyrics: ElementScore;
    vocal: ElementScore;
    harmony: ElementScore;
    spectral: ElementScore;
    structure: ElementScore;
    rhythm: ElementScore;
  };
  matches: SimilarityMatch[]; // matched reference works
  provenance: ProvenanceRecord; // audit trail
  recommendations: Recommendation[]; // suggested actions
  scanDurationMs: number;
}

type RiskLevel = 'pass' | 'advisory' | 'flag' | 'high_risk' | 'reject';

interface SimilarityMatch {
  referenceWorkId: string;
  referenceTitle: string;
  referenceArtist: string;
  copyrightHolder: string;
  matchedElements: MatchedElement[];
  compoundScore: number; // compound similarity score
  legalRiskAssessment: string; // natural language risk summary
  timeSegments: TimeSegment[]; // where in the tracks the match occurs
}
```

#### 15.2 Integration Points

- **Calliope integration** — Every AI artist's music passes through the shield
  before publication. The shield is configured per-artist based on their genre,
  influences, and vocal identity.
- **Euterpe integration** — The DAW/studio engine calls the shield API before
  exporting any generated or AI-assisted content.
- **Isis integration** — The generative factory's music production pipeline
  includes the shield as a mandatory post-generation step.
- **Nous integration** — Leverages existing `@nous/audio` fingerprinting and
  `@nous/core` similarity search infrastructure.
- **Real-time mode** — For interactive generation (live jamming, real-time
  composition), a lightweight version of the shield runs in real-time, providing
  instant feedback with lower fidelity. Full scan runs asynchronously.

#### 15.3 Performance Requirements

- **Full scan latency** — Complete multi-engine scan in < 30 seconds for a
  standard 3-minute track. This is acceptable for batch/publication workflows.
- **Quick scan latency** — Melody + fingerprint scan in < 5 seconds. Used for
  interactive feedback during composition.
- **Real-time mode** — Continuous melody comparison at < 100ms latency. Used
  during live generation.
- **Throughput** — Support scanning 10,000+ tracks per day at full scan depth.
- **Scalability** — Horizontally scalable across scan engines. Each engine runs
  independently and can be scaled based on load.

---

### 16. Monitoring, Analytics & Continuous Improvement (`@themis/shield-analytics`)

The system must learn and improve continuously.

#### 16.1 False Positive/Negative Tracking

- **False positive tracking** — When human reviewers override a FLAG or REJECT
  decision, record this as a false positive. Track false positive rates per
  engine, per genre, per reference work.
- **False negative tracking** — When a published work receives a third-party
  copyright claim that the shield did not catch, record this as a false
  negative. This is the most critical metric.
- **Threshold tuning** — Use accumulated false positive/negative data to
  continuously calibrate risk thresholds. The goal: zero false negatives with
  minimal false positives.

#### 16.2 Analytics Dashboard

- **Scan volume metrics** — Tracks scanned/day, scans by risk level, average
  scan latency.
- **Match analytics** — Most frequently matched reference works, most common
  match elements, match trends over time.
- **Genre risk heatmap** — Risk levels by genre. Some genres (pop, hip-hop) have
  higher match rates due to more formulaic structure; others (experimental
  electronic) have lower match rates.
- **Model risk tracking** — Track which generation models produce the most
  flagged content. Models with high flag rates may need additional training data
  deduplication or fine-tuning.
- **Legal landscape tracker** — Monitor new copyright infringement cases,
  legislative changes, and regulatory guidance that may require threshold
  adjustments.

#### 16.3 Feedback Loop

- **Reviewer feedback → model improvement** — Patterns identified by human
  reviewers (e.g., "this model consistently generates melodies similar to 2010s
  pop hooks") feed back into model training and prompt engineering.
- **Post-publication monitoring** — Monitor published tracks for third-party
  claims (Content ID, DMCA) and feed results back into the reference database
  and threshold calibration.
- **Industry benchmarking** — Compare our flag/reject rates against industry
  norms. If we're flagging 50% of content while competitors publish freely, our
  thresholds may be too aggressive.

---

## Library Architecture

```
libs/themis/
├── music-shield/              # Core shield orchestration
│   ├── src/
│   │   ├── shield.ts          # Main MusicShield class
│   │   ├── config.ts          # Shield configuration
│   │   ├── pipeline.ts        # Scan pipeline orchestration
│   │   ├── decision-engine.ts # Risk classification logic
│   │   └── index.ts
│   ├── project.json
│   ├── package.json
│   └── tsconfig.json
│
├── melodic-analysis/          # Melodic similarity detection
│   ├── src/
│   │   ├── pitch-extraction.ts
│   │   ├── contour-analysis.ts
│   │   ├── ngram-matching.ts
│   │   ├── similarity-metrics.ts
│   │   ├── transposition.ts
│   │   ├── common-melody-filter.ts
│   │   └── index.ts
│   └── ...
│
├── harmonic-analysis/         # Harmonic similarity detection
│   ├── src/
│   │   ├── chord-extraction.ts
│   │   ├── progression-matching.ts
│   │   ├── common-progression-filter.ts
│   │   ├── protectability-scoring.ts
│   │   └── index.ts
│   └── ...
│
├── rhythmic-analysis/         # Rhythmic similarity detection
│   ├── src/
│   │   ├── beat-extraction.ts
│   │   ├── pattern-matching.ts
│   │   ├── groove-analysis.ts
│   │   ├── drum-break-db.ts
│   │   └── index.ts
│   └── ...
│
├── spectral-analysis/         # Spectral & timbral similarity
│   ├── src/
│   │   ├── feature-extraction.ts
│   │   ├── timbral-fingerprint.ts
│   │   ├── sample-detection.ts
│   │   ├── embedding-comparison.ts
│   │   └── index.ts
│   └── ...
│
├── lyric-analysis/            # Lyric similarity detection
│   ├── src/
│   │   ├── text-matching.ts
│   │   ├── semantic-similarity.ts
│   │   ├── phonetic-matching.ts
│   │   ├── common-phrase-filter.ts
│   │   ├── lyric-melody-joint.ts
│   │   └── index.ts
│   └── ...
│
├── vocal-analysis/            # Voice similarity & anti-impersonation
│   ├── src/
│   │   ├── speaker-embedding.ts
│   │   ├── vocal-characteristic.ts
│   │   ├── anti-impersonation.ts
│   │   ├── voice-modification.ts
│   │   ├── consent-registry.ts
│   │   └── index.ts
│   └── ...
│
├── structural-analysis/       # Song structure similarity
│   ├── src/
│   │   ├── section-segmentation.ts
│   │   ├── arrangement-analysis.ts
│   │   ├── energy-contour.ts
│   │   └── index.ts
│   └── ...
│
├── audio-fingerprint/         # Extended fingerprinting
│   ├── src/
│   │   ├── neural-fingerprint.ts
│   │   ├── content-id-proxy.ts
│   │   ├── near-duplicate.ts
│   │   ├── segment-matching.ts
│   │   └── index.ts
│   └── ...
│
├── reference-db/              # Reference database management
│   ├── src/
│   │   ├── melody-db.ts
│   │   ├── fingerprint-db.ts
│   │   ├── lyric-db.ts
│   │   ├── voice-db.ts
│   │   ├── ingestion-pipeline.ts
│   │   ├── deduplication.ts
│   │   ├── metadata-enrichment.ts
│   │   └── index.ts
│   └── ...
│
├── risk-scoring/              # Legal risk assessment
│   ├── src/
│   │   ├── composite-scorer.ts
│   │   ├── legal-precedent-db.ts
│   │   ├── jurisdiction-rules.ts
│   │   ├── compound-detection.ts
│   │   ├── protectability-analysis.ts
│   │   └── index.ts
│   └── ...
│
├── provenance/                # Audit trail & provenance
│   ├── src/
│   │   ├── generation-provenance.ts
│   │   ├── training-data-audit.ts
│   │   ├── decision-trail.ts
│   │   ├── opt-out-registry.ts
│   │   └── index.ts
│   └── ...
│
├── review-pipeline/           # Human review workflow
│   ├── src/
│   │   ├── review-queue.ts
│   │   ├── reviewer-assignment.ts
│   │   ├── comparison-tools.ts
│   │   ├── escalation.ts
│   │   └── index.ts
│   └── ...
│
├── remediation/               # Auto-fix & regeneration
│   ├── src/
│   │   ├── melody-variation.ts
│   │   ├── harmonic-reharmonization.ts
│   │   ├── lyric-reformulation.ts
│   │   ├── vocal-modification.ts
│   │   ├── constrained-regeneration.ts
│   │   ├── prompt-risk-assessment.ts
│   │   └── index.ts
│   └── ...
│
├── model-governance/          # Training data & model safety
│   ├── src/
│   │   ├── license-verification.ts
│   │   ├── memorization-detection.ts
│   │   ├── model-red-team.ts
│   │   ├── canary-testing.ts
│   │   └── index.ts
│   └── ...
│
├── shield-api/                # Platform integration API
│   ├── src/
│   │   ├── scan-api.ts
│   │   ├── real-time-mode.ts
│   │   ├── batch-mode.ts
│   │   ├── webhook-notifications.ts
│   │   └── index.ts
│   └── ...
│
└── shield-analytics/          # Monitoring & continuous improvement
    ├── src/
    │   ├── false-positive-tracker.ts
    │   ├── false-negative-tracker.ts
    │   ├── analytics-dashboard.ts
    │   ├── threshold-tuning.ts
    │   ├── legal-landscape-monitor.ts
    │   └── index.ts
    └── ...
```

---

## Technology Stack

| Component                            | Technology                                | Rationale                                   |
| ------------------------------------ | ----------------------------------------- | ------------------------------------------- |
| Core similarity engines              | TypeScript + ONNX Runtime                 | ML inference with type safety               |
| Audio DSP (melody/chroma extraction) | Rust via WASM / napi-rs                   | Real-time performance for audio processing  |
| Vector similarity search             | pgvector + Qdrant                         | Approximate nearest neighbor for embeddings |
| Audio fingerprint matching           | Rust (constellation matching)             | High-throughput hash matching               |
| Lyric NLP                            | TypeScript + sentence-transformers (ONNX) | Semantic embedding comparison               |
| Reference database                   | PostgreSQL + Redis                        | Structured metadata + caching               |
| Message queue (async scans)          | BullMQ                                    | Job queue for scan pipeline                 |
| API layer                            | TypeScript (Hono/Fastify)                 | Low-latency HTTP API                        |
| Review UI                            | React (within Yemaya admin)               | Internal review interface                   |
| Monitoring                           | Prometheus + Grafana                      | Metrics and alerting                        |

---

## Integration with Existing Infrastructure

| Existing System                         | Integration                                                                   |
| --------------------------------------- | ----------------------------------------------------------------------------- |
| `@nous/audio` (fingerprinting)          | Extend landmark/chroma/hybrid fingerprinting with copyright-specific matching |
| `@nous/core` (similarity search)        | Use similarity search engine for embedding-based audio comparison             |
| `@nous/audio` (audio-search)            | Extend audio search with copyright reference database                         |
| `@calliope/voice` (anti-similarity)     | Plug shield's vocal analysis into Calliope's voice creation pipeline          |
| `@euterpe/genesis` (generation)         | Shield gate on all generated music output                                     |
| `@euterpe/theory` (music theory)        | Use theory primitives for melodic/harmonic analysis                           |
| `@isis/audio-generation`                | Shield gate on factory music generation                                       |
| `@yemaya/agents` (audio-style-enforcer) | Feed shield signals into style enforcement                                    |

---

## Development Phases

### Phase 1: Foundation (Weeks 1-4)

- `@themis/melodic-analysis` — Pitch extraction, contour analysis, n-gram
  matching
- `@themis/audio-fingerprint` — Extend `@nous/audio` fingerprinting for
  copyright matching
- `@themis/reference-db` — Core database schema, MusicBrainz/AcoustID
  integration
- `@themis/risk-scoring` — Basic composite scoring with melody + fingerprint
  signals
- `@themis/music-shield` — Core pipeline orchestration, PASS/FLAG/REJECT
  decisions
- **Deliverable:** Working end-to-end pipeline for melody + fingerprint scanning

### Phase 2: Depth (Weeks 5-8)

- `@themis/harmonic-analysis` — Chord extraction, progression matching, common
  filtering
- `@themis/lyric-analysis` — Text matching, semantic similarity, phonetic
  matching
- `@themis/spectral-analysis` — MFCC/chroma features, timbral fingerprinting,
  sample detection
- `@themis/provenance` — Generation provenance, audit trail, decision logging
- **Deliverable:** Multi-element scanning with lyric + harmonic + spectral
  analysis

### Phase 3: Voice & Legal (Weeks 9-12)

- `@themis/vocal-analysis` — Speaker embeddings, anti-impersonation, consent
  registry
- `@themis/structural-analysis` — Section segmentation, arrangement analysis
- `@themis/risk-scoring` — Legal precedent database, jurisdiction-aware
  assessment, compound detection
- `@themis/shield-api` — Full REST API, webhook notifications, batch mode
- **Deliverable:** Complete multi-engine scanning with legal risk assessment

### Phase 4: Human Loop & Remediation (Weeks 13-16)

- `@themis/review-pipeline` — Review queue, reviewer assignment, comparison
  tools
- `@themis/remediation` — Melody variation, reharmonization, lyric
  reformulation, constrained regeneration
- `@themis/model-governance` — License verification, memorization detection,
  red-teaming
- **Deliverable:** Full human-in-the-loop review and automatic remediation

### Phase 5: Scale & Intelligence (Weeks 17-20)

- `@themis/shield-analytics` — False positive/negative tracking, threshold
  tuning, dashboards
- `@themis/reference-db` — Real-time ingestion pipeline, chart monitoring, viral
  content tracking
- Performance optimization — Rust WASM for hot paths, caching, parallel scan
  engines
- Calliope/Euterpe/Isis integration — Deploy shield into all production music
  pipelines
- **Deliverable:** Production-grade, continuously improving shield at scale

---

## Success Metrics

| Metric                          | Target          | Measurement                                                             |
| ------------------------------- | --------------- | ----------------------------------------------------------------------- |
| False negative rate             | < 0.01%         | Third-party claims on published works that shield missed                |
| False positive rate             | < 5%            | Human review overrides of FLAG/REJECT decisions                         |
| Full scan latency (3-min track) | < 30s           | P95 scan duration                                                       |
| Quick scan latency              | < 5s            | P95 melody + fingerprint scan                                           |
| Reference database coverage     | > 10M works     | Indexed commercial recordings                                           |
| Review SLA (flagged content)    | < 4 hours (90%) | Time from flag to human decision                                        |
| Remediation success rate        | > 90%           | % of flagged content successfully remediated without human intervention |
| Uptime                          | 99.9%           | Shield API availability                                                 |

---

## Legal Disclaimer

This system is a risk mitigation tool, not a legal opinion generator. All
HIGH_RISK and FLAG decisions should be reviewed by qualified music copyright
attorneys before final publication decisions. The system's risk assessments are
based on analysis of publicly available case law and musicological principles
but do not constitute legal advice.

---

## References

### Case Law

- Arnstein v. Porter, 154 F.2d 464 (2d Cir. 1946) — foundational access +
  similarity test
- Bright Tunes Music Corp. v. Harrisongs Music, Ltd., 420 F. Supp. 177
  (S.D.N.Y. 1976) — subconscious copying
- Three Boys Music Corp. v. Bolton, 212 F.3d 477 (9th Cir. 2000) — audience test
  for infringement
- Williams v. Gaye, 895 F.3d 1106 (9th Cir. 2018) — "Blurred Lines" groove/feel
- Gray v. Hudson, No. 2:15-cv-05642 (C.D. Cal. 2020) — "Dark Horse" reversal on
  commonplace elements
- Griffin v. Sheeran, No. 1:17-cv-05221 (S.D.N.Y. 2023) — "Thinking Out Loud" no
  infringement
- Structured Asset Sales v. Sheeran, No. 1:18-cv-05839 (S.D.N.Y. 2023) — chord
  progressions not protectable

### Legislation

- US Copyright Act, 17 U.S.C. §§ 101-1332
- NO FAKES Act (proposed) — digital replica rights
- EU AI Act (2024) — AI system transparency and risk classification
- EU Copyright Directive, Art. 3-4 — text and data mining exceptions

### Technical References

- Wang, A. (2003). "An Industrial-Strength Audio Search Algorithm" (Shazam
  fingerprinting)
- Müller, M. (2015). "Fundamentals of Music Processing" (DTW, chroma features)
- Serra, J. et al. (2009). "Cross recurrence quantification for cover song
  identification"
- Doras, G. & Peeters, G. (2020). "Audio-based detection of explicit content in
  music"

---

_This proposal establishes Oshun's Themis Music Shield as the most comprehensive
AI music copyright protection system in the industry — not as a competitive
advantage, but as a moral and legal necessity. Every generated note must be
defensible._
