Bootstrap: Reorganize Scss folder structure

Created on 24 Mar 2019  ยท  9Comments  ยท  Source: twbs/bootstrap

Our current scss file and folder architecture is a bit unclear. We have a _variables.scss file on the same level as the components. There's also a _mixins.scss file which includes the mixins in another folder. There might be some room for reorganisation.

We could come up with our own folder structure but it might be interesting to have a look at existing solutions. Maybe ITCSS could help us out.

ITCSS has been discussed already in https://github.com/twbs/bootstrap/issues/18233 but this was also about splitting our variables file, I wouldn't do that for now. Just reorganising the files into folders would be a great start.

Feel free to spread your thoughts on this here

/CC @twbs/css-review

css v5

Most helpful comment

I guess a folder structure like this would be the result in the end:

bootstrap/
โ””โ”€โ”€ scss/
    โ”œโ”€โ”€ settings/
    โ”‚   โ””โ”€โ”€ variables.scss
    โ”œโ”€โ”€ tools/
    โ”‚   โ”œโ”€โ”€ functions.scss
    โ”‚   โ””โ”€โ”€ mixins
    โ”‚       โ””โ”€โ”€ ... All mixin files here
    โ”œโ”€โ”€ generic/
    โ”‚   โ”œโ”€โ”€ reboot.scss
    โ”‚   โ””โ”€โ”€ root.scss
    โ”œโ”€โ”€ elements/
    โ”‚   โ””โ”€โ”€ type.scss
    โ”œโ”€โ”€ objects/
    โ”‚   โ”œโ”€โ”€ images.scss
    โ”‚   โ”œโ”€โ”€ code.scss
    โ”‚   โ”œโ”€โ”€ grid.scss
    โ”‚   โ””โ”€โ”€ transitions.scss
    โ”œโ”€โ”€ components/
    โ”‚   โ”œโ”€โ”€ tables.scss
    โ”‚   โ”œโ”€โ”€ forms.scss
    โ”‚   โ”œโ”€โ”€ buttons.scss
    โ”‚   โ”œโ”€โ”€ dropdown.scss
    โ”‚   โ”œโ”€โ”€ button-group.scss
    โ”‚   โ”œโ”€โ”€ input-group.scss
    โ”‚   โ”œโ”€โ”€ custom-forms.scss
    โ”‚   โ”œโ”€โ”€ nav.scss
    โ”‚   โ”œโ”€โ”€ navbar.scss
    โ”‚   โ”œโ”€โ”€ card.scss
    โ”‚   โ”œโ”€โ”€ breadcrumb.scss
    โ”‚   โ”œโ”€โ”€ pagination.scss
    โ”‚   โ”œโ”€โ”€ badge.scss
    โ”‚   โ”œโ”€โ”€ alert.scss
    โ”‚   โ”œโ”€โ”€ progress.scss
    โ”‚   โ”œโ”€โ”€ list-group.scss
    โ”‚   โ”œโ”€โ”€ close.scss
    โ”‚   โ”œโ”€โ”€ toasts.scss
    โ”‚   โ”œโ”€โ”€ modal.scss
    โ”‚   โ”œโ”€โ”€ tooltip.scss
    โ”‚   โ”œโ”€โ”€ popover.scss
    โ”‚   โ”œโ”€โ”€ carousel.scss
    โ”‚   โ””โ”€โ”€ spinners.scss
    โ”œโ”€โ”€ utilities/
    โ”‚   โ””โ”€โ”€ utilities.scss
    โ”œโ”€โ”€ bootstrap.scss
    โ”œโ”€โ”€ bootstrap-grid.scss
    โ””โ”€โ”€ bootstrap-reboot.scss

In each folder some files could be grouped into folders if needed (like the form stuff).

All 9 comments

With the forms redux, I already want to move all that into a new subfolder. What other changes would you be interested in making?

I guess a folder structure like this would be the result in the end:

bootstrap/
โ””โ”€โ”€ scss/
    โ”œโ”€โ”€ settings/
    โ”‚   โ””โ”€โ”€ variables.scss
    โ”œโ”€โ”€ tools/
    โ”‚   โ”œโ”€โ”€ functions.scss
    โ”‚   โ””โ”€โ”€ mixins
    โ”‚       โ””โ”€โ”€ ... All mixin files here
    โ”œโ”€โ”€ generic/
    โ”‚   โ”œโ”€โ”€ reboot.scss
    โ”‚   โ””โ”€โ”€ root.scss
    โ”œโ”€โ”€ elements/
    โ”‚   โ””โ”€โ”€ type.scss
    โ”œโ”€โ”€ objects/
    โ”‚   โ”œโ”€โ”€ images.scss
    โ”‚   โ”œโ”€โ”€ code.scss
    โ”‚   โ”œโ”€โ”€ grid.scss
    โ”‚   โ””โ”€โ”€ transitions.scss
    โ”œโ”€โ”€ components/
    โ”‚   โ”œโ”€โ”€ tables.scss
    โ”‚   โ”œโ”€โ”€ forms.scss
    โ”‚   โ”œโ”€โ”€ buttons.scss
    โ”‚   โ”œโ”€โ”€ dropdown.scss
    โ”‚   โ”œโ”€โ”€ button-group.scss
    โ”‚   โ”œโ”€โ”€ input-group.scss
    โ”‚   โ”œโ”€โ”€ custom-forms.scss
    โ”‚   โ”œโ”€โ”€ nav.scss
    โ”‚   โ”œโ”€โ”€ navbar.scss
    โ”‚   โ”œโ”€โ”€ card.scss
    โ”‚   โ”œโ”€โ”€ breadcrumb.scss
    โ”‚   โ”œโ”€โ”€ pagination.scss
    โ”‚   โ”œโ”€โ”€ badge.scss
    โ”‚   โ”œโ”€โ”€ alert.scss
    โ”‚   โ”œโ”€โ”€ progress.scss
    โ”‚   โ”œโ”€โ”€ list-group.scss
    โ”‚   โ”œโ”€โ”€ close.scss
    โ”‚   โ”œโ”€โ”€ toasts.scss
    โ”‚   โ”œโ”€โ”€ modal.scss
    โ”‚   โ”œโ”€โ”€ tooltip.scss
    โ”‚   โ”œโ”€โ”€ popover.scss
    โ”‚   โ”œโ”€โ”€ carousel.scss
    โ”‚   โ””โ”€โ”€ spinners.scss
    โ”œโ”€โ”€ utilities/
    โ”‚   โ””โ”€โ”€ utilities.scss
    โ”œโ”€โ”€ bootstrap.scss
    โ”œโ”€โ”€ bootstrap-grid.scss
    โ””โ”€โ”€ bootstrap-reboot.scss

In each folder some files could be grouped into folders if needed (like the form stuff).

@mdo @MartijnCuppens

May I propose and a split on the variables.scss?

It has being too big... Or Maybe One main File with the main variables and a second which will have all the inherited variables

Splitting the variables.scss file is something we could look in to, imo that something we can do after cleaning up the folder structure.

I agree with @GeoSot, it would be handy to have two separate variable files, one for the initial variables and another for derived ones. It would save having to redeclare some variables such as colors as this is usually the file that is imported first in the SCSS setup.

That will be awesome if V5 adopts ITCSS architecture.

FWIW I got used to @HugoGiraudel's 7-1 pattern which would be very consistent with our current namings:

  • base/
  • components/
  • layout/
  • pages/
  • themes/
  • abstracts/
  • vendors/

Except for pages and themes (that could be used in our docs, eg. for the Examples section) I think that could be a good candidate :)

7-1 pattern

I think Magical Number helps Information Architecture.
https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two

I like setting it to 3-4, but I don't think it must set maximum to 7.

In fact it does, since it's not magical but describes the number of folders. You may think of .col-2 as a reference.

And at least, this pattern has a name, is documented and pretty common.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eddywashere picture eddywashere  ยท  3Comments

MrCsabaToth picture MrCsabaToth  ยท  3Comments

IamManchanda picture IamManchanda  ยท  3Comments

iklementiev picture iklementiev  ยท  3Comments

cvrebert picture cvrebert  ยท  3Comments