Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 39 ยท Modules and Architecture

Project Architecture and the 7-1 Pattern

Organize a Sass project with the 7-1 pattern, index files and layered entry points. Learn what goes in abstracts, base, layout and components, and how @use ties them together.

A Sass project starts as one file and, six months later, is a 4,000-line file nobody wants to touch. Architecture is how you avoid that. The goal is simple: when you need to change the button, you know which file it lives in; when you delete a feature, you can delete its file; and when two people work on the site, they rarely edit the same file.

The most widely used layout is called the 7-1 pattern: seven folders of partials and one main file that loads them. This lesson explains each folder, how to connect them with the module system from @use and @forward, and the rules that keep the structure healthy.

The seven folders and one file

TEXT
sass/
  abstracts/    variables, functions, mixins (no CSS output)
    _index.scss
    _tokens.scss
    _functions.scss
    _mixins.scss
  vendors/      third-party CSS or Sass (normalize, datepicker...)
  base/         reset, typography, element defaults
  layout/       header, footer, grid, sidebar, containers
  components/   button, card, modal, nav... one file each
  pages/        styles used by one page only (home, checkout)
  themes/       dark theme, seasonal, brand overrides
  main.scss     the only file you compile

Tools, not output

abstracts Variables, functions, mixins
vendors Third-party code

These two folders produce little or no CSS by themselves.

1 / 4

What goes where

abstracts contains everything that produces no CSS by itself: design tokens, helper functions, mixins, placeholders. Everyone can use it, and it never depends on the other folders. Because nothing in it outputs CSS, it can be loaded as often as you like at no cost.

vendors holds third-party stylesheets you want to include in your bundle. Keep them untouched. If you must override a vendor style, do it in a separate file in themes, so you can upgrade the vendor cleanly.

base is the foundation: a reset or normalize, box-sizing, body typography, link and heading defaults, form element resets. It styles elements, not classes.

layout is the macro structure of the page: site header, footer, navigation bar, grid system, containers. These styles decide where big areas go.

components is where most CSS lives. One file per self-contained piece of UI (_button.scss, _card.scss, _modal.scss). A component should work anywhere you drop it.

pages is for styles that only one page uses (a landing hero with unusual spacing). If a second page needs it, promote it to a component.

themes holds alternate looks: dark mode, a holiday skin, a white-label brand. Themes mostly change token values or override components.

The main file

main.scss loads the layers from the most general to the most specific, so later rules win ties by source order, which is how CSS cascades:

SCSS
// main.scss
@use "vendors/normalize";

@use "base/reset";
@use "base/typography";

@use "layout/grid";
@use "layout/header";
@use "layout/footer";

@use "components/button";
@use "components/card";
@use "components/modal";

@use "pages/home";

@use "themes/dark";

Each of these is a partial named with a leading underscore (base/_reset.scss). Because @use is evaluated once, the order of these lines is the order of the CSS in the output.

flowchart LR
  A["abstracts"] --> B["base"]
  A --> L["layout"]
  A --> C["components"]
  A --> P["pages"]
  A --> T["themes"]
  V["vendors"] --> M["main.scss"]
  B --> M
  L --> M
  C --> M
  P --> M
  T --> M

Abstracts feed every other layer; main.scss assembles the output in order.

Each file loads what it needs

With @import you could pull everything into main.scss once and every partial would see it. With modules, each partial must @use its own dependencies. This feels like more typing but makes every file self-explanatory and testable on its own:

SCSS
// components/_button.scss
@use "../abstracts" as a;

.button {
  padding: a.$space-md;
  background: a.$color-primary;
  @include a.focus-ring;
}

../abstracts loads the folder's _index.scss, which forwards the three abstract files:

SCSS
// abstracts/_index.scss
@forward "tokens";
@forward "functions";
@forward "mixins";

Adding a new abstract file means adding one line to the index; no consumer changes.

Configure a library once, in the entry file: @use "abstracts" with ($color-primary: #0f766e); placed before any other file loads the abstracts. See module configuration.

A tiny 7-1 project

Count how often abstracts is loaded (twice) and how many times its CSS appears (zero). Loading it from many files is free.

Rules that keep it healthy

  1. Dependencies point one way. Components may use abstracts; abstracts never use components. Components should not depend on each other. If they do, extract the shared part into a mixin or a base style.
  2. One component, one file. A 600-line _components.scss is the 4,000-line file all over again.
  3. No selectors in abstracts. If a file emits CSS, it belongs in another folder.
  4. Name partials after what they contain, not how big they are. _forms.scss, not _misc.scss.
  5. Do not nest folders for their own sake. Three levels deep is usually too many.
  6. Keep the order meaningful. Resets first, then elements, then layout, then components, then overrides.

Beyond 7-1: other layouts

The seven folders are a convention, not a law. Small sites may use base/, components/ and utilities/. Large products often organize by feature (features/checkout/_cart.scss) and keep shared tokens in a core/ folder. Design systems often split into:

  • tokens/: raw values (colors, spacing, type scale)
  • foundation/: reset, typography, layout primitives
  • components/: accessible UI parts
  • utilities/: single-purpose classes

A related idea is ITCSS (Inverted Triangle CSS), which orders layers from low specificity and wide reach (settings, tools, generic, elements) to high specificity and narrow reach (objects, components, utilities). The 7-1 pattern fits this triangle nicely.

Multiple entry points

You are not limited to one compiled file. Common reasons for more than one:

  • critical.scss for above-the-fold CSS to inline in the page.
  • admin.scss for a back-office section.
  • print.scss for printing.
  • theme-dark.scss loaded only on request.

Each entry file @uses what it needs from the same partials. Shared code is never duplicated in your source, only in the compiled outputs.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which 7-1 folder should hold variables, functions and mixins that output no CSS by themselves?

    abstracts is the toolbox: tokens, functions, mixins and placeholders, used by everything else.
  2. 2. With the module system, how does _button.scss get access to the project's variables?

    Modules do not share a global scope, so each file loads its own dependencies.
  3. 3. What is the purpose of abstracts/_index.scss?

    An index file lets consumers write @use "abstracts" and get everything the folder forwards.
  4. 4. Where does a style used by only one page belong?

    pages is for single-page styles; promote to components when a second page needs it.
  5. 5. Which dependency direction is healthy?

    Dependencies should flow from specific layers toward general ones, never backwards.

Summary

  • The 7-1 pattern: abstracts, vendors, base, layout, components, pages, themes, plus one main.scss.
  • main.scss loads layers from general to specific; the order of @use is the order of the CSS.
  • Each partial @uses what it needs; _index.scss with @forward gives a folder a single public entry.
  • Keep dependencies one-directional, one component per file, and no CSS output in abstracts.
  • Use several entry points when pages or contexts need different bundles.

Next: Design Tokens and Theming