> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spn.wtf/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

> Project structure and frontend routes

## Project Structure

```
sahyog-heena-jwellers/
├── backend/
│   ├── src/sj/
│   │   ├── __init__.py                   # App initialization & CORS
│   │   ├── app.py                        # FastAPI app factory
│   │   ├── config.py                     # Env var config
│   │   ├── db.py                         # DB engine & session
│   │   ├── deps.py                       # Dependency injection
│   │   ├── schema.py                     # SQLAlchemy ORM models
│   │   ├── routes.py                     # Main API routes (~2600 lines)
│   │   ├── order_draft_routes.py         # Order draft routes
│   │   ├── khata_router.py               # Khata submission routes
│   │   ├── gupshup_incoming_webhook.py   # WhatsApp webhook handler
│   │   ├── gupshup.py                    # Gupshup API helpers
│   │   ├── services.py                   # Core business logic
│   │   ├── khata_services.py             # Khata processing (v1)
│   │   ├── khata_services_v2.py          # Khata processing (v2)
│   │   ├── khata_upload.py               # Khata upload handlers
│   │   └── pdf_service.py               # PDF generation helpers
│   ├── tests/                            # Pytest test suite
│   ├── alembic/                          # DB migrations
│   ├── pyproject.toml                    # Poetry config
│   └── .env                             # Environment variables
│
└── frontend/
    ├── src/
    │   ├── main.tsx                      # React entry point
    │   ├── App.tsx                       # Root component + routing
    │   ├── pages/                        # Page-level components
    │   ├── components/                   # Reusable UI components
    │   ├── store/                        # Zustand stores
    │   ├── lib/
    │   │   └── axiosInstance.ts          # Configured Axios instance
    │   ├── types/
    │   │   └── RecordTypes.ts            # TypeScript interfaces
    │   └── utils/
    │       └── helper.ts
    ├── package.json
    └── vite.config.ts
```

***

## Frontend Routes

All routes are nested under `DashboardLayout` which renders the sidebar navigation.

| Path                     | Component        | Description                         |
| ------------------------ | ---------------- | ----------------------------------- |
| `/order-drafts`          | `OrderDrafts`    | Pending WhatsApp order drafts       |
| `/order-drafts/:draftId` | `OrderDraftEdit` | Review and edit a specific draft    |
| `/client-order`          | `ClientOrder`    | Manage client orders                |
| `/takada`                | `Takada`         | Manage takadas (partial deliveries) |
| `/karigar-account`       | `KarigarAccount` | List of all karigars                |
| `/karigar-account/:id`   | `KarigarLedger`  | Karigar ledger detail               |
| `/polisher-account`      | `PolishAccount`  | List of all polishers               |
| `/polisher-account/:id`  | `PolisherLedger` | Polisher ledger detail              |
| `/client-account`        | `ClientAccount`  | List of all clients                 |
| `/client-account/:id`    | `ClientLedger`   | Client ledger detail                |
| `/bank-account`          | `BankAccount`    | List of all bank accounts           |
| `/bank-account/:id`      | `BankLedger`     | Bank ledger detail                  |
| `/bullion-account`       | `BullionAccount` | List of all bullion accounts        |
| `/bullion-account/:id`   | `BullionLedger`  | Bullion ledger detail               |
| `/khata-upload`          | `KhataUpload`    | Khata OCR upload (v1)               |
| `/khata-upload-2`        | `KhataUpload2`   | Khata OCR upload (v2)               |

***

## State Management

The frontend uses **Zustand** for global state.

### `useDataStore`

Holds master data loaded at app startup.

| State            | Type               | Description                 |
| ---------------- | ------------------ | --------------------------- |
| `clients`        | `Client[]`         | All clients                 |
| `karigars`       | `Karigar[]`        | All karigars                |
| `karigarList`    | `Karigar[]`        | Karigar list for dropdowns  |
| `polisherList`   | `Polisher[]`       | Polisher list for dropdowns |
| `polishAccount`  | `Polisher[]`       | Polisher account data       |
| `clientAccount`  | `Client[]`         | Client account data         |
| `bankAccount`    | `BankAccount[]`    | Bank accounts               |
| `bullionAccount` | `BullionAccount[]` | Bullion accounts            |
| `takada`         | `Takada[]`         | All takadas                 |

**Actions:**

* `fetchClientsAndKarigars()` — fetches clients and karigars
* `fetchPolishers()` — fetches polisher data

### `clientOrdersStore`

Manages client order state including filtering, pagination, and selected order.

### `useAccessibilityStore`

Stores user accessibility preferences (e.g. font size, high contrast).
