GithubHelp home page GithubHelp logo

junhoyeo / feature-oriented-next Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 638 KB

โšก๏ธ This proposes a truly feature-oriented structure to Next.js. ๐Ÿš€ Powered by TypeScript, styled-components and more

JavaScript 24.89% TypeScript 75.11%

feature-oriented-next's Introduction

Feature oriented Next.js

This proposes a truly feature-oriented structure to Next.js.

๐Ÿช‚ Looking for an module?

๐Ÿ”‹ Included

Structure

๐Ÿ‘ฉโ€โค๏ธโ€๐Ÿ‘จ Tightly coupled, Feature-oriented

โŒ As-is

.
โ”œโ”€โ”€ components/ 1๏ธโƒฃ
โ”‚   โ”œโ”€โ”€ Home/
โ”‚   โ”‚   โ”œโ”€โ”€ Button.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ Header.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ FirstSection.tsx
โ”‚   โ”‚   โ””โ”€โ”€ SecondSection.tsx
โ”‚   โ””โ”€โ”€ Profile/
โ”œโ”€โ”€ utils/
โ”‚   โ”œโ”€โ”€ Home/
โ”‚   โ””โ”€โ”€ Profile/
โ”œโ”€โ”€ public/
โ””โ”€โ”€ pages/ 2๏ธโƒฃ
    โ”œโ”€โ”€ index.tsx # Home
    โ””โ”€โ”€ profile.tsx # Profile

The most commonly used structure for Next.js is like the above; Each page component goes into the pages folder, with the intended route as their filename. Uncommon code fragments used only by specific pages, like components and utilities, are grouped inside each folder named after the page component. So the pages and their components were bound to be loosely coupled.

Because pages are strongly dependent on components of the same interest, this makes it difficult to find the fragments used in the page - or identify related changes inside your domain.

โœ… To-be

.
โ”œโ”€โ”€ public/
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ domains/
    โ”‚   โ”œโ”€โ”€ Home/ 1๏ธโƒฃ
    โ”‚   โ”‚   โ”œโ”€โ”€ components/
    โ”‚   โ”‚   โ”œโ”€โ”€ utils/
    โ”‚   โ”‚   โ”œโ”€โ”€ hooks/
    โ”‚   โ”‚   โ””โ”€โ”€ HomePage.tsx
    โ”‚   โ””โ”€โ”€ Profile/
    โ””โ”€โ”€ pages/ โญ๏ธ
        โ”œโ”€โ”€ index.tsx
        โ””โ”€โ”€ profile.tsx

How's this? ๐Ÿ™‹

The pages are separated by each domain and tightly coupled to the components it consumes.

// index.tsx
import { HomePage } from 'src/domains/Home/HomePage'

const Home = () => <HomePage />

export default Home

In this structure, the files inside the original pages folder have only one lightweight role: Importing 'real' page components from the domain folder and linking them to the desired path.

This way we can...

๐Ÿ”— Link multiple routes to one page

You can easily link multiple routes to one page. You can just import the page with another route and that's it.

// index.tsx
import { HomePage } from 'src/domains/Home/HomePage'

const Index = () => <HomePage />

export default Index
// home.tsx
import { HomePage } from 'src/domains/Home/HomePage'

const Home = () => <HomePage />

export default Home

Write tests next each page

TBD

feature-oriented-next's People

Contributors

junhoyeo avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.