# 3obhan/mantec architecture

> Architecture diagram of the GitHub repository 3obhan/mantec, 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/3obhan/mantec
- Repository: https://github.com/3obhan/mantec

## Overview

Mantec is a bilingual logical-fallacy analyzer. Users choose a language, submit text for analysis, review and export findings, and revisit saved analyses; the UI also exposes spiritual feedback and financial-support pages. Analysis has an online Gemini path and an offline heuristic fallback, while the repository includes a separate payment API for paid reports. The shown excerpts establish the server’s Gemini and offline calls, but do not expose the frontend’s analysis or checkout request wiring, so those links are marked unverified or omitted.

Main entry points: [`src/App.tsx`](https://github.com/3obhan/mantec/blob/main/src/App.tsx) (App Router), [`src/components/Analyze.tsx`](https://github.com/3obhan/mantec/blob/main/src/components/Analyze.tsx) (Analyze & Export), [`src/store.tsx`](https://github.com/3obhan/mantec/blob/main/src/store.tsx) (App State), [`functions/api/payment/_lib.js`](https://github.com/3obhan/mantec/blob/main/functions/api/payment/_lib.js) (Payment Helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Application UI"]
  node_app["App Router<br/>[App.tsx]"]
  node_language["Language Choice<br/>[LanguageSelect.tsx]"]
  node_home["Home<br/>[Home.tsx]"]
  node_analyze["Analyze &amp; Export<br/>[Analyze.tsx]"]
  node_history["History &amp; Handbook<br/>[History.tsx]"]
  node_spiritual["Spiritual Feedback<br/>[Spiritual.tsx]"]
  node_exam["Exam Paper<br/>[ExamPaper.tsx]"]
  node_translations["Translations<br/>[i18n.ts]"]
end

subgraph group_analysis["Analysis Runtime"]
  node_server["Analysis Server<br/>[server.ts]"]
  node_offline["Offline Heuristics<br/>[offlineAnalyzer.ts]"]
  node_cache[("Analysis Cache")]
end

subgraph group_payments["Report Payments"]
  node_payment_create["Create Payment<br/>[create.js]"]
  node_payment_status["Payment Status<br/>[status.js]"]
  node_payment_report["Report Access<br/>[report.js]"]
  node_stripe_webhook["Stripe Webhook<br/>[stripe-webhook.js]"]
  node_zibal_callback["Zibal Callback<br/>[zibal-callback.js]"]
  node_payment_lib["Payment Helpers<br/>[_lib.js]"]
  node_payment_db[("Payments Database<br/>[schema.sql]")]
end

subgraph group_state["Local State"]
  node_state["App State<br/>[store.tsx]"]
  node_localstorage[("Browser Storage")]
end

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

node_user -->|"opens"| node_app
node_app -->|"provides state"| node_state
node_app -->|"routes to"| node_language
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_analyze
node_app -->|"routes to"| node_history
node_app -->|"routes to"| node_spiritual
node_language -->|"sets language"| node_state
node_home -->|"reads state"| node_state
node_analyze -->|"reads and updates"| node_state
node_history -->|"manages history"| node_state
node_spiritual -->|"reads state"| node_state
node_state -->|"persists"| node_localstorage
node_analyze -->|"uses labels"| node_translations
node_home -->|"uses labels"| node_translations
node_history -->|"uses labels"| node_translations
node_server -->|"queries"| node_gemini
node_server -->|"falls back to"| node_offline
node_analyze -->|"runs locally"| node_offline
node_server -->|"reads and writes"| node_cache
node_analyze -.->|"submits analysis"| node_server
node_payment_create -->|"uses helpers"| node_payment_lib
node_payment_status -->|"uses helpers"| node_payment_lib
node_payment_report -->|"uses helpers"| node_payment_lib
node_stripe_webhook -->|"verifies signature"| node_payment_lib
node_zibal_callback -->|"uses helpers"| node_payment_lib
node_stripe_webhook -->|"updates payment"| node_payment_db
node_analyze -.->|"starts checkout"| node_payment_create
node_analyze -.->|"exports report"| node_exam

click node_app "https://github.com/3obhan/mantec/blob/main/src/App.tsx"
click node_language "https://github.com/3obhan/mantec/blob/main/src/components/LanguageSelect.tsx"
click node_home "https://github.com/3obhan/mantec/blob/main/src/components/Home.tsx"
click node_analyze "https://github.com/3obhan/mantec/blob/main/src/components/Analyze.tsx"
click node_history "https://github.com/3obhan/mantec/blob/main/src/components/History.tsx"
click node_spiritual "https://github.com/3obhan/mantec/blob/main/src/components/Spiritual.tsx"
click node_exam "https://github.com/3obhan/mantec/blob/main/src/components/ExamPaper.tsx"
click node_translations "https://github.com/3obhan/mantec/blob/main/src/i18n.ts"
click node_state "https://github.com/3obhan/mantec/blob/main/src/store.tsx"
click node_server "https://github.com/3obhan/mantec/blob/main/server.ts"
click node_offline "https://github.com/3obhan/mantec/blob/main/src/offlineAnalyzer.ts"
click node_cache "https://github.com/3obhan/mantec/blob/main/analysis_cache.json"
click node_payment_create "https://github.com/3obhan/mantec/blob/main/functions/api/payment/create.js"
click node_payment_status "https://github.com/3obhan/mantec/blob/main/functions/api/payment/status.js"
click node_payment_report "https://github.com/3obhan/mantec/blob/main/functions/api/payment/report.js"
click node_stripe_webhook "https://github.com/3obhan/mantec/blob/main/functions/api/payment/stripe-webhook.js"
click node_zibal_callback "https://github.com/3obhan/mantec/blob/main/functions/api/payment/zibal-callback.js"
click node_payment_lib "https://github.com/3obhan/mantec/blob/main/functions/api/payment/_lib.js"
click node_payment_db "https://github.com/3obhan/mantec/blob/main/functions/schema.sql"

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_app,node_language,node_home,node_analyze,node_history,node_spiritual,node_exam,node_translations,node_user toneBlue
class node_server,node_offline,node_cache toneAmber
class node_payment_create,node_payment_status,node_payment_report,node_stripe_webhook,node_zibal_callback,node_payment_lib,node_payment_db toneMint
class node_state,node_localstorage toneRose
class node_gemini toneIndigo
```

## Components

### Application UI

- [App Router](https://github.com/3obhan/mantec/blob/main/src/App.tsx): `src/App.tsx`
- [Language Choice](https://github.com/3obhan/mantec/blob/main/src/components/LanguageSelect.tsx): `src/components/LanguageSelect.tsx`
- [Home](https://github.com/3obhan/mantec/blob/main/src/components/Home.tsx): `src/components/Home.tsx`
- [Analyze & Export](https://github.com/3obhan/mantec/blob/main/src/components/Analyze.tsx): `src/components/Analyze.tsx`
- [History & Handbook](https://github.com/3obhan/mantec/blob/main/src/components/History.tsx): `src/components/History.tsx`
- [Spiritual Feedback](https://github.com/3obhan/mantec/blob/main/src/components/Spiritual.tsx): `src/components/Spiritual.tsx`
- [Exam Paper](https://github.com/3obhan/mantec/blob/main/src/components/ExamPaper.tsx): `src/components/ExamPaper.tsx`
- [Translations](https://github.com/3obhan/mantec/blob/main/src/i18n.ts): `src/i18n.ts`

### Analysis Runtime

- [Analysis Server](https://github.com/3obhan/mantec/blob/main/server.ts): `server.ts`
- [Offline Heuristics](https://github.com/3obhan/mantec/blob/main/src/offlineAnalyzer.ts): `src/offlineAnalyzer.ts`
- [Analysis Cache](https://github.com/3obhan/mantec/blob/main/analysis_cache.json): `analysis_cache.json`

### Report Payments

- [Create Payment](https://github.com/3obhan/mantec/blob/main/functions/api/payment/create.js): `functions/api/payment/create.js`
- [Payment Status](https://github.com/3obhan/mantec/blob/main/functions/api/payment/status.js): `functions/api/payment/status.js`
- [Report Access](https://github.com/3obhan/mantec/blob/main/functions/api/payment/report.js): `functions/api/payment/report.js`
- [Stripe Webhook](https://github.com/3obhan/mantec/blob/main/functions/api/payment/stripe-webhook.js): `functions/api/payment/stripe-webhook.js`
- [Zibal Callback](https://github.com/3obhan/mantec/blob/main/functions/api/payment/zibal-callback.js): `functions/api/payment/zibal-callback.js`
- [Payment Helpers](https://github.com/3obhan/mantec/blob/main/functions/api/payment/_lib.js): `functions/api/payment/_lib.js`
- [Payments Database](https://github.com/3obhan/mantec/blob/main/functions/schema.sql): `functions/schema.sql`

### Local State

- [App State](https://github.com/3obhan/mantec/blob/main/src/store.tsx): `src/store.tsx`
- **Browser Storage**

### Other components

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

## Connections

- User → App Router: opens
- App Router → App State: provides state (evidence: `src/App.tsx`)
- App Router → Language Choice: routes to (evidence: `src/App.tsx`)
- App Router → Home: routes to (evidence: `src/App.tsx`)
- App Router → Analyze & Export: routes to (evidence: `src/App.tsx`)
- App Router → History & Handbook: routes to (evidence: `src/App.tsx`)
- App Router → Spiritual Feedback: routes to (evidence: `src/App.tsx`)
- Language Choice → App State: sets language (evidence: `src/components/LanguageSelect.tsx`)
- Home → App State: reads state (evidence: `src/components/Home.tsx`)
- Analyze & Export → App State: reads and updates (evidence: `src/components/Analyze.tsx`)
- History & Handbook → App State: manages history (evidence: `src/components/History.tsx`)
- Spiritual Feedback → App State: reads state (evidence: `src/components/Spiritual.tsx`)
- App State → Browser Storage: persists (evidence: `src/store.tsx`)
- Analyze & Export → Translations: uses labels (evidence: `src/components/Analyze.tsx`)
- Home → Translations: uses labels (evidence: `src/components/Home.tsx`)
- History & Handbook → Translations: uses labels (evidence: `src/components/History.tsx`)
- Analysis Server → Google Gemini: queries (evidence: `server.ts`)
- Analysis Server → Offline Heuristics: falls back to (evidence: `server.ts`)
- Analyze & Export → Offline Heuristics: runs locally (evidence: `src/components/Analyze.tsx`)
- Analysis Server → Analysis Cache: reads and writes (evidence: `server.ts`)
- Analyze & Export → Analysis Server: submits analysis
- Create Payment → Payment Helpers: uses helpers (evidence: `functions/api/payment/create.js`)
- Payment Status → Payment Helpers: uses helpers (evidence: `functions/api/payment/status.js`)
- Report Access → Payment Helpers: uses helpers (evidence: `functions/api/payment/report.js`)
- Stripe Webhook → Payment Helpers: verifies signature (evidence: `functions/api/payment/stripe-webhook.js`)
- Zibal Callback → Payment Helpers: uses helpers (evidence: `functions/api/payment/zibal-callback.js`)
- Stripe Webhook → Payments Database: updates payment (evidence: `functions/api/payment/stripe-webhook.js`)
- Analyze & Export → Create Payment: starts checkout
- Analyze & Export → Exam Paper: exports report
