Skip to content

Instantly share code, notes, and snippets.

@hedleysmith
Last active November 8, 2016 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hedleysmith/46023c5a683aef8e62eb38cf47b7468e to your computer and use it in GitHub Desktop.
Save hedleysmith/46023c5a683aef8e62eb38cf47b7468e to your computer and use it in GitHub Desktop.
Structuring a Component Driven Frontend Application Using Spaces

Structuring a Component Driven Frontend Application Using Spaces

This structure should work well for small and medium size web applications or more document-focused websites. It provides a balance between co-location of component files and separation of components by function.

A 'layered' approach can be used when starting a build using this structure, starting with base styling, a few reusable components and some of your favourite utilities then building each space up.

The aim of this structure is to keep it obvious as to where things go, be able to define areas of ownership and importance and to keep things out of your way when working in a space. This structure scales well to many hundreds of components and works well with a single team workig on a frontend project.

In general, everything should be viewed as some type of encapsulated and independent component.

  • /app/src/base - Global styling and the initial 'layer' included across the entire application.
  • /app/src/components - Reusable components, these could be React, CSS or other types of components.
  • /app/src/components/[Component]/ - An individual component, has a single well defined purpose.
  • /app/src/spaces - Spaces represent unique parts of a project, they can be single pages or an area. Spaces can overlap, be nested and include reusable components unique to that space.
  • /app/src/spaces/[Space] - A single space may consist of a container component, multiple presentational components and even some components which are reused within the space.
  • /app/src/state - Global state management (Redux or MobX files would go here). Subfolders could have very different structures beneath here depending on the state management style.

Space & Component Examples

  • Spaces: Straightforward pages can be spaces (e.g homepage, listing page), an 'area' of a project could be a space (e.g blog section, user dashboard). As an application grows and components need to be shared across spaces they can be moved to /components and made more generic and reusable.
  • Components: Button, Header, Footer, Modal, SearchBox, FormTextInput, Carousel

Extras]

  • /app/src/utilities - General purpose utilities used globally, often CSS classes like '.u-clearfix' (optional). Utilities could also be stored in a utilities.css file in /base.
  • Styleguide - A styleguide can be generated using the base styling and reusable components with some additional boilerplate to demonstrate how styling looks and any other guidelines needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment