# mohammad200326/zakaty architecture

> Architecture diagram of the GitHub repository mohammad200326/zakaty, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohammad200326/zakaty
- Repository: https://github.com/mohammad200326/zakaty

## Overview

Zakaty offers two routes from user-provided financial data to a Zakat result: a manual calculator and a guided AI assistant that extracts and structures data. Both account for currency and a selectable gold-or-silver Nisab threshold; results can be viewed and saved for later history review. The graph includes documented capabilities whose wiring is not shown in the excerpts. Some UI-to-API and result-to-save relationships are therefore documented at product-workflow level rather than verified from sampled calls.

Main entry points: [`app/api/zakat-assistant/route.ts`](https://github.com/mohammad200326/zakaty/blob/main/app/api/zakat-assistant/route.ts) (Assistant API), [`app/(root)/result/components/ZakatResultView.tsx`](https://github.com/mohammad200326/zakaty/blob/main/app/(root)/result/components/ZakatResultView.tsx) (Detailed results), [`app/(root)/calculator/components/ZakatCalculatorClient.tsx`](https://github.com/mohammad200326/zakaty/blob/main/app/(root)/calculator/components/ZakatCalculatorClient.tsx) (Manual calculator), [`lib/ai/check-ai-limit.ts`](https://github.com/mohammad200326/zakaty/blob/main/lib/ai/check-ai-limit.ts) (AI usage limits)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_calculation["Calculation modes"]
  node_calculator["Manual calculator"]
  node_assistant_ui["Guided assistant"]
  node_assistant_api["Assistant API<br/>[route.ts]"]
end

subgraph group_result_history["Results and history"]
  node_result_view["Detailed results"]
  node_save_action["Calculation storage actions"]
  node_history_page["History list<br/>[HistoryClient.tsx]"]
  node_history_detail["History detail<br/>[page.tsx]"]
  node_calculations_db[("Saved calculations")]
end

subgraph group_account["Access and plans"]
  node_access_api["AI access check<br/>[route.ts]"]
  node_ai_limits["AI usage limits<br/>[check-ai-limit.ts]"]
  node_subscription["Plan rules"]
  node_subscription_service["User plan lookup"]
  node_usage_db[("AI usage records")]
end

subgraph group_shared["Shared calculation services"]
  node_nisab["Nisab calculation<br/>[nisab.ts]"]
  node_rates["Exchange rates"]
  node_currency_data["Currency constants<br/>[constants.ts]"]
  node_supabase["Supabase client<br/>[server.ts]"]
end

node_user(("User"))
node_gemini{{"Google Gemini"}}

node_user -->|"enters assets"| node_calculator
node_user -->|"starts guided flow"| node_assistant_ui
node_assistant_ui -.->|"submits answers"| node_assistant_api
node_assistant_api -.->|"extracts data"| node_gemini
node_assistant_api -->|"loads rates"| node_rates
node_assistant_api -->|"uses fallback rates"| node_currency_data
node_assistant_api -->|"calculates threshold"| node_nisab
node_calculator -->|"calculates threshold"| node_nisab
node_calculator -->|"uses rates"| node_currency_data
node_assistant_api -->|"checks and records usage"| node_ai_limits
node_assistant_ui -->|"opens detailed result"| node_result_view
node_calculator -->|"opens detailed result"| node_result_view
node_result_view -->|"loads rates"| node_rates
node_result_view -->|"calculates threshold"| node_nisab
node_result_view -.->|"saves calculation"| node_save_action
node_save_action -->|"writes and reads"| node_calculations_db
node_history_page -->|"loads calculations"| node_save_action
node_history_page -->|"opens selected record"| node_history_detail
node_history_detail -->|"loads calculation"| node_save_action
node_access_api -->|"looks up plan"| node_subscription_service
node_access_api -->|"uses plan limits"| node_subscription
node_access_api -->|"reads usage"| node_supabase
node_ai_limits -->|"looks up plan"| node_subscription_service
node_ai_limits -->|"uses plan limits"| node_subscription
node_ai_limits -->|"reads and updates usage"| node_supabase
node_supabase -.->|"accesses records"| node_usage_db
node_supabase -.->|"accesses records"| node_calculations_db

click node_calculator "https://github.com/mohammad200326/zakaty/blob/main/app/(root)/calculator/components/ZakatCalculatorClient.tsx"
click node_assistant_ui "https://github.com/mohammad200326/zakaty/blob/main/app/(root)/assistant/components/AssistantClient.tsx"
click node_assistant_api "https://github.com/mohammad200326/zakaty/blob/main/app/api/zakat-assistant/route.ts"
click node_nisab "https://github.com/mohammad200326/zakaty/blob/main/lib/nisab.ts"
click node_rates "https://github.com/mohammad200326/zakaty/blob/main/lib/services/exchangeRates.service.ts"
click node_currency_data "https://github.com/mohammad200326/zakaty/blob/main/lib/constants.ts"
click node_result_view "https://github.com/mohammad200326/zakaty/blob/main/app/(root)/result/components/ZakatResultView.tsx"
click node_save_action "https://github.com/mohammad200326/zakaty/blob/main/lib/actions/save-zakat-calculation.ts"
click node_history_page "https://github.com/mohammad200326/zakaty/blob/main/app/(root)/history/HistoryClient.tsx"
click node_history_detail "https://github.com/mohammad200326/zakaty/blob/main/app/(root)/history/%5Bid%5D/page.tsx"
click node_access_api "https://github.com/mohammad200326/zakaty/blob/main/app/api/check-access/route.ts"
click node_ai_limits "https://github.com/mohammad200326/zakaty/blob/main/lib/ai/check-ai-limit.ts"
click node_subscription "https://github.com/mohammad200326/zakaty/blob/main/lib/subscription-constants.ts"
click node_subscription_service "https://github.com/mohammad200326/zakaty/blob/main/lib/subscription.server.ts"
click node_supabase "https://github.com/mohammad200326/zakaty/blob/main/lib/supabase/server.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_calculator,node_assistant_ui,node_assistant_api,node_user toneBlue
class node_result_view,node_save_action,node_history_page,node_history_detail,node_calculations_db toneAmber
class node_access_api,node_ai_limits,node_subscription,node_subscription_service,node_usage_db toneMint
class node_nisab,node_rates,node_currency_data,node_supabase toneRose
class node_gemini toneIndigo
```

## Components

### Calculation modes

- [Manual calculator](https://github.com/mohammad200326/zakaty/blob/main/app/(root)/calculator/components/ZakatCalculatorClient.tsx): `app/(root)/calculator/components/ZakatCalculatorClient.tsx`
- [Guided assistant](https://github.com/mohammad200326/zakaty/blob/main/app/(root)/assistant/components/AssistantClient.tsx): `app/(root)/assistant/components/AssistantClient.tsx`
- [Assistant API](https://github.com/mohammad200326/zakaty/blob/main/app/api/zakat-assistant/route.ts): `app/api/zakat-assistant/route.ts`

### Results and history

- [Detailed results](https://github.com/mohammad200326/zakaty/blob/main/app/(root)/result/components/ZakatResultView.tsx): `app/(root)/result/components/ZakatResultView.tsx`
- [Calculation storage actions](https://github.com/mohammad200326/zakaty/blob/main/lib/actions/save-zakat-calculation.ts): `lib/actions/save-zakat-calculation.ts`
- [History list](https://github.com/mohammad200326/zakaty/blob/main/app/(root)/history/HistoryClient.tsx): `app/(root)/history/HistoryClient.tsx`
- [History detail](https://github.com/mohammad200326/zakaty/blob/main/app/(root)/history/%5Bid%5D/page.tsx): `app/(root)/history/[id]/page.tsx`
- **Saved calculations**

### Access and plans

- [AI access check](https://github.com/mohammad200326/zakaty/blob/main/app/api/check-access/route.ts): `app/api/check-access/route.ts`
- [AI usage limits](https://github.com/mohammad200326/zakaty/blob/main/lib/ai/check-ai-limit.ts): `lib/ai/check-ai-limit.ts`
- [Plan rules](https://github.com/mohammad200326/zakaty/blob/main/lib/subscription-constants.ts): `lib/subscription-constants.ts`
- [User plan lookup](https://github.com/mohammad200326/zakaty/blob/main/lib/subscription.server.ts): `lib/subscription.server.ts`
- **AI usage records**

### Shared calculation services

- [Nisab calculation](https://github.com/mohammad200326/zakaty/blob/main/lib/nisab.ts): `lib/nisab.ts`
- [Exchange rates](https://github.com/mohammad200326/zakaty/blob/main/lib/services/exchangeRates.service.ts): `lib/services/exchangeRates.service.ts`
- [Currency constants](https://github.com/mohammad200326/zakaty/blob/main/lib/constants.ts): `lib/constants.ts`
- [Supabase client](https://github.com/mohammad200326/zakaty/blob/main/lib/supabase/server.ts): `lib/supabase/server.ts`

### Other components

- **User**
- **Google Gemini**

## Connections

- User → Manual calculator: enters assets (evidence: `README.md`)
- User → Guided assistant: starts guided flow (evidence: `README.md`)
- Guided assistant → Assistant API: submits answers
- Assistant API → Google Gemini: extracts data
- Assistant API → Exchange rates: loads rates (evidence: `app/api/zakat-assistant/route.ts`)
- Assistant API → Currency constants: uses fallback rates (evidence: `app/api/zakat-assistant/route.ts`)
- Assistant API → Nisab calculation: calculates threshold (evidence: `app/api/zakat-assistant/route.ts`)
- Manual calculator → Nisab calculation: calculates threshold (evidence: `app/(root)/calculator/components/ZakatCalculatorClient.tsx`)
- Manual calculator → Currency constants: uses rates (evidence: `app/(root)/calculator/components/ZakatCalculatorClient.tsx`)
- Assistant API → AI usage limits: checks and records usage (evidence: `app/api/zakat-assistant/route.ts`)
- Guided assistant → Detailed results: opens detailed result (evidence: `README.md`)
- Manual calculator → Detailed results: opens detailed result (evidence: `README.md`)
- Detailed results → Exchange rates: loads rates (evidence: `app/(root)/result/page.tsx`)
- Detailed results → Nisab calculation: calculates threshold (evidence: `app/(root)/result/page.tsx`)
- Detailed results → Calculation storage actions: saves calculation (evidence: `app/(root)/result/components/ZakatResultView.tsx`)
- Calculation storage actions → Saved calculations: writes and reads (evidence: `lib/actions/save-zakat-calculation.ts`)
- History list → Calculation storage actions: loads calculations (evidence: `app/(root)/history/page.tsx`)
- History list → History detail: opens selected record (evidence: `app/(root)/history/HistoryClient.tsx`)
- History detail → Calculation storage actions: loads calculation (evidence: `app/(root)/history/[id]/page.tsx`)
- AI access check → User plan lookup: looks up plan (evidence: `app/api/check-access/route.ts`)
- AI access check → Plan rules: uses plan limits (evidence: `app/api/check-access/route.ts`)
- AI access check → Supabase client: reads usage (evidence: `app/api/check-access/route.ts`)
- AI usage limits → User plan lookup: looks up plan (evidence: `lib/ai/check-ai-limit.ts`)
- AI usage limits → Plan rules: uses plan limits (evidence: `lib/ai/check-ai-limit.ts`)
- AI usage limits → Supabase client: reads and updates usage (evidence: `lib/ai/check-ai-limit.ts`)
- Supabase client → AI usage records: accesses records
- Supabase client → Saved calculations: accesses records
