Skip to main content

Overview

The Invenicum project follows Flutter conventions with a well-organized structure that separates concerns and promotes maintainability.

Root Directory Structure

lib/ Directory Breakdown

High-Level Organization

Detailed Structure

1. Entry Point

lib/main.dart The application bootstraps here:
  • Provider hierarchy setup (lib/main.dart:64-261)
  • Router configuration
  • Theme initialization
  • Localization configuration

2. Configuration Layer

lib/config/ Centralized configuration management:
Purpose: Single source of truth for environment variables, avoiding hardcoded values throughout the app.

3. Core Infrastructure

lib/core/ Core utilities shared across the application:
Key files:
  • app_router.dart: Defines all routes, auth guards, deep-link handling
  • sdk_plugin_parser.dart: Custom action parser for the plugin system

4. Data Layer

lib/data/ Contains all data-related code:

Models (lib/data/models/)

Data Transfer Objects (DTOs) representing API responses and business entities:
Pattern: All models implement fromJson() and toJson() for serialization.

Services (lib/data/services/)

API integration layer:
Service Pattern:
  • All services receive ApiService via constructor
  • Use dio from ApiService for HTTP calls
  • Transform JSON to models using Model.fromJson()
  • Throw exceptions for error handling
Example:

5. State Management Layer

lib/providers/ All application state is managed through ChangeNotifier providers:
Provider Responsibilities:
  • Manage domain-specific state (loading, data, errors)
  • Call services for data operations
  • Implement caching strategies
  • Notify listeners on state changes
  • Handle filtering, sorting, pagination (client-side)
See State Management for detailed patterns.

6. Presentation Layer

lib/screens/ Full-page screens organized by feature:
Screen Organization Pattern:
  • Each feature has its own directory
  • Main screens at the top level
  • local_widgets/ for screen-specific components (not reusable)
  • CRUD pattern: List, Detail, Create, Edit screens

7. Reusable Widgets

lib/widgets/ Shared widgets used across multiple screens:
Key widgets:
  • main_layout.dart: Wraps all authenticated routes, provides header, sidebar, and plugin slots
  • sidebar_layout.dart: Hierarchical navigation (containers, asset types, locations)
  • stac_slot.dart: Dynamic widget slot for plugin UI injection

8. Localization

lib/l10n/ Internationalization files:
Usage:
Configuration: pubspec.yaml:89 enables generate: true for l10n.

Assets Organization

assets/
Declared in: pubspec.yaml:92-93

Dependencies

pubspec.yaml Key dependencies:

File Naming Conventions

  1. Dart files: snake_case.dart
    • Example: inventory_item_provider.dart
  2. Screens: {feature}_{action}_screen.dart
    • Example: asset_create_screen.dart
  3. Widgets: {name}_widget.dart
    • Example: search_bar_widget.dart
  4. Models: {entity}_model.dart or {entity}.dart
    • Example: user_data_model.dart, loan.dart
  5. Services: {domain}_service.dart
    • Example: inventory_item_service.dart
  6. Providers: {domain}_provider.dart
    • Example: auth_provider.dart

Code Organization Best Practices

Import Ordering

Follow this order in import statements:

Directory Depth

  • Keep nesting to maximum 3 levels when possible
  • Use local_widgets/ to avoid cluttering screen directories
  • Group related screens in feature directories

Module Boundaries

  • Screens should NOT import from other screen directories
  • Widgets should be truly reusable (no business logic)
  • Providers should NOT import screens or widgets
  • Services should be pure (no Flutter dependencies except debugPrint)

Route Paths

Routes follow REST-like patterns:
Defined in: lib/core/routing/app_router.dart

Next Steps