···4646โโโ alf/ # Design system (ALF) - themes, atoms, tokens
4747โโโ components/ # Shared UI components (Button, Dialog, Menu, etc.)
4848โโโ screens/ # Full-page screen components (newer pattern)
4949+โโโ features/ # Macro-features that bridge components/screens
4950โโโ view/
5051โ โโโ screens/ # Full-page screens (legacy location)
5152โ โโโ com/ # Reusable view components
···5960โโโ locale/ # i18n configuration and language files
6061โโโ Navigation.tsx # Main navigation configuration
6162```
6363+6464+### Project Structure in Depth
6565+6666+When building new things, follow these guidelines for where to put code.
6767+6868+#### Components vs Screens vs Features
6969+7070+**Components** are reusable UI elements that are not full screens. Should be
7171+platform-agnostic when possible. Examples: Button, Dialog, Menu, TextField. Put
7272+these in `/components` if they are shared across screens.
7373+7474+**Screens** are full-page components that represent a route in the app. They
7575+often contain multiple components and handle layout for a page. New screens
7676+should go in `/screens` (not `/view/screens`) to encourage better organization
7777+and separation from legacy code.
7878+7979+For complex screens that have specific components or data needs that _are not
8080+shared by other screens_, we encourage subdirectoreis within `/screens/<name>`
8181+e.g. `/screens/ProfileScreen/ProfileScreen.tsx` and
8282+`/screens/ProfileScreen/components/`.
8383+8484+**Features** are higher-level modules that may include context, data fetching,
8585+components, and utilities related to a specific feature e.g.
8686+`/features/liveNow`. They don't neatly fit into components or screens and often
8787+span multiple screens. This is an optional pattern for organizing complex
8888+features.
8989+9090+#### Legacy Directories
9191+9292+For the most part, avoid writing new files into the `/view` directory and
9393+subdirectories. This is the older pattern for organizing screens and components,
9494+and it has become a bit disorganized over time. New development should go into
9595+`/screens`, `/components`, and `/features`.
9696+9797+#### State
9898+9999+The `/state` directory is where we've historically put all our data fetching and
100100+state management logic. This is perfectly fine, but for new features, consider
101101+organizing state logic closer to the components that use it, either within a
102102+feature directory or co-located with a screen. The key is to keep related code
103103+together and avoid having "god files" with too much unrelated logic.
104104+105105+#### Lib
106106+107107+The `/lib` directory is for utilities and helpers that don't fit into other
108108+categories. This can include things like API clients, formatting functions,
109109+constants, and other shared logic.
110110+111111+#### Top Level Directories
112112+113113+Avoid writing new top-level subdirectories within `/src`. We've done this for a
114114+few things in the past that, but we have stronger patterns now. Examples:
115115+`/logger` should probably have been written into `/lib`. And `ageAssurance` is
116116+better classified within `/features`. We will probably migrate these things
117117+eventually.
118118+119119+### File and Directory Naming Conventions
120120+121121+Typically JS style for variables, functions, etc. We use ProudCamelCase for
122122+components, and camelCase directories and files.
123123+124124+When organizing new code, consider if it fits into a single file, or if it
125125+should be broken down into multiple files. For "macro" component cases, or
126126+things that live in `/features` or `/screens`, we often follow a pattern of
127127+having an `index.tsx` for the main component, and then co-locating related
128128+components, hooks, and utilities in the same directory. For example:
129129+130130+```
131131+src
132132+โโโ screens/
133133+โ โโโ ProfileScreen/
134134+โ โ โโโ index.tsx # Main screen component
135135+โ โ โโโ components/ # Sub-components used only by this screen
136136+```
137137+138138+Similar patterns can be found in `/features` and `/components`. The idea here is
139139+to keep related code together and make it easier to navigate.
140140+141141+You should ask yourself: if someone new was looking for the code related to this
142142+feature or screen, where would they expect to find it? Organizing code in a way
143143+that matches developer expectations can make the codebase much more
144144+approachable. Being able to say "Live Now stuff lives in `/features/liveNow`" is
145145+easier to understand than having it scattered across multiple directories.
146146+147147+No need to go overboard with this. If a component or feature fits into a single
148148+file, there's no reason to have a `/Component/index.tsx` file when it could just
149149+be `/Component.tsx`. Use your judgment based on the complexity and amount of
150150+related code.
151151+152152+#### Platform Specific Files
153153+154154+We have conflicting patterns in the app for this. The preferred approach is to
155155+group platform-specific files into a directory as much as possible. For example,
156156+rather than having `Component.tsx`, `Component.web.tsx`, and
157157+`Component.native.tsx` in the same directory, we prefer to have a `Component/`
158158+directory with `index.tsx`, `index.web.tsx`, and `index.native.tsx`. This keeps
159159+related code together and gives us a better visual cue that there are probably
160160+other files contained within this "macro" feature, whereas `Component.tsx` on
161161+its own looks more like a single component file.
162162+163163+### Documentation and Tests Within Features
164164+165165+For larger features or components, it's helpful to include a README.md file
166166+within the directory that explains the purpose of the feature, how it works, and
167167+any important implementation details. The `/Component/index.tsx` pattern lends
168168+itself well to this, since the `index.tsx` can be the main component file, and
169169+the `README.md` can provide documentation for the whole feature. This is
170170+optional, but can be a nice way to keep documentation close to the code it
171171+describes.
172172+173173+Similarly, if there are tests that are specific to a component or feature, it
174174+can be helpful to include them in the same directory, either as
175175+`Component.test.tsx` or in a `__tests__/` subdirectory. This keeps everything
176176+related to the component or feature in one place and makes it easier to find and
177177+maintain tests.
6217863179## Styling System (ALF)
64180