Frontend structure and architecture¶
1. Overview¶
2. General principles¶
- Modularization: Organize code into feature-based modules rather than generic categories. A module may import from the global layers (
shared/,shared_modules/,design_system/,utils/, legacyeasy-ui/), never from another feature module. - Rendering approach: Prefer Hotwire for dynamic Rails-rendered interactions; use Vue for rich client-side state or features inside an existing Vue module.
- Separation of Concerns: Keep UI components, API interactions, state management, and utilities separate.
- Naming Consistency: Follow a strict and predictable naming convention for files and folders.
- Single Responsibility Principle: Each file should have a clearly defined purpose.
3. Structure¶
3.1 Base structure¶
app/frontend/
├── entrypoints/ # Vite entrypoints loaded by Rails views
│ ├── <module_name>.ts # Entry point for a specific module, e.g. issue_detail_v2.ts
│ ├── application.js # Global entrypoint loaded on every page
│ ├── easy_legacy_js.js # Global entrypoint for legacy jQuery-era scripts
│ ├── stimulus.js # Registers Stimulus controllers from src/controllers/
├── src/ # Contains all frontend modules
│ ├── <module_name>/ # Feature module, e.g. issue_detail_v2/ (see 3.2)
│ │ ├── <submodule_name>/ # Nested submodules (if needed) with the same structure as a module
│ │ ├── shared/ # Shared between submodules, contains a subset of the module structure
│ ├── design_system/ # Design system components (DS* prefix)
│ ├── shared_modules/ # Global shared components with business logic, built on the design system
│ ├── shared/ # Global shared code, contains a subset of the module structure
│ ├── utils/ # Utilities exposed through entrypoints for code outside app/frontend/src/
│ ├── easy-ui/ # Legacy global shared UI components, exposed as window.EasyUI
│ ├── easy_legacy_js/ # Legacy non-Vue (jQuery-era) scripts
│ ├── controllers/ # Stimulus controllers (*_controller.js|ts)
│ ├── tests/ # Unit and integration frontend tests, see Frontend testing
Legacy plugin scripts outside Vite live in plugins/<plugin>/assets/javascripts/ and load through Sprockets javascript_include_tag.
3.2 Module structure¶
<module_name>/
├── api/ # API services
├── components/ # Vue components
├── composables/ # Reusable feature-specific logic (Vue composables)
├── constants/ # Module-related constants
├── directives/ # Module-specific directives
├── graphql/ # GraphQL definitions
│ ├── fragments/ # GraphQL fragments definitions
│ ├── mutations/ # GraphQL mutations definitions
│ ├── queries/ # GraphQL queries definitions
├── store/ # Module-specific state management stores
├── stylesheets/ # Global stylesheets for the module or shared layer; see Frontend styling
├── types/ # TypeScript interfaces & types & enums
├── utils/ # Utility functions
Note: Module can contain submodules and shared folder or subset of module structure. Not submodules and subset of module structure at the same time. If we need to share something between submodules we can use shared folder.
3.3 Layer responsibilities¶
- Feature modules own their components, API services, stores, and GraphQL definitions. A larger module splits into submodules plus a module-level
shared/. design_system/holds genericDS*components without business logic; see Design system.shared_modules/holds DS-based components with business logic, e.g.autocomplete/,tags_editor/. Import them by direct path.shared/holds global API helpers, plugins (Apollo client), stores, types, utils, and stylesheets. Put a utility used only by frontend modules inshared/utils/.utils/holds utilities that an entrypoint exposes to code outsideapp/frontend/src/, such as ERB views and legacy scripts;entrypoints/utils.jspublishes them onwindow.EASY.utils. Modules may import them too.easy-ui/is the historical shared UI layer. Do not add new components; build them indesign_system/orshared_modules/.easy_legacy_js/and pluginassets/javascripts/are legacy script layers. Keep changes there minimal; put new behaviour in a feature module, a Stimulus controller, or a Hotwire flow.
Historical folder names such as easy-ui/ and easy-ai/ keep their spelling; new folders follow Directory naming.
4. Naming conventions¶
4.1 File naming¶
- Use camelCase for .ts and .js filenames.
- Use PascalCase for Vue component filenames.
- API services: Filename ends with
Apisuffix likeeasyAIFeedbackApi.ts - Composables: Filename starts with
useprefix likeuseScrollToBottomMessages.ts - Stores: Filename has suffix
StorelikeeasyAIFeedbackStore.ts
4.2 Directory naming¶
- Use snake_case for folder names (
easy_scrum_boards) - Use module-based or shared folders under
src/. - Use shared/ inside modules when common components/utils exist across submodules.
4.3 Code naming¶
- API services: Class name ends with
Apisuffix likeclass EasyAIFeedbackApi ... - Composables: Function name starts with
useprefix likeconst useScrollToBottomMessages = ... - Directives: Directive name starts with
vprefix likeconst vTrapTab = ... - Graphql fragments: Definitions name ends with
Fragmentsuffix likeconst easyAIFeedbackFragment = gql`...` - Graphql mutations: Definitions name ends with
Mutationsuffix likeconst easyAIFeedbackMutation = gql`...` - Graphql queries: Definitions name ends with
Querysuffix likeconst easyAIFeedbackQuery = gql`...` - Store: Store name has prefix
useand suffixStorelikeconst useEasyAIFeedbackStore = ... - Typescript enums: Enum has singular name like
enum EasyAIFeedbackStatus { ... }; for new domain values preferas constobjects (see Enums)
5. Initialisation and cleanup¶
A Vue feature mounted into a Rails page has an entrypoint and a main.ts, with this lifecycle:
- The entrypoint (
entrypoints/<module_name>.ts) registers a smallwindowAPI (init,destroy) and lazy-importssrc/<module_name>/main.ts, so the feature chunk loads only when a page callsinit. init(appWrapperId, props)resolves the root element by id and queries mount targets only inside that root. It never mounts into global selectors.- Each root gets one Pinia shared by all of its apps; see Feature-root Pinia shared across islands.
- After async preloads (locales, settings),
initre-checks that the root is still connected and current before mounting. destroy(appWrapperId)unmounts every app and disposes the Pinia. Call it before Rails or a dialog removes the rendered markup, including whileinitis still pending.
For mount targets inside Ruby-rendered DS elements, follow Mount Vue apps inside Ruby-rendered DS elements.