GithubHelp home page GithubHelp logo

tona-mangobyte / bloc-vue-3-clean-pattern Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shamscorner/bloc-vue-3-clean-pattern

0.0 0.0 0.0 264 KB

A Vue 3 project with Typescript to mimic the Bloc architecture pattern. (Flutter way)

TypeScript 73.46% HTML 1.63% Vue 19.24% CSS 5.67%

bloc-vue-3-clean-pattern's Introduction

Separating business logic from UI frameworks (React, Vue, Svelte, Angular, etc.) using clean architecture pattern

Moving away from the framework

A Vue 3 project with Typescript to mimic the Bloc architecture pattern (Flutter way). If you are not familiar with Vue, you can still use the core package to whatever frontend framework you like.

If you want to create a frontend application, there are many frameworks to choose from (React, Vue.js, Angular, Svelte, etc.). Let's say you select one of these frameworks and start developing your project. But on the long run if you want to change with something else, you have to change the entire codebase from start to finish. And that's why moving away from frameworks and separating the core business logics will give you the ultimate power to avoid those mistakes in the future.

I have read this awesome blog post - moving away from framework on frontend using clean architecture and decided to use that approach on my own. Turned out, implementing the clean architecture pattern on (Vue 3 + Typescript) project is not that big of a deal.

Overview

In this demo project you will find 2 folders,

  • core - the core business logic
  • vue3-app - the UI framework to show the frontend views

This is basically a products - cart project where you will see the following functionalities,

  • add products to cart
  • remove products from cart
  • filters products by their title
  • adjust the product's quantity
  • finally, you will see the total number of product items and their total price.

Project Structures

Inside the core folder

Inside the src folder, you will find 3 folders. One for the common functionalities and the other two are responsible for products and cart management respectively. The breakdown is as follows,

  • products
    • data
      • data level repositories
      • in memory repositories
      • API level repositories
      • data models
    • domain
      • entities
        • product
        • product item
      • repositories
        • product repository
      • usecases
        • get products usecase
    • presentation
      • ProductPloc
      • ProductState
  • cart
    • data
      • data level repositories
      • in memory repositories
      • API level repositories
      • data models
    • domain
      • entities
        • cart
        • cart item
      • repositories
        • cart repository
      • usecases
        • add product to cart usecase
        • edit quantity of cart item usecase
        • get cart usecase
        • remove item from cart usecase
    • presentation
      • CartPloc
      • CartState
  • common
    • dependencies
      • dependencies locator
    • domain
      • DataError
      • Either
      • EitherAsync
    • presentation
      • Ploc

note: When you use BLoC with Clean Architecture, it makes more sense to call them PLoC (Presentation Logic Component). For more details, check out this article - moving away from framework on frontend using clean architecture

Inside the vue3-app folder

This Vue 3 project is made with the "Vitesse" starter template created by Anthony Fu (Vue core team member) but configured with the clean architectural pattern instead of monolithic architecture. If you want to use this modified version, check out this repository.

Here you will find the following folders under src/,

  • cart
    • components
    • pages
  • common
    • components
    • layouts
    • logic
    • modules
    • pages
    • styles
    • use-ploc-state
  • products
    • components
    • pages

As you can see, this is very similar with the base folder structure of the core setup mentioned earlier.

Why move away from the framework?

These are the advantages you will encounter while developing your project.

  • It is well structured and you will find the attributes you are looking for pretty easily.
  • Everything is modular design by its nature.
  • You can infinitely introduce new feature without breaking any changes.
  • UI library or framework is not tightly coupled to the business logic. So if you want to change your frontend framework from vue to react later for some reason, just replace the UI part and you are good to go.

How to run this demo project?

step 1 - clone this repository

$ git clone https://github.com/shamscorner/bloc-vue-3-clean-pattern.git [your repo name]

step 2 - setup core

$ cd core
$ pnpm install
$ pnpm build
$ yalc publish

note: install pnpm and yalc

step 3 - setup vue app

$ cd vue3-app
$ pnpm install
$ yalc add pkg-bloc-core
$ pnpm install

Checkout this article if you want some more in-depth explanation.

step 4 - running the app

$ pnpm dev

If you want to make some changes to the core folder, then you have to do the following after each changes.

$ cd core
$ pnpm build
$ yalc push

and in the vue app, restart the server. If that doesn't work, then run this command as well.

$ cd vue3-app
$ yalc update

Happy Coding :)

bloc-vue-3-clean-pattern's People

Contributors

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