Control plane for runtime environment abstraction with Cloud Foundry REI implementation
PAPI (Platform API) is a Go-based control plane that provides a unified REST API for managing namespaces across multiple runtime environments (Cloud Foundry, Kubernetes, etc.) through a pluggable Runtime Environment Interface (REI).
- Namespace Management: Create and list namespaces with template-based naming and metadata validation
- Multi-Environment Groups: Organize runtime environments into groups with orchestrated provisioning
- Async Provisioning: Queue-based operation execution across grouped environments with eventual consistency
- OIDC Authentication: Secure endpoints with OpenID Connect token validation
- Role-Based Access Control: Platform-level roles (admin, namespace-creator) and namespace-level permissions
- Identity Group Integration: Cache-based membership resolution with TTL refresh
- Pluggable REI: Extensible Runtime Environment Interface for supporting multiple platforms
- Cloud Foundry Support: Built-in REII (REI Implementation) for Cloud Foundry (org/space provisioning)
- API Versioning: Contract-first development with OpenAPI 3.1 specifications
- Observability: Structured logging (slog), Prometheus metrics, OpenTelemetry tracing
┌─────────────────────────────────────────────────────────────┐
│ PAPI REST API (v1) │
│ /namespaces /groups /health /info │
└───────────────────┬─────────────────────────────────────────┘
│
┌───────────┴───────────┐
│ Domain Services │
│ (Namespace, Groups) │
└───────────┬───────────┘
│
┌───────────────┼────────────────────┐
│ │ │
┌───▼────┐ ┌────▼────┐ ┌──────▼──────┐
│ OIDC │ │ Queue │ │ PostgreSQL │
│ Auth │ │ Worker │ │ Storage │
└────────┘ └────┬────┘ └─────────────┘
│
│ REI Interface
┌────┴────┬────────────┐
│ │ │
┌────▼───┐ ┌───▼────┐ ┌───▼────┐
│ CF │ │ k8s │ │ ... │
│ REII │ │ REII │ │ REII │
└────────┘ └────────┘ └────────┘
- Go 1.22+
- Docker & Docker Compose
- PostgreSQL 15+
-
Clone the repository
git clone https://github.com/jcvrabo/papi.git cd papi -
Start dependencies
docker-compose up -d
This starts:
- PostgreSQL (port 5432)
- Mock OAuth2 Server (port 8888)
-
Configure environment
export PAPI_DB_URL="postgres://papi:papi@localhost:5432/papi?sslmode=disable" export PAPI_OIDC_ISSUER="http://localhost:8888/default" export PAPI_LISTEN_ADDR=":8080" export PAPI_LOG_LEVEL="info"
-
Run migrations
go build -o papi ./cmd/papi ./papi migrate up
-
Start the server
./papi serve
-
Verify it's running
curl http://localhost:8080/api/v1/health curl http://localhost:8080/api/v1/info
# Build binary
make build
# Run tests
make test
# Run linter
make lint
# Build Docker image
docker build -t papi:latest .PAPI exposes a versioned REST API (/api/v1/) with the following endpoints:
GET /api/v1/health- Health check with environment statusGET /api/v1/info- Platform version and OIDC issuer info
GET /api/v1/namespaces- List namespaces (filtered by user access)POST /api/v1/namespaces- Create namespace (requiresnamespace-creatorrole)GET /api/v1/namespaces/{id}/status- Get namespace provisioning statusGET /api/v1/groups- List runtime environment groupsPOST /api/v1/groups- Create group (admin only)PUT /api/v1/groups/{id}- Update group (admin only)DELETE /api/v1/groups/{id}- Delete group (admin only)
Full OpenAPI specification: api/openapi/v1.yaml
PAPI is configured via environment variables:
| Variable | Required | Default | Description |
|---|---|---|---|
PAPI_DB_URL |
Yes | - | PostgreSQL connection string |
PAPI_OIDC_ISSUER |
Yes | - | OIDC provider issuer URL |
PAPI_LISTEN_ADDR |
No | :8080 |
HTTP server listen address |
PAPI_LOG_LEVEL |
No | info |
Log level (debug, info, warn, error) |
PAPI_METRICS_ADDR |
No | :9090 |
Prometheus metrics endpoint address |
PAPI_IDENTITY_CACHE_TTL |
No | 300 |
Identity group cache TTL (seconds) |
PAPI abstracts runtime environments through a pluggable REI. The interface is defined in pkg/rei/rei.go:
type RuntimeEnvironment interface {
CreateNamespace(ctx context.Context, req CreateNamespaceRequest) (*CreateNamespaceResult, error)
DeleteNamespace(ctx context.Context, req DeleteNamespaceRequest) error
HealthCheck(ctx context.Context) error
}- Cloud Foundry REII (
internal/rei/cloudfoundry/) - Creates CF orgs and spaces
- Implement the
rei.RuntimeEnvironmentinterface - Register a factory function in the REI registry
- Configure runtime environments in PostgreSQL to use your REII type
See pkg/rei/rei.go and internal/rei/cloudfoundry/cloudfoundry.go for examples.
.
├── cmd/papi/ # Application entry point
├── internal/
│ ├── api/v1/ # HTTP handlers, middleware, router
│ ├── config/ # Configuration, logging, metrics, tracing
│ ├── domain/ # Business logic (namespace, group, operation)
│ ├── platform/ # Platform-level auth and roles
│ ├── queue/ # Async operation processor
│ ├── rei/ # REI implementations (Cloud Foundry)
│ └── store/ # PostgreSQL repositories and migrations
├── pkg/rei/ # Public REI interface (importable)
├── tests/
│ ├── contract/ # API contract tests
│ ├── integration/ # Integration tests (testcontainers)
│ └── e2e/ # End-to-end tests
├── api/openapi/ # OpenAPI 3.1 specifications
└── specs/ # Feature specifications and design docs
PAPI follows TDD and contract-first development:
- Specification - Write user stories and acceptance criteria
- Contract - Define OpenAPI spec for API changes
- Tests - Write contract and integration tests (failing)
- Implementation - Implement features to pass tests
- Verification - Run full test suite and linter
# All tests
go test ./...
# Contract tests only
go test ./tests/contract/...
# With coverage
go test -cover ./...# Run linter
golangci-lint run
# Format code
gofumpt -w .PAPI development follows strict engineering principles defined in .specify/memory/constitution.md:
- API Versioning - URI-based (
/api/v1/), breaking changes require version bump - Contract-First Development - OpenAPI specs before implementation
- Test-First Development - TDD mandatory, tests written before code
- Observability - Structured logging, metrics, and tracing on all operations
- Governance - Constitution changes require explicit approval
MIT License - see LICENSE for details
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Follow TDD and contract-first development
- Ensure tests pass and linter is happy
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Documentation: See
specs/directory for detailed design docs - Issues: https://github.com/jcvrabo/papi/issues
- Discussions: https://github.com/jcvrabo/papi/discussions
See specs/001-papi-control-plane/tasks.md for the full implementation plan.
Current Status: ✅ Phase 1-8 Complete (80/81 tasks)
- ✅ MVP features (namespace list/create, health/info)
- ✅ Group management CRUD
- ✅ Async provisioning with Cloud Foundry REII
- ✅ OIDC auth, RBAC, rate limiting, observability
- ⏳ Manual smoke testing pending
Built with ❤️ using Go, PostgreSQL, and contract-first development