This is the primary API used by the Shop website.
- Local guide: ./agents.md
See design documentation:
- Version 1 - README (Current) - Represents
version 1target state.
The overall API design follows a layered architecture using a Modular Monolith design. Each module uses a layered architecture similar to the Clean Architecture.
The following diagram illustrates that an API will use one or more modules to satisfy the the API resource requirements:
The following diagram illustrates the various layers of the architecture, along with the direction of dependencies:
Ensure that you have followed the project infrastructure README guide and have the required services running on your local machine.
The following requirements must be satisfied before running Shop API:
- ✅️ Postgresql service is running
- ✅️ Keycloak service is running
- ✅️ Flyway migrations applied
# ./apps/shop
dotnet watch run --project ./src/Offgrid.Shop.Api
The REST Client VSCode extension is required to run requests.
-
Root:
-
Customers:
- Upsert - See
./requests/customers-upsert.http
- Upsert - See
When the API is packaged into a Docker container, it will use Docker as an environment setting. For example, the ASPNETCORE_ENVIRONMENT setting is set in the ./compose.yaml file:
environment:
- ASPNETCORE_ENVIRONMENT=DockerThis will ensure that the appsettings.Docker.json file is used when initialising Docker container.
The following appsettings are used for Docker. Note that Docker Compose service names are used instead of localhost. Inside a container, localhost refers to the container itself, not your host machine or other containers. Each service runs on its own network namespace, so containers must reach each other via the Compose network DNS name (the service name), not localhost.
Important
Add a keycloak entry to your hosts file so the browser can resolve http://keycloak:8080 during login/redirect callbacks when running locally. This maps the hostname to your local machine.
- Windows: Edit
C:\Windows\System32\drivers\etc\hostsas Administrator and add:127.0.0.1 keycloak - Linux: Edit
/etc/hostsas root and add:127.0.0.1 keycloak
"ConnectionStrings": {
"Offgrid": "Server=postgres:5432;User Id=postgres;Password=password;Database=offgrid"
},
"KeycloakSettings": {
"Authority": "http://keycloak:8080/realms/offgrid-public",
"Audience": "shop-api",
"RequireHttpsMetadata": false
},
"CorsPolicySettings": {
"DefaultPolicyName": "AllowShopApp",
"Policies": [
{
"Name": "AllowShopApp",
"AllowedOrigins": [
"http://shop-app:7000"
]
}
]
}The shop-api defines its own Dockerfile and compose.yaml file.
The containers are managed using docker compose as follows:
# location: ./apps/shop/infra
# start containers
docker compose up --build
# stop containers
docker compose down --volumes --remove-orphans
# recreate shop-api container
docker compose up --build -d --force-recreate shop-api
# recreate shop-app container
docker compose up --build -d --force-recreate shop-appWhen using the ./requests to test API endpoints, please ensure to select the correct environment in VSCode. See .vscode/settings.json.
"rest-client.environmentVariables": {
"$shared": {
"SHOP_API_BASE_URL": "http://localhost:7000",
"OG_KC_BASE_URL": "http://localhost:8080",
},
"docker": {
"SHOP_API_BASE_URL": "http://localhost:7000",
"OG_KC_BASE_URL": "http://keycloak:8080",
}
}Switch / choose the active environment:
- Status bar (easiest & most visible)
- Look at the bottom-right of VS Code window → you'll see something like REST Client: No Environment or REST Client: local.
- Click it → pick from the list (local / staging / prod / No Environment / …).
- Keyboard shortcut:
- Ctrl + Alt + E (Windows/Linux)
- Cmd + Alt + E (macOS)
- Command Palette:
- Ctrl + Shift + P (or Cmd + Shift + P) → type Rest Client: Switch Environment → select one.

