What is Feature-First Architecture?
Feature-First (also called Feature-Driven or Package-by-Feature) architecture organizes code around business features rather than technical layers. Instead of grouping all screens together, all providers together, etc., each feature contains everything it needs to function independently.Traditional Layered
Feature-First
Benefits of Feature-First Design
1. Complete Isolation
Each feature is a self-contained module that can be developed, tested, and maintained independently:- No Cross-Feature Dependencies: Features don’t import from each other
- Parallel Development: Multiple developers can work on different features simultaneously
- Easy Testing: Test each feature in isolation without complex setup
- Simple Removal: Delete a feature directory to remove functionality
2. Scalability
As the app grows, adding new features is straightforward:- Create a new feature directory
- Implement the feature following established patterns
- No need to modify existing features
- Codebase remains organized regardless of size
3. Clear Ownership
Each feature directory clearly shows what belongs to that business domain:- All related code lives together
- Easy to understand feature scope
- Simplified code reviews
- Clear boundaries for refactoring
Feature Structure
Each feature in Numix follows a consistent internal structure:Example: Discount Calculator Feature
Example: Sales Price Calculator Feature
Real Feature Example: Discount Calculator
Let’s examine how the discount calculator feature is structured:Provider (Business Logic)
The provider handles all calculations and state management:lib/features/discount_calculator/providers/discount_provider.dart
Screen (UI Presentation)
The screen is a “dumb widget” that only displays data and triggers events:lib/features/discount_calculator/screens/discount_calculator_screen.dart
Notice how the screen uses
context.read() for triggering actions and context.watch() for reactive updates. This ensures optimal performance.Current Features in Numix
Here are all the features currently implemented:Discount Calculator
Calculate discounts with percentage or fixed amounts, including cascading discounts and tax calculation.Location:
lib/features/discount_calculator/Sales Price Calculator
Determine sales prices based on cost, markup/margin, and tax percentages.Location:
lib/features/sales_price_calculator/Product Inventory
Manage product inventory tracking and stock levels.Location:
lib/features/product_inventory/Sales History
View and manage historical sales records.Location:
lib/features/sales_history/Home
Main navigation hub for accessing all calculators and tools.Location:
lib/features/home/Welcome
Onboarding screen shown on first app launch.Location:
lib/features/welcome/Adding a New Feature
Follow these steps to add a new feature to Numix:Step 1: Create Feature Directory
Step 2: Create Provider
Create your state management class:lib/features/my_feature/providers/my_provider.dart
Step 3: Create Screen
Build your UI:lib/features/my_feature/screens/my_screen.dart
Step 4: Register in main.dart
Add your provider to the app:lib/main.dart
Step 5: Add Navigation
Link to your feature from the home screen:Best Practices
Do’s ✅
- Keep features completely independent
- Put all feature-related code in the feature directory
- Use descriptive feature names based on business domains
- Follow the established directory structure
- Write tests for each feature’s provider logic
Don’ts ❌
- Don’t import from other features
- Don’t put business logic in widgets
- Don’t create shared state between features
- Don’t skip the provider layer
- Don’t forget to register providers in
main.dart
Next Steps
State Management
Learn about provider patterns and state persistence
Architecture Overview
Review the high-level architecture principles