# farazpatwegar/testapp architecture

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

- Interactive diagram: https://gitdiagram.com/farazpatwegar/testapp
- Repository: https://github.com/farazpatwegar/testapp

## Overview

DukaanSaathi is a shop-management app: shop staff onboard or sign in, manage products and customers, record sales and expenses, track credit (Udhaar), and review reports. The React Native app keeps a local cache and syncs domain actions with a versioned backend API; the backend authenticates shop membership and persists business operations. The sampled code confirms the app entry, sale flow, API client, cache/sync behavior, and selected backend routes. Other documented-by-tree screens and backend modules are represented, but their internal calls are not inferred where source excerpts were unavailable.

Main entry points: [`backend/src/server.ts`](https://github.com/farazpatwegar/testapp/blob/main/backend/src/server.ts) (API server), [`backend/src/middleware/auth.ts`](https://github.com/farazpatwegar/testapp/blob/main/backend/src/middleware/auth.ts) (Auth middleware), [`App.tsx`](https://github.com/farazpatwegar/testapp/blob/main/App.tsx) (App navigation), [`src/screens/main_navigation_screen.tsx`](https://github.com/farazpatwegar/testapp/blob/main/src/screens/main_navigation_screen.tsx) (Shop workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile app"]
  node_app_shell["App navigation<br/>[App.tsx]"]
  node_onboarding["Onboarding"]
  node_main_nav["Shop workspace"]
  node_pos["POS scanner"]
  node_sale_screen["Sale entry"]
  node_dashboard["Dashboard"]
  node_inventory["Stock management<br/>[stock_screen.tsx]"]
  node_customers["Customer credit<br/>[udhaar_screen.tsx]"]
  node_customer_detail["Customer detail"]
  node_expenses["Expense tracking"]
  node_reports_screen["Reports view<br/>[reports_screen.tsx]"]
  node_upi_dialog["UPI payment dialog<br/>[upi_qr_dialog.tsx]"]
end

subgraph group_client_services["Client services"]
  node_app_state["Local app state<br/>[app_data.ts]"]
  node_api_services["Domain API services"]
  node_api_client["API transport<br/>[api_client.ts]"]
  node_offline_sync["Offline sync queue<br/>[sync_service.ts]"]
  node_receipt_pdf["Receipt PDF<br/>[pdf_service.ts]"]
end

subgraph group_api["API backend"]
  node_api_server["API server<br/>[server.ts]"]
  node_auth_middleware["Auth middleware<br/>[auth.ts]"]
  node_prisma[("PostgreSQL access<br/>[prisma.ts]")]
end

subgraph group_backend_domain["Backend operations"]
  node_auth_routes["Authentication<br/>[auth.routes.ts]"]
  node_business_routes["Business data<br/>[business.routes.ts]"]
  node_sales_routes["Sales and receipts<br/>[sales.routes.ts]"]
  node_payments_routes["Payment operations<br/>[payments.routes.ts]"]
  node_reports_routes["Report operations<br/>[reports.routes.ts]"]
  node_shops_routes["Shop settings<br/>[shops.routes.ts]"]
end

node_shop_staff(("Shop staff"))
node_shop_owner(("Shop owner"))

node_shop_staff -->|"uses"| node_app_shell
node_app_shell -->|"loads"| node_app_state
node_app_shell -->|"routes to"| node_onboarding
node_app_shell -->|"routes to"| node_main_nav
node_app_shell -->|"routes to"| node_sale_screen
node_app_shell -->|"routes to"| node_pos
node_onboarding -->|"authenticates via"| node_api_services
node_main_nav -.->|"offers views"| node_dashboard
node_main_nav -.->|"offers views"| node_inventory
node_main_nav -.->|"offers views"| node_customers
node_main_nav -.->|"offers views"| node_expenses
node_main_nav -.->|"offers views"| node_reports_screen
node_customers -.->|"opens"| node_customer_detail
node_pos -->|"scans products"| node_app_state
node_sale_screen -->|"records sale"| node_app_state
node_sale_screen -->|"requests payment"| node_api_services
node_sale_screen -->|"creates receipt"| node_receipt_pdf
node_sale_screen -->|"shows UPI"| node_upi_dialog
node_app_state -->|"loads and mutates"| node_api_services
node_app_state -->|"queues failed writes"| node_offline_sync
node_api_services -->|"sends requests"| node_api_client
node_api_client -.->|"HTTP requests"| node_api_server
node_api_server -->|"mounts routes"| node_auth_routes
node_api_server -->|"mounts routes"| node_business_routes
node_api_server -->|"mounts routes"| node_sales_routes
node_api_server -->|"mounts routes"| node_payments_routes
node_api_server -->|"mounts routes"| node_reports_routes
node_api_server -->|"mounts routes"| node_shops_routes
node_shop_owner -->|"registers or signs in"| node_auth_routes
node_auth_routes -->|"reads and writes"| node_prisma
node_business_routes -->|"reads and writes"| node_prisma
node_sales_routes -->|"records sales"| node_prisma
node_payments_routes -->|"persists payments"| node_prisma
node_reports_routes -->|"queries reports"| node_prisma
node_shops_routes -->|"reads and writes"| node_prisma
node_auth_routes -->|"requires auth"| node_auth_middleware
node_business_routes -->|"requires auth"| node_auth_middleware
node_sales_routes -->|"requires auth"| node_auth_middleware
node_payments_routes -->|"requires auth"| node_auth_middleware
node_reports_routes -->|"requires auth"| node_auth_middleware
node_shops_routes -->|"requires auth"| node_auth_middleware
node_auth_middleware -->|"checks membership"| node_prisma

click node_app_shell "https://github.com/farazpatwegar/testapp/blob/main/App.tsx"
click node_onboarding "https://github.com/farazpatwegar/testapp/blob/main/src/screens/onboarding_screen.tsx"
click node_main_nav "https://github.com/farazpatwegar/testapp/blob/main/src/screens/main_navigation_screen.tsx"
click node_pos "https://github.com/farazpatwegar/testapp/blob/main/src/screens/pos_scanner_screen.tsx"
click node_sale_screen "https://github.com/farazpatwegar/testapp/blob/main/src/screens/add_sale_screen.tsx"
click node_dashboard "https://github.com/farazpatwegar/testapp/blob/main/src/screens/dashboard_screen.tsx"
click node_inventory "https://github.com/farazpatwegar/testapp/blob/main/src/screens/stock_screen.tsx"
click node_customers "https://github.com/farazpatwegar/testapp/blob/main/src/screens/udhaar_screen.tsx"
click node_customer_detail "https://github.com/farazpatwegar/testapp/blob/main/src/screens/customer_detail_screen.tsx"
click node_expenses "https://github.com/farazpatwegar/testapp/blob/main/src/screens/expenses_screen.tsx"
click node_reports_screen "https://github.com/farazpatwegar/testapp/blob/main/src/screens/reports_screen.tsx"
click node_app_state "https://github.com/farazpatwegar/testapp/blob/main/src/models/app_data.ts"
click node_api_services "https://github.com/farazpatwegar/testapp/tree/main/src/services/api"
click node_api_client "https://github.com/farazpatwegar/testapp/blob/main/src/services/api/api_client.ts"
click node_offline_sync "https://github.com/farazpatwegar/testapp/blob/main/src/services/sync_service.ts"
click node_receipt_pdf "https://github.com/farazpatwegar/testapp/blob/main/src/services/pdf_service.ts"
click node_upi_dialog "https://github.com/farazpatwegar/testapp/blob/main/src/widgets/upi_qr_dialog.tsx"
click node_api_server "https://github.com/farazpatwegar/testapp/blob/main/backend/src/server.ts"
click node_auth_routes "https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/auth/auth.routes.ts"
click node_business_routes "https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/business/business.routes.ts"
click node_sales_routes "https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/sales/sales.routes.ts"
click node_payments_routes "https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/payments/payments.routes.ts"
click node_reports_routes "https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/reports/reports.routes.ts"
click node_shops_routes "https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/shops/shops.routes.ts"
click node_auth_middleware "https://github.com/farazpatwegar/testapp/blob/main/backend/src/middleware/auth.ts"
click node_prisma "https://github.com/farazpatwegar/testapp/blob/main/backend/src/config/prisma.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_app_shell,node_onboarding,node_main_nav,node_pos,node_sale_screen,node_dashboard,node_inventory,node_customers,node_customer_detail,node_expenses,node_reports_screen,node_upi_dialog toneBlue
class node_app_state,node_api_services,node_api_client,node_offline_sync,node_receipt_pdf toneAmber
class node_api_server,node_auth_middleware,node_prisma toneMint
class node_auth_routes,node_business_routes,node_sales_routes,node_payments_routes,node_reports_routes,node_shops_routes toneRose
class node_shop_staff,node_shop_owner toneIndigo
```

## Components

### Mobile app

- [App navigation](https://github.com/farazpatwegar/testapp/blob/main/App.tsx): `App.tsx`
- [Onboarding](https://github.com/farazpatwegar/testapp/blob/main/src/screens/onboarding_screen.tsx): `src/screens/onboarding_screen.tsx`
- [Shop workspace](https://github.com/farazpatwegar/testapp/blob/main/src/screens/main_navigation_screen.tsx): `src/screens/main_navigation_screen.tsx`
- [POS scanner](https://github.com/farazpatwegar/testapp/blob/main/src/screens/pos_scanner_screen.tsx): `src/screens/pos_scanner_screen.tsx`
- [Sale entry](https://github.com/farazpatwegar/testapp/blob/main/src/screens/add_sale_screen.tsx): `src/screens/add_sale_screen.tsx`
- [Dashboard](https://github.com/farazpatwegar/testapp/blob/main/src/screens/dashboard_screen.tsx): `src/screens/dashboard_screen.tsx`
- [Stock management](https://github.com/farazpatwegar/testapp/blob/main/src/screens/stock_screen.tsx): `src/screens/stock_screen.tsx`
- [Customer credit](https://github.com/farazpatwegar/testapp/blob/main/src/screens/udhaar_screen.tsx): `src/screens/udhaar_screen.tsx`
- [Customer detail](https://github.com/farazpatwegar/testapp/blob/main/src/screens/customer_detail_screen.tsx): `src/screens/customer_detail_screen.tsx`
- [Expense tracking](https://github.com/farazpatwegar/testapp/blob/main/src/screens/expenses_screen.tsx): `src/screens/expenses_screen.tsx`
- [Reports view](https://github.com/farazpatwegar/testapp/blob/main/src/screens/reports_screen.tsx): `src/screens/reports_screen.tsx`
- [UPI payment dialog](https://github.com/farazpatwegar/testapp/blob/main/src/widgets/upi_qr_dialog.tsx): `src/widgets/upi_qr_dialog.tsx`

### Client services

- [Local app state](https://github.com/farazpatwegar/testapp/blob/main/src/models/app_data.ts): `src/models/app_data.ts`
- [Domain API services](https://github.com/farazpatwegar/testapp/tree/main/src/services/api): `src/services/api`
- [API transport](https://github.com/farazpatwegar/testapp/blob/main/src/services/api/api_client.ts): `src/services/api/api_client.ts`
- [Offline sync queue](https://github.com/farazpatwegar/testapp/blob/main/src/services/sync_service.ts): `src/services/sync_service.ts`
- [Receipt PDF](https://github.com/farazpatwegar/testapp/blob/main/src/services/pdf_service.ts): `src/services/pdf_service.ts`

### API backend

- [API server](https://github.com/farazpatwegar/testapp/blob/main/backend/src/server.ts): `backend/src/server.ts`
- [Auth middleware](https://github.com/farazpatwegar/testapp/blob/main/backend/src/middleware/auth.ts): `backend/src/middleware/auth.ts`
- [PostgreSQL access](https://github.com/farazpatwegar/testapp/blob/main/backend/src/config/prisma.ts): `backend/src/config/prisma.ts`

### Backend operations

- [Authentication](https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/auth/auth.routes.ts): `backend/src/modules/auth/auth.routes.ts`
- [Business data](https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/business/business.routes.ts): `backend/src/modules/business/business.routes.ts`
- [Sales and receipts](https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/sales/sales.routes.ts): `backend/src/modules/sales/sales.routes.ts`
- [Payment operations](https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/payments/payments.routes.ts): `backend/src/modules/payments/payments.routes.ts`
- [Report operations](https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/reports/reports.routes.ts): `backend/src/modules/reports/reports.routes.ts`
- [Shop settings](https://github.com/farazpatwegar/testapp/blob/main/backend/src/modules/shops/shops.routes.ts): `backend/src/modules/shops/shops.routes.ts`

### Other components

- **Shop staff**
- **Shop owner**

## Connections

- Shop staff → App navigation: uses (evidence: `App.tsx`)
- App navigation → Local app state: loads (evidence: `App.tsx`)
- App navigation → Onboarding: routes to (evidence: `App.tsx`)
- App navigation → Shop workspace: routes to (evidence: `App.tsx`)
- App navigation → Sale entry: routes to (evidence: `App.tsx`)
- App navigation → POS scanner: routes to (evidence: `App.tsx`)
- Onboarding → Domain API services: authenticates via (evidence: `src/screens/onboarding_screen.tsx`)
- Shop workspace → Dashboard: offers views
- Shop workspace → Stock management: offers views
- Shop workspace → Customer credit: offers views
- Shop workspace → Expense tracking: offers views
- Shop workspace → Reports view: offers views
- Customer credit → Customer detail: opens
- POS scanner → Local app state: scans products (evidence: `src/screens/pos_scanner_screen.tsx`)
- Sale entry → Local app state: records sale (evidence: `src/screens/add_sale_screen.tsx`)
- Sale entry → Domain API services: requests payment (evidence: `src/screens/add_sale_screen.tsx`)
- Sale entry → Receipt PDF: creates receipt (evidence: `src/screens/add_sale_screen.tsx`)
- Sale entry → UPI payment dialog: shows UPI (evidence: `src/screens/add_sale_screen.tsx`)
- Local app state → Domain API services: loads and mutates (evidence: `src/models/app_data.ts`)
- Local app state → Offline sync queue: queues failed writes (evidence: `src/models/app_data.ts`)
- Domain API services → API transport: sends requests (evidence: `src/services/api/sale_service.ts`)
- API transport → API server: HTTP requests
- API server → Authentication: mounts routes (evidence: `backend/src/server.ts`)
- API server → Business data: mounts routes (evidence: `backend/src/server.ts`)
- API server → Sales and receipts: mounts routes (evidence: `backend/src/server.ts`)
- API server → Payment operations: mounts routes (evidence: `backend/src/server.ts`)
- API server → Report operations: mounts routes (evidence: `backend/src/server.ts`)
- API server → Shop settings: mounts routes (evidence: `backend/src/server.ts`)
- Shop owner → Authentication: registers or signs in (evidence: `backend/src/modules/auth/auth.routes.ts`)
- Authentication → PostgreSQL access: reads and writes (evidence: `backend/src/modules/auth/auth.routes.ts`)
- Business data → PostgreSQL access: reads and writes (evidence: `backend/src/modules/business/business.routes.ts`)
- Sales and receipts → PostgreSQL access: records sales (evidence: `backend/src/modules/sales/sales.routes.ts`)
- Payment operations → PostgreSQL access: persists payments (evidence: `backend/src/modules/payments/payments.routes.ts`)
- Report operations → PostgreSQL access: queries reports (evidence: `backend/src/modules/reports/reports.routes.ts`)
- Shop settings → PostgreSQL access: reads and writes (evidence: `backend/src/modules/shops/shops.routes.ts`)
- Authentication → Auth middleware: requires auth (evidence: `backend/src/modules/auth/auth.routes.ts`)
- Business data → Auth middleware: requires auth (evidence: `backend/src/modules/business/business.routes.ts`)
- Sales and receipts → Auth middleware: requires auth (evidence: `backend/src/modules/sales/sales.routes.ts`)
- Payment operations → Auth middleware: requires auth (evidence: `backend/src/modules/payments/payments.routes.ts`)
- Report operations → Auth middleware: requires auth (evidence: `backend/src/modules/reports/reports.routes.ts`)
- Shop settings → Auth middleware: requires auth (evidence: `backend/src/modules/shops/shops.routes.ts`)
- Auth middleware → PostgreSQL access: checks membership (evidence: `backend/src/middleware/auth.ts`)
