# opencore-x/opensociety architecture

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

- Interactive diagram: https://gitdiagram.com/opencore-x/opensociety
- Repository: https://github.com/opencore-x/opensociety

## Overview

OpenSociety serves residents, gate staff, and community administrators through native mobile and web apps backed by a society-specific API and database. The main workflow is a user action in an app, an authenticated API request, and a domain operation that reads or updates community records; gate staff can also queue visitor registration offline. The product spans visitor access, community operations, and finance/reporting, with push, identity, and file-storage integrations. Some route and client internals were not sampled, so uncertain links are omitted or marked unverified.

Main entry points: [`apps/api/src/index.ts`](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/index.ts) (API runtime), [`apps/mobile/app`](https://github.com/opencore-x/opensociety/tree/main/apps/mobile/app) (Mobile app), [`apps/api/src/middleware.ts`](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/middleware.ts) (Identity and access), [`apps/api/src/routes/reports.ts`](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/reports.ts) (Reports and exports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["User apps"]
  node_mobile_app["Mobile app"]
  node_offline_queue["Offline visitor queue<br/>[query-client.ts]"]
  node_web_dashboard["Admin dashboard"]
  node_mobile_api["Mobile API client<br/>[client.ts]"]
end

subgraph group_api["API and access"]
  node_api_runtime["API runtime<br/>[index.ts]"]
  node_auth_middleware["Identity and access<br/>[middleware.ts]"]
  node_push_dispatch["Push dispatch<br/>[push-dispatch.ts]"]
end

subgraph group_community["Community operations"]
  node_visitor_access["Visitor access<br/>[visitors.ts]"]
  node_community_admin["Community management<br/>[apartments.ts]"]
  node_gate_operations["Gate operations<br/>[guards.ts]"]
  node_notices_tickets["Notices and tickets<br/>[notices.ts]"]
  node_house_help["Household help<br/>[house-help.ts]"]
end

subgraph group_finance["Finance and reporting"]
  node_billing["Billing and payments<br/>[bills.ts]"]
  node_ledger["Ledger posting<br/>[ledger-posting.ts]"]
  node_reports["Reports and exports<br/>[reports.ts]"]
end

subgraph group_data["Persistence and services"]
  node_database[("Society database<br/>[client.ts]")]
  node_clerk{{"Clerk identity"}}
  node_r2[("Cloudflare R2")]
  node_expo_push{{"Expo Push"}}
end

node_resident(("Resident"))
node_gate_staff(("Gate staff"))
node_administrator(("Administrator"))

node_resident -->|"uses"| node_mobile_app
node_gate_staff -->|"uses"| node_mobile_app
node_administrator -->|"manages community"| node_web_dashboard
node_mobile_app -.->|"requests data"| node_mobile_api
node_mobile_api -.->|"calls API"| node_api_runtime
node_web_dashboard -.->|"calls API"| node_api_runtime
node_offline_queue -->|"queues registration"| node_mobile_app
node_api_runtime -->|"applies access"| node_auth_middleware
node_api_runtime -->|"routes requests"| node_visitor_access
node_api_runtime -->|"routes requests"| node_community_admin
node_api_runtime -->|"routes requests"| node_gate_operations
node_api_runtime -->|"routes requests"| node_notices_tickets
node_api_runtime -->|"routes requests"| node_house_help
node_api_runtime -->|"routes requests"| node_billing
node_api_runtime -->|"routes requests"| node_reports
node_billing -->|"posts bills"| node_ledger
node_api_runtime -->|"creates database client"| node_database
node_auth_middleware -->|"loads user records"| node_database
node_auth_middleware -->|"verifies sessions"| node_clerk
node_reports -->|"queries records"| node_database
node_reports -.->|"reads ledger data"| node_ledger
node_api_runtime -->|"dispatches pushes"| node_push_dispatch
node_push_dispatch -.->|"sends notifications"| node_expo_push
node_api_runtime -.->|"stores uploads"| node_r2

click node_mobile_app "https://github.com/opencore-x/opensociety/tree/main/apps/mobile/app"
click node_offline_queue "https://github.com/opencore-x/opensociety/blob/main/apps/mobile/lib/offline/query-client.ts"
click node_web_dashboard "https://github.com/opencore-x/opensociety/tree/main/apps/web/src/routes/admin"
click node_mobile_api "https://github.com/opencore-x/opensociety/blob/main/apps/mobile/api/client.ts"
click node_api_runtime "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/index.ts"
click node_auth_middleware "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/middleware.ts"
click node_visitor_access "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/visitors.ts"
click node_community_admin "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/apartments.ts"
click node_gate_operations "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/guards.ts"
click node_notices_tickets "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/notices.ts"
click node_house_help "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/house-help.ts"
click node_billing "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/bills.ts"
click node_ledger "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/lib/ledger-posting.ts"
click node_reports "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/reports.ts"
click node_database "https://github.com/opencore-x/opensociety/blob/main/packages/db/src/client.ts"
click node_push_dispatch "https://github.com/opencore-x/opensociety/blob/main/apps/api/src/lib/push-dispatch.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_mobile_app,node_offline_queue,node_web_dashboard,node_mobile_api toneBlue
class node_api_runtime,node_auth_middleware,node_push_dispatch toneAmber
class node_visitor_access,node_community_admin,node_gate_operations,node_notices_tickets,node_house_help toneMint
class node_billing,node_ledger,node_reports toneRose
class node_database,node_clerk,node_r2,node_expo_push,node_resident,node_gate_staff,node_administrator toneIndigo
```

## Components

### User apps

- [Mobile app](https://github.com/opencore-x/opensociety/tree/main/apps/mobile/app): `apps/mobile/app`
- [Offline visitor queue](https://github.com/opencore-x/opensociety/blob/main/apps/mobile/lib/offline/query-client.ts): `apps/mobile/lib/offline/query-client.ts`
- [Admin dashboard](https://github.com/opencore-x/opensociety/tree/main/apps/web/src/routes/admin): `apps/web/src/routes/admin`
- [Mobile API client](https://github.com/opencore-x/opensociety/blob/main/apps/mobile/api/client.ts): `apps/mobile/api/client.ts`

### API and access

- [API runtime](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/index.ts): `apps/api/src/index.ts`
- [Identity and access](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/middleware.ts): `apps/api/src/middleware.ts`
- [Push dispatch](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/lib/push-dispatch.ts): `apps/api/src/lib/push-dispatch.ts`

### Community operations

- [Visitor access](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/visitors.ts): `apps/api/src/routes/visitors.ts`
- [Community management](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/apartments.ts): `apps/api/src/routes/apartments.ts`
- [Gate operations](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/guards.ts): `apps/api/src/routes/guards.ts`
- [Notices and tickets](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/notices.ts): `apps/api/src/routes/notices.ts`
- [Household help](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/house-help.ts): `apps/api/src/routes/house-help.ts`

### Finance and reporting

- [Billing and payments](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/bills.ts): `apps/api/src/routes/bills.ts`
- [Ledger posting](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/lib/ledger-posting.ts): `apps/api/src/lib/ledger-posting.ts`
- [Reports and exports](https://github.com/opencore-x/opensociety/blob/main/apps/api/src/routes/reports.ts): `apps/api/src/routes/reports.ts`

### Persistence and services

- [Society database](https://github.com/opencore-x/opensociety/blob/main/packages/db/src/client.ts): `packages/db/src/client.ts`
- **Clerk identity**
- **Cloudflare R2**
- **Expo Push**

### Other components

- **Resident**
- **Gate staff**
- **Administrator**

## Connections

- Resident → Mobile app: uses
- Gate staff → Mobile app: uses
- Administrator → Admin dashboard: manages community
- Mobile app → Mobile API client: requests data
- Mobile API client → API runtime: calls API
- Admin dashboard → API runtime: calls API
- Offline visitor queue → Mobile app: queues registration (evidence: `apps/mobile/lib/offline/query-client.ts`)
- API runtime → Identity and access: applies access (evidence: `apps/api/src/index.ts`)
- API runtime → Visitor access: routes requests (evidence: `apps/api/src/index.ts`)
- API runtime → Community management: routes requests (evidence: `apps/api/src/index.ts`)
- API runtime → Gate operations: routes requests (evidence: `apps/api/src/index.ts`)
- API runtime → Notices and tickets: routes requests (evidence: `apps/api/src/index.ts`)
- API runtime → Household help: routes requests (evidence: `apps/api/src/index.ts`)
- API runtime → Billing and payments: routes requests (evidence: `apps/api/src/index.ts`)
- API runtime → Reports and exports: routes requests (evidence: `apps/api/src/index.ts`)
- Billing and payments → Ledger posting: posts bills (evidence: `apps/api/src/routes/bills.ts`)
- API runtime → Society database: creates database client (evidence: `apps/api/src/index.ts`)
- Identity and access → Society database: loads user records (evidence: `apps/api/src/middleware.ts`)
- Identity and access → Clerk identity: verifies sessions (evidence: `apps/api/src/middleware.ts`)
- Reports and exports → Society database: queries records (evidence: `apps/api/src/routes/reports.ts`)
- Reports and exports → Ledger posting: reads ledger data
- API runtime → Push dispatch: dispatches pushes (evidence: `apps/api/src/index.ts`)
- Push dispatch → Expo Push: sends notifications
- API runtime → Cloudflare R2: stores uploads
