Mochi Web is a front-end repository for the Mochi Web application. It's built using modern web technologies and follows best practices for scalable and maintainable web development.
- NextJS - React framework for building web applications
- TailwindCSS - Utility-first CSS framework
- TypeScript - Typed superset of JavaScript
- wagmi - React Hooks library for Ethereum
- iconify - Icon framework
- headlessui - Unstyled, fully accessible UI components
- @dwarvesf/react-hooks - Custom React hooks
- @dwarvesv/react-utils - React utility functions
- Storybook - Tool for developing UI components in isolation
- ESLint - JavaScript linting utility
- Prettier - Code formatter
The project follows a typical Next.js structure with some custom directories:
app/
: App router components and layoutscomponents/
: Reusable React componentsconstants/
: Constant values and configurationscontext/
: React context providershooks/
: Custom React hookspages/
: Next.js pages (for pages router)public/
: Static assetsstore/
: State management (likely using Zustand)styles/
: Global styles and CSS modulestypes/
: TypeScript type definitionsutils/
: Utility functions.storybook/
: Storybook configuration
The project uses TailwindCSS for styling, with a custom configuration defined in tailwind.config.js
. This includes:
- Custom color palette
- Custom font families
- Extended theme configurations for spacing, shadows, and animations
Based on the analysis of Storybook files, the following design conventions are used in the project:
-
Component Variants: Components often have multiple variants or appearances. For example, buttons have the following appearances:
- primary
- secondary
- tertiary
- gray
- mochi
- text
- pill
Example usage:
<Button appearance="primary">Primary Button</Button> <Button appearance="secondary">Secondary Button</Button>
-
Component Sizes: Components typically come in multiple sizes. For buttons, the sizes are:
- xs (extra small)
- sm (small)
- base (default)
- icon
- icon-sm (small icon)
Example usage:
<Button size="sm">Small Button</Button> <Button size="base">Default Size Button</Button>
-
Consistent Prop Naming: Props for appearance and size are consistently named across components (e.g.,
appearance
andsize
). -
Storybook Usage: Each component has a corresponding Storybook file (e.g.,
button.stories.tsx
) that documents its usage and variants. -
Autodocs: Storybook's Autodocs feature is used to automatically generate documentation for components.
-
Tailwind CSS: Tailwind classes are used for layout and styling within components and their stories. This ensures consistency in spacing, colors, and other design aspects.
-
TypeScript: Components and their stories are written in TypeScript, providing type safety and better developer experience.
-
Centralized Layout: Stories often use a centered layout for better visibility in Storybook.
-
Color Scheme: The project uses a consistent color scheme across components. The main colors include:
- Primary: Used for primary actions and key UI elements
- Secondary: Used for secondary actions and less prominent UI elements
- Mochi: A custom color specific to the Mochi brand
- Gray: Used for neutral UI elements and text Refer to the Tailwind configuration for the exact color values.
-
Accessibility: Components are designed with accessibility in mind. This includes:
- Proper contrast ratios for text and background colors
- Keyboard navigation support
- ARIA attributes where necessary
-
Responsive Design: Components are built to be responsive by default. This is achieved through:
- Use of Tailwind's responsive utility classes
- Flexible layouts that adapt to different screen sizes
- Mobile-first approach in component design
Example of responsive design in a component:
<div className="flex flex-col md:flex-row">
<Button className="w-full md:w-auto mb-2 md:mb-0 md:mr-2">Primary Action</Button>
<Button appearance="secondary" className="w-full md:w-auto">Secondary Action</Button>
</div>
When creating new components or modifying existing ones, adhere to these conventions to maintain consistency across the project.
The components/
directory is organized into several subdirectories:
base/
: Contains basic UI components like alerts, avatars, buttons, inputs, etc.Dashboard/
: Components specific to the dashboard functionalityHome/
: Components used on the home pageMochiWidget/
: Components for the Mochi widget functionalityPay/
: Components related to payment featuresTipNetwork/
: Components for the tip network featureToast/
: Toast notification componentsWallet/
: Wallet-related components
- Use PascalCase for component file names (e.g.,
Button.tsx
,ProfileDropdown.tsx
) - Use kebab-case for non-component files (e.g.,
gift-icon.tsx
) - Group related components in subdirectories (e.g.,
Dashboard/
,Home/
)
When creating new components:
- Place reusable components in the appropriate subdirectory within
components/
- Use functional components with TypeScript
- Utilize TailwindCSS for styling
- For complex components, consider breaking them down into smaller, more manageable pieces
- Use the
@consolelabs/mochi-ui
component library when possible - Create story files for components using Storybook (e.g.,
button.stories.tsx
) - Follow the established design conventions for variants, sizes, and prop naming
-
Home Components (
components/Home/
):- Used to build the landing page
- Include sections like Banner, ApiIntegration, ChainAndPartner, etc.
-
Dashboard Components (
components/Dashboard/
):- Used for the main application dashboard
- Include reusable elements like Card, Form, Input, Menu, Pagination, etc.
-
MochiWidget (
components/MochiWidget/
):- Implements the core Mochi functionality
- Includes features like gift, paylink, payme, and tip
-
Pay Components (
components/Pay/
):- Handle payment-related functionality
- Include elements like PaymentButton, WalletButton, QRCodeButton, etc.
To create a new page:
- Add a new file in the
pages/
directory (for pages router) orapp/
directory (for app router) - Use the appropriate Next.js conventions (e.g.,
export default function
for pages router or React Server Components for app router) - Implement SEO using the custom
seo.tsx
component in theapp/layout/
directory
The project uses a combination of React hooks, context, and Zustand for state management:
- Use React's
useState
anduseReducer
for component-level state - Utilize React Context for sharing state across components (see
context/
directory) - For more complex global state, use Zustand stores (found in the
store/
directory)
The project uses SWR for data fetching and caching. When integrating with APIs:
- Create custom hooks for data fetching in the
hooks/
directory - Use the
@consolelabs/mochi-rest
package for API calls - Handle loading and error states appropriately
- Use Storybook for component development and documentation
- Run Storybook with
pnpm storybook
- Write stories for new components in their respective
.stories.tsx
files - Utilize Storybook's Autodocs feature for automatic documentation generation
- Run Storybook with
- Implement unit tests for critical components and functions (testing framework to be determined)
- Use ESLint for code linting (configuration in
.eslintrc
)- Run linting with
pnpm lint
(add this script to package.json if not present)
- Run linting with
- Use Prettier for code formatting (configuration in
.prettierrc
)- Run formatting with
pnpm format
(add this script to package.json if not present)
- Run formatting with
- Consider setting up pre-commit hooks to run linting and formatting automatically
The project uses Vercel for continuous integration and deployment:
- Preview builds are automatically created for each pull request
- Production builds are triggered on merging into the
master
branch - Ensure all tests pass and there are no linting errors before merging
- Follow the conventional commits specification for version control
- Use TypeScript for type safety
- Implement responsive design using TailwindCSS classes
- Optimize performance by lazy loading components and images where appropriate
- Write unit tests for critical components and functions
- Use environment variables for configuration (refer to
.env.example
) - Follow accessibility guidelines, utilizing headlessui components for accessible UI elements
- Adhere to the established design conventions when creating or modifying components
- Use
pnpm
as the package manager - Run
pnpm dev:https
for local development with HTTPS (required for wallet connect debugging) - Follow the PR process: create a PR into
master
when changes are ready - Use Vercel for deployments (preview builds on PR, production build on merging into
master
)
This document provides an overview of the project structure and development practices. For more detailed information, refer to specific files and the project's documentation.