How akylas/oss-documentscanner works
Project type and purpose
• This is a cross-platform mobile application repository hosting two apps (“OSS DocumentScanner” and “OSS CardWallet”) built with NativeScript+Svelte.
• It also contains a native image-processing plugin (plugin-nativeprocessor) leveraging OpenCV, Tesseract and ZXing, a core C++ library (cpp folder), a web PDF viewer SPA (webpdfviewer), end-to-end tests, and CI/CD scripts (fastlane, GitHub Actions).
Top-level components
• App Layer (app/): Svelte UI components, application bootstrap (bootstrap.ts), themes, i18n, models, helpers.
• Services Layer (app/services/): business logic for backend API, OCR, PDF export, QR code, security, shortcuts, sync (WebDAV/local).
• Native Bridge (shims/ + Nativescript runtime): platform shims for Android/iOS to bind JS → native calls.
• Native Processor Plugin (plugin-nativeprocessor/):
• Android submodule: Java/Kotlin bridge, JNI + C++ wrappers, OpenCV and Tesseract libs.
• iOS submodule: Swift/ObjC bridge, modulemap, OpenCV2.xcframework, Tesseract.
• Core C++ Library (cpp/): image-processing algorithms (document detection, OCR wrappers, QRCode, transforms) and JSONcons.
• Web PDF Viewer (webpdfviewer/): standalone Svelte+TypeScript SPA for viewing exported PDFs.
• Testing & CI (e2e/, fastlane/, .github/workflows/): Appium-Mocha tests, Fastlane metadata and release pipelines, GitHub Actions release build.
• Build & Config (webpack.config.js, tsconfig.json, svelte.config.js, env files, scripts/): compile, bundle, environment management.
Key interactions and data flows
• At runtime, the Svelte app uses NativeScript to render UI in a WebView-style or native UI layer.
• User actions → UI Components → invoke Services (OCRService, OCRDataView) → call into Native Bridge → plugin-nativeprocessor → native libs (OpenCV/Tesseract) → return processed image/text.
• PDF export triggers PDFExporter → PDFCanvas (platform-specific implementations) → may spawn PDFExportWorker for background rendering.
• Sync services (BaseDataSyncService, WebdavDataSyncService, LocalFolderPDFSyncService) read/write files from the device file system, manage metadata, and communicate over HTTP/WebDAV with external file servers or remote drives.
• QR code generation is handled via services/qrcode.ts and plugin code (ZXing).
• Preferences and security (passcode, storage encryption) are managed locally via services/preferences.ts and services/security.ts.
• The webpdfviewer is a separate static SPA that consumes exported PDF assets, unrelated to mobile runtime but sharing some transformer logic where feasible.
Architectural patterns and design principles
• Modular layered architecture: UI → Services → Native Bridge → Native Modules → External libs.
• Plugin pattern: plugin-nativeprocessor acts as an extensibility point for performance-critical image processing.
• Worker threads: heavy operations (PDF rendering, sync) offloaded to WebWorker‐style workers (SyncWorker, PDFExportWorker).
• Environment-based configuration: uses APP_ID, APP_RESOURCES to toggle between the two apps.
• Cross-platform abstraction: shims and ts “.common/.android/.ios” files implement platform differences.
• CI/CD integration: fastlane for store publishing, GitHub Actions for releases, environment files for signing credentials.
• Clear component labels with folder path hints (e.g., “app/services/ocr.ts”).
• A note on environment‐driven app selection (APP_ID → App_Resources).