4.1 KiB
4.1 KiB
System Architecture
LyricFlow is built using Python 3 and the PyQt6 framework. The codebase follows a strict separation of concerns between the linguistic engine and the user interface.
Directory Structure
lyricflow/
├── docs/ # Technical documentation
├── src/
│ ├── engine/ # Linguistic logic (Rhymes, Phonetics, Syllables)
│ ├── gui/ # UI components and styling
│ │ └── components/ # Specialized widgets (Editor, Explorer, Sidebar)
│ ├── lyricflow_core/ # Shared core for desktop/mobile clients
│ │ ├── api/ # Stable service/facade APIs
│ │ ├── engine/ # Core linguistic implementation
│ │ └── storage/ # Core persistence implementation
│ └── utils/ # Legacy compatibility wrappers
├── run.py # Main entry point script
└── README.md # Project overview
Module Responsibilities
src/engine
phonetics.py: Wrapsnltk.cmudict. Handles word normalization and phonetic extraction. Contains thePhoneticProcessorsingleton.rhyme_engine.py: The core logic. Indexes the phonetic dictionary into memory for O(1) slant/perfect rhyme lookup. Implements word association (synonyms/vibes) using NLTK WordNet. These now proxy tosrc/lyricflow_core/enginefor backward compatibility.
src/lyricflow_core
api/analysis.py: Stable analysis service used by GUI and future mobile clients.api/project_state.py: Stable project state read/write and defensive parsing.api/facade.py: AggregatedLyricFlowCoreFacadeintegration point.engine/andstorage/: Canonical implementation modules shared across clients.
src/gui
main_window.py: The central orchestrator.- Manages the
QSplitterlayout. - Handles Tab Management for multi-file editing.
- Implements Project Persistence via
.lyricprojectJSON files. - Manages app-level restore and preferences via
QSettingsand recovered session snapshots.
- Manages the
components/explorer.py: UsesQFileSystemModelandQTreeViewto provide an IDE-like project explorer with context menu file operations.components/editor.py: A specializedQPlainTextEditimplementing:- RhymeHighlighter: Real-time coloring based on flow density and LyricDown syntax.
- Syllable Margin: Custom painting to show the meter of each line.
- Debounced Analysis: Performance-optimized logic to prevent UI lag.
components/sidebar.py: A composite widget that displays dynamic lists of rhymes, synonyms, and vibe concepts based on the current cursor selection.components/preferences_dialog.py: Modal preferences UI for startup/session defaults and appearance toggles.
src/utils
app_settings.py: DefinesAppPreferencesandAppSettingsStore, persisting app-level behavior and UI chrome state throughQSettings.session_store.py: Stores and restores recovered unsaved tabs (untitled and dirty files) under app data as JSON snapshots.
Data Flow
- User Types:
LyricEditordetects change -> Reset Debounce Timer. - Timer Expires:
LyricEditorcallsengine.get_rhyme_groups(). - Highlighter Updates:
RhymeHighlighterreceives results and colors the text, while strictly excluding LyricDown keywords/comments. - Project Save:
MainWindowwrites.lyricprojectwith open files, active file, and cursor positions. - Session Autosave: Every 30s (and on close), unsaved tabs are captured to app data for crash/quit recovery.
- Startup Restore: Preferences are loaded first, then last project and recovered snapshots are optionally restored.
- Selection: User clicks a word ->
wordSelectedsignal sent toSidebar-> Sidebar fetches creative suggestions from the engine.
Styling
The application uses a custom CSS-like dictionary approach within PyQt to implement a Dracula Theme. This theme is consistently applied to the menu bar, tabs, explorer, editor, and sidebar to ensure a premium look and feel.