> For the complete documentation index, see [llms.txt](https://payana-saas.gitbook.io/payana-saas-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://payana-saas.gitbook.io/payana-saas-docs/arsitektur/arsitektur.md).

# Gambaran Umum

Payana terdiri dari empat lapisan, masing-masing dengan tanggung jawab yang jelas dan tidak tumpang tindih. Prinsip desainnya sederhana: **hanya smart contract yang menjadi sumber kebenaran untuk pergerakan uang** — tiga lapisan lainnya membaca, menampilkan, atau memfasilitasi, tapi tidak pernah menjadi otoritas atas saldo siapa pun.

```mermaid
flowchart TD
    subgraph L1["1. Smart Contract — Base Sepolia"]
        direction LR
        PF["PayrollFactory"] -->|deploy| CV["CompanyVault<br/>(satu per perusahaan)"]
        CV --> SBT["EmploymentSBT"]
    end

    subgraph L2["2. Indexer — Ponder"]
        direction LR
        LISTEN["Dengar semua event kontrak"] --> DB1[("PostgreSQL<br/>skema public")]
        DB1 --> API1["HTTP API"]
    end

    subgraph L3["3. Backend — Express + Drizzle"]
        direction LR
        AUTH["Auth & JWT"] --- ROUTES["REST API"]
        ROUTES --> DB2[("PostgreSQL<br/>skema app")]
        ROUTES --> BUNDLER["Relay ke Bundler<br/>(ERC-4337)"]
        CRON["Cron: monitor Paymaster,<br/>deteksi anomali"]
    end

    subgraph L4["4. Frontend — Next.js"]
        direction LR
        UI["Dashboard Karyawan/HR/Owner"] --> PRIVY["Smart Account<br/>via Privy"]
    end

    L1 -.emit event.-> L2
    L4 -->|baca data terindeks| L2
    L4 -->|baca/tulis off-chain,<br/>relay transaksi| L3
    L3 -.baca tabel indexer<br/>langsung dari DB.-> L2
    L4 -->|kirim UserOperation<br/>gasless| L1
```

## Ringkasan tiap lapisan

| Lapisan            | Teknologi                     | Tanggung jawab                                                                                                                                                     |
| ------------------ | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Smart Contract** | Solidity, Foundry             | Sumber kebenaran untuk uang: saldo, streaming gaji, kasbon, vesting, PHK, pesangon. Tidak bisa "dibohongi".                                                        |
| **Indexer**        | Ponder                        | Mendengarkan setiap event kontrak secara real-time, memasukkannya ke PostgreSQL — supaya pembacaan data tidak pernah harus menunggu RPC call on-chain yang lambat. |
| **Backend**        | Node.js, Express, Drizzle ORM | Urusan off-chain saja: PII terenkripsi, autentikasi JWT, dokumen PDF, cron terjadwal. Tidak pernah menjadi sumber kebenaran untuk uang.                            |
| **Frontend**       | Next.js 16, React 19, Privy   | Smart Account tertanam — karyawan tidak pernah menyentuh seed phrase atau membayar gas; terasa seperti aplikasi biasa.                                             |

## Kenapa dipisah begini

* **Kontrak jadi sumber kebenaran** — tidak ada database yang bisa "salah" tentang berapa saldo seseorang, karena angka itu selalu dihitung ulang dari state on-chain.
* **Indexer jadi lapisan performa** — tanpa itu, setiap halaman yang menampilkan riwayat transaksi harus memanggil node RPC berkali-kali, lambat dan mahal. Ponder memindahkan biaya itu ke proses background sekali jalan.
* **Backend jadi lapisan yang menangani apa yang tidak seharusnya ada di blockchain publik** — data pribadi karyawan (NIK, nomor telepon) tidak pernah disimpan on-chain; itu tetap di database terenkripsi yang hanya bisa diakses lewat autentikasi yang tepat.
* **Frontend jadi lapisan yang menyembunyikan kompleksitas Web3** — pengguna akhir tidak pernah perlu tahu bahwa di baliknya ada blockchain sama sekali.

Detail tiap lapisan: [Smart Contract](/payana-saas-docs/arsitektur/smart-contract.md) · [Indexer](/payana-saas-docs/arsitektur/indexer.md) · [Backend](/payana-saas-docs/arsitektur/backend.md) · [Frontend](/payana-saas-docs/arsitektur/frontend.md). Untuk pola-pola yang berulang di semua lapisan (seperti Smart Account vs EOA), lihat [Konvensi Kunci](/payana-saas-docs/arsitektur/konvensi-kunci.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://payana-saas.gitbook.io/payana-saas-docs/arsitektur/arsitektur.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
