components/
, hooks/
, lib/
, etc., forcing tedious manual context assembly for every task.
Bottleneck
A modern, AI-assisted development process often splits into two distinct phases:- Research & Planning: Using a powerful, large-context AI (like Gemini Pro) to analyze an existing feature, brainstorm solutions, or draft a technical specification. This requires providing the AI with all the relevant code for that feature.
- Implementation: Using a specialized coding agent or CLI tool to translate the plan from the research phase into clean, functional code.
Types Driven
app/
, components/
, hooks/
, trpc/
, and zustand/
.
This manual process of creating a “context package” is a tedious bottleneck. It breaks your development flow and makes it harder to get accurate, contextual responses from your AI.
Solution (Feature-First Architecture)
A feature-first (or feature-based) architecture solves this problem by reorganizing the project around functionality rather than file types. The core idea is to create a new top-levelfeatures/
directory, where each subdirectory is a self-contained module representing a distinct part of your application.
Here is the same project, refactored for a feature-first approach:
Feature Driven
src/features/
: This is the new home for all feature-specific logic. Each feature, likeprofile
, is a self-contained module with its own components, hooks, API endpoints, and state management.src/components/
: This directory is now reserved for truly global components. This includes your UI primitive library (likeshadcn/ui
) and application-wide components like the main navigation or footer.src/lib/
,src/hooks/
,etc.
: Top-level directories like these are now used only for genuinely global, cross-cutting concerns that are shared across multiple features.
Speed, Scalability, and Sanity
Adopting a feature-first structure yields immediate and long-term advantages that extend beyond just AI collaboration.AI Workflow Efficiency
This is the most significant and immediate payoff. Instead of spending time manually gathering scattered files, you can now easily create comprehensive context for an AI using tools like Repomix by simply pointing to the feature directory:src/features/profile
.
This simple shift can save you 1 to 3 minutes every time you build context for a task, leading to faster analysis, more accurate suggestions, and a more fluid development cycle.
Improved Maintainability & Scalability
By grouping related code, features become modular and decoupled. This makes the entire codebase easier to reason about.- Onboarding: New developers can quickly understand a feature by exploring a single directory.
- Debugging: When a bug appears in the user profile, you know exactly where to look.
- Refactoring & Deletion: Modifying or removing a feature becomes a trivial task. You can confidently change or delete a feature’s directory without worrying about leaving orphaned files scattered across the repository.