How ankidroid/anki-android works
1. Overall shape
This is a large multi-module Android application: AnkiDroid, a flashcard/spaced-repetition client that is mostly offline-first but syncs with AnkiWeb. The repo is organized around a core app module plus shared libraries for the backend engine, cross-module utilities, compatibility shims, and API surface.
2. Top-level module boundaries
The main runtime app is AnkiDroid/. Supporting modules are libanki/ for the collection/scheduler engine, common/ and anki-common/ for shared Kotlin utilities and navigation abstractions, compat/ for API-level/platform shims, api/ for the external add-card contract, vbpd/ for view-binding helpers, and lint-rules/ for project-specific static checks. These modules keep Android UI code separated from engine logic and platform compatibility code.
3. Core domain engine
libanki/ is the heart of the app’s data model and scheduling logic. It owns collections, decks, cards, notes, note types, media, storage, sync, import/export, undo, and the scheduler/FSRS-related logic. If you’re drawing the architecture, treat this as the canonical domain layer and persistence engine beneath the UI.
4. UI and feature entry points
AnkiDroid/src/main/java/com/ichi2/anki/ contains the Android-facing presentation layer: activities, fragments, view models, dialogs, custom views, and feature packages. Major user-facing areas include deck picking, reviewing, card browser, note editor, notetype management, statistics, settings, shared decks, previewers, multimedia editing, review reminders, and widgets.
5. Card review pipeline
The review flow is a distinct subsystem: reviewer UI classes, gesture/button mappings, answer timers, whiteboard, audio recording/playback, TTS, and type-answer support. Card content is rendered through WebView-backed card viewer components, using HTML/CSS/JS assets plus a JS bridge (AnkiDroidJsAPI) to connect template scripts and Android-native actions.
6. Content authoring and browsing
Card creation and editing are centered around the note editor, multimedia editor, image cropping/occlusion, notetype editor, tag dialogs, and card browser/search. The browser subsystem supports advanced filtering, saved searches, bulk operations, and column selection, while the previewer and template previewer provide inspection/editing paths for note/card templates.
7. Storage and profile model
User data is stored in Anki collections and media files, with profile-aware storage paths and restrictions managed by the multiprofile layer. The app also keeps separate local stores for app metadata, preferences, and review reminders; this means the diagram should distinguish collection data from application settings and auxiliary databases.
8. Background/system integration
Long-running or deferred work is handled by services, workers, alarms, and broadcast receivers. Key examples are sync workers, notification scheduling, boot/day-rollover handling, media sync, and widgets; these are the boundary where Android system events re-enter the app and trigger domain work.
9. External integrations
The primary external service is AnkiWeb for synchronization. The app also integrates with crash reporting/analytics, system TTS/STT, Android permissions/scoped storage, and notification APIs; there is also support for add-ons and external content import via intents and provider-style interfaces.
10. Shared platform abstractions
common/, anki-common/, and compat/ exist to reduce duplication and isolate platform-specific behavior. common/ provides time/json/filesystem utilities and annotations; compat/ wraps Android version differences; anki-common/ carries shared navigation destination abstractions; and vbpd/ supports view binding ergonomics across the app.
11. Public API surface
The api/ module exposes a separate, smaller API for external callers to create or inspect notes/cards. This is a deliberate boundary: external apps should interact with the API module, not with the main app internals or libanki directly.
12. Build, quality, and localization
The repo is heavily tooling-driven: Gradle multi-module builds, custom lint rules, extensive unit/instrumentation tests, and GitHub Actions workflows. The UI is localized via a large resource set and uses theme/resource overlays to support many languages, tablet layouts, night modes, and device-specific variants.
13. How the data flows end-to-end
Typical flows start in an Activity/Fragment, pass through a ViewModel or service layer, then into libanki for collection operations, scheduling, or sync. Results come back as model state/UI state, while side effects fan out to storage, media files, notifications/widgets, or external sync endpoints.
Main entry points: LibAnki.kt LibAnki · AnkiDroidApp.kt App shell · DeckPicker.kt Deck picker · ReviewerFragment.kt Reviewer
Components 21
Android app
Main AnkiDroid runtime, UI, and Android integration.
- App shell · Application bootstrap, lifecycle, intent handling, and top-level navigation.
AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidApp.kt - Deck picker · Entry screen for selecting decks, starting study, and reaching key app areas.
AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt - Reviewer · Review session UI, answer controls, gestures, timers, audio, TTS, and whiteboard.
AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt - Card viewer · Template rendering and JS bridge for card question/answer content.
AnkiDroid/src/main/java/com/ichi2/anki/AnkiDroidJsAPI.kt - Note editor · Card and note creation/editing, field management, and media editing entry points.
AnkiDroid/src/main/java/com/ichi2/anki/NoteEditorActivity.kt - Card browser · Browse, filter, search, bulk edit, and inspect cards and notes.
AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserFragment.kt - Settings · Preference screens, reviewer controls, sync settings, and profile-related settings.
AnkiDroid/src/main/java/com/ichi2/anki/preferences/SettingsFragment.kt - Widgets · Home screen widgets and their configuration flows.
AnkiDroid/src/main/java/com/ichi2/widget/AddNoteWidget.kt - System work · Boot, alarms, notifications, scheduled sync, and other deferred Android entry points.
AnkiDroid/src/main/java/com/ichi2/anki/services/BootService.kt - Storage & profile · Collection location, profile isolation, metadata storage, and local app databases.
AnkiDroid/src/main/java/com/ichi2/anki/multiprofile/ProfileManager.kt - Sync & import · AnkiWeb sync, import/export, backups, and media synchronization orchestration.
AnkiDroid/src/main/java/com/ichi2/anki/Sync.kt
Core engine
Collection, scheduling, media, and sync domain logic.
- LibAnki · Collection model, scheduling, decks/cards/notes, media, storage, sync, and templates.
libanki/src/main/java/com/ichi2/anki/libanki/LibAnki.kt - Scheduler · Due calculation, card states, deck counts, and scheduling rules including FSRS-related logic.
libanki/src/main/java/com/ichi2/anki/libanki/sched/Scheduler.kt - Collection store · Collection files, DB access, storage helpers, and media-backed domain persistence.
libanki/src/main/java/com/ichi2/anki/libanki/Collection.kt - Templates & media · Card templates, HTML/template filters, LaTeX, audio/TTS, and media handling.
libanki/src/main/java/com/ichi2/anki/libanki/TemplateManager.kt
Shared modules
Reusable utilities, compatibility layers, API surface, and UI helpers.
- Common utils · Shared time, JSON, file, and utility primitives used across modules.
common/src/main/java/com/ichi2/anki/common/time/TimeManager.kt - Compat layer · Android API-level compatibility helpers and file/package abstractions.
compat/src/main/java/com/ichi2/anki/compat/Compat.kt - Public API · Separate contract for external callers to add or inspect notes/cards.
api/src/main/java/com/ichi2/anki/api/AddContentApi.kt - Nav shared · Reusable destination and navigator abstractions shared by app modules.
anki-common/src/main/java/com/ichi2/anki/common/destinations/Navigator.kt - VB helpers · View binding property helpers used across Android UI code.
vbpd/src/main/java/dev/androidbroadcast/vbpd/ViewBindingProperty.kt
Tooling
Build, quality, lint, and release support.
- Lint rules · Project-specific static analysis rules and lint registry.
lint-rules/src/main/java/com/ichi2/anki/lint/IssueRegistry.kt
Connections 26
- App shell → Deck picker: starts at · Bootstraps the main home/navigation flow.
- App shell → System work: receives system events · Application lifecycle and broadcast entry points re-enter through services and receivers.
- App shell → Storage & profile: selects storage · Chooses profile-aware paths and collection access.
- Deck picker → Reviewer: opens · Starts a study session from selected decks.
- Deck picker → Card browser: navigates to · Moves into card browsing and search workflows.
- Deck picker → Note editor: creates cards · Launches editing and note creation flows.
- Reviewer → Card viewer: renders cards · Uses the web-backed viewer for question/answer display and JS bridge actions.
- Reviewer → Scheduler: grades cards · Pulls due state and applies answer outcomes through scheduling logic.
- Reviewer → Templates & media: plays media · Handles audio, TTS, video, and template-driven content.
- Note editor → LibAnki: edits notes · Creates and updates notes, fields, notetypes, and cards in the collection.
- Card browser → LibAnki: queries collection · Searches, filters, and bulk-edits collection data.
- Settings → Storage & profile: configures profiles · Manages preferences and profile-scoped settings.
- Widgets → System work: refreshes via · Widget updates are scheduled and refreshed by alarms and workers.
- System work → Sync & import: runs sync · Deferred jobs trigger syncing, media sync, reminders, and notifications.
- Sync & import → LibAnki: syncs collection · Synchronizes collection and media state through the engine.
- LibAnki → Collection store: persists in · Stores the collection, decks, notes, cards, and media metadata.
- LibAnki → Scheduler: uses scheduler · Domain engine delegates spaced-repetition calculations to scheduler logic.
- LibAnki → Templates & media: manages templates · Owns templates, rendering helpers, and media-related domain logic.
- Common utils → App shell: shared by · App code depends on shared time, JSON, file, and utility primitives.
- Common utils → LibAnki: shared by · Core engine shares common primitives and test utilities.
- Compat layer → App shell: supports · Wraps Android version differences for app runtime behavior.
- Public API → LibAnki: separates from · Public API is a deliberate boundary and should not expose app internals directly.
- Nav shared → App shell: shared by · Navigation abstractions are reused across app modules.
- VB helpers → App shell: supports UI · Provides view binding ergonomics for Android screens and fragments.
- Lint rules → App shell: checks · Static analysis enforces project-specific app code conventions.
- Lint rules → Common utils: checks · Static analysis also enforces shared-module conventions and API hygiene.