# astra1127/civilcraft architecture

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

- Interactive diagram: https://gitdiagram.com/astra1127/civilcraft
- Repository: https://github.com/astra1127/civilcraft

## Overview

Civil Craft is a game community website with player and administrator dashboards. Visitors browse public content; players sign in through PlayFab to use dashboard features, including the shop; staff use separate server-verified administrator credentials to manage the site and game data. Server-side request handling dispatches API requests to wallet and content services. The repository also documents payment and game-wallet capabilities, represented here as distinct stages. Several routes and integrations were not sampled, so their internal links are omitted rather than inferred.

Main entry points: [`src/server.ts`](https://github.com/astra1127/civilcraft/blob/main/src/server.ts) (API dispatcher), [`src/routes/dashboard.index.tsx`](https://github.com/astra1127/civilcraft/blob/main/src/routes/dashboard.index.tsx) (Dashboard pages), [`src/lib/payments/orders.server.ts`](https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/orders.server.ts) (Payment orders), [`src/lib/game-wallet/service.server.ts`](https://github.com/astra1127/civilcraft/blob/main/src/lib/game-wallet/service.server.ts) (Game wallet)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Public website"]
  node_public_routes["Public pages<br/>[index.tsx]"]
  node_community["Community and news"]
  node_cms["Content services"]
end

subgraph group_player["Player experience"]
  node_player_routes["Dashboard pages"]
  node_auth["Player authentication<br/>[auth.tsx]"]
  node_leaderboards["Leaderboards<br/>[leaderboard.ts]"]
  node_almanac["Almanac<br/>[content.ts]"]
end

subgraph group_admin["Administration"]
  node_admin_routes["Admin pages<br/>[admin.index.tsx]"]
  node_admin_auth["Admin authentication"]
  node_admin_playfab["PlayFab admin<br/>[admin-service.ts]"]
end

subgraph group_services["Game services"]
  node_playfab_client["PlayFab client<br/>[client.ts]"]
  node_request_dispatch["API dispatcher<br/>[server.ts]"]
end

subgraph group_commerce["Commerce and wallet"]
  node_payment_routes["Payment API<br/>[api.server.ts]"]
  node_payment_orders["Payment orders<br/>[orders.server.ts]"]
  node_paymongo["PayMongo<br/>[paymongo.server.ts]"]
  node_products["Shop products<br/>[products.ts]"]
  node_fulfillment["Order fulfillment"]
  node_wallet_service["Game wallet<br/>[service.server.ts]"]
  node_wallet_db[("Wallet database<br/>[database.server.ts]")]
  node_currency_db[("Currency database")]
end

node_visitor(("Visitor"))
node_player_actor(("Player"))
node_staff(("Staff"))

node_visitor -->|"browses"| node_public_routes
node_visitor -->|"browses"| node_community
node_player_actor -->|"uses"| node_player_routes
node_staff -->|"uses"| node_admin_routes
node_player_routes -->|"checks identity"| node_auth
node_auth -->|"validates session"| node_playfab_client
node_player_routes -.->|"views"| node_leaderboards
node_player_routes -.->|"views"| node_almanac
node_admin_routes -.->|"authenticates"| node_admin_auth
node_admin_routes -.->|"manages game data"| node_admin_playfab
node_request_dispatch -->|"dispatches requests"| node_cms
node_request_dispatch -->|"dispatches requests"| node_admin_auth
node_request_dispatch -->|"dispatches requests"| node_admin_playfab
node_request_dispatch -->|"dispatches requests"| node_wallet_service
node_request_dispatch -.->|"dispatches requests"| node_payment_routes
node_player_routes -->|"shows shop"| node_products
node_payment_routes -.->|"handles orders"| node_payment_orders
node_payment_orders -.->|"creates checkout"| node_paymongo
node_payment_orders -.->|"fulfills paid orders"| node_fulfillment
node_fulfillment -->|"credits rewards"| node_wallet_service
node_wallet_service -->|"updates order"| node_payment_orders
node_wallet_service -->|"reads and writes"| node_wallet_db
node_wallet_db -->|"uses connection"| node_currency_db
node_wallet_db -->|"resolves game config"| node_admin_playfab

click node_public_routes "https://github.com/astra1127/civilcraft/blob/main/src/routes/index.tsx"
click node_community "https://github.com/astra1127/civilcraft/blob/main/src/routes/community.index.tsx"
click node_cms "https://github.com/astra1127/civilcraft/tree/main/src/lib/cms"
click node_player_routes "https://github.com/astra1127/civilcraft/blob/main/src/routes/dashboard.index.tsx"
click node_auth "https://github.com/astra1127/civilcraft/blob/main/src/lib/auth.tsx"
click node_playfab_client "https://github.com/astra1127/civilcraft/blob/main/src/lib/playfab/client.ts"
click node_leaderboards "https://github.com/astra1127/civilcraft/blob/main/src/lib/playfab/leaderboard.ts"
click node_almanac "https://github.com/astra1127/civilcraft/blob/main/src/lib/almanac/content.ts"
click node_admin_routes "https://github.com/astra1127/civilcraft/blob/main/src/routes/admin.index.tsx"
click node_admin_auth "https://github.com/astra1127/civilcraft/tree/main/src/lib/admin-auth"
click node_admin_playfab "https://github.com/astra1127/civilcraft/blob/main/src/lib/playfab/admin-service.ts"
click node_request_dispatch "https://github.com/astra1127/civilcraft/blob/main/src/server.ts"
click node_payment_routes "https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/api.server.ts"
click node_payment_orders "https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/orders.server.ts"
click node_paymongo "https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/paymongo.server.ts"
click node_products "https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/products.ts"
click node_fulfillment "https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/fulfillment.server.ts"
click node_wallet_service "https://github.com/astra1127/civilcraft/blob/main/src/lib/game-wallet/service.server.ts"
click node_wallet_db "https://github.com/astra1127/civilcraft/blob/main/src/lib/game-wallet/database.server.ts"
click node_currency_db "https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/currency-database.server.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_public_routes,node_community,node_cms toneBlue
class node_player_routes,node_auth,node_leaderboards,node_almanac toneAmber
class node_admin_routes,node_admin_auth,node_admin_playfab toneMint
class node_playfab_client,node_request_dispatch toneRose
class node_payment_routes,node_payment_orders,node_paymongo,node_products,node_fulfillment,node_wallet_service,node_wallet_db,node_currency_db,node_visitor,node_player_actor,node_staff toneIndigo
```

## Components

### Public website

- [Public pages](https://github.com/astra1127/civilcraft/blob/main/src/routes/index.tsx): `src/routes/index.tsx`
- [Community and news](https://github.com/astra1127/civilcraft/blob/main/src/routes/community.index.tsx): `src/routes/community.index.tsx`
- [Content services](https://github.com/astra1127/civilcraft/tree/main/src/lib/cms): `src/lib/cms`

### Player experience

- [Dashboard pages](https://github.com/astra1127/civilcraft/blob/main/src/routes/dashboard.index.tsx): `src/routes/dashboard.index.tsx`
- [Player authentication](https://github.com/astra1127/civilcraft/blob/main/src/lib/auth.tsx): `src/lib/auth.tsx`
- [Leaderboards](https://github.com/astra1127/civilcraft/blob/main/src/lib/playfab/leaderboard.ts): `src/lib/playfab/leaderboard.ts`
- [Almanac](https://github.com/astra1127/civilcraft/blob/main/src/lib/almanac/content.ts): `src/lib/almanac/content.ts`

### Administration

- [Admin pages](https://github.com/astra1127/civilcraft/blob/main/src/routes/admin.index.tsx): `src/routes/admin.index.tsx`
- [Admin authentication](https://github.com/astra1127/civilcraft/tree/main/src/lib/admin-auth): `src/lib/admin-auth`
- [PlayFab admin](https://github.com/astra1127/civilcraft/blob/main/src/lib/playfab/admin-service.ts): `src/lib/playfab/admin-service.ts`

### Game services

- [PlayFab client](https://github.com/astra1127/civilcraft/blob/main/src/lib/playfab/client.ts): `src/lib/playfab/client.ts`
- [API dispatcher](https://github.com/astra1127/civilcraft/blob/main/src/server.ts): `src/server.ts`

### Commerce and wallet

- [Payment API](https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/api.server.ts): `src/lib/payments/api.server.ts`
- [Payment orders](https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/orders.server.ts): `src/lib/payments/orders.server.ts`
- [PayMongo](https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/paymongo.server.ts): `src/lib/payments/paymongo.server.ts`
- [Shop products](https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/products.ts): `src/lib/payments/products.ts`
- [Order fulfillment](https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/fulfillment.server.ts): `src/lib/payments/fulfillment.server.ts`
- [Game wallet](https://github.com/astra1127/civilcraft/blob/main/src/lib/game-wallet/service.server.ts): `src/lib/game-wallet/service.server.ts`
- [Wallet database](https://github.com/astra1127/civilcraft/blob/main/src/lib/game-wallet/database.server.ts): `src/lib/game-wallet/database.server.ts`
- [Currency database](https://github.com/astra1127/civilcraft/blob/main/src/lib/payments/currency-database.server.ts): `src/lib/payments/currency-database.server.ts`

### Other components

- **Visitor**
- **Player**
- **Staff**

## Connections

- Visitor → Public pages: browses (evidence: `README.md`)
- Visitor → Community and news: browses (evidence: `README.md`)
- Player → Dashboard pages: uses (evidence: `README.md`)
- Staff → Admin pages: uses (evidence: `README.md`)
- Dashboard pages → Player authentication: checks identity (evidence: `src/lib/auth.tsx`)
- Player authentication → PlayFab client: validates session (evidence: `src/lib/auth.tsx`)
- Dashboard pages → Leaderboards: views
- Dashboard pages → Almanac: views
- Admin pages → Admin authentication: authenticates (evidence: `README.md`)
- Admin pages → PlayFab admin: manages game data
- API dispatcher → Content services: dispatches requests (evidence: `src/server.ts`)
- API dispatcher → Admin authentication: dispatches requests (evidence: `src/server.ts`)
- API dispatcher → PlayFab admin: dispatches requests (evidence: `src/server.ts`)
- API dispatcher → Game wallet: dispatches requests (evidence: `src/server.ts`)
- API dispatcher → Payment API: dispatches requests (evidence: `src/server.ts`)
- Dashboard pages → Shop products: shows shop
- Payment API → Payment orders: handles orders
- Payment orders → PayMongo: creates checkout
- Payment orders → Order fulfillment: fulfills paid orders (evidence: `src/lib/payments/fulfillment.server.ts`)
- Order fulfillment → Game wallet: credits rewards (evidence: `src/lib/payments/fulfillment.server.ts`)
- Game wallet → Payment orders: updates order (evidence: `src/lib/game-wallet/service.server.ts`)
- Game wallet → Wallet database: reads and writes (evidence: `src/lib/game-wallet/service.server.ts`)
- Wallet database → Currency database: uses connection (evidence: `src/lib/game-wallet/database.server.ts`)
- Wallet database → PlayFab admin: resolves game config (evidence: `src/lib/game-wallet/database.server.ts`)
