Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

45 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

World Currency Converter

A modern, feature-rich currency converter application specializing in Moroccan currencies (Dirham, Riyal, Franc) with support for major world currencies. Built with Next.js 15, TypeScript, Redux Toolkit, and TanStack Query.

Light Mode Dark Mode TypeScript Next.js

๐ŸŒŸ Features

โœจ Core Features

  • Bidirectional Conversion - Type amounts in either the "From" or "To" field
  • Real-time Exchange Rates - Live rates via ExchangeRate-API
  • Moroccan Currency Support - MAD (Dirham), Riyal, and Franc with automatic conversions
  • World Currencies - 10+ major currencies (USD, EUR, GBP, JPY, CAD, AUD, CHF, CNY, INR, MXN)
  • Denomination Breakdown - Visual breakdown of MAD banknotes and coins
  • Dark/Light Mode - Full theme support with automatic system detection
  • Responsive Design - Works perfectly on mobile, tablet, and desktop

๐Ÿ’ฐ Moroccan Currency Features

  • MAD to Riyal: 1 MAD = 20 Riyals
  • MAD to Franc: 1 MAD = 100 Francs
  • Automatic Denomination Display: When converting to MAD, see the exact coins and banknotes needed
  • Authentic Currency Images: Real Moroccan currency images included

๐ŸŽจ Design

Light Mode

  • Soft blue/indigo/purple gradient background
  • Clean white cards with subtle shadows
  • Blue-tinted input fields for better visual hierarchy
  • Excellent contrast and readability

Dark Mode

  • Dark gray gradient background
  • Dark cards with proper borders
  • All text and UI elements adapt automatically
  • Smooth transitions between modes

๐Ÿ› ๏ธ Tech Stack

Frontend Framework

  • Next.js 15 - React framework with App Router
  • React 19 - Latest React with concurrent features
  • TypeScript - Type safety throughout

State Management

  • Redux Toolkit - Global state management
  • TanStack Query (React Query) - Server state & caching

Styling

  • Tailwind CSS - Utility-first CSS framework
  • shadcn/ui - Beautiful, accessible components
  • Lucide Icons - Clean, modern icon library

API & Data

  • ExchangeRate-API - Real-time exchange rates
  • Local Currency Data - Pre-configured Moroccan currency rates

๐Ÿ“ Project Structure

currencito/
โ”œโ”€โ”€ app/                          # Next.js App Router
โ”‚   โ”œโ”€โ”€ layout.tsx               # Root layout with providers
โ”‚   โ””โ”€โ”€ page.tsx                 # Home page
โ”‚
โ”œโ”€โ”€ components/                   # React components
โ”‚   โ”œโ”€โ”€ ui/                      # shadcn/ui components
โ”‚   โ”‚   โ”œโ”€โ”€ button.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ card.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ input.tsx
โ”‚   โ”‚   โ””โ”€โ”€ select.tsx
โ”‚   โ”œโ”€โ”€ CurrencyConverter.tsx    # Main converter component
โ”‚   โ”œโ”€โ”€ CurrencySelect.tsx       # Currency dropdown
โ”‚   โ””โ”€โ”€ DenominationBreakdown.tsx # MAD denomination display
โ”‚
โ”œโ”€โ”€ lib/                          # Core logic & utilities
โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ””โ”€โ”€ exchangeRates.ts     # API client
โ”‚   โ”œโ”€โ”€ currency/
โ”‚   โ”‚   โ”œโ”€โ”€ converter.ts         # Conversion logic
โ”‚   โ”‚   โ”œโ”€โ”€ denominations.ts     # Denomination calculations
โ”‚   โ”‚   โ”œโ”€โ”€ constants.ts         # Currency metadata
โ”‚   โ”‚   โ””โ”€โ”€ types.ts             # TypeScript types
โ”‚   โ”œโ”€โ”€ query/
โ”‚   โ”‚   โ””โ”€โ”€ hooks/
โ”‚   โ”‚       โ””โ”€โ”€ useExchangeRates.ts # React Query hook
โ”‚   โ””โ”€โ”€ store/
โ”‚       โ”œโ”€โ”€ index.ts             # Redux store
โ”‚       โ”œโ”€โ”€ hooks.ts             # Typed Redux hooks
โ”‚       โ””โ”€โ”€ slices/
โ”‚           โ””โ”€โ”€ converterSlice.ts # Converter state
โ”‚
โ””โ”€โ”€ public/
    โ””โ”€โ”€ currency/                 # Currency images
        โ”œโ”€โ”€ mad-200-note.jpg
        โ”œโ”€โ”€ mad-100-note.jpg
        โ””โ”€โ”€ ... (coins & notes)

๐Ÿ—๏ธ Architecture

State Management

Redux Toolkit (UI State)

Manages user input and currency selections:

interface ConverterState {
  amount: string;        // From amount
  toAmount: string;      // To amount
  fromCurrency: Currency;
  toCurrency: Currency;
}

Actions:

  • setAmount(value) - Set from amount (clears to amount)
  • setToAmount(value) - Set to amount (clears from amount)
  • setFromCurrency(currency) - Change from currency
  • setToCurrency(currency) - Change to currency
  • swapCurrencies() - Swap currencies and amounts

TanStack Query (Server State)

Handles exchange rate fetching with caching:

  • Cache Time: 5 minutes
  • Stale Time: 1 minute
  • Refetch: On window focus
  • API: ExchangeRate-API (free tier)

Currency Conversion Logic

World Currencies

convertCurrency(amount, fromCurrency, toCurrency, rates)

Uses the USD as the base currency:

  1. Convert from currency to USD
  2. Convert USD to target currency

Moroccan Internal Conversions

// Direct conversions (no API needed)
MAD โ†” Riyal: multiply/divide by 20
MAD โ†” Franc: multiply/divide by 100
Riyal โ†” Franc: multiply/divide by 5

Denomination Algorithm

Greedy algorithm to calculate minimum coins/notes:

calculateDenominations(amount: number): Denomination[]

MAD Denominations:

  • Notes: 200, 100, 50, 20
  • Coins: 10, 5, 2, 1, 0.5, 0.2, 0.1

๐Ÿš€ Getting Started

Prerequisites

  • Node.js 18+
  • pnpm (recommended) or npm

Installation

  1. Clone the repository
git clone <repository-url>
cd currencito
  1. Install dependencies
pnpm install
# or
npm install
  1. Run development server
pnpm dev
# or
npm run dev
  1. Open your browser
http://localhost:3002

Production Build

pnpm build
pnpm start

๐Ÿ“– Usage Guide

Basic Conversion

  1. Enter amount in the "From" field
  2. Select currencies from dropdowns
  3. View result in the "To" field automatically

Bidirectional Input

  1. Type in either field - the other updates automatically
  2. Start typing in one field, the other clears
  3. Perfect for "how much would I need" calculations

Swap Currencies

Click the swap button (โ†”) between fields to:

  • Exchange the from/to currencies
  • Swap the amounts
  • Quick reverse calculation

Denomination Breakdown

When converting to MAD:

  • Automatic denomination breakdown appears below
  • Shows exact banknotes and coins needed
  • Displays authentic Moroccan currency images
  • Calculates minimum number of denominations

Dark Mode

  • Automatic: Follows system preference
  • Manual: Toggle in browser/system settings
  • Smooth: Instant theme switching

๐Ÿ”ง Configuration

Exchange Rate API

Located in lib/api/exchangeRates.ts:

const API_KEY = 'YOUR_API_KEY'; // Free tier available
const BASE_URL = 'https://v6.exchangerate-api.com/v6';

Get your free API key at: https://www.exchangerate-api.com/

Moroccan Currency Rates

Hardcoded in lib/currency/constants.ts:

export const MOROCCAN_RATES = {
  MAD_TO_RIYAL: 20,
  MAD_TO_FRANC: 100,
} as const;

Supported Currencies

Moroccan:

  • MAD - Moroccan Dirham (๐Ÿ‡ฒ๐Ÿ‡ฆ)
  • RIYAL - Moroccan Riyal (๐Ÿ‡ฒ๐Ÿ‡ฆ)
  • FRANC - Moroccan Franc (๐Ÿ‡ฒ๐Ÿ‡ฆ)

World:

  • USD - US Dollar (๐Ÿ‡บ๐Ÿ‡ธ)
  • EUR - Euro (๐Ÿ‡ช๐Ÿ‡บ)
  • GBP - British Pound (๐Ÿ‡ฌ๐Ÿ‡ง)
  • JPY - Japanese Yen (๐Ÿ‡ฏ๐Ÿ‡ต)
  • CAD - Canadian Dollar (๐Ÿ‡จ๐Ÿ‡ฆ)
  • AUD - Australian Dollar (๐Ÿ‡ฆ๐Ÿ‡บ)
  • CHF - Swiss Franc (๐Ÿ‡จ๐Ÿ‡ญ)
  • CNY - Chinese Yuan (๐Ÿ‡จ๐Ÿ‡ณ)
  • INR - Indian Rupee (๐Ÿ‡ฎ๐Ÿ‡ณ)
  • MXN - Mexican Peso (๐Ÿ‡ฒ๐Ÿ‡ฝ)

๐ŸŽฏ Component API

CurrencyConverter

Main converter component with all logic.

State:

  • Manages amounts (from/to)
  • Handles currency selection
  • Fetches exchange rates
  • Calculates conversions

Features:

  • Bidirectional input
  • Real-time conversion
  • Denomination breakdown
  • Exchange rate display

CurrencySelect

Currency dropdown selector.

Props:

interface CurrencySelectProps {
  value: Currency;
  onChange: (value: Currency) => void;
}

Features:

  • Grouped currencies (Moroccan/World)
  • Flag icons
  • Currency codes and names
  • Dark mode support

DenominationBreakdown

Visual display of MAD denominations.

Props:

interface DenominationBreakdownProps {
  denominations: Denomination[];
  total: number;
}

Features:

  • Currency images
  • Count display
  • Total calculation
  • Responsive grid

๐Ÿงช Type Definitions

Currency Type

type Currency = 
  | 'MAD' | 'RIYAL' | 'FRANC'  // Moroccan
  | 'USD' | 'EUR' | 'GBP' | 'JPY' | 'CAD' 
  | 'AUD' | 'CHF' | 'CNY' | 'INR' | 'MXN'; // World

Currency Info

interface CurrencyInfo {
  code: string;
  name: string;
  symbol: string;
  flag: string;
  isMoroccan: boolean;
}

Denomination

interface Denomination {
  value: number;
  count: number;
  type: 'note' | 'coin';
  imageUrl: string;
}

๐ŸŽจ Customization

Adding New Currencies

  1. Add to types in lib/currency/types.ts:
type Currency = ... | 'NEW_CURRENCY';
  1. Add metadata in lib/currency/constants.ts:
NEW_CURRENCY: {
  code: 'NEW',
  name: 'New Currency',
  symbol: 'N$',
  flag: '๐Ÿณ๏ธ',
  isMoroccan: false,
}
  1. Add to groups in lib/currency/constants.ts:
export const WORLD_CURRENCIES = [..., 
  CURRENCIES.NEW_CURRENCY
];

Styling

Theme Colors:

  • Edit tailwind.config.ts for global theme
  • Component styles use Tailwind utilities
  • Dark mode variants: dark: prefix

Gradients:

// Light mode
bg-gradient-to-br from-blue-50 via-indigo-50 to-purple-50

// Dark mode
dark:from-gray-900 dark:via-gray-800 dark:to-gray-900

๐Ÿ“Š Performance

  • React Query Caching - Reduces API calls
  • Optimized Re-renders - Redux selectors
  • Code Splitting - Next.js automatic splitting
  • Image Optimization - Next.js Image component (if used)

๐Ÿ”’ Security

  • No sensitive data stored
  • API key can be environment variable
  • Client-side only calculations
  • No user authentication required

๐Ÿ› Known Issues

  • Exchange rates update every 24 hours on free API tier
  • Some currency symbols may not display on all systems
  • Denomination images require manual addition

๐Ÿšง Future Enhancements

  • Historical exchange rate charts
  • Multiple currency comparison
  • Favorite currency pairs
  • Conversion history
  • Offline mode with cached rates
  • PWA support
  • Currency alerts/notifications
  • Export conversion results

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“ž Support

For issues or questions, please open an issue on GitHub.


Made with โค๏ธ for the Moroccan community

๐Ÿ‡ฒ๐Ÿ‡ฆ Supporting MAD, Riyal, and Franc conversions since 2026

Releases

Packages

Contributors

Languages