A comprehensive Islamic zakat calculator application built with Next.js that helps users calculate their zakat obligations based on various asset types.
- Getting Started
- Project Overview
- Architecture
- Core Components
- Asset Calculators
- State Management
- UI Components
- Development Guidelines
- Testing
- Deployment
First, install dependencies:
npm install
# or
yarn installThen, run the development server:
npm run dev
# or
yarn devOpen http://localhost:3000 with your browser to see the result.
Zakat Guide is a comprehensive tool for calculating zakat obligations according to Islamic principles. The application handles various asset types, each with its own calculation logic, and provides a centralized dashboard for viewing zakat obligations.
- Multiple asset type calculators (Cash, Precious Metals, Stocks, Real Estate, Cryptocurrency, Retirement accounts)
- Real-time calculation updates
- Customizable currency settings
- Nisab threshold tracking
- Asset breakdown and visualization
- Hawl (Islamic fiscal year) status tracking
- Responsive design for all devices
The project follows a layered architecture as illustrated below:
+-------------------------------------------------------------------+
| UI LAYER |
| +----------------+ +----------------+ +----------------+ |
| | Cash | | Metals | | Summary | |
| | Calculator | | Calculator | | Component | |
| +--------+-------+ +--------+-------+ +--------+-------+ |
+----------|--------------------|------------------|------------------+
| | |
v v v
+-------------------------------------------------------------------+
| STORE LAYER |
| +----------------+ +----------------+ +----------------+ |
| | Values | | State | | Computed | |
| | cashValues |<-->| hawlStatus |<-->| Results | |
| | metalsValues | | prices | | | |
| +--------+-------+ +--------+-------+ +--------+-------+ |
+----------|--------------------|------------------|------------------+
| | |
v v v
+-------------------------------------------------------------------+
| ASSET TYPE SYSTEM |
| +----------------+ +----------------+ +----------------+ |
| | Registry | | Asset Type | | Asset | |
| | |<-->| Interface |<-->| Implementations | |
| | getAssetType | | | | cash/metals | |
| +--------+-------+ +--------+-------+ +--------+-------+ |
+----------|--------------------|------------------|------------------+
| | |
v v v
+-------------------------------------------------------------------+
| CALCULATION LAYER |
| +----------------+ +----------------+ +----------------+ |
| | Business | | Calculation | | Shared | |
| | Rules |<-->| Logic |<-->| Utilities | |
| | NISAB/HAWL | | | | | |
| +----------------+ +----------------+ +----------------+ |
+-------------------------------------------------------------------+
/src/app: Next.js app router pages and layouts/src/components: UI components organized by feature/calculators: Asset-specific calculator components/dashboard: Summary and visualization components/ui: Base UI components (buttons, inputs, etc.)
/src/store: State management using Zustand/modules: Asset-specific store logic/types: TypeScript interfaces for the store
/src/lib: Utility functions and shared logic/src/services: External service integrations (APIs, etc.)/src/types: Global TypeScript type definitions
- Home Page (
src/app/page.tsx): Entry point with setup and asset selection - Dashboard (
src/app/dashboard/page.tsx): Main calculator interface with all asset types
Zakat Guide uses Zustand for state management with:
- Main Store (
src/store/zakatStore.ts): Central state store with modules for each asset type - Persisted State: Local storage persistence for saving user data
- Module System: Separate business logic for each asset type
Each asset type implements a standardized interface:
- Asset Interfaces: Defined in
src/store/types.ts - Asset Implementation: In respective modules under
src/store/modules/ - Asset Registry: Dynamic loading of asset calculators
The application includes the following asset calculators:
- Tracks cash on hand, checking accounts, savings accounts, and digital wallets
- Supports multiple currencies with real-time conversion
- Handles foreign currency holdings
- Gold and silver calculations based on market prices
- Supports investment, personal use, and occasional use categories
- Automatic nisab threshold calculation
- Active trading vs long-term investment calculations
- Company financial data integration
- Dividend tracking
- Rental property calculation
- Property for sale vs personal residence handling
- Income and expense tracking
- Support for multiple cryptocurrencies
- Market value integration
- Trading vs holding distinction
- Traditional vs Roth accounts
- Tax and penalty considerations
- Customizable withdrawal assumptions
The main store (zakatStore.ts) combines multiple slices:
export interface ZakatState {
// Core data
currency: string
// Asset values
cashValues: CashValues
metalsValues: MetalsValues
stockValues: StockValues
realEstateValues: RealEstateValues
retirementValues: RetirementValues
cryptoValues: CryptoValues
// Hawl status per asset type
cashHawlMet: boolean
metalsHawlMet: boolean
stockHawlMet: boolean
realEstateHawlMet: boolean
retirementHawlMet: boolean
cryptoHawlMet: boolean
// Functions
getBreakdown: () => ZakatBreakdown
reset: () => void
// And many more asset-specific functions
}- User inputs values in calculator components
- Store updates via setter functions
- Computed values recalculate automatically
- UI components read from store and display updated values
- Breakdown data is generated for summary components
Each asset type has a dedicated calculator component in /src/components/calculators/ with:
- Input fields for asset details
- Real-time validation
- Value conversion
- Help text and guidance
- Summary (
/src/components/dashboard/Summary): Displays total zakat due - Asset Distribution (
/src/components/dashboard/Summary/AssetDistribution): Visual breakdown - Breakdown Table (
/src/components/dashboard/Summary/BreakdownTable): Detailed asset list - Nisab Status (
/src/components/dashboard/Summary/NisabStatus): Threshold tracking
- CurrencySelector: Robust currency selection with formatting
- Input Components: Form inputs with validation
- Tooltips: Contextual help system
- Components must be client-side (
'use client') - Use base UI components from
src/components/ui/ - Keep form logic separate from calculation logic
- Handle user input validation at this layer
- Single source of truth (zakatStore)
- All state mutations through setters
- Computed values update automatically
- Persist only necessary state
- Each asset type implements AssetType interface
- Register new assets in registry.ts
- Keep asset-specific logic self-contained
- Use shared utilities for common calculations
- Business rules in constants/types
- Asset-specific calculations in implementations
- Shared utilities for common operations
- Maintain type safety throughout
- Create module in
src/store/modules/ - Define types in
src/store/types.ts - Implement calculator component in
src/components/calculators/ - Add to the asset registry
- Create appropriate tests
Run the test suite with:
npm testThe testing architecture includes:
- Unit tests for calculation logic
- Component tests for UI
- Integration tests for store updates
- Validation tests for all asset types
The Zakat Guide application can be deployed using Vercel:
npm run buildFor production deployment, configure appropriate environment variables in .env.production.
The application includes robust i18n and currency support:
- Multi-currency calculations with real-time conversion
- Currency formatting according to locale
- Support for various number formats
- Customizable currency display options
For more detailed information, refer to the Asset Calculator Guidelines and Flow Documentation.