# ayumu203/nisekue architecture

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

- Interactive diagram: https://gitdiagram.com/ayumu203/nisekue
- Repository: https://github.com/ayumu203/nisekue

## Overview

1. This repo is a full-stack game system split into a React client and a .NET backend, with Supabase providing database and authentication. The codebase is organized around game domains rather than around UI screens.

2. The frontend lives in `client/` and uses React + Vite + TypeScript + MUI. It is a single-page app that renders game pages such as home, players, items, quest, training, ranking, chat, and treasure map. The client also owns localization under `client/locale/` and static art/assets under `client/public/`.

3. The frontend’s data access layer is explicit: `client/src/api/` contains HTTP clients per feature, `client/src/schema/` contains validation/contract models, and `client/src/lib/` holds shared client utilities such as auth, Supabase integration, quest-run hub helpers, and player-related formatting. UI components are grouped by feature under `client/src/components/`.

4. The backend is a .NET Minimal API app in `server/`. It is layered into `domain/`, `application/`, `infrastructure/`, and `endpoints/`. This is the main architectural boundary: endpoints are thin adapters, application services orchestrate use cases, domain contains the game model and rules, and infrastructure implements persistence and resource loading.

5. The `server/domain/` folder is the core of the system. It contains separate bounded contexts for battle, chat, move, player, quest, training, and treasure map. Each domain defines entities/value objects, enums, repository interfaces, and pure business rules such as damage calculation, status ranking, quest room/run state, and treasure-map reward logic.

6. The `server/application/` layer implements use cases and workflows. This is where domain objects are assembled into player actions like job change, rebirth, move-set sanitization, item stat boosts, quest room lifecycle, quest run execution, training battles, ranking aggregation, thread handling, and cleanup jobs. Several application services act as coordinators over multiple repositories and domain services.

7. Real-time quest execution is a notable subsystem. `server/application/quest/QuestRunHub.cs` and the client’s quest hub hook indicate SignalR-backed live updates for quest runs, alongside persistent quest run state in the database. This suggests a mixed model: authoritative turn resolution on the server, with streaming UI updates to clients.

8. Persistence is handled in `server/infrastructure/`. EF Core `AppDbContext` and migrations manage relational state such as players, items, market listings, quest rooms/runs, chat threads, rankings, and treasure-map expeditions. Infrastructure also maps domain repositories to database tables and contains CSV-backed repositories for master data.

9. Master/reference data is split from transactional data. CSV files in `server/resources/` define move, player, quest, training, and treasure-map masters; corresponding CSV repositories load them. This means many game rules and content tables are data-driven rather than hardcoded, which is important for diagramming the content pipeline.

10. The backend exposes feature-specific HTTP surfaces in `server/endpoints/` for chat, items, players, quests, ranking, threads, training, and treasure maps. These endpoints are likely the only public API boundary the client talks to, with shared endpoint contract helpers keeping request/response shapes aligned.

11. There are background and maintenance workflows in the backend, not just request/response handlers. Examples include ranking rebuilds, quest run timeout processing, development data cleanup, and market listing cleanup. These are also mirrored in GitHub Actions workflows, so operational jobs are part of the architecture, not separate scripts.

12. Deployment and environment boundaries are clear: frontend is deployed to GitHub Pages, backend to Azure App Service, and Supabase hosts the DB/auth layer. The `.github/workflows/` directory includes separate dev/prod deployment, migration, ranking rebuild, and cleanup pipelines, showing that infrastructure automation is a first-class part of the system.

13. Testing is concentrated in `tests/server.tests/` with xUnit coverage for domain and application services. The tests reinforce the architecture by validating pure domain logic and orchestration services independently of the UI and deployment layers.

14. Supporting material in `docs/` is substantial and domain-oriented. The MMD/MD documents capture domain models and design notes for battle, chat, player, quest, ranking, training, treasure map, and maintenance, which suggests the repository is designed with explicit domain modeling and long-lived feature specs.

Main entry points: [`server/domain`](https://github.com/ayumu203/nisekue/tree/main/server/domain) (Domain), [`server/application`](https://github.com/ayumu203/nisekue/tree/main/server/application) (Application), [`client/src/App.tsx`](https://github.com/ayumu203/nisekue/blob/main/client/src/App.tsx) (React app), [`client/src/pages`](https://github.com/ayumu203/nisekue/tree/main/client/src/pages) (Pages)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_client_app["React app<br/>SPA<br/>[App.tsx]"]
  node_client_pages["Pages<br/>routes"]
  node_client_components["UI features<br/>components"]
  node_client_api["API layer<br/>http client"]
  node_client_schema["Contracts<br/>validation models"]
  node_client_lib["Client lib<br/>shared utilities"]
  node_client_locale["Locales<br/>i18n"]
end

subgraph group_backend["Backend"]
  node_server_program["API host<br/>minimal api<br/>[Program.cs]"]
  node_server_endpoints["Endpoints<br/>http surface"]
  node_server_application["Application<br/>use cases"]
  node_server_domain["Domain<br/>game model"]
  node_server_infra["Infrastructure<br/>persistence"]
  node_server_resources["Master data<br/>csv content"]
  node_server_shared["Shared constants<br/>shared kernel"]
  node_server_quest_run["Quest runs<br/>realtime subsystem<br/>[QuestRunHub.cs]"]
  node_server_player["Player workflows<br/>use cases"]
  node_server_quest["Quest system<br/>use cases"]
  node_server_training["Training<br/>use case"]
  node_server_ranking["Ranking<br/>aggregation"]
  node_server_chat["Chat<br/>threads"]
  node_server_treasure["Treasure maps<br/>claim flow"]
  node_server_battle_domain["Battle rules<br/>combat domain"]
  node_server_player_domain["Player model<br/>progression domain"]
  node_server_quest_domain["Quest model<br/>quest domain"]
  node_server_infra_db[("AppDbContext<br/>ef core db<br/>[AppDbContext.cs]")]
  node_server_infra_csv["CSV repositories<br/>master-data loaders"]
end

subgraph group_ops["Ops"]
  node_server_workflows["Workflows<br/>ci/cd<br/>[workflows]"]
  node_supabase[("Supabase<br/>auth/db<br/>[config.toml]")]
end

subgraph group_quality["Quality"]
  node_tests_server["Server tests<br/>xunit suite<br/>[server.tests]"]
  node_docs_domain["Domain docs<br/>specs"]
end

node_client_app -->|"renders"| node_client_pages
node_client_pages -->|"composes"| node_client_components
node_client_pages -->|"loads data"| node_client_api
node_client_api -->|"validates"| node_client_schema
node_client_app -->|"uses"| node_client_lib
node_client_app -->|"localizes"| node_client_locale
node_client_lib -->|"auth/db"| node_supabase
node_client_api -->|"calls"| node_server_endpoints
node_server_program -->|"hosts"| node_server_endpoints
node_server_endpoints -->|"dispatches"| node_server_application
node_server_application -->|"orchestrates"| node_server_domain
node_server_application -->|"persists via"| node_server_infra
node_server_application -->|"shares constants"| node_server_shared
node_server_domain -->|"contains"| node_server_battle_domain
node_server_domain -->|"contains"| node_server_player_domain
node_server_domain -->|"contains"| node_server_quest_domain
node_server_application -->|"streams"| node_server_quest_run
node_server_quest_run -->|"state"| node_server_quest_domain
node_server_quest -->|"simulates"| node_server_battle_domain
node_server_training -->|"simulates"| node_server_battle_domain
node_server_player -->|"modifies"| node_server_player_domain
node_server_ranking -->|"aggregates"| node_server_player_domain
node_server_chat -->|"uses"| node_server_domain
node_server_treasure -->|"uses"| node_server_domain
node_server_infra -->|"implements"| node_server_infra_db
node_server_infra -->|"implements"| node_server_infra_csv
node_server_infra_csv -->|"loads"| node_server_resources
node_server_infra_db -->|"targets"| node_supabase
node_server_workflows -->|"migrates"| node_server_infra_db
node_server_workflows -->|"runs jobs"| node_server_application
node_tests_server -->|"verifies"| node_server_domain
node_tests_server -->|"verifies"| node_server_application
node_docs_domain -->|"describes"| node_server_domain

click node_client_app "https://github.com/ayumu203/nisekue/blob/main/client/src/App.tsx"
click node_client_pages "https://github.com/ayumu203/nisekue/tree/main/client/src/pages"
click node_client_components "https://github.com/ayumu203/nisekue/tree/main/client/src/components"
click node_client_api "https://github.com/ayumu203/nisekue/tree/main/client/src/api"
click node_client_schema "https://github.com/ayumu203/nisekue/tree/main/client/src/schema"
click node_client_lib "https://github.com/ayumu203/nisekue/tree/main/client/src/lib"
click node_client_locale "https://github.com/ayumu203/nisekue/tree/main/client/locale"
click node_server_program "https://github.com/ayumu203/nisekue/blob/main/server/Program.cs"
click node_server_endpoints "https://github.com/ayumu203/nisekue/tree/main/server/endpoints"
click node_server_application "https://github.com/ayumu203/nisekue/tree/main/server/application"
click node_server_domain "https://github.com/ayumu203/nisekue/tree/main/server/domain"
click node_server_infra "https://github.com/ayumu203/nisekue/tree/main/server/infrastructure"
click node_server_resources "https://github.com/ayumu203/nisekue/tree/main/server/resources"
click node_server_shared "https://github.com/ayumu203/nisekue/tree/main/server/shared/constants"
click node_server_quest_run "https://github.com/ayumu203/nisekue/blob/main/server/application/quest/QuestRunHub.cs"
click node_server_player "https://github.com/ayumu203/nisekue/tree/main/server/application/player"
click node_server_quest "https://github.com/ayumu203/nisekue/tree/main/server/application/quest"
click node_server_training "https://github.com/ayumu203/nisekue/tree/main/server/application/training"
click node_server_ranking "https://github.com/ayumu203/nisekue/tree/main/server/application/ranking"
click node_server_chat "https://github.com/ayumu203/nisekue/tree/main/server/application/chat"
click node_server_treasure "https://github.com/ayumu203/nisekue/tree/main/server/domain/treasuremap"
click node_server_battle_domain "https://github.com/ayumu203/nisekue/tree/main/server/domain/battle"
click node_server_player_domain "https://github.com/ayumu203/nisekue/tree/main/server/domain/player"
click node_server_quest_domain "https://github.com/ayumu203/nisekue/tree/main/server/domain/quest"
click node_server_infra_db "https://github.com/ayumu203/nisekue/blob/main/server/infrastructure/AppDbContext.cs"
click node_server_infra_csv "https://github.com/ayumu203/nisekue/tree/main/server/infrastructure"
click node_server_workflows "https://github.com/ayumu203/nisekue/blob/main/.github/workflows"
click node_supabase "https://github.com/ayumu203/nisekue/blob/main/supabase/supabase/config.toml"
click node_tests_server "https://github.com/ayumu203/nisekue/blob/main/tests/server.tests"
click node_docs_domain "https://github.com/ayumu203/nisekue/tree/main/docs"

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_client_app,node_client_pages,node_client_components,node_client_api,node_client_schema,node_client_lib,node_client_locale toneBlue
class node_server_program,node_server_endpoints,node_server_application,node_server_domain,node_server_infra,node_server_resources,node_server_shared,node_server_quest_run,node_server_player,node_server_quest,node_server_training,node_server_ranking,node_server_chat,node_server_treasure,node_server_battle_domain,node_server_player_domain,node_server_quest_domain,node_server_infra_db,node_server_infra_csv toneAmber
class node_server_workflows,node_supabase toneMint
class node_tests_server,node_docs_domain toneRose
```

## Components

### Frontend

React client and feature UI

- [React app](https://github.com/ayumu203/nisekue/blob/main/client/src/App.tsx): SPA · Vite entry and route shell for the game client · `client/src/App.tsx`
- [Pages](https://github.com/ayumu203/nisekue/tree/main/client/src/pages): routes · Feature pages such as home, players, items, quest, training, ranking, chat, and treasure map · `client/src/pages`
- [UI features](https://github.com/ayumu203/nisekue/tree/main/client/src/components): components · Feature-scoped React components and page layouts · `client/src/components`
- [API layer](https://github.com/ayumu203/nisekue/tree/main/client/src/api): http client · Feature HTTP clients and shared endpoint helpers · `client/src/api`
- [Contracts](https://github.com/ayumu203/nisekue/tree/main/client/src/schema): validation models · Client-side request/response schemas and domain contracts · `client/src/schema`
- [Client lib](https://github.com/ayumu203/nisekue/tree/main/client/src/lib): shared utilities · Auth, Supabase, quest hub, and player formatting helpers · `client/src/lib`
- [Locales](https://github.com/ayumu203/nisekue/tree/main/client/locale): i18n · Translation bundles for app features and dialogs · `client/locale`

### Backend

.NET API, domain, and persistence

- [API host](https://github.com/ayumu203/nisekue/blob/main/server/Program.cs): minimal api · ASP.NET entrypoint and service wiring · `server/Program.cs`
- [Endpoints](https://github.com/ayumu203/nisekue/tree/main/server/endpoints): http surface · Thin feature-specific HTTP adapters for chat, items, players, quests, ranking, threads, training, and treasure maps · `server/endpoints`
- [Application](https://github.com/ayumu203/nisekue/tree/main/server/application): use cases · Orchestrates game workflows and background services · `server/application`
- [Domain](https://github.com/ayumu203/nisekue/tree/main/server/domain): game model · Core bounded contexts, entities, value objects, and business rules · `server/domain`
- [Infrastructure](https://github.com/ayumu203/nisekue/tree/main/server/infrastructure): persistence · EF Core, repositories, migrations, and data mapping · `server/infrastructure`
- [Master data](https://github.com/ayumu203/nisekue/tree/main/server/resources): csv content · Data-driven game content and balance tables loaded by repositories · `server/resources`
- [Shared constants](https://github.com/ayumu203/nisekue/tree/main/server/shared/constants): shared kernel · Cross-cutting constants used by backend layers · `server/shared/constants`
- [Quest runs](https://github.com/ayumu203/nisekue/blob/main/server/application/quest/QuestRunHub.cs): realtime subsystem · SignalR-backed live quest execution with persistent run state · `server/application/quest/QuestRunHub.cs`
- [Player workflows](https://github.com/ayumu203/nisekue/tree/main/server/application/player): use cases · Job change, rebirth, move-set cleanup, item boosts, and market maintenance · `server/application/player`
- [Quest system](https://github.com/ayumu203/nisekue/tree/main/server/application/quest): use cases · Room lifecycle, stage policies, NPC assignment, battle factory, and run resolution · `server/application/quest`
- [Training](https://github.com/ayumu203/nisekue/tree/main/server/application/training): use case · Enemy selection, battle resolution, exp, mastery, and cooldown logic · `server/application/training`
- [Ranking](https://github.com/ayumu203/nisekue/tree/main/server/application/ranking): aggregation · Ranking reads, rebuilds, and period aggregation · `server/application/ranking`
- [Chat](https://github.com/ayumu203/nisekue/tree/main/server/application/chat): threads · Chat rooms, messages, and thread views · `server/application/chat`
- [Treasure maps](https://github.com/ayumu203/nisekue/tree/main/server/domain/treasuremap): claim flow · Map expeditions, reward pools, and claim history · `server/domain/treasuremap`
- [Battle rules](https://github.com/ayumu203/nisekue/tree/main/server/domain/battle): combat domain · Turn resolution, targeting, damage, and action state · `server/domain/battle`
- [Player model](https://github.com/ayumu203/nisekue/tree/main/server/domain/player): progression domain · Players, items, equipment, moves, status, and market rules · `server/domain/player`
- [Quest model](https://github.com/ayumu203/nisekue/tree/main/server/domain/quest): quest domain · Rooms, runs, stages, enemies, traps, and rewards · `server/domain/quest`
- [AppDbContext](https://github.com/ayumu203/nisekue/blob/main/server/infrastructure/AppDbContext.cs): ef core db · Relational persistence for transactional game state · `server/infrastructure/AppDbContext.cs`
- [CSV repositories](https://github.com/ayumu203/nisekue/tree/main/server/infrastructure): master-data loaders · Repositories that load reference content from CSV files · `server/infrastructure`

### Ops

Deployment, workflows, and external services

- [Workflows](https://github.com/ayumu203/nisekue/blob/main/.github/workflows): ci/cd · Deployments, migrations, rebuilds, and cleanup pipelines · `.github/workflows`
- [Supabase](https://github.com/ayumu203/nisekue/blob/main/supabase/supabase/config.toml): auth/db · External database and authentication platform · `supabase/supabase/config.toml`

### Quality

Tests and documentation

- [Server tests](https://github.com/ayumu203/nisekue/blob/main/tests/server.tests): xunit suite · Domain and application tests for core game logic · `tests/server.tests`
- [Domain docs](https://github.com/ayumu203/nisekue/tree/main/docs): specs · MMD and markdown notes for battle, player, quest, chat, ranking, training, and treasure map · `docs`

## Connections

- React app → Pages: renders · App shell routes to game pages
- Pages → UI features: composes · Pages assemble feature UI components
- Pages → API layer: loads data · Pages call feature HTTP clients
- API layer → Contracts: validates · API payloads are shaped by client contracts
- React app → Client lib: uses · Client shell relies on shared auth and runtime helpers
- React app → Locales: localizes · UI text is sourced from locale bundles
- Client lib → Supabase: auth/db · Client integrates with Supabase auth
- API layer → Endpoints: calls · Client talks to feature HTTP surfaces
- API host → Endpoints: hosts · Program wires the public API surface
- Endpoints → Application: dispatches · Endpoints forward requests into use cases
- Application → Domain: orchestrates · Use cases coordinate domain objects and rules
- Application → Infrastructure: persists via · Application services use repositories and storage adapters
- Application → Shared constants: shares constants · Use cases consume shared backend constants
- Domain → Battle rules: contains · Battle is a major bounded context
- Domain → Player model: contains · Player progression and economy rules
- Domain → Quest model: contains · Quest rooms, runs, and rewards
- Application → Quest runs: streams · Quest execution publishes live updates
- Quest runs → Quest model: state · Live run logic is built on quest run domain state
- Quest system → Battle rules: simulates · Quest battles use battle resolution primitives
- Training → Battle rules: simulates · Training battles reuse combat rules
- Player workflows → Player model: modifies · Player workflows act on progression and economy model
- Ranking → Player model: aggregates · Ranking is derived from player state and history
- Chat → Domain: uses · Chat services use chat domain repositories and models
- Treasure maps → Domain: uses · Treasure map workflows use treasure-map domain rules
- Infrastructure → AppDbContext: implements · Relational persistence is centered on EF Core context
- Infrastructure → CSV repositories: implements · CSV repositories load master/reference data
- CSV repositories → Master data: loads · Reference content is read from CSV files
- AppDbContext → Supabase: targets · Production persistence sits behind Supabase-managed data services
- Workflows → AppDbContext: migrates · CI/CD includes database migration pipelines
- Workflows → Application: runs jobs · Workflows rebuild ranking and clean up expired data
- Server tests → Domain: verifies · Tests cover pure domain behavior
- Server tests → Application: verifies · Tests cover orchestration services and workflows
- Domain docs → Domain: describes · Documentation captures the modeled game domains
