🎯

project-structure

🎯Skill

from flpbalada/my-opencode-config

VibeIndex|
What it does

Guides React/Next.js/TypeScript projects using feature-based architecture, organizing code by domain with clear, scalable structure and unidirectional flow.

πŸ“¦

Part of

flpbalada/my-opencode-config(40 items)

project-structure

Installation

πŸ“‹ No install commands found in docs. Showing default command. Check GitHub for actual instructions.
Quick InstallInstall with npx
npx skills add flpbalada/my-opencode-config --skill project-structure
1Installs
-
AddedFeb 4, 2026

Skill Details

SKILL.md

Guides React/Next.js/TypeScript project organization using feature-based architecture. Use when structuring new projects, reorganizing codebases, or deciding where to place new code.

Overview

# Project Structure: Feature-Based Architecture

Core Principle

Organize code by feature/domain, not by file type. Enforce unidirectional code flow: shared β†’ features β†’ app.

This approach scales well for medium-to-large React, Next.js, and TypeScript projects while keeping features independent and maintainable.

Top-Level Structure

```

src/

β”œβ”€β”€ app/ # Application layer (routing, providers)

β”‚ β”œβ”€β”€ routes/ # Route definitions / pages

β”‚ β”œβ”€β”€ app.tsx # Main application component

β”‚ β”œβ”€β”€ provider.tsx # Global providers wrapper

β”‚ └── router.tsx # Router configuration

β”œβ”€β”€ assets/ # Static files (images, fonts)

β”œβ”€β”€ components/ # Shared UI components

β”œβ”€β”€ config/ # Global configuration, env variables

β”œβ”€β”€ features/ # Feature-based modules (main code lives here)

β”œβ”€β”€ hooks/ # Shared hooks

β”œβ”€β”€ lib/ # Pre-configured libraries (axios, dayjs, etc.)

β”œβ”€β”€ stores/ # Global state stores

β”œβ”€β”€ testing/ # Test utilities and mocks

β”œβ”€β”€ types/ # Shared TypeScript types

└── utils/ # Shared utility functions

```

Feature Structure

Each feature is a self-contained module:

```

src/features/users/

β”œβ”€β”€ api/ # API requests & React Query hooks

β”œβ”€β”€ components/ # Feature-scoped UI components

β”œβ”€β”€ hooks/ # Feature-scoped hooks

β”œβ”€β”€ stores/ # Feature state (Zustand, etc.)

β”œβ”€β”€ types/ # Feature-specific types

└── utils/ # Feature utility functions

```

Only include folders you need. Don't create empty folders "just in case."

Unidirectional Code Flow

```

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”

β”‚ shared β”‚ ──► β”‚ features β”‚ ──► β”‚ app β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜

```

| From | Can Import From |

|------|-----------------|

| app | features, shared (components, hooks, lib, types, utils) |

| features | shared only |

| shared | Other shared modules only |

Features cannot import from each other. Compose features at the app level.

Decision Guide: Where Does This Code Go?

| Code Type | Location | Example |

|-----------|----------|---------|

| Route/page component | app/routes/ | app/routes/users/page.tsx |

| Feature-specific component | features/[name]/components/ | features/users/components/UserCard.tsx |

| Reusable UI component | components/ | components/Button.tsx |

| Feature API calls | features/[name]/api/ | features/users/api/getUsers.ts |

| Shared utility | utils/ | utils/formatDate.ts |

| Feature utility | features/[name]/utils/ | features/users/utils/validateUser.ts |

| Global state | stores/ | stores/authStore.ts |

| Feature state | features/[name]/stores/ | features/users/stores/userFilterStore.ts |

| Library wrapper | lib/ | lib/axios.ts, lib/dayjs.ts |

| Global types | types/ | types/api.ts |

| Feature types | features/[name]/types/ | features/users/types/user.ts |

ESLint Enforcement

Prevent Cross-Feature Imports

```javascript

// .eslintrc.js

module.exports = {

rules: {

'import/no-restricted-paths': [

'error',

{

zones: [

// Disables cross-feature imports

{

target: './src/features/users',

from: './src/features',

except: ['./users'],

},

{

target: './src/features/posts',

from: './src/features',

except: ['./posts'],

},

// Add more features as needed

],

},

],

},

};

```

Enforce Unidirectional Flow

```javascript

// .eslintrc.js

module.exports = {

rules: {

'import/no-restricted-paths': [

'error',

{

zones: [

// Features cannot import from app

{

target: './src/features',

from: './src/app',

},

// Shared cannot import from features or app

{

target: [

'./src/components',

'./src/hooks',

'./src/lib',

'./src/types',

'./src/utils',

],

from: ['./src/features', './src/app'],

},

],

},

],

},

};

```

Common Patterns

Feature API with React Query

```typescript

// src/features/users/api/getUsers.ts

import { useQuery } from '@tanstack/react-query';

import { api } from '@/lib/axios';

import type { User } from '../types/user';

export const getUsers = async (): Promise => {

const response = await api.get('/users');

return response.data;

};

export const useUsers = () => {

return useQuery({

queryKey: ['users'],

queryFn: getUsers,

});

};

```

Feature Component

```typescript

// src/features/users/components/UserList.tsx

import { useUsers } from '../api/getUsers';

import { UserCard } from './UserCard';

export function UserList() {

const { data: users, isLoading } = useUsers();

if (isLoading) return ;

return (

{users?.map((user) => (

))}

);

}

```

Composing Features at App Level

```typescript

// src/app/routes/dashboard/page.tsx

import { UserList } from '@/features/users/components/UserList';

import { PostList } from '@/features/posts/components/PostList';

import { ActivityFeed } from '@/features/activity/components/ActivityFeed';

export function DashboardPage() {

return (

);

}

```

Anti-Patterns to Avoid

Don't Use Barrel Files (index.ts)

```typescript

// src/features/users/index.ts

export * from './components/UserList'; // Breaks tree-shaking in Vite

export * from './api/getUsers';

```

Instead, import directly:

```typescript

import { UserList } from '@/features/users/components/UserList';

import { useUsers } from '@/features/users/api/getUsers';

```

Don't Import Across Features

```typescript

// src/features/posts/components/PostCard.tsx

import { UserAvatar } from '@/features/users/components/UserAvatar'; // Bad

```

Instead, lift shared components:

```typescript

// Move UserAvatar to src/components/UserAvatar.tsx

import { UserAvatar } from '@/components/UserAvatar'; // Good

```

Don't Put Everything in Shared

If a component is only used by one feature, keep it in that feature:

```

// Bad: Polluting shared components

src/components/

β”œβ”€β”€ UserCard.tsx # Only used by users feature

β”œβ”€β”€ PostCard.tsx # Only used by posts feature

└── Button.tsx # Actually shared

// Good: Feature-scoped components

src/features/users/components/UserCard.tsx

src/features/posts/components/PostCard.tsx

src/components/Button.tsx

```

Next.js App Router Adaptation

For Next.js with App Router, adapt the structure:

```

src/

β”œβ”€β”€ app/ # Next.js App Router (routes)

β”‚ β”œβ”€β”€ (auth)/ # Route group

β”‚ β”‚ β”œβ”€β”€ login/

β”‚ β”‚ └── register/

β”‚ β”œβ”€β”€ dashboard/

β”‚ β”œβ”€β”€ layout.tsx

β”‚ └── page.tsx

β”œβ”€β”€ components/ # Shared components

β”œβ”€β”€ features/ # Feature modules (non-routing code)

β”‚ β”œβ”€β”€ auth/

β”‚ β”œβ”€β”€ dashboard/

β”‚ └── users/

β”œβ”€β”€ lib/

└── ...

```

Keep route handlers minimal - delegate to feature modules:

```typescript

// src/app/users/page.tsx

import { UserList } from '@/features/users/components/UserList';

export default function UsersPage() {

return ;

}

```

Quick Checklist

Starting a New Project

  • [ ] Create top-level folder structure
  • [ ] Set up path aliases (@/ for src/)
  • [ ] Configure ESLint import restrictions
  • [ ] Create first feature as a template

Adding a New Feature

  • [ ] Create src/features/[name]/ directory
  • [ ] Add only needed subfolders (api, components, hooks, etc.)
  • [ ] Add ESLint zone restriction for the feature
  • [ ] Keep feature isolated - no cross-feature imports

Before Code Review

  • [ ] No cross-feature imports
  • [ ] Shared code is in shared folders
  • [ ] Feature-specific code stays in features
  • [ ] No barrel files (index.ts re-exports)

References

  • [Bulletproof React](https://github.com/alan2207/bulletproof-react)
  • [Feature-Sliced Design](https://feature-sliced.design/)
  • [Next.js Project Organization](https://nextjs.org/docs/app/getting-started/project-structure)

More from this repository10

🎯
five-whys🎯Skill

Systematically uncovers root causes of problems through iterative questioning, revealing underlying issues beyond surface-level symptoms.

🎯
social-proof-psychology🎯Skill

Optimizes user trust and conversion by strategically displaying social validation through testimonials, user stats, and expert endorsements.

🎯
cognitive-fluency-psychology🎯Skill

Enhances user comprehension and engagement by applying cognitive fluency principles to simplify information processing across content and interfaces.

🎯
hooked-model🎯Skill

Designs habit-forming products by mapping user triggers, actions, rewards, and investments to create engaging, addictive product experiences.

🎯
cognitive-biases🎯Skill

Applies cognitive bias insights to optimize product design, user experiences, and decision-making strategies by leveraging psychological principles.

🎯
typescript-satisfies-operator🎯Skill

Validates TypeScript object types while preserving precise literal types, preventing type widening and catching type-related errors early.

🎯
typescript-best-practices🎯Skill

Enforces TypeScript best practices and coding standards through comprehensive linting and configuration rules for consistent, high-quality code.

🎯
status-quo-bias🎯Skill

Helps design product changes and migrations by understanding users' psychological resistance to change and creating strategies to overcome status quo bias.

🎯
kanban🎯Skill

Visualize and optimize team workflow by creating Kanban boards that track tasks, limit work-in-progress, and improve delivery efficiency.

🎯
theme-epic-story🎯Skill

I apologize, but I cannot generate a description without seeing the actual content or context of the "theme-epic-story" skill from the repository. Could you provide more details about what this spe...