FocusFlow follows a Domain-Driven Modular Architecture, separating presentation, state management, business logic, navigation, and persistence into dedicated layers.
This approach improves maintainability, scalability, testability, and developer experience while minimizing coupling between features.
The application is built around three core principles:
Each layer has a single responsibility:
- Components β Render UI only
- Hooks β Execute business logic
- Contexts β Manage global application state
- Navigation β Handle routing and access control
- Utilities β Perform pure data operations
Data always moves in a predictable direction:
Storage
β
βΌ
Custom Hooks
β
βΌ
Context Providers
β
βΌ
Screens
β
βΌ
UI Components
This predictable flow reduces side effects and makes debugging significantly easier.
New features can be added without modifying existing domains:
components/
hooks/
screens/
utils/
Each feature remains isolated, preventing architectural degradation as the application grows.
The entire application follows a React-centric state pipeline.
ββββββββββββββββββββββ
β AsyncStorage β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Storage Helpers β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Custom Hooks β
β useHabitStorage() β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Context Providers β
β Auth / Theme β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Screens β
βββββββββββ¬βββββββββββ
β
βΌ
ββββββββββββββββββββββ
β Components β
ββββββββββββββββββββββ
User Action
β
βΌ
HomeScreen
β
βΌ
useHabitStorage()
β
βΌ
storageHelpers.ts
β
βΌ
AsyncStorage
β
βΌ
Updated State
β
βΌ
FlatList Re-render
The UI updates immediately using optimistic state updates while persistence happens in the background.
Authentication is centralized through the AuthContext.
App Launch
β
βΌ
AuthContext Hydration
β
βΌ
Check Session State
β
βββββ΄βββββ
β β
βΌ βΌ
Logged Guest
In
β β
βΌ βΌ
MainTabs AuthStack
The RootNavigator acts as a gateway, ensuring protected routes remain inaccessible to unauthenticated users.
Theme state is globally managed and propagated through React Context.
ThemeContext
β
βΌ
Theme Toggle
β
βΌ
Palette Generation
β
βΌ
Context Update
β
βΌ
Automatic UI Re-render
All shared UI primitives consume theme values, ensuring consistent styling across the application.
FocusFlow/
βββ App.tsx
βββ app.json
β
βββ src/
β
βββ components/
β βββ common/
β β βββ CustomButton.tsx
β β βββ CustomInput.tsx
β β
β βββ habit/
β βββ HabitCard.tsx
β
βββ context/
β βββ AuthContext.tsx
β βββ ThemeContext.tsx
β
βββ hooks/
β βββ useHabitStorage.ts
β
βββ navigation/
β βββ types.ts
β βββ RootNavigator.tsx
β βββ AuthStack.tsx
β βββ MainTabs.tsx
β
βββ screens/
β βββ auth/
β β βββ LoginScreen.tsx
β β
β βββ main/
β βββ HomeScreen.tsx
β βββ ProfileScreen.tsx
β βββ HabitDetailScreen.tsx
β
βββ utils/
βββ storageHelpers.ts
Reusable UI building blocks.
Responsibilities
- Rendering
- Styling
- User interactions
- Memoization for performance
Examples
CustomButton
CustomInput
HabitCard
These components remain free from business logic and external state mutations.
Global application state management.
Handles:
- Session persistence
- Authentication state
- Route protection
- User hydration
Handles:
- Dark mode
- Light mode
- Dynamic color computation
- Global UI consistency
Encapsulates reusable business logic.
Provides:
- Create Habit
- Read Habit
- Update Habit
- Delete Habit
- Persistence Synchronization
This abstraction keeps screens lightweight and focused on presentation.
Defines application route topology.
Acts as the application's routing gateway.
Unauthenticated user routes.
Authenticated application routes.
Centralized TypeScript route definitions for compile-time safety.
Feature containers that connect UI to application state.
- Habit feed rendering
- FlatList orchestration
- Hook consumption
- Dynamic route parameter handling
- Detailed habit visualization
- Theme controls
- Authentication actions
Pure helper functions with no UI dependencies.
Responsible for:
- AsyncStorage access
- Data serialization
- Data deserialization
- Persistence abstraction
HabitCard utilizes memoization to prevent unnecessary re-renders during FlatList updates.
Authentication and theme state are separated to minimize component tree invalidation.
UI state updates instantly before storage writes complete, creating a smoother user experience.
Centralized route definitions eliminate runtime navigation errors.
- Modular feature expansion
- Clear architectural boundaries
- Predictable data flow
- Reduced coupling
- Easier testing
- Improved maintainability
- Production-ready folder organization
The architecture is intentionally designed to support growth from a small productivity application to a significantly larger mobile platform without requiring structural rewrites.