BattleShips.API is the backend service for the Battleships trainee project. It exposes authenticated REST endpoints for player profiles, game creation, joining games, ship placement, firing shots, lobby polling and game-state polling.
The solution is split into:
BattleShips.API- ASP.NET Core Web API host and controllers.BattleShips.API.Library- game and player service logic.BattleShips.API.Data- Entity Framework Core data access, repositories and models.BattleShips.API.Tests- API/controller tests.BattleShips.API.Library.Tests- service-layer tests.Build- Terraform configuration for Azure infrastructure.
- .NET 10, targeting
net10.0across all projects. - .NET SDK
10.0.0, pinned byglobal.jsonwithlatestMinorroll-forward. - ASP.NET Core Web API with controllers and Newtonsoft.Json.
- Entity Framework Core 10 using SQL Server.
- Microsoft Identity Web with Azure AD B2C JWT bearer authentication.
- Swagger/OpenAPI via Swashbuckle, enabled in Development.
- NUnit, FakeItEasy and coverlet for tests.
- Azure Pipelines and Terraform for packaging and infrastructure deployment.
The API reads configuration from BattleShips.API/appsettings.json and environment
overrides.
Required configuration:
ConnectionStrings:Db-ConnString- SQL Server connection string used byBattleShipsContext.AzureAd- Azure AD B2C settings used byAddMicrosoftIdentityWebApi.
The default local connection string uses SQL Server LocalDB:
"ConnectionStrings": {
"Db-ConnString": "Data source = (localdb)\\MSSQLLocalDB;Initial Catalog = GameDb;Integrated Security=True;"
}For environment variables, use .NET's double-underscore format, for example:
ConnectionStrings__Db-ConnString="Server=localhost;Database=GameDb;Trusted_Connection=True;TrustServerCertificate=True;"Install the .NET 10 SDK, then restore and build the solution:
dotnet restore
dotnet buildRun the API locally:
dotnet run --project BattleShips.APIThe development launch profile uses:
- HTTPS:
https://localhost:7235 - HTTP:
http://localhost:5235 - Swagger UI:
https://localhost:7235/swagger - Health check:
https://localhost:7235/health
The API registers BattleShipsContext with SQL Server and exposes repositories for
games, boards, players, ships, ship types and shots.
There are no Entity Framework migrations currently checked into the repository. If the database schema is not present locally, create or migrate it before running the API.
All API controllers are protected with [Authorize] and expect a valid Azure AD B2C JWT
bearer token.
PlayerController also verifies the battleships.api scope before returning or creating
the current player profile.
The configured CORS policy allows:
https://bsstaticstorage.z6.web.core.windows.nethttp://localhost:4200
Player routes:
GET /api/player/get- get or create the current authenticated player.
Game routes:
POST /api/game/create- create a new game for the authenticated player.POST /api/game/join/{gameCode}- join a game by game code.POST /api/game/addships- add ships to a board and ready the player.POST /api/game/fire- fire at a board coordinate.GET /api/game/ready/{gameId}- poll lobby ready status.POST /api/game/start/{gameId}- set the game start time.GET /api/game/state/{gameId}/{hostId}- get the host and opponent game state.GET /api/game/last/{gameId}- get the most recent shot for a game.
Run all tests with:
dotnet testThe test projects target .NET 10 and use NUnit with FakeItEasy.
azure-pipelines.yml contains three stages:
package- restores, tests and publishes the API.azure- runs Terraform from theBuilddirectory.publish- deploys the published package to thebattleships-apiAzure Web App.
Note: the pipeline currently requests the .NET 8.x SDK, while the projects target
net10.0. Update the pipeline SDK version before relying on CI for .NET 10 builds.
The repository contains a dockerfile, but it still references .NET 7 SDK/runtime images
and an entrypoint that does not match the current API assembly. Update it to .NET 10
before using Docker for this project.