What is Screaming Architecture?
When you open a project, do you instantly know what it's about, or do you have to dig into the code to understand it? If your answer is the latter, this article is for you.
I'm going to tell you about Screaming Architecture, a code organization approach that, instead of screaming the technology you use, screams the business's purpose and its functionalities.
Why use it in the frontend?
- π§ Immediate clarity: You understand the code's purpose just by looking at its structure.
- π§± True scalability: Each functionality grows in an isolated, orderly manner.
- π₯ Faster onboarding: New devs understand the project better and quicker.
- π§Ή Safer refactorings: Everything is more encapsulated.
- π Facilitates testing, modularization, and team division.
The Problem with "Generic" Structures
Most frontend projects, especially at the beginning, use a folder structure based on technical types: components/
, views/
, services/
, utils/
, store/
, etc.
src/
βββ components/
βββ views/
βββ services/
βββ utils/
βββ store/
βββ ...
While it's a starting point, this structure has its problems, especially as your application grows:
Logic dispersion: For a single functionality (e.g., "User Management"), its parts (UI components, store logic, API calls) are scattered throughout the entire project.
Navigation difficulty: You have to jump between many folders to understand how a complete feature works.
Painful maintenance: A change in one function might require modifying files in several folders, increasing the risk of introducing errors.
Infrastructure coupling: The structure tells you how it's built (with services, components), not what your business does.
Imagine a house blueprint. You don't see a "bricks" section, another for "cement," and another for "windows." You see "kitchen," "bedroom," "bathroom." The blueprints "scream" the purpose and functions of each space.
Screaming Architecture seeks the same for your code. Your high-level folder structure should "scream" the main features or business domains of your application, not the technologies you use.
Advantages of using Screaming Architecture
Implementing this approach isn't just about aesthetics; it brings tangible benefits that allow you to scale your application and your team.
Instant understanding: You open the project and, at a glance, you know what the business does.
Fast onboarding: New developers understand the business structure much faster.
Simplified maintenance: Changes to a functionality are kept localized within its own module.
Isolated changes, fewer errors: You reduce the risk of breaking other parts of the system when modifying a feature.
More scalable code: You can add new functionalities (features) without affecting existing code.
Intuitive navigation: You look for business functionalities, not generic file types.
Less coupling: The core business logic is more independent of technical details.
Safer refactorings: Moving or refactoring an entire feature is less risky.
Facilitates testing: Functionalities are easier to isolate and test.
Your project becomes predictable: Growth is organized and controlled.
Applying Screaming Architecture
We'll use a Vue project as an example, but it's 100% applicable to any other technology.
The key is to group code by features or business domains. Each feature folder will contain everything needed for that functionality.
Here's a practical example of what the structure might look like in your project:
src/
βββ modules/ # Could also be called "Features" or "Domain," something that groups
β β # functionalities
β βββ Auth/ # Everything related to authentication
β β βββ components/ # LoginButton.vue, RegisterForm.vue
β β βββ views/ # LoginView.vue, RegisterView.vue
β β βββ routes/ # Specific routes for this module
β β βββ store/ # auth.store.js (Pinia store for Auth)
β β βββ services/ # auth.service.js (Auth API calls)
β βββ Products/ # Everything related to products
β β βββ components/ # ProductCard.vue, ProductList.vue
β β βββ views/ # ProductsView.vue, ProductDetailView.vue
β β βββ routes/ # Specific routes for this module
β β βββ store/ # products.store.js
β β βββ services/ # products.service.js
β βββ Orders/ # Everything related to orders
β β βββ components/
β β βββ routes/
β β βββ views/
β β βββ store/
β β βββ services/
β βββ Profile/ # And so on for other features...
β βββ components/
β βββ ...
βββ shared/ # Truly cross-cutting elements that don't belong to a
β β # specific feature
β βββ ui/
β β βββ components/ # BaseButton.vue, ModalBase.vue (generic UI components)
β β βββ composables/# useModal.js, useDarkMode.js (composables that only affect
β β # UI components)
β βββ composables/ # useDebounce.js, useLocalStorage.js (reusable logic
β β # without business state)
β βββ utils/ # formatDate.js, validateEmail.js
β βββ assets/ # Global images, base styles
βββ layouts/ # Layout templates (DefaultLayout.vue, AuthLayout.vue)
βββ router/ # General application router
βββ app.vue
βββ main.js
βββ vite.config.js # Vite configuration
The structure mentioned is just an example; you can adapt it to your own needs.
The important thing is that each Module has its own folder structure as you need it; you won't always have a "Store" or "Services" in every module, for example.
When to Use Screaming Architecture? (and when not to?)
This approach is powerful, but it's not a silver bullet for all projects:
Ideal for:
- Medium to large projects with complex business logic.
- Applications expected to grow significantly.
- Teams with multiple developers.
- When clarity and long-term maintenance are priorities.
Perhaps excessive for:
- Very small projects or MVPs ("Minimum Viable Products") that you know won't scale much.
- Very simple CRUD (Create, Read, Update, Delete) applications where the logic is minimal.
Considerations:
- If your project has the potential to grow, adopting Screaming Architecture from the beginning, or at least in early stages, will save you a lot of headaches in the future.
- In an existing application, you can progressively adopt Screaming Architecture by migrating one module at a time.
Conclusion: Make Your Architecture Scream Its Purpose
Screaming Architecture is more than just a way to organize folders; it's a mindset that prioritizes business cohesion over technical infrastructure. By making your code scream its functionalities, you not only improve readability and maintainability but also lay a solid foundation for your frontend to scale efficiently and in a controlled manner.
Are you ready for your next project's architecture to start screaming?
Top comments (0)