Database overview
TheNimazDatabase is the central database class containing 34 entities and 14 DAOs, organized by feature area.
data/local/database/NimazDatabase.kt:56-108
The database version is 10, with schema exports stored in
app/schemas/ for migration tracking.Entities by feature
Quran entities (7)
SurahEntity - Surah metadata
SurahEntity - Surah metadata
Stores information about each Surah (chapter) including name in Arabic and English, revelation type, ayah count, and ordering.
AyahEntity - Quranic verses
AyahEntity - Quranic verses
Contains the full text of every Quranic verse with positioning metadata (Juz, Hizb, Rub, Page) and Sajdah information.
TranslationEntity - Ayah translations
TranslationEntity - Ayah translations
Stores translations in multiple languages. Each translation is linked to an ayah and translator.
QuranBookmarkEntity - Bookmarked verses
QuranBookmarkEntity - Bookmarked verses
User bookmarks with notes, color tags, and timestamps.
QuranFavoriteEntity - Favorite surahs
QuranFavoriteEntity - Favorite surahs
Quick access to frequently read surahs.
ReadingProgressEntity - Reading history
ReadingProgressEntity - Reading history
Tracks last read position and reading session history.
SurahInfoEntity - Extended surah information
SurahInfoEntity - Extended surah information
Additional details like themes, key verses, and recitation info.
Hadith entities (3)
- HadithBookEntity: Six major hadith books (Bukhari, Muslim, Abu Dawud, etc.)
- HadithEntity: Individual hadiths with Arabic text, translation, narrator chain, and grading
- HadithBookmarkEntity: Bookmarked hadiths with notes
Dua entities (4)
- DuaCategoryEntity: 12 dua categories (Morning, Evening, Prayer, etc.)
- DuaEntity: Complete duas with Arabic, transliteration, translation, and source
- DuaBookmarkEntity: Favorite duas
- DuaProgressEntity: Tracks daily dua completion
Prayer & Fasting entities (3)
- PrayerRecordEntity: Prayer tracking with status, timing, and Jamaah info
- FastRecordEntity: Fasting records with Suhoor/Iftar times
- MakeupFastEntity: Qada fast tracking
Tasbih entities (2)
- TasbihPresetEntity: Counter presets with target counts
- TasbihSessionEntity: Tasbih session history
Zakat entity (1)
- ZakatHistoryEntity: Saved zakat calculations with assets and liabilities
Tafseer entities (3)
- TafseerTextEntity: Quranic commentary text
- TafseerHighlightEntity: User highlights in tafseer
- TafseerNoteEntity: Personal notes on verses
Khatam entities (3)
- KhatamEntity: Quran completion goals with progress tracking
- KhatamAyahEntity: Individual ayah completion records
- KhatamDailyLogEntity: Daily reading statistics
Islamic Names entities (6)
- AsmaUlHusnaEntity: 99 Names of Allah
- AsmaUlHusnaBookmarkEntity: Bookmarked names
- AsmaUnNabiEntity: Names of Prophet Muhammad (PBUH)
- AsmaUnNabiBookmarkEntity: Bookmarked prophet names
- ProphetEntity: Stories of 25 prophets
- ProphetBookmarkEntity: Bookmarked prophet stories
Other entities (2)
- LocationEntity: Saved prayer time locations
- IslamicEventEntity: Islamic calendar events (13 major events)
Data Access Objects (DAOs)
Nimaz provides 14 DAOs for type-safe database operations:data/local/database/NimazDatabase.kt:109-123
DAO capabilities
All DAOs provide:- Flow-based queries for reactive UI updates
- Suspend functions for coroutine-based operations
- Comprehensive CRUD operations (Create, Read, Update, Delete)
- Complex queries with joins and aggregations
Example: QuranDao
Example: QuranDao
Database migrations
Nimaz maintains database schema compatibility through Room migrations.Migration 9 → 10
Added Asma ul Husna, Asma un Nabi, and Prophet entities with their bookmark tables. Source:data/local/database/NimazDatabase.kt:127-216
Migration 8 → 9
Added Khatam tracking tables with daily log and ayah completion records. Source:data/local/database/NimazDatabase.kt:218-270
Database initialization
The database is provided via Hilt dependency injection:core/di/DatabaseModule.kt
Schema export
Room generates JSON schema files for each version:- Migration testing
- Schema version tracking
- Documentation of database structure
Best practices
Use Flow for UI-bound data
Use Flow for UI-bound data
DAOs return
Flow<T> for data that updates the UI. This ensures automatic updates when the database changes.Use suspend functions for one-time operations
Use suspend functions for one-time operations
For inserts, updates, and deletes that don’t need reactive updates, use suspend functions.
Leverage indices for query performance
Leverage indices for query performance
All foreign keys and frequently queried columns have indices defined in entity classes.
Test migrations thoroughly
Test migrations thoroughly
Use Room’s migration testing utilities to validate schema changes don’t break existing data.