# Architecture

## Architecture

### Overview

AfriWage is a Next.js 14 monorepo with three layers:

* Frontend app (apps/web)
* Backend API routes (apps/web/src/app/api)
* Stellar SDK package (packages/sdk)

### Payment flow

\[Employer Wallet] │ │ Signs transaction in Freighter ▼ \[AfriWage Frontend] │ │ Builds + submits Stellar transaction ▼ \[Stellar Network (testnet)] │ │ Settles in 3–5 seconds ▼ \[Horizon API] │ │ Confirms payment + returns tx hash ▼ \[AfriWage dashboard + worker passport]

### Monorepo structure

AfriWage/ ├── apps/ │ └── web/ │ ├── src/app/ ← Next.js pages │ ├── src/app/api/ ← serverless API routes │ ├── src/components/ ← UI components │ └── src/lib/ ← Stellar + Freighter helpers ├── packages/ │ └── sdk/ ← @afriwage/sdk └── docs/ ← documentation

### API layer

All API routes are Next.js Route Handlers deployed as Vercel serverless functions:

GET /api/rates → live USDC exchange rates GET /api/account/\[address] → account balances GET /api/transactions/\[address] → payment history GET /api/payment/verify?hash= → verify transaction POST /api/fund-testnet → fund via Friendbot

### Tech stack

| Layer      | Technology                  |
| ---------- | --------------------------- |
| Frontend   | Next.js 14 (App Router)     |
| Language   | TypeScript strict mode      |
| Styling    | Tailwind CSS + shadcn/ui    |
| Blockchain | Stellar testnet             |
| Asset      | USDC                        |
| Wallet     | Freighter browser extension |
| SDK        | @stellar/stellar-sdk v12    |
| State      | React Query v5              |
| Deploy     | Vercel (free tier)          |


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://k1ngd4vid.gitbook.io/afriwage-doc/architecture.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
