How hiravem/lunarconsole works
1. Repository shape
- This is a .NET 10 solution split into two main runtime projects: Lunar.Core and Lunar.Console, plus Lunar.Core.Tests.
- The architecture is intentionally layered for a future Unity port: the game rules live in Lunar.Core; the console app only handles I/O, persistence, randomness, and wiring.
2. Core boundary
- Lunar.Core is the business-logic center.
- It contains the Domain model, Application orchestration, DTOs, and interfaces that abstract infrastructure concerns.
- Nothing in Lunar.Core depends on console APIs, JSON storage, or random number implementation details.
3. Domain subsystem
- Lunar.Core/Domain is organized by gameplay concepts: Characters, Combat, Inventory, Items, Bosses, World, Skills, and Events.
- The domain uses a rich OOP style: entities and aggregates own behavior such as taking damage, equipping items, resolving combat commands, and boss phase transitions.
- Important aggregates include CombatSession, Inventory, and EquipmentLoadout.
4. Character and combat model
- Characters are modeled under Domain/Characters with shared stat/health abstractions and specialized player/enemy/boss behavior.
- Combat is command-driven: ICombatCommand has concrete actions like attack, flee, skill use, and item use.
- Combat resolution is centralized in CombatSession, while damage/crit calculation is pushed into domain services such as DamageCalculator and CriticalCalculator.
5. World and encounter flow
- Exploration is separated from combat in Domain/World.
- EncounterTable and EnemyFactory support weighted/random encounter generation, while Explore and encounter-related types represent the result of a day action.
- Boss logic is isolated in Domain/Bosses, with factory/phase abstractions so boss behavior can evolve without changing combat orchestration.
6. Inventory, items, and equipment
- Inventory and equipment are distinct aggregates rather than one flat bag-of-items implementation.
- Inventory tracks item stacks and capacity; EquipmentLoadout manages slots and stat modifiers.
- ItemFactory and item polymorphism make items data-driven and extensible, which matters for loot, save/load, and merchant flows.
7. Application layer orchestration
- Lunar.Core/Application contains the use cases that coordinate the domain without embedding rules.
- Key use cases include StartGameUseCase, ExploreUseCase, CombatUseCase, BossBattleUseCase, RestUseCase, AdvanceDayUseCase, EquipItemUseCase, UseItemUseCase, and save/load use cases.
- These use cases are the main integration points for the UI and are the right abstraction level for sequence diagrams.
8. Runtime state and save model
- GameSession is the in-memory source of truth for a running game: player state, current day, difficulty, day flags, and active combat session.
- GameState is the save/load snapshot representation, designed to be serialized cleanly rather than persisting live object graphs.
- This separation means save/load does not leak runtime object identity into storage.
9. Event flow
- Domain events are defined in Domain/Events as pure data.
- The application layer exposes IEventBus; the domain collects events, and use cases publish them after execution.
- This creates a clear boundary: the domain records what happened, while the outer layers decide how to react.
10. Console infrastructure
- Lunar.Console/Infrastructure implements application interfaces:
- JsonSaveRepository for persistence,
- RandomService for randomness,
- InMemoryEventBus for event dispatch.
- These are replaceable adapters, which is important for testing and later Unity integration.
11. Console presentation
- Lunar.Console/Presentation is a text UI layer composed of ConsoleGamePresenter, InputReader, OutputWriter, and screen classes.
- Screens are split by gameplay mode: main menu, gameplay, combat, inventory, equipment, and merchant.
- Presentation calls use cases and renders DTOs; it should not touch domain objects directly for rules like damage, equip validation, or loot generation.
12. Primary data flow
- The typical flow is: console input → screen/presenter → application use case → domain aggregate/service → event publication and state mutation → DTO returned → console output.
- Example paths include:
- New game → StartGameUseCase → GameSession
- Explore → ExploreUseCase → encounter resolution → possible combat
- Combat → CombatUseCase → CombatSession → loot/event updates
- Save/Load → GameSession ↔ GameState ↔ JsonSaveRepository
13. Testing structure
- Lunar.Core.Tests targets the core logic directly, which matches the architecture goal of keeping gameplay rules testable without the console layer.
- The sprint-named test files indicate the repo is organized around incremental gameplay milestones rather than UI tests.
- For an architecture diagram, this project is best shown as verifying domain/application behavior at the core boundary.
14. What matters most for a diagram
- Draw Lunar.Core as the central reusable engine.
- Show Lunar.Console as a thin shell with two branches: Infrastructure adapters and Presentation screens.
- Emphasize that use cases orchestrate domain behavior, GameSession holds runtime state, and GameState handles persistence snapshots.
- External effects are limited to console I/O, JSON file save/load, and random number generation.
Main entry points: UseCases Use Cases · Combat Combat · Lunar.Core.Tests Core Tests · Infrastructure Infrastructure
Components 20
Lunar.Core
Reusable game engine: domain rules, application orchestration, and runtime state.
- Application · Coordinates game use cases, session state, DTO mapping, and boundary interfaces.
Lunar.Core/Application - GameSession · In-memory source of truth for a running game: player state, day, difficulty, flags, and active combat.
Lunar.Core/Application/GameSession.cs - GameState · Serializable snapshot model used for persistence instead of live object graphs.
Lunar.Core/Application/GameState.cs - Presenter Mapper · Shapes application data into presentation-friendly DTOs and views.
Lunar.Core/Application/UseCases/GameplayPresenterMapper.cs - Event Bus · Application-facing event publishing abstraction used after domain execution.
Lunar.Core/Application/Interfaces/IEventBus.cs - Save Repo · Persistence abstraction for loading and storing game state snapshots.
Lunar.Core/Application/Interfaces/ISaveRepository.cs - Random Service · Randomness abstraction used by use cases and domain-adjacent logic.
Lunar.Core/Application/Interfaces/IRandomService.cs - Use Cases · Start, explore, combat, rest, equip, merchant, and save/load flows.
Lunar.Core/Application/UseCases - Combat · Command-driven combat resolution with calculators, commands, and encounter results.
Lunar.Core/Domain/Combat - Characters · Shared character model with stats, health, damage, and damageable behavior.
Lunar.Core/Domain/Characters - Inventory · Tracks item stacks, capacity, and equipment loadout interactions.
Lunar.Core/Domain/Inventory - Items · Item polymorphism, factories, types, and loot tables.
Lunar.Core/Domain/Items - World · Day actions and weighted encounter generation for exploration flow.
Lunar.Core/Domain/World - Bosses · Boss model, factory, and phase abstractions for special encounters.
Lunar.Core/Domain/Bosses - Domain Events · Event payloads recorded by the domain and published by the application layer.
Lunar.Core/Domain/Events
Lunar.Console
Thin runtime shell for console I/O, persistence, randomness, and presentation.
- Program · Bootstraps the console runtime and wires adapters to the core application.
Lunar.Console/Program.cs - Infrastructure · Console-side implementations of persistence, randomness, and event dispatch.
Lunar.Console/Infrastructure - Presentation · Console presenters and screens that read input and render DTOs.
Lunar.Console/Presentation - Screens · Mode-specific UI for menu, gameplay, combat, inventory, equipment, and merchant.
Lunar.Console/Presentation/Screens
Lunar.Core.Tests
Core behavior tests focused on gameplay rules and application flows.
- Core Tests · Verifies domain and application behavior at the reusable core boundary.
Lunar.Core.Tests
Connections 25
- Program → Infrastructure: wires · Composition root connects adapters used by the runtime.
- Program → Presentation: runs · Program starts the text UI shell.
- Presentation → Screens: navigates · Presenter delegates to gameplay-specific screens.
- Presentation → Use Cases: calls · Screens invoke application use cases rather than domain objects directly.
- Infrastructure → Event Bus: implements · Console event bus adapter satisfies the application boundary.
- Infrastructure → Save Repo: implements · JSON repository persists and loads game snapshots.
- Infrastructure → Random Service: implements · Console random service supplies randomness to the core.
- Use Cases → GameSession: mutates · Use cases coordinate runtime state changes.
- Use Cases → GameState: persists · Save/load use cases translate to and from snapshot state.
- Use Cases → Presenter Mapper: maps · Use cases prepare DTOs for presentation.
- Use Cases → World: explores · Exploration use cases drive encounter generation.
- Use Cases → Combat: resolves · Combat and boss battle use cases execute combat sessions.
- Use Cases → Inventory: applies · Equip and item use cases manipulate inventory and loadout.
- Use Cases → Bosses: spawns · Boss battle flows create or advance boss encounters.
- Combat → Characters: targets · Combat commands and calculators act on characters.
- Combat → Items: uses · Item use commands pull from the item model.
- Inventory → Items: stores · Inventory and loadout manage item stacks and equipment.
- World → Characters: generates · Encounter tables and enemy factories produce combatants.
- World → Bosses: may trigger · Exploration can lead into boss encounters.
- Bosses → Combat: enters · Boss phases resolve through the combat engine.
- Combat → Domain Events: emits · Combat records domain events for later publication.
- Core Tests → Use Cases: verifies · Tests cover orchestration and boundary behavior.
- Core Tests → Combat: verifies · Tests cover core combat rules and outcomes.
- Core Tests → Inventory: verifies · Tests cover item, equip, and capacity behavior.
- Core Tests → World: verifies · Tests cover exploration and encounter selection.