# joeseos/mundamanager architecture

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

- Interactive diagram: https://gitdiagram.com/joeseos/mundamanager
- Repository: https://github.com/joeseos/mundamanager

## Overview

#### Purpose and entry points
Munda Manager is a Next.js 15 App Router application for managing Necromunda gangs, fighters, equipment, campaigns, battle sessions, and activity history. Primary user entry points are the home dashboard and entity pages: `app/page.tsx`, `app/gang/[id]/page.tsx`, `app/fighter/[id]/page.tsx`, and `app/campaigns/[id]/page.tsx`. Global shell, providers, and styling originate in `app/layout.tsx`, `app/providers/query-client-provider.tsx`, and `app/globals.css`.

#### Gang and fighter domain
Gang pages compose roster, stash, vehicles, campaign participation, and notes into an interactive client experience. The main hierarchy is represented by `components/gang/gang-page-content.tsx`, `components/gang/gang.tsx`, and `components/gang/my-fighters.tsx`. Fighter detail pages expose equipment, injuries, skills, advancement, loadouts, and status through `components/fighter/fighter-page.tsx`, `components/fighter/fighter-details-card.tsx`, and `components/fighter/fighter-equipment-list.tsx`.

Mutations are server-side actions organized by domain, including fighter creation/editing, equipment transfers, and vehicle operations: `app/actions/add-fighter.ts`, `app/actions/equipment.ts`, and `app/actions/update-gang.ts`.

#### Rules, effects, and derived state
Fighter statistics are derived rather than treated as only stored values: base characteristics are combined with categorized effects from injuries, equipment, skills, advancements, and vehicle damage. The central calculation and type boundary are `utils/effect-modifiers.ts`, `types/fighter.ts`, and `app/lib/shared/fighter-data.ts`. Actions that change domain state are expected to create related effect records and invalidate/refetch data, notably `app/actions/fighter-advancement.ts` and `app/actions/add-vehicle-damage.ts`.

#### Campaigns and battle sessions
Campaigns aggregate members, gangs, allegiances, territories, resources, maps, battle logs, and battle sessions. Server data assembly is centered on `app/lib/campaigns/[id]/get-campaign-data.ts`; the page-level UI is `components/campaigns/[id]/campaign-page-content.tsx`; map editing/rendering is `components/campaigns/[id]/campaign-map.tsx`. Battle-session lifecycle data is fetched through `app/lib/battle-sessions/get-battle-session-data.ts` and rendered via `components/battle-session/active-session.tsx` and `components/battle-session/completed-session.tsx`. Realtime session synchronization is isolated in `hooks/use-battle-session-realtime.ts`.

#### Data-access and authorization boundaries
The application has two server mutation/query interfaces: Next server actions under `app/actions/` for its own UI, and route handlers under `app/api/` for programmatic/admin access. Representative public entity endpoints are `app/api/gangs/[id]/route.ts`, `app/api/fighters/[id]/route.ts`, and `app/api/campaigns/[campaignId]/route.ts`; admin catalog/support APIs reside under `app/api/admin/`. Supabase client/server adapters at `utils/supabase/client.ts` and `utils/supabase/server.ts` separate browser and server database/auth usage. Permission checks are implemented in database SQL and application utilities: `supabase/functions/check_permission.sql` and `utils/user-permissions.ts`.

#### Persistence, events, and integrations
Supabase provides PostgreSQL, Auth, Realtime, storage policy enforcement, database functions, triggers, and Edge Functions. Schema evolution is migration-driven in `supabase/migrations/`, with a schema snapshot at `supabase/schema/schema.public.sql`. SQL RPCs encapsulate data-heavy business operations such as `supabase/functions/get_gang_details.sql` and `supabase/functions/get_available_skills.sql`.

Notifications are persisted and delivered through database enqueueing plus an Edge Function: `supabase/functions/enqueue_notification_email.sql` and `supabase/edge-functions/send-notification-email/index.ts`. External integrations include Discord campaign/interactions functions, Patreon webhook/sync routes, and Cloudflare Turnstile for sign-in protection: `supabase/edge-functions/discord-interactions/index.ts`, `app/api/patreon/webhook/route.ts`, and `app/sign-in/TurnstileWidget.tsx`. Deployment targets Vercel/Next plus Supabase, automated by `.github/workflows/deploy.yml` and Supabase deployment workflows.

Main entry points: [`supabase/schema/schema.public.sql`](https://github.com/joeseos/mundamanager/blob/main/supabase/schema/schema.public.sql) (PostgreSQL, Auth & Storage), [`utils/supabase/server.ts`](https://github.com/joeseos/mundamanager/blob/main/utils/supabase/server.ts) (Supabase adapters), [`app/layout.tsx`](https://github.com/joeseos/mundamanager/blob/main/app/layout.tsx) (App shell & providers), [`app/actions/add-fighter.ts`](https://github.com/joeseos/mundamanager/blob/main/app/actions/add-fighter.ts) (Domain server actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Next.js UI"]
  node_shell["App shell &amp; providers<br/>Next.js App Router<br/>[layout.tsx]"]
  node_dashboard["Dashboard<br/>page<br/>[page.tsx]"]
  node_gang_ui["Gang workspace<br/>client UI"]
  node_fighter_ui["Fighter detail<br/>client UI<br/>[fighter-page.tsx]"]
  node_campaign_ui["Campaign workspace<br/>client UI"]
  node_campaign_map["Campaign map<br/>map editor<br/>[campaign-map.tsx]"]
  node_battle_ui["Battle session views<br/>session UI<br/>[active-session.tsx]"]
  node_realtime_hook["Session realtime sync<br/>React hook"]
end

subgraph group_server["Application server"]
  node_server_actions{{"Domain server actions<br/>mutation interface<br/>[add-fighter.ts]"}}
  node_api_routes{{"Entity &amp; admin APIs<br/>route handlers<br/>[route.ts]"}}
  node_campaign_data["Campaign data assembly<br/>server query"]
  node_session_data["Battle session data<br/>server query"]
  node_effects["Effect modifier engine<br/>derived-state logic"]
  node_fighter_types["Fighter data contract<br/>shared types<br/>[fighter.ts]"]
  node_supabase_adapters["Supabase adapters<br/>browser/server clients<br/>[server.ts]"]
  node_permission_layer{{"Permission layer<br/>authorization"}}
end

subgraph group_supabase["Supabase platform"]
  node_postgres[("PostgreSQL, Auth &amp; Storage<br/>Supabase backend<br/>[schema.public.sql]")]
  node_sql_rpcs{{"SQL business RPCs<br/>database functions"}}
  node_realtime["Supabase Realtime<br/>event stream"]
  node_notifications["Notification delivery"]
end

subgraph group_integrations["External integrations"]
  node_discord{{"Discord interactions<br/>Edge Function<br/>[index.ts]"}}
  node_patreon{{"Patreon webhook<br/>integration route<br/>[route.ts]"}}
  node_turnstile["Turnstile sign-in<br/>bot protection"]
end

node_shell -->|"hosts"| node_dashboard
node_shell -->|"hosts"| node_gang_ui
node_shell -->|"hosts"| node_fighter_ui
node_shell -->|"hosts"| node_campaign_ui
node_gang_ui -->|"mutates"| node_server_actions
node_fighter_ui -->|"mutates"| node_server_actions
node_campaign_ui -->|"loads"| node_campaign_data
node_campaign_ui -->|"includes"| node_campaign_map
node_battle_ui -->|"loads"| node_session_data
node_battle_ui -->|"synchronizes"| node_realtime_hook
node_realtime_hook -->|"subscribes"| node_realtime
node_server_actions -->|"creates effects / derives stats"| node_effects
node_effects -->|"uses"| node_fighter_types
node_server_actions -->|"uses"| node_supabase_adapters
node_api_routes -->|"uses"| node_supabase_adapters
node_campaign_data -->|"queries via"| node_supabase_adapters
node_session_data -->|"queries via"| node_supabase_adapters
node_supabase_adapters -->|"authorizes"| node_permission_layer
node_permission_layer -->|"enforces against"| node_postgres
node_supabase_adapters -->|"reads and writes"| node_postgres
node_postgres -->|"executes"| node_sql_rpcs
node_postgres -->|"publishes changes"| node_realtime
node_postgres -->|"enqueues"| node_notifications
node_api_routes -->|"receives"| node_patreon
node_postgres -->|"supports campaign interactions"| node_discord
node_shell -->|"protects sign-in"| node_turnstile

click node_shell "https://github.com/joeseos/mundamanager/blob/main/app/layout.tsx"
click node_dashboard "https://github.com/joeseos/mundamanager/blob/main/app/page.tsx"
click node_gang_ui "https://github.com/joeseos/mundamanager/blob/main/components/gang/gang-page-content.tsx"
click node_fighter_ui "https://github.com/joeseos/mundamanager/blob/main/components/fighter/fighter-page.tsx"
click node_campaign_ui "https://github.com/joeseos/mundamanager/blob/main/components/campaigns/%5Bid%5D/campaign-page-content.tsx"
click node_campaign_map "https://github.com/joeseos/mundamanager/blob/main/components/campaigns/%5Bid%5D/campaign-map.tsx"
click node_battle_ui "https://github.com/joeseos/mundamanager/blob/main/components/battle-session/active-session.tsx"
click node_realtime_hook "https://github.com/joeseos/mundamanager/blob/main/hooks/use-battle-session-realtime.ts"
click node_server_actions "https://github.com/joeseos/mundamanager/blob/main/app/actions/add-fighter.ts"
click node_api_routes "https://github.com/joeseos/mundamanager/blob/main/app/api/gangs/%5Bid%5D/route.ts"
click node_campaign_data "https://github.com/joeseos/mundamanager/blob/main/app/lib/campaigns/%5Bid%5D/get-campaign-data.ts"
click node_session_data "https://github.com/joeseos/mundamanager/blob/main/app/lib/battle-sessions/get-battle-session-data.ts"
click node_effects "https://github.com/joeseos/mundamanager/blob/main/utils/effect-modifiers.ts"
click node_fighter_types "https://github.com/joeseos/mundamanager/blob/main/types/fighter.ts"
click node_supabase_adapters "https://github.com/joeseos/mundamanager/blob/main/utils/supabase/server.ts"
click node_permission_layer "https://github.com/joeseos/mundamanager/blob/main/utils/user-permissions.ts"
click node_postgres "https://github.com/joeseos/mundamanager/blob/main/supabase/schema/schema.public.sql"
click node_sql_rpcs "https://github.com/joeseos/mundamanager/blob/main/supabase/functions/get_gang_details.sql"
click node_notifications "https://github.com/joeseos/mundamanager/blob/main/supabase/functions/enqueue_notification_email.sql"
click node_discord "https://github.com/joeseos/mundamanager/blob/main/supabase/edge-functions/discord-interactions/index.ts"
click node_patreon "https://github.com/joeseos/mundamanager/blob/main/app/api/patreon/webhook/route.ts"
click node_turnstile "https://github.com/joeseos/mundamanager/blob/main/app/sign-in/TurnstileWidget.tsx"

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_shell,node_dashboard,node_gang_ui,node_fighter_ui,node_campaign_ui,node_campaign_map,node_battle_ui,node_realtime_hook toneBlue
class node_server_actions,node_api_routes,node_campaign_data,node_session_data,node_effects,node_fighter_types,node_supabase_adapters,node_permission_layer toneAmber
class node_postgres,node_sql_rpcs,node_realtime,node_notifications toneMint
class node_discord,node_patreon,node_turnstile toneRose
```

## Components

### Next.js UI

- [App shell & providers](https://github.com/joeseos/mundamanager/blob/main/app/layout.tsx): Next.js App Router · `app/layout.tsx`
- [Dashboard](https://github.com/joeseos/mundamanager/blob/main/app/page.tsx): page · `app/page.tsx`
- [Gang workspace](https://github.com/joeseos/mundamanager/blob/main/components/gang/gang-page-content.tsx): client UI · Composes roster, stash, vehicles, campaigns, and notes. · `components/gang/gang-page-content.tsx`
- [Fighter detail](https://github.com/joeseos/mundamanager/blob/main/components/fighter/fighter-page.tsx): client UI · Shows equipment, injuries, skills, advancement, loadouts, and status. · `components/fighter/fighter-page.tsx`
- [Campaign workspace](https://github.com/joeseos/mundamanager/blob/main/components/campaigns/%5Bid%5D/campaign-page-content.tsx): client UI · `components/campaigns/[id]/campaign-page-content.tsx`
- [Campaign map](https://github.com/joeseos/mundamanager/blob/main/components/campaigns/%5Bid%5D/campaign-map.tsx): map editor · `components/campaigns/[id]/campaign-map.tsx`
- [Battle session views](https://github.com/joeseos/mundamanager/blob/main/components/battle-session/active-session.tsx): session UI · Renders active and completed sessions. · `components/battle-session/active-session.tsx`
- [Session realtime sync](https://github.com/joeseos/mundamanager/blob/main/hooks/use-battle-session-realtime.ts): React hook · `hooks/use-battle-session-realtime.ts`

### Application server

- [Domain server actions](https://github.com/joeseos/mundamanager/blob/main/app/actions/add-fighter.ts): mutation interface · UI mutations for fighters, equipment, gangs, advancements, and vehicles. · `app/actions/add-fighter.ts`
- [Entity & admin APIs](https://github.com/joeseos/mundamanager/blob/main/app/api/gangs/%5Bid%5D/route.ts): route handlers · Programmatic and admin access alongside the UI action interface. · `app/api/gangs/[id]/route.ts`
- [Campaign data assembly](https://github.com/joeseos/mundamanager/blob/main/app/lib/campaigns/%5Bid%5D/get-campaign-data.ts): server query · Aggregates campaign members, gangs, maps, logs, and sessions. · `app/lib/campaigns/[id]/get-campaign-data.ts`
- [Battle session data](https://github.com/joeseos/mundamanager/blob/main/app/lib/battle-sessions/get-battle-session-data.ts): server query · `app/lib/battle-sessions/get-battle-session-data.ts`
- [Effect modifier engine](https://github.com/joeseos/mundamanager/blob/main/utils/effect-modifiers.ts): derived-state logic · Combines base statistics with categorized effects. · `utils/effect-modifiers.ts`
- [Fighter data contract](https://github.com/joeseos/mundamanager/blob/main/types/fighter.ts): shared types · `types/fighter.ts`
- [Supabase adapters](https://github.com/joeseos/mundamanager/blob/main/utils/supabase/server.ts): browser/server clients · Separates browser and server database/auth access. · `utils/supabase/server.ts`
- [Permission layer](https://github.com/joeseos/mundamanager/blob/main/utils/user-permissions.ts): authorization · Application checks backed by database permission SQL. · `utils/user-permissions.ts`

### Supabase platform

- [PostgreSQL, Auth & Storage](https://github.com/joeseos/mundamanager/blob/main/supabase/schema/schema.public.sql): Supabase backend · Persistent domain data, identities, policies, triggers, and storage. · `supabase/schema/schema.public.sql`
- [SQL business RPCs](https://github.com/joeseos/mundamanager/blob/main/supabase/functions/get_gang_details.sql): database functions · Encapsulates data-heavy domain operations. · `supabase/functions/get_gang_details.sql`
- **Supabase Realtime**: event stream
- [Notification delivery](https://github.com/joeseos/mundamanager/blob/main/supabase/functions/enqueue_notification_email.sql): SQL queue + Edge Function · Database enqueueing invokes email delivery. · `supabase/functions/enqueue_notification_email.sql`

### External integrations

- [Discord interactions](https://github.com/joeseos/mundamanager/blob/main/supabase/edge-functions/discord-interactions/index.ts): Edge Function · `supabase/edge-functions/discord-interactions/index.ts`
- [Patreon webhook](https://github.com/joeseos/mundamanager/blob/main/app/api/patreon/webhook/route.ts): integration route · `app/api/patreon/webhook/route.ts`
- [Turnstile sign-in](https://github.com/joeseos/mundamanager/blob/main/app/sign-in/TurnstileWidget.tsx): bot protection · `app/sign-in/TurnstileWidget.tsx`

## Connections

- App shell & providers → Dashboard: hosts
- App shell & providers → Gang workspace: hosts
- App shell & providers → Fighter detail: hosts
- App shell & providers → Campaign workspace: hosts
- Gang workspace → Domain server actions: mutates
- Fighter detail → Domain server actions: mutates
- Campaign workspace → Campaign data assembly: loads
- Campaign workspace → Campaign map: includes
- Battle session views → Battle session data: loads
- Battle session views → Session realtime sync: synchronizes
- Session realtime sync → Supabase Realtime: subscribes
- Domain server actions → Effect modifier engine: creates effects / derives stats
- Effect modifier engine → Fighter data contract: uses
- Domain server actions → Supabase adapters: uses
- Entity & admin APIs → Supabase adapters: uses
- Campaign data assembly → Supabase adapters: queries via
- Battle session data → Supabase adapters: queries via
- Supabase adapters → Permission layer: authorizes
- Permission layer → PostgreSQL, Auth & Storage: enforces against
- Supabase adapters → PostgreSQL, Auth & Storage: reads and writes
- PostgreSQL, Auth & Storage → SQL business RPCs: executes
- PostgreSQL, Auth & Storage → Supabase Realtime: publishes changes
- PostgreSQL, Auth & Storage → Notification delivery: enqueues
- Entity & admin APIs → Patreon webhook: receives
- PostgreSQL, Auth & Storage → Discord interactions: supports campaign interactions
- App shell & providers → Turnstile sign-in: protects sign-in
