> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formae.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy the bookstore webapp

> A Kubernetes infrastructure pattern, deployed with formae.

A two-tier web application in a single namespace: an nginx frontend that serves a
static page and proxies `/api` to a Node.js backend API. One forma provisions the
namespace, the frontend and backend ConfigMaps, a database-credentials Secret, a
backend ServiceAccount, the two Deployments, and the two Services (the frontend
exposed as a LoadBalancer).

```mermaid theme={"languages":{"custom":["/languages/pkl.json"]}}
flowchart LR
  target["k8s-target-local-bookstore"]:::tgt

  subgraph stack["k8s-bookstore-local"]
    direction LR
    ns["Namespace"]:::res
    frontendCm["Frontend ConfigMap"]:::res
    backendCm["Backend ConfigMap"]:::res
    dbSecret["DB credentials Secret"]:::res
    backendSa["Backend ServiceAccount"]:::res
    frontendDep["Frontend Deployment (nginx)"]:::res
    backendDep["Backend Deployment (Node API)"]:::res
    frontendSvc["Frontend Service (LoadBalancer)"]:::res
    backendSvc["Backend Service"]:::res

    ns --> frontendCm
    ns --> backendCm
    ns --> dbSecret
    ns --> backendSa
    frontendCm --> frontendDep
    backendCm --> backendDep
    dbSecret --> backendDep
    backendSa --> backendDep
    frontendDep --> frontendSvc
    backendDep --> backendSvc
    backendSvc --> frontendDep
  end

  target --> stack

  classDef tgt fill:#FF8201,stroke:#B25900,color:#ffffff
  classDef res fill:#FFF3E6,stroke:#FF8201,color:#02024B
  style stack fill:#ffffff,stroke:#02024B,stroke-width:2px,stroke-dasharray:6 4,color:#02024B
```

**Deploy.** Apply the example forma. formae orders the resources by their
dependencies automatically, so the namespace comes up before the workloads and
the backend Service before the frontend that proxies to it:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae apply --mode reconcile \
  /opt/pel/formae/examples/formae-plugin-kubernetes/bookstore/local.pkl
```

**Verify.** Once the command completes, the stack's resources are under
management:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae inventory resources --query="type:K8S::Apps::Deployment"
```

**Tear down.** Remove everything the forma created:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae destroy \
  /opt/pel/formae/examples/formae-plugin-kubernetes/bookstore/local.pkl
```

The full forma is in the
[bookstore example](https://github.com/platform-engineering-labs/formae-plugin-kubernetes/tree/main/examples/bookstore).
