Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—οΈ Architecture & Project Structure

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.


🧠 Architectural Philosophy

The application is built around three core principles:

1. Separation of Concerns

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

2. Unidirectional Data Flow

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.

3. Feature Scalability

New features can be added without modifying existing domains:

components/
hooks/
screens/
utils/

Each feature remains isolated, preventing architectural degradation as the application grows.


πŸ”„ Application Data Flow

The entire application follows a React-centric state pipeline.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    AsyncStorage    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Storage Helpers   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Custom Hooks     β”‚
β”‚ useHabitStorage()  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Context Providers  β”‚
β”‚ Auth / Theme       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Screens       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚
          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     Components     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Example: Habit Creation Flow

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 Flow

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 Management Flow

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.


πŸ“‚ Directory Structure

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

🧩 Layer Breakdown

Components Layer

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.


Context Layer

Global application state management.

AuthContext

Handles:

  • Session persistence
  • Authentication state
  • Route protection
  • User hydration

ThemeContext

Handles:

  • Dark mode
  • Light mode
  • Dynamic color computation
  • Global UI consistency

Hooks Layer

Encapsulates reusable business logic.

useHabitStorage()

Provides:

  • Create Habit
  • Read Habit
  • Update Habit
  • Delete Habit
  • Persistence Synchronization

This abstraction keeps screens lightweight and focused on presentation.


Navigation Layer

Defines application route topology.

RootNavigator

Acts as the application's routing gateway.

AuthStack

Unauthenticated user routes.

MainTabs

Authenticated application routes.

types.ts

Centralized TypeScript route definitions for compile-time safety.


Screens Layer

Feature containers that connect UI to application state.

HomeScreen

  • Habit feed rendering
  • FlatList orchestration
  • Hook consumption

HabitDetailScreen

  • Dynamic route parameter handling
  • Detailed habit visualization

ProfileScreen

  • Theme controls
  • Authentication actions

Utility Layer

Pure helper functions with no UI dependencies.

storageHelpers.ts

Responsible for:

  • AsyncStorage access
  • Data serialization
  • Data deserialization
  • Persistence abstraction

⚑ Performance Considerations

React.memo Optimization

HabitCard utilizes memoization to prevent unnecessary re-renders during FlatList updates.

Context Isolation

Authentication and theme state are separated to minimize component tree invalidation.

Optimistic Updates

UI state updates instantly before storage writes complete, creating a smoother user experience.

Type-Safe Navigation

Centralized route definitions eliminate runtime navigation errors.


πŸš€ Scalability Benefits

  • 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.

About

A minimalist, offline-first habit & task tracker built with React Native (Expo) and strict TypeScript. This is a guided learning project focused on mastering mobile architecture, global state management, and performance optimization.

Resources

Stars

Watchers

Forks

Contributors

Languages