How dinesh-sowndar/flutter_billing_app works
1. Overall shape
This is a Flutter mobile POS/billing app organized as a feature-first Clean Architecture codebase. The app is primarily offline and runs on-device across Android, iOS, and web targets, with the business logic centered in lib/ and platform shell code in android/, ios/, and web/.
2. Application bootstrap
lib/main.dart is the entry point and likely wires together the global app setup: dependency injection, local storage initialization, theme, and routing. The repository also has lib/core/service_locator.dart, which indicates get_it is used to register repositories, blocs, and shared services before the UI starts.
3. Routing and top-level navigation
lib/config/routes/app_routes.dart is the central route map. The UI is split into page-level screens for product management, billing/checkout, shop settings, and printer settings, so the navigation boundary is probably route-driven rather than a single monolithic shell.
4. Core shared layer
lib/core/ contains app-wide concerns that are reused across features:
- data/hive_database.dart for local persistence initialization
- error/failure.dart for standardized failure handling
- usecase/usecase.dart for domain use case contracts
- theme/app_theme.dart for global styling
- utils/ for helpers such as validation and printer support
- widgets/ for reusable UI components like primary buttons and labeled inputs
This layer acts as the shared foundation for all feature modules.
5. Offline data persistence
The main persistence mechanism is Hive (hive / hive_flutter), which supports the app’s offline-first operation. Generated adapters/models like product_model.g.dart and shop_model.g.dart show that entities are serialized locally and stored without a backend dependency. That makes local storage the authoritative source for inventory, shop info, and likely cart/billing state.
6. Feature modules and bounded contexts
The repo is split into four main feature areas:
- billing for cart, checkout, and receipt flow
- product for inventory CRUD
- shop for shop profile/details
- settings for printer and device-related configuration
Each feature has its own data, domain, and presentation subfolders, which keeps dependencies flowing inward from UI to domain to data.
7. Domain layer patterns
The domain folders define the core business entities and contracts:
- product.dart, shop.dart, cart_item.dart
- repository interfaces such as product_repository.dart, shop_repository.dart, printer_repository.dart
- usecase collections like product_usecases.dart and shop_usecases.dart
This indicates the app isolates business rules from persistence and UI, with repositories as the boundary between domain logic and local/device-specific implementations.
8. State management and presentation flow
Each feature has a BLoC in presentation/bloc/ plus page widgets under presentation/pages/. The likely flow is: UI page dispatches an event → BLoC executes a use case/repository call → BLoC emits a new immutable state → page rebuilds. This pattern appears in billing_bloc.dart, product_bloc.dart, shop_bloc.dart, and printer_bloc.dart.
9. Data layer responsibilities
Feature data folders contain model classes and repository implementations:
- product_repository_impl.dart
- shop_repository_impl.dart
- printer_repository_impl.dart
along with model classes like product_model.dart and shop_model.dart. This suggests the data layer adapts Hive or hardware APIs into repository contracts, keeping the domain layer free of storage and platform details.
10. Hardware and device integrations
The app is not just a CRUD system; it integrates with device hardware:
- mobile_scanner for barcode/QR scanning in the checkout and product workflows
- print_bluetooth_thermal for thermal receipt printing
- printer-specific helpers in lib/core/utils/printer_helper.dart
These integrations are important architectural boundaries because they sit outside pure app logic and likely feed into the billing and settings features.
11. Primary user workflows
The main data flow is retail-oriented: product data is created/edited in the product feature, shop details are configured in shop settings, checkout uses scanned or manually entered items to build a cart, and printing produces a receipt using shop metadata plus cart totals. In other words, billing depends on product and shop data, while printer configuration influences the final output stage.
12. Shared UI and validation
Reusable widgets such as input_label.dart and primary_button.dart, along with app_validators.dart, suggest the UI is built from shared form primitives rather than duplicated per screen. This reduces friction across product, shop, and settings forms and keeps validation rules consistent.
13. Platform-specific shells
The Android and iOS directories are standard Flutter platform hosts. Android contains the Kotlin MainActivity and Gradle setup; iOS contains the Swift AppDelegate, Xcode project, Podfile, and launch assets. These do not define business architecture, but they are the platform boundaries where Flutter plugins for scanning, Bluetooth, and local storage are activated.
14. Project intent for diagramming
If you draw the architecture, the highest-level boxes should be: Flutter UI/Presentation, Feature-specific BLoC layer, Domain use cases and entities, Data/repository implementations, and Shared infrastructure (Hive, DI, printer/scanner helpers). The key external dependencies are local device storage and hardware peripherals, not a remote API or server backend.
Main entry points: billing_bloc.dart Billing BLoC · app_routes.dart Routes · service_locator.dart DI · main.dart main.dart
Components 29
App Shell
Flutter entrypoint, navigation, and platform hosts
Shared Core
Reusable infrastructure and app-wide utilities
- DI · Registers repositories, blocs, and shared services
lib/core/service_locator.dart - Hive DB · Hive initialization and persistence setup
lib/core/data/hive_database.dart - Theme · Global app styling
lib/core/theme/app_theme.dart - Validators · Shared input validation helpers
lib/core/utils/app_validators.dart - Printer Helper · Shared thermal printer support
lib/core/utils/printer_helper.dart
Billing
Checkout and receipt flow
- Billing BLoC · Checkout and scan state orchestration
lib/features/billing/presentation/bloc/billing_bloc.dart - Checkout · Cart and payment UI
lib/features/billing/presentation/pages/checkout_page.dart - Scanner · Barcode/QR scanning UI
lib/features/billing/presentation/pages/scanner_page.dart - Cart Item · Billing cart domain model
lib/features/billing/domain/entities/cart_item.dart
Product
Inventory management feature
- Product BLoC · Inventory state orchestration
lib/features/product/presentation/bloc/product_bloc.dart - Products · Inventory list and management UI
lib/features/product/presentation/pages/product_list_page.dart - Product Usecases · Product business operations
lib/features/product/domain/usecases/product_usecases.dart - Product Repo · Product persistence contract
lib/features/product/domain/repositories/product_repository.dart - Product Store · Product repository implementation over local storage
lib/features/product/data/repositories/product_repository_impl.dart - Product Model · Hive-backed product serialization
lib/features/product/data/models/product_model.dart - Product · Inventory domain entity
lib/features/product/domain/entities/product.dart
Shop
Shop profile feature
- Shop BLoC · Shop settings orchestration
lib/features/shop/presentation/bloc/shop_bloc.dart - Shop Details · Shop profile and metadata UI
lib/features/shop/presentation/pages/shop_details_page.dart - Shop Usecases · Shop business operations
lib/features/shop/domain/usecases/shop_usecases.dart - Shop Repo · Shop persistence contract
lib/features/shop/domain/repositories/shop_repository.dart - Shop Store · Shop repository implementation over local storage
lib/features/shop/data/repositories/shop_repository_impl.dart - Shop Model · Hive-backed shop serialization
lib/features/shop/data/models/shop_model.dart - Shop · Shop domain entity
lib/features/shop/domain/entities/shop.dart
Settings
Printer and device settings
- Printer BLoC · Printer configuration orchestration
lib/features/settings/presentation/bloc/printer_bloc.dart - Settings · Printer and device settings UI
lib/features/settings/presentation/pages/settings_page.dart - Printer Repo · Printer configuration contract
lib/features/settings/domain/repositories/printer_repository.dart - Printer Config · Printer repository implementation
lib/features/settings/data/repositories/printer_repository_impl.dart
Connections 36
- main.dart → DI: initializes · Bootstraps dependency registration before the app starts
- main.dart → Routes: uses · Starts the route-driven UI shell
- main.dart → Theme: applies · Sets global visual theme
- DI → Hive DB: registers · Wires local persistence services
- DI → Product Store: registers · Provides product data implementation
- DI → Shop Store: registers · Provides shop data implementation
- DI → Printer Config: registers · Provides printer configuration implementation
- Routes → Checkout: navigates to · Checkout screen route
- Routes → Products: navigates to · Inventory screens route
- Routes → Shop Details: navigates to · Shop details route
- Routes → Settings: navigates to · Settings route
- Checkout → Billing BLoC: drives · Dispatches checkout and scan events
- Scanner → Billing BLoC: feeds · Scanner input updates billing state
- Billing BLoC → Cart Item: manages · Operates on cart domain items
- Billing BLoC → Product Repo: reads · Looks up product data for cart and scan flows
- Billing BLoC → Shop Repo: reads · Uses shop metadata for checkout context
- Billing BLoC → Printer Helper: prints via · Sends receipt output to thermal printer support
- Products → Product BLoC: drives · Dispatches inventory events
- Product BLoC → Product Usecases: executes · Uses product business operations
- Product Usecases → Product Repo: depends on · Depends on repository boundary
- Product Store → Product Repo: implements · Adapts storage to repository contract
- Product Store → Product Model: maps · Persists product data as local model
- Product Model → Hive DB: stored in · Hive-backed serialization
- Product Usecases → Product: operates on · Business rules around product entity
- Shop Details → Shop BLoC: drives · Dispatches shop events
- Shop BLoC → Shop Usecases: executes · Uses shop business operations
- Shop Usecases → Shop Repo: depends on · Depends on repository boundary
- Shop Store → Shop Repo: implements · Adapts storage to repository contract
- Shop Store → Shop Model: maps · Persists shop data as local model
- Shop Model → Hive DB: stored in · Hive-backed serialization
- Shop Usecases → Shop: operates on · Business rules around shop entity
- Settings → Printer BLoC: drives · Dispatches printer settings events
- Printer BLoC → Printer Repo: executes · Uses printer configuration contract
- Printer Config → Printer Repo: implements · Adapts device configuration to repository contract
- Product BLoC → Validators: uses · Shares form validation logic
- Shop BLoC → Validators: uses · Shares form validation logic