You are on page 1of 9

Smooth Capital

TECHNICAL
DOCUMENTATION
Oluwatobi Odekunle,

Lead Developer.
PACKAGING BEST PRACTICES

Description: Understanding the overview of packaging and its benefit.

Written By: Oluwatobi Odekunle (Lead Developer)

Contact Information: ✉️ooluwatobialao@gmail.om 📞 +2348110951215

Last Updated: February 5, 2021

Summary:

This documentation explains step by step what packaging is all about with respect to
laravel, vueJS, bagisto and general development.
Laravel Packaging
Packages are the primary way of adding functionality to Laravel. Packages might be
anything from a great way to work with dates like Carbon or a package that allows you
to associate files with Eloquent models like Spatie's Laravel Media Library.

There are different types of packages. Some packages are stand-alone, meaning they
work with any PHP framework. Carbon and PHPUnit are examples of stand-alone
packages. Any of these packages may be used with Laravel by requiring them in your
composer.json file.

On the other hand, other packages are specifically intended for use with Laravel. These
packages may have routes, controllers, views, and configuration specifically intended to
enhance a Laravel application. To learn more about how to develop your own package,
kindly follow this official laravel guide https://laravel.com/docs/7.x/packages

Bagisto Package Development

A package is a unit added to your application for enhancement which includes routes,
controllers, views, and configuration specifically. Packages are created to manage your
large applications into smaller units.

In Bagisto, several packages are available at path packages/Webkul/. You can find a
basic tree-structure of the package below:

- ACME/HelloWorld/

- publishable/assets

- css/

- images/

- js/

- src/
- Config/

- acl.php

- admin-menu.php

- Console/

- Commands/

- Contracts/

- Database/

- Migrations/

- Seeders/

- Events/

- Http/

- Controllers/

- Admin/

- HelloWorldController.php

- Shop/

- HelloWorldController.php

- Middleware/

- Requests/

- admin-routes.php

- shop-routes.php

- Listeners/

- Mail/

- Models/

- Providers/

- HelloWorldServiceProvider.php

- ModuleServiceProvider.php

- Repositories/
- Resources/

- assets/

- images/

- js/

- app.js

- sass/

- admin.scss

- default.scss

- velocity.scss

- lang/

- views/

- admin/

- layouts/

- style.blade.php

- index.blade.php

- shop/

- default/

- index.blade.php

- velocity/

- index.blade.php

- package.json

- webpack.mix.js

You want to learn how to create your own package? Follow this link if yes. Bagisto Package
Development
Available Packages from WebKul
Bagisto comes with several interesting packages which can be found inside the
packages folder. The WebKul folder in the packages folder contains the following
packages:
❖ Admin
❖ API
❖ Attribute
❖ BookingProduct
❖ CartRule
❖ CatalogRule
❖ Category
❖ Checkout
❖ CMS
❖ Core
❖ Customer
❖ Inventory
❖ Payment
❖ PayPal
❖ Product
❖ Rule
❖ Sales
❖ Shipping
❖ Shop
❖ SocialLogin
❖ Tax
❖ Theme
❖ Ui
❖ User
❖ Velocity
NOTE: All of those packages communicate with one another, do not break them when
creating a new package.
WHY DO WE NEED PACKAGING
Basically, a laravel package is a mini laravel application that is built to enhance a laravel
application. Those packages can be re-used on any laravel application that supports it.
These packages may have routes, controllers, views, and configuration specifically
intended to enhance a Laravel application.
Since Bagisto is a complete eCommerce solution, why then do we need to create
package and what are the impact?
The following will talk about the effect of implementing a package for every new feature
you want to create.

1. Effect on implementing a new feature: According to Bagisto developers and also


professional laravel developers, the best thing to do when introducing a new
feature to your laravel application is to create a package for it. If that is not
followed, if you continue to edit the main application instead of using packaging,
you might run to a problem especially when the new feature has some bugs
which will affect the whole application but if you leverage on a package, it will
make it independent and during debugging, you do not have to worry about the
whole application but the new created package only. Package is just a folder that
contains another application to enhance the whole app, and if that is a problem, it
can be easily removed and disconnected from the whole app.
2. Effect on multiple developers: If you are working on a project with other
developers, it is a great idea to leverage on packaging. Each developer can
create their own package that will be connected to the whole application to
enhance the performance and also can be used on another application. Each
developer can then maintain their own created package independently.
3. Effect on Version Control System: This is very important when it comes to
working with several developers. Sometimes, pushing and accepting PRs might
be funny. To avoid issues, it is a good practice for each developer to create their
own package and also take responsibility of pushing it to the VCS which make it
more reasonable to work on each module of the complete system without code
breaking. You do not have to depend on other developers if your package is well
created and well configured.
4. Effect on extending created package: Using Bagisto as a case study, if as a
developer you need to extend or edit the source code of Bagisto or the packages
inside WebKul folder, it is good to create your own package or probably duplicate
the created one and configure it. You can then make changes to the one created.
Why do you need that? If you run through some errors, it can be easily fixed by
comparing the two packages and switch back to the default one if possible.
5. Effect on Bagisto upgrade: Directly from Bagisto, if you do not want to lose all
your codes added to their packages created, create or duplicate the package. It
is better to do that because if you have a new update from Bagisto it will modify
all the ones given to you including the packages folder. If you have something
you do not want to lose, create a package for it, you can publish it or save it
locally and re-use it after the upgrade.
6. Effect on front end development: Bagisto comes with Velocity theme as default. If
you are not cool with the theme, create a new package for your theme and
configure it. After upgrading to new version, all your edits would be modified with
the default one from Bagisto but if you have your own theme as a pacakge
already, it can be easily configured to work with the new update rather than
editing the source code of all the pages created (Or do you want to be updating
all blade and vueJS files? NO.)
7. Effect on general development: A system is defined as the combination of
several parts working together to achieve a goal. Imagine you have to build the
whole facebook alone without dividing them into modules that can be
implemented independently, it is going to be difficult. Packaging enhances
smooth development because it will let you focus on one module at a time
independently rather than editing all the (routes, controllers, databases etc, of the
complete app).

However, as a professional, you might not need to create a new package if you are not
inroducing a new feature. If you are only extending the created ones by WebKul, you
can modify them but be careful. If you now need to upgrade, make sure you have a
backup. A package is just a folder that contains a laravel mini app. You can then re-use
them on the new upgrade.
Also, you can assign each package to other developers if you are working with many,
each developer will take ownership of the assigned package.
Finally, if you are creating a new feature that is not part of Bagisto, kindly create your
own package and save it (either locally or on the cloud, you can even publish it) to avoid
losing all your solutions.

PACKAGES CREATED
Since Bagisto comes with Velocity theme and we might need to use another theme in
future. To follow the best practices, I created a theme called Smooth which is exactly
like Velocity for now. This theme would be the one we will be working on as soon as we
have a new multi vendor extension.
How to create a bagisto theme
Also, Bagisto comes with only PayPal and since Paystack is what we need to
implement. I have created and configured a new package called Paystack which is
registed under the WebKul folder as well. The package is configured to work with every
other packages like Payment, Shop, Checkout etc.

You might also like