The application utilizes shadcn/ui as its primary UI library. Shadcn UI provides a set of re-usable components built using Radix UI and Tailwind CSS.
Unlike traditional component libraries, shadcn/ui components are not installed as a dependency. Instead, the code for each component is added directly to your project, allowing for full customization.
The application follows a modular architecture organized into four main levels:
│ src/
├── app/ # Global app setup (providers, configs, env, main.tsx)
├── common/ # Reusable code (everything shared by 2+ features/XXX)
│ ├── components/ # All shared components (Shadcn primitives, custom reusable components)
│ ├── constants/ # All shared constants (CANISTER_ID_ICP_LEDGER, ...)
│ ├── hooks/ # All shared hooks (useMediaQuery, useDebounce, ...)
│ │ ├── icpLedger/ # IcpLedger hooks
│ │ ├── icpIndex/ # IcpIndex hooks
│ │ ├── governance/ # Governance hooks
│ │ └── ...
│ ├── types/ # All shared types (NeuronInfo, ...)
│ └── utils/ # Formatting, analytics...
├── features/ # THE MAIN CONTENT (Business Logic & UI)
│ ├── dashboard/ # Dashboard Feature
│ │ ├── components/ # Dashboard-specific components (e.g. StatsWidget)
│ │ ├── constants/ # Dashboard specific constants
│ │ ├── hooks/ # Dashboard specific hooks
│ │ ├── types/ # Dashboard specific types
│ │ └── utils/ # Dashboard specific utils
│ ├── staking/ # Staking Feature (Neurons)
│ │ ├── components/ # Staking specific components (e.g. NeuronCard, StakeModal)
│ │ └── ...
│ └── ...
├── routes/ # The "Wiring" (TanStack Router)
│ ├── dashboard/ # Dashboard routes
│ │ ├── index.tsx # Imports from features/dashboard
│ ├── staking/ # Staking routes
│ │ ├── index.tsx # Imports from features/staking
│ │ └── $id.tsx # Detail view wiring
│ └── ...
-
app/: Contains global application setup, such as:- Providers (
QueryClientProvider,ThemeProvider). - Global configurations (
env,i18n). - Entry point (
main.tsx).
- Providers (
-
common/: Contains code that is reused across multiple features.- Rule of Thumb: If it's used by 2 or more features, it belongs here.
src/common/components: Location for all Shadcn UI primitives and shared custom components.
-
features/: The core of the application logic and UI.- Contains business logic broken down by domain (e.g.,
dashboard,staking). - Each feature folder is self-contained with its own components, hooks, and utils.
- Contains business logic broken down by domain (e.g.,
-
routes/: Handles the routing logic using TanStack Router.- This layer acts as the "wiring" that connects URLs to
features. - Ideally, route files should be thin wrappers that import and render components from
features/.
- This layer acts as the "wiring" that connects URLs to
-
dev/: Contains development utilities.
Icons are provided by Lucide, which is the default icon library for shadcn/ui.
To add a new shadcn/ui component:
-
Navigate to the frontend directory:
cd src/governance-app-frontend -
Run the add command:
npx shadcn@latest add [component-name]
Example:
npx shadcn@latest add button -
The component will be installed in
src/common/components/[component-name].tsx.
If your branch is failing E2E due to outdated snapshots, run the scripts/update-snapshots.sh script. It will download the updated files so you can review and commit them.
- Script:
src/governance-app-frontend/scripts/convert-known-neurons.ts - Command:
npm run generate:known-neurons - Description: Converts the
data/known-neurons.tsvfile into a TypeScript map used for sorting and displaying known neurons in the app. Run this script after updating the TSV data.