CLAUDE
SmartCrew Admin - CLAUDE
CLAUDE.md
This file provides comprehensive guidance to Claude Code (claude.ai/code) when working with the SmartCrew Admin Console codebase.
Project Overview
SmartCrew Admin Console is a Flutter web application for managing construction projects. It provides comprehensive administrative interfaces for managing projects, labor, materials, equipment, customers, vendors, and generating reports.
Technology Stack
- Framework: Flutter Web (Material Design)
- State Management: Provider pattern with ChangeNotifier
- Backend: Firebase (Auth, Firestore, Functions, Storage)
- Code Generation: flutter_gen for assets, build_runner for various generators
- Deployment: Firebase Hosting
Development Commands
Running the Application
# Start development server
flutter run -d web-server --web-hostname 0.0.0.0 --web-port 8080
# Run with specific browser
flutter run -d chromeBuilding & Deployment
# Build for production
flutter build web
# Deploy to Firebase Hosting
firebase deploy --only hostingCode Generation
# Generate code for assets, colors, fonts
flutter packages pub run build_runner build --delete-conflicting-outputs
# Watch mode for continuous generation
flutter packages pub run build_runner watch --delete-conflicting-outputsDependency Management
flutter pub get # Install dependencies
flutter pub upgrade # Upgrade dependencies
flutter pub outdated # Check for outdated packagesTesting & Quality
flutter test # Run unit tests
flutter analyze # Static code analysis
flutter format . # Format codeEnvironment Configuration
The app uses config.env file with these key variables:
FUNCTIONS_REGION: Cloud Functions region (default: us-central1)PROJECT_NAME: SmartCrewCURRENT_URL: Web app URL for deep linking
Project Structure
Root Directory
smartcrew_admin/
├── .firebase/ # Firebase hosting cache
├── ai/ # AI-related scripts and configurations
├── assets/ # Static assets (images, icons, fonts)
├── build/ # Build output directory
├── lib/ # Main source code
├── web/ # Web-specific files (index.html, favicon, manifest)
├── config.env # Environment configuration
├── firebase.json # Firebase configuration
├── pubspec.yaml # Flutter dependencies and project configuration
└── CLAUDE.md # This file - project documentation for ClaudeCore Library Structure (lib/)
/lib/main.dart
- Entry point of the application
- Initializes Firebase, environment variables, and providers
- Sets up MultiProvider with all necessary providers
- Configures routing and theme
/lib/providers/ - State Management Layer
All state management using Provider pattern with ChangeNotifier.
Core Providers:
auth_provider.dart: Manages Firebase authentication state, user sessions, and auth tokenshome_provider.dart: Controls navigation state, screen switching, and sidebar managementtable_filter_controller.dart: Generic table filtering, pagination, and sorting logicreport_provider.dart: Report generation and managementusers_data_provider.dart: User-specific data management
/lib/providers/network_data_providers/ - Data Fetching Layer
Central data management using mixin pattern:
network_data_provider.dart: Singleton that aggregates all data providers via mixins- Initializes all repositories on app startup
- Manages Firebase Functions and Firestore instances
- Orchestrates parallel data fetching
Domain-Specific Provider Mixins:
users_provider.dart: Employee/user managementproject_provider.dart: Project CRUD operationscustomers_provider.dart: Customer relationship managementvendors_provider.dart: Vendor/supplier managementmaterials_provider.dart: Construction materials inventoryequipment_provider.dart: Equipment tracking and managementequipment_category_provider.dart: Equipment categorizationactivity_provider.dart: Activity logging and trackingcompany_provider.dart: Company/organization settingsadmin_log_provider.dart: Administrative action loggingdocument_provider.dart: Document managementtime_off_provider.dart: Employee time-off requests
/lib/providers/ui_providers/ - UI State Management
UI-specific state providers for complex UI components
/lib/screens/ - Presentation Layer
/lib/screens/logged_out/
login_screen.dart: Authentication interfaceforgot_password_screen.dart: Password recovery
/lib/screens/logged_in/ - Main Application Screens
Each feature follows this organizational pattern:
feature/
├── feature_screen.dart # Main screen widget
├── tables/ # Data table components
├── widgets/ # Feature-specific widgets
├── modals/ # Feature-specific modals
└── charts/ # Visualization componentsFeature Modules:
-
dashboard/: Main dashboard with statistics and overview- Real-time metrics display
- Quick actions and navigation
- Activity feed
-
labor/: Employee and labor management- Employee time tracking
- Labor allocation to projects
- Time card management
- Payroll calculations
-
project/: Project management- Project creation and editing
- Jobsite management
- Resource allocation
- Timeline tracking
-
materials/: Materials inventory- Inventory tracking
- Usage reports
- Purchase orders
- Material allocation to projects
-
equipment/: Equipment management- Equipment inventory
- Service records
- Maintenance scheduling
- Usage tracking
-
customers/: Customer relationship management- Customer profiles
- Contact management
- Project associations
- Notes and communications
-
vendors/: Vendor management- Vendor profiles
- Purchase history
- Contract management
-
reports/: Reporting and analytics- Custom report generation
- Data export functionality
- Analytics dashboards
-
settings/: Application settings- User preferences
- Company configuration
- System settings
- Integration configurations
-
tables/: Shared table components- Abstract base classes for tables
- Common table widgets
- Filtering and sorting utilities
/lib/services/ - Business Logic Layer
Domain-driven service organization for business logic:
Service Directory Structure:
base/: Base service classes and interfacesactivity/: Activity logging servicescustomer/: Customer-related business logicdashboard/: Dashboard data aggregationequipment/: Equipment lifecycle managementlabor/: Complex labor calculationstime_card/: Time card processing- Various calculation services (daily, weekly, range)
log/: Logging services for different entitiesmaterial/: Material inventory logicproject/: Project management logicreport/: Report generation servicesutils/: Shared utility services
/lib/models/ - Data Layer
Data models and DTOs:
Core Models:
- User/Auth Models:
app_user.dart, authentication data - Project Models:
project.dart,jobsite.dart,location.dart - Resource Models:
materials.dart,equipment.dart,labor.dart - Business Models:
customer.dart,vendor.dart,company.dart - System Models:
activity.dart,admin_log.dart,document.dart - Utility Models:
status.dart,months.dart,currency.dart
/lib/models/log/ - Specialized Log Models
Various log types for different tracking needs
/lib/components/ - Reusable UI Components
Component Categories:
cards/: Reusable card components for data displaycustom/: Custom widgets specific to the applicationdropdowns/: Specialized dropdown componentsmodals/: Base modal classes and implementationssettings/: Settings modal with tabbed interfacesettings/tabs/: Individual setting tabs
page_prefabs/: Pre-built page templates
Key Components:
search_box.dart: Universal search componenttypeahead_textfield.dart: Auto-complete text inputshimmer_container.dart: Loading placeholdervideo_thumbnail.dart: Video preview widget
/lib/util/ - Utilities and Helpers
Utility Categories:
adapter/: Data adapters and transformers (19 adapters)extensions/: Dart extension methods (10 extensions)- String extensions
- DateTime extensions
- List extensions
- Context extensions
Core Utilities:
app_dialog.dart: Dialog utilitiesapp_spacing.dart: Spacing constants and helperschoose_file.dart: File picker utilitiesloading.dart: Loading indicatorslog_utils.dart: Logging utilitiestext_styles.dart: Text style definitionsnotifications_helper.dart: Toast/notification helpers
/lib/repositories/ - Data Access Layer
Repository pattern implementations for data access
/lib/gen/ - Generated Code
Auto-generated files (DO NOT EDIT MANUALLY):
assets.gen.dart: Type-safe asset referencescolors.gen.dart: Color constants from design systemfonts.gen.dart: Font family definitions
Architecture Patterns
State Management Architecture
NetworkDataProvider (Singleton)
├── UsersProvider (Mixin)
├── ProjectProvider (Mixin)
├── CustomersProvider (Mixin)
├── VendorsProvider (Mixin)
├── MaterialsProvider (Mixin)
├── EquipmentProvider (Mixin)
└── [Other Provider Mixins]Data Flow Pattern
- Initialization: NetworkDataProvider.init() fetches all initial data in parallel
- State Updates: Providers notify listeners on data changes
- UI Reaction: Widgets rebuild using context.watch<Provider>()
- User Actions: UI triggers provider methods
- Backend Sync: Providers update Firestore/Functions
- Real-time Updates: Firestore listeners update provider state
Navigation Architecture
- Route Guard: Wraps all routes to check authentication
- Screen Enum: Centralized screen definitions in HomeProvider
- Dynamic Routing: Screen switching via HomeProvider.setScreen()
- Responsive Layout: Adapts between wide and mobile layouts
Modal System Pattern
class CustomModal extends StatelessWidget {
static Future<void> show(BuildContext context, {required params}) {
// Standard modal showing pattern
}
}Service Layer Pattern
Services encapsulate complex business logic:
- Stateless service classes
- Domain-specific organization
- Testable business logic
- Separation from UI and data layers
Key Conventions
Code Organization
- Feature-First Structure: Screens organized by feature, not by type
- Barrel Exports: Use index files for clean imports
- Mixin Composition: NetworkDataProvider uses mixins for separation of concerns
- Service Isolation: Business logic separated from UI and data access
Provider Usage Guidelines
// One-time read (actions)
context.read<MyProvider>().callMethod();
// Reactive updates (UI binding)
final data = context.watch<MyProvider>().property;
// Selective watching
final specific = context.select<MyProvider, SpecificType>((p) => p.specific);Firebase Integration Points
- Authentication: Firebase Auth with custom claims
- Database: Firestore with offline support
- Functions: Cloud Functions for complex operations
- Storage: Firebase Storage for file uploads
- Hosting: Firebase Hosting for deployment
Responsive Design Approach
- Breakpoints: Wide layout (>960px), Mobile layout (<960px)
- Adaptive Widgets: Different widgets for different screen sizes
- Flexible Layouts: Use Flex widgets for responsive design
Error Handling Strategy
- Try-catch blocks in service methods
- User-friendly error messages via toast notifications
- Logging errors to console in development
- Firebase Crashlytics in production
Performance Optimizations
- Lazy Loading: Load data on-demand
- Pagination: TableFilterController for large datasets
- Caching: Provider state caching
- Parallel Fetching: Future.wait for concurrent operations
Common Tasks
Adding a New Feature
- Create feature folder in
/lib/screens/logged_in/ - Add provider mixin to NetworkDataProvider if needed
- Create service classes in
/lib/services/ - Add models in
/lib/models/ - Update HomeProvider with new screen enum
- Add navigation item to sidebar
Creating a New Modal
- Extend base modal class
- Implement static show() method
- Handle form validation and submission
- Use Provider for state management
Adding a New Table
- Create table widget in feature's
tables/folder - Use TableFilterController for filtering/pagination
- Implement sorting and search
- Add export functionality if needed
Implementing a New Service
- Create service class in appropriate
/lib/services/subfolder - Keep services stateless
- Return typed results
- Handle errors appropriately
- Write unit tests
Testing Strategy
Unit Tests
- Test services independently
- Mock Firebase dependencies
- Test model serialization
- Validate business logic
Widget Tests
- Test individual components
- Mock providers
- Verify user interactions
- Check responsive behavior
Integration Tests
- Test complete user flows
- Verify Firebase integration
- Test real-time updates
- Validate navigation
Deployment Checklist
- Run
flutter analyze- fix any issues - Run
flutter test- ensure all tests pass - Update version in
pubspec.yaml - Build production:
flutter build web - Test locally:
firebase serve - Deploy:
firebase deploy - Verify deployment at production URL
- Monitor error logs in Firebase Console
Performance Monitoring
Key Metrics to Track
- Initial load time
- Time to interactive
- API response times
- Memory usage
- Frame rendering performance
Optimization Areas
- Bundle size optimization
- Image optimization
- Lazy loading implementation
- Code splitting
- Tree shaking
Security Considerations
- Authentication: All routes protected by RouteGuard
- Authorization: Role-based access control via custom claims
- Data Validation: Client and server-side validation
- Sensitive Data: Never log sensitive information
- API Security: Cloud Functions validate auth tokens
- CORS Configuration: Properly configured for web
Troubleshooting Guide
Common Issues
- Provider Not Found: Ensure provider is added to MultiProvider
- Navigation Issues: Check HomeProvider screen enum
- Data Not Loading: Verify NetworkDataProvider initialization
- Build Errors: Run
flutter cleanand rebuild - Firebase Errors: Check Firebase configuration and rules
Important Notes
- Singleton Pattern: NetworkDataProvider is a singleton - use factory constructor
- Async Initialization: Wait for NetworkDataProvider.init() before showing UI
- Generated Files: Never edit files in
/lib/gen/- they're auto-generated - Environment Variables: Always use config.env for configuration
- Code Style: Follow Flutter style guide and use
flutter format - Commits: Write clear, descriptive commit messages
- Documentation: Update this file when adding major features
External Dependencies
Key packages and their purposes:
provider: State managementfirebase_*: Firebase integrationbot_toast: User notificationsdata_table_2: Advanced data tablesflutter_gen: Code generationintl: Internationalizationpdf: PDF generation for reportssyncfusion_flutter_charts: Data visualization
Contact & Support
For questions about the codebase architecture or development practices, consult the team lead or refer to the internal documentation.