# darkenergyprocessor/npps4 architecture

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

- Interactive diagram: https://gitdiagram.com/darkenergyprocessor/npps4
- Repository: https://github.com/darkenergyprocessor/npps4

## Overview

NPPS4 is a Python/FastAPI private server for SIF1. Its principal workflow is a game client request entering the server, reaching game endpoint handlers, using game-system logic and persistent account/game state, then returning a response. The repository also provides configurable client-data download backends and a separate HTML web UI. The graph preserves major domain areas visible in the tree and README; many endpoint registrations and subsystem interactions were not sampled, so those links are omitted rather than inferred.

Main entry points: [`npps4/game/unit.py`](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/game/unit.py) (Game endpoints), [`npps4/run/app.py`](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/run/app.py) (ASGI entry), [`npps4/system/unit.py`](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/system/unit.py) (Unit management), [`npps4/db/main.py`](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/db/main.py) (Persistent models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_entry["ASGI entry<br/>[app.py]"]
  node_http["HTTP application<br/>[app.py]"]
  node_gameapi["Game endpoints<br/>[unit.py]"]
  node_webviews["Web views<br/>[__init__.py]"]
end

subgraph group_gameplay["Game services"]
  node_unit["Unit management<br/>[unit.py]"]
  node_achievements["Achievements<br/>[achievement.py]"]
  node_rewards["Rewards and items<br/>[reward.py]"]
  node_advanced["Game calculations<br/>[advanced.py]"]
end

subgraph group_state["State and data"]
  node_context["User context<br/>[session.py]"]
  node_database["Database sessions<br/>[database.py]"]
  node_dbmodels[("Persistent models<br/>[main.py]")]
  node_game_data[("Client game data<br/>[unit.py]")]
end

subgraph group_operations["Configuration and admin"]
  node_download["Download backends<br/>[download.py]"]
  node_configuration["Server configuration<br/>[config.py]"]
  node_admin["Admin web UI"]
end

node_client(("Game client"))

node_client -->|"sends requests"| node_entry
node_entry -->|"starts app"| node_http
node_entry -->|"loads routes"| node_gameapi
node_entry -->|"loads views"| node_webviews
node_http -->|"reads settings"| node_configuration
node_gameapi -->|"uses context"| node_context
node_gameapi -->|"uses unit logic"| node_unit
node_gameapi -->|"uses achievement logic"| node_achievements
node_gameapi -->|"uses reward logic"| node_rewards
node_gameapi -->|"uses game logic"| node_advanced
node_context -->|"creates sessions"| node_database
node_database -->|"opens main session"| node_dbmodels
node_database -->|"opens unit session"| node_game_data
node_unit -->|"reads player state"| node_dbmodels
node_unit -->|"reads unit data"| node_game_data
node_achievements -->|"reads and updates"| node_dbmodels
node_rewards -->|"stores incentives"| node_dbmodels
node_advanced -->|"calculates team stats"| node_unit
node_game_data -->|"uses game data"| node_download
node_configuration -.->|"selects backend"| node_download

click node_entry "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/run/app.py"
click node_http "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/app/app.py"
click node_gameapi "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/game/unit.py"
click node_webviews "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/webview/__init__.py"
click node_context "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/idol/session.py"
click node_database "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/idol/database.py"
click node_dbmodels "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/db/main.py"
click node_game_data "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/db/unit.py"
click node_unit "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/system/unit.py"
click node_achievements "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/system/achievement.py"
click node_rewards "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/system/reward.py"
click node_advanced "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/system/advanced.py"
click node_download "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/download/download.py"
click node_configuration "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/config/config.py"
click node_admin "https://github.com/darkenergyprocessor/npps4/blob/master/npps4/webui/endpoints/unlock_backgrounds.py"

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_entry,node_http,node_gameapi,node_webviews,node_client toneBlue
class node_unit,node_achievements,node_rewards,node_advanced toneAmber
class node_context,node_database,node_dbmodels,node_game_data toneMint
class node_download,node_configuration,node_admin toneRose
```

## Components

### Server runtime

- [ASGI entry](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/run/app.py): `npps4/run/app.py`
- [HTTP application](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/app/app.py): `npps4/app/app.py`
- [Game endpoints](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/game/unit.py): `npps4/game/unit.py`
- [Web views](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/webview/__init__.py): `npps4/webview/__init__.py`

### Game services

- [Unit management](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/system/unit.py): `npps4/system/unit.py`
- [Achievements](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/system/achievement.py): `npps4/system/achievement.py`
- [Rewards and items](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/system/reward.py): `npps4/system/reward.py`
- [Game calculations](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/system/advanced.py): `npps4/system/advanced.py`

### State and data

- [User context](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/idol/session.py): `npps4/idol/session.py`
- [Database sessions](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/idol/database.py): `npps4/idol/database.py`
- [Persistent models](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/db/main.py): `npps4/db/main.py`
- [Client game data](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/db/unit.py): `npps4/db/unit.py`

### Configuration and admin

- [Download backends](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/download/download.py): `npps4/download/download.py`
- [Server configuration](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/config/config.py): `npps4/config/config.py`
- [Admin web UI](https://github.com/darkenergyprocessor/npps4/blob/master/npps4/webui/endpoints/unlock_backgrounds.py): `npps4/webui/endpoints/unlock_backgrounds.py`

### Other components

- **Game client**

## Connections

- Game client → ASGI entry: sends requests (evidence: `README.md`)
- ASGI entry → HTTP application: starts app (evidence: `npps4/run/app.py`)
- ASGI entry → Game endpoints: loads routes (evidence: `npps4/run/app.py`)
- ASGI entry → Web views: loads views (evidence: `npps4/run/app.py`)
- HTTP application → Server configuration: reads settings (evidence: `npps4/app/app.py`)
- Game endpoints → User context: uses context (evidence: `npps4/game/unit.py`)
- Game endpoints → Unit management: uses unit logic (evidence: `npps4/game/unit.py`)
- Game endpoints → Achievements: uses achievement logic (evidence: `npps4/game/unit.py`)
- Game endpoints → Rewards and items: uses reward logic (evidence: `npps4/game/unit.py`)
- Game endpoints → Game calculations: uses game logic (evidence: `npps4/game/unit.py`)
- User context → Database sessions: creates sessions (evidence: `npps4/idol/session.py`)
- Database sessions → Persistent models: opens main session (evidence: `npps4/idol/database.py`)
- Database sessions → Client game data: opens unit session (evidence: `npps4/idol/database.py`)
- Unit management → Persistent models: reads player state (evidence: `npps4/system/unit.py`)
- Unit management → Client game data: reads unit data (evidence: `npps4/system/unit.py`)
- Achievements → Persistent models: reads and updates (evidence: `npps4/system/achievement.py`)
- Rewards and items → Persistent models: stores incentives (evidence: `npps4/system/reward.py`)
- Game calculations → Unit management: calculates team stats (evidence: `npps4/system/advanced.py`)
- Client game data → Download backends: uses game data (evidence: `npps4/db/unit.py`)
- Server configuration → Download backends: selects backend (evidence: `README.md`)
