Project Architecture
Natours is built using a modern, scalable Sass architecture following the 7-1 pattern. This architectural approach organizes stylesheets into seven distinct folders and one main file that imports them all.The 7-1 pattern is a widely-adopted architecture for large-scale Sass projects, providing clear separation of concerns and making the codebase easy to navigate and maintain.
Directory Structure
The Natours project follows a modified 7-1 pattern with the following structure:The 7-1 Pattern Explained
Abstracts Layer
Contains Sass tools and helpers that don’t output CSS by themselves. This includes variables, functions, and mixins.Files in Natours:
_variables.scss- Color palette, font sizes, grid settings_mixins.scss- Reusable mixins likeclearfix,absCenter, andrespond_functions.scss- Custom Sass functions (currently empty but ready for future use)
Base Layer
Contains the foundational styles that apply globally across the project.Files in Natours:
_base.scss- CSS reset and global box-sizing_typography.scss- Typography definitions (headings, paragraphs)_animations.scss- Keyframe animations_utilities.scss- Utility classes for spacing and alignment
Components Layer
Contains all reusable UI components. Each component is self-contained in its own file.Files in Natours:
_button.scss- Button styles and variants_card.scss- Flip card component_form.scss- Form inputs and controls_feature-box.scss- Feature box component- And more…
Layout Layer
Contains styles for major layout components that structure the page.Files in Natours:
layout/_header.scss- Header sectionlayout/_footer.scss- Footer sectionlayout/_navigation.scss- Navigation menulayout/_grid.scss- Grid system
Module System
Natours uses the modern Sass module system with@use directives instead of the older @import approach. This provides better namespacing and prevents naming conflicts.
Main Entry Point
Themain.scss file serves as the single entry point that imports all partial files:
main.scss
How Components Connect
Abstracts → Components
Components import abstracts to access variables and mixins. This creates a dependency flow where abstracts are the foundation.
Base → Global Styles
Base styles apply globally and set up the foundation for all components. They import abstracts for responsive design.
Real-World Example: Button Component
Here’s how the architecture works in practice with the button component:components/_button.scss
The button component imports variables using
@use "../abstracts/variables" as * which allows it to access all color and sizing variables defined in the abstracts layer.Architecture Benefits
Maintainability
Each component is isolated in its own file, making updates and debugging straightforward.
Scalability
New components can be added without affecting existing code. Simply create a new file and import it.
Reusability
Abstracts (variables, mixins) are shared across all components, ensuring consistency.
Build Process
The project uses the Dart Sass compiler to transform the modular Sass files into a single CSS file:package.json
- Takes
sass/main.scssas input - Compiles all imported files
- Outputs to
css/style.css - Watches for changes with the
-wflag
Next Steps
Sass Structure
Learn about the module system and file organization in detail
Responsive Design
Explore the responsive design system and breakpoint management