Introduction
Numix is built on a Domain-Driven Feature-First (DDD) architecture that emphasizes modularity, separation of concerns, and scalability. This architectural approach ensures that each business domain is completely isolated and self-contained, making the codebase easier to maintain, test, and scale.The architecture strictly enforces that UI components remain “dumb” - they only display data and trigger events, while all business logic resides in providers or services.
Core Principles
Feature Isolation
Each feature is a completely independent module with its own screens, widgets, providers, and business logic. Features don’t depend on each other.
Separation of Concerns
Clear boundaries between UI (screens/widgets), state management (providers), and business logic (services) ensure maintainable code.
Mathematical Precision
All calculations use
math_expressions library with proper error handling to prevent floating-point errors and crashes.State Persistence
User inputs and calculations are automatically saved using
SharedPreferences, providing seamless app restart recovery.Directory Structure
Thelib/ directory is organized into two main sections:
Features Directory
Thefeatures/ directory contains all business domains, where each feature is completely self-contained:
Core Directory (Planned)
While not currently implemented, the architecture reserves space for acore/ directory that would contain:
- Utilities: App-wide helper functions and formatters
- Theme: Material 3 theme configuration and constants
- Constants: Global app constants and configurations
- Formatters: Number formatting utilities for mathematical precision
Technology Stack
| Component | Technology | Purpose |
|---|---|---|
| Framework | Flutter (Dart ^3.6.0) | Cross-platform mobile development |
| State Management | provider package | Reactive state management with ChangeNotifier |
| Persistence | shared_preferences | Local key-value storage for state persistence |
| Math Engine | math_expressions | Safe mathematical expression evaluation |
| UI Design | Material Design 3 | Modern, consistent user interface |
Architectural Guarantees
1. Dumb Widgets Pattern
UI components are strictly presentational. They:- Display data received from providers
- Trigger events through provider methods
- Never contain business logic or calculations
- Use
context.read()for events andcontext.watch()for reactive updates
2. Mathematical Safety
All numerical operations follow strict safety rules:- Use
double.tryParse()instead ofdouble.parse()to prevent crashes - Wrap calculations in try-catch blocks for
FormatExceptionhandling - Validate all inputs before performing calculations
- Use precise decimal arithmetic to avoid floating-point errors
3. Performance Optimization
The architecture ensures optimal performance:context.read()for one-time operations (no rebuilds)context.watch()orConsumeronly for reactive UI elements- Minimal widget rebuilds maintain 60/120 fps
- Efficient state updates through
ChangeNotifier
Development Workflow
When adding new features to Numix:- Create Feature Directory: Add a new directory under
lib/features/ - Implement Provider: Create state management logic in
providers/ - Build UI: Implement screens and widgets with no business logic
- Register Provider: Add to
MultiProviderinmain.dart - Test: Write unit tests for provider logic (100% coverage required)
The codebase is maintained collaboratively with an AI ecosystem. See
AGENTS.md and the .ai/ directory for agent guidelines, skills, and architectural constraints.Next Steps
Feature-First Architecture
Deep dive into how features are structured and isolated
State Management
Learn about provider patterns and state persistence