DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Choosing the Right Path Among a Plethora of Mobile App Development Methodologies
  • Cross-Platform Mobile Application Development: Evaluating Flutter, React Native, HTML5, Xamarin, and Other Frameworks
  • Common Problems in Redux With React Native

Trending

  • Strategies for Securing E-Commerce Applications
  • Data Lake vs. Warehouse vs. Lakehouse vs. Mart: Choosing the Right Architecture for Your Business
  • Designing AI Multi-Agent Systems in Java
  • Yet Another GenAI Nightmare: Seven Shadow AI Pitfalls to Avoid
  1. DZone
  2. Culture and Methodologies
  3. Agile
  4. Modular Feature-Driven Development: The Smartphone Pattern (OS) with React and Redux

Modular Feature-Driven Development: The Smartphone Pattern (OS) with React and Redux

In this post, see how feature-driven development should play a main role in the software development cycle, and design and implement modular features.

By 
Oren Farhi user avatar
Oren Farhi
·
Mar. 17, 22 · Opinion
Likes (3)
Comment
Save
Tweet
Share
3.1K Views

Join the DZone community and get the full member experience.

Join For Free

Front-end architecture is a very important aspect I consider when developing apps. I've been developing front end since around 2007, and since then, I've been interested in software architecture concepts, design patterns, and code organization.

Once, in a code review session, I was trying to explain a certain strategy I would have liked the code would be, then a colleague told me:

Not everyone thinks the same you do. That's hard to understand.

He was right. I was trying to explain what to right and was going through all the necessary parts, but I missed one thing: showing the big picture.

This article is focusing on an approach I'm taking when designing a feature. It is only then I can refer to directory structure and follow what makes sense. My goal is to share a perspective, show a way of thinking, a Style Guide (if I may), that I follow. I think it may help others as well.

Feature Driven Development from Wikipedia states:

Feature-driven development (FDD) is an iterative and incremental software development process.

The Big Picture

I was once told it's easier if you show us rather than tell us.

There are many good articles recommending a certain directory structure, where to have what, and how to divide the code files into parts. Smartphones and mobile devices have been around for quite some time now. When I'm coding or starting to design a feature, I consider a Smart Phone as the Mental Model for the app.

Simply put, when I need to add a feature to an existing app, I'm instantly thinking where it would have belonged if it was a smartphone feature that was built into the code operating system.

That's it in a nutshell: that's how I explain the Smartphone Pattern (SPP) - but there's more to it.

Rules of the Smartphone Pattern

In a smartphone, most of these basic features are included with the device's API: camera, user, contacts, geolocation, microphone, sound, etc. Usually, when an app is installed on the device, it asks the user to approve access for a few of these APIs. Most often, the user just confirms, meaning: the app relies on the device's API and the user's approval to access those APIs. This is the perspective that I look at when adding features to an app.

Coming into the web front end development world, chances are that the basic APIs would be included within these layers:

  1. Containers/Pages layer: Component that reflects a certain view that is usually bound to a URL
  2. State management: Some form of state layer (Redux, react-query, etc.) 
  3. Components
  4. Hooks (React)
  5. Utilities
  6. API layer
  7. Modules/features (the goal of this article)

I consider items 2-6 as the building blocks of an app: it's the base framework on which the entire app relies. Once these exist, any feature that consumes any of these would probably be consumed in item #1, Containers/Pages.

Features/Modules take the role of an app in a smartphone. Let's see how this perspective translates in a React app.

Feature-Driven Development

First, I usually keep new features in the modules/features folder (or whatever works best for the team).

A feature can expose components, hooks, or utilities. Think of an npm package that accesses directly one of the layers I mentioned before. By using and importing a certain building block of one of the layers, the app "gives" permission to the feature (the smartphone app) to use these.

A feature can do whatever permissions it is granted, like to bind a feature around a store's slice. That means:

  1. Updating the app state (phone settings, user's data, etc.)
  2. Share state with other features (app within an app)
  3. Link to other views within the app (in a smartphone, open other apps, open browser, etc.)

A good example would be a playlist component of a music app:

 
<Player>
  <MediaView />
  <Controls />
  <Playlist />
</Player>


There are a few principles to notice about the Playlist module/feature:

  1. It doesn't take any props, although it might to set features on/off within the playlist component.
  2. It has permissions to use these layers: state, API, components.
  3. We understand this feature is consumed by the Playlist component.

Similarly to an app on the smartphone, a feature may expose more ways to interact with its data, i.e:

  1. Exposing a <CurrentlyPlaying /> module (widgets in Android)
  2. Exposing a hook to interact with the feature usePlaylistController()

Folder and Files Structure

A feature lives within the modules/features folder. As I mentioned before, it asks for permission to use any of the existing building blocks that exist in the app.

If the feature requires a state layer (in Redux), it is the "store" folder that includes all the state definitions and clean store API hooks.

Plain Text
 
- src
  - modules
    - Playlist
      - index.ts
      - Playlist
        - Playlist.tsx
      - CurrentlyPlaying
        - CurrentlyPlaying.tsx
      - hooks
        - index.ts
        - usePlaylistController.ts
        - useCurrentlyPlaying.ts
      - store
        - index.ts
        - playlist.slice.ts


Notice the Playlist/index.ts. This is the entry point of the module. This file includes all the relevant export statements this module is exposing for the app to consume. i.e:

TypeScript-JSX
 
export * from "./Playlist/Playlist"
export * from "./CurrentlyPlaying/CurrentlyPlaying"
export * from "./hooks"
export * from "./store"


I like this approach because eventually, I would like to consume these like that:

TypeScript-JSX
 
import { Playlist, CurrentlyPlaying } from "modules/Playlist"


Organizing features with this strategy is useful for a few reasons:

  1. Isolated and incremental development
  2. Feature flag ready
  3. Easily testable
  4. Low risk in touching any of the existing app's code
  5. Plug and play within the app

During phases of development, a feature may introduce new components or hooks that expose a different kind of interaction or visual elements. Usually, when there's a requirement to use or view information from the feature's store, I tend to create either a new component inside the feature's folder. Doing that, I know any aspect of that feature's state is encapsulated and saved inside this feature's folders. It becomes intuitive to search and skim through when searching for anything related to that feature.

What Is the Limit of This Smartphone Modular Development?

Usually, a feature's component would be consumed in a container/page component. Like any other strategy, there are always exceptions. For me, when a new feature is agnostic and doesn't have to rely on a state layer, it would directly go into the components folder.

A feature may not include its own "store" folder, but rather use existing store slices.

I think feature-driven development should play a main role in the software development cycle. Being able to design and implement modular features contributes to an app's architecture, stability, and testability.

Feature-driven development Smartphone mobile app React (JavaScript library)

Published at DZone with permission of Oren Farhi. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Choosing the Right Path Among a Plethora of Mobile App Development Methodologies
  • Cross-Platform Mobile Application Development: Evaluating Flutter, React Native, HTML5, Xamarin, and Other Frameworks
  • Common Problems in Redux With React Native

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!