Skip to content

Star Wars CAP Showcase โ€‹

A learning-focused SAP Cloud Application Programming Model (CAP) sample built on the Star Wars universe. Every feature in this repo exists to demonstrate a real production pattern โ€” not just to make it run.

Jump to a learning track: Beginner ยท Intermediate ยท Advanced


Project Structure โ€‹

PathPurpose
db/schema.cdsDomain model โ€“ entities, types, associations
db/hana/ db/sqlite/ db/postgres/Profile-specific model extensions
srv/*-service.cdsService definitions โ€“ projections, actions, functions
srv/*-fiori.cdsFiori/UI5 annotations (kept separate from service contracts)
srv/episode-service.cdsRead-only StarWarsEpisode service (OData v4, GraphQL, REST)
srv/episode-fiori.cdsFiori annotations for the Episodes list
srv/services-auth.cdsCentralized authorization โ€“ @requires / @restrict
srv/*.jsService handlers โ€“ before / on / after hooks
test/Automated tests by layer (model, service, handler)
docs/Architecture, learning path, cheat sheet, pitfalls
labs/Hands-on exercises with guided steps
app/Fiori web apps (People, Media, Film, Show) + launchpad (launchpadPage.html)
../scripts/scraper/Wookieepedia scraper โ€” rate-limited MediaWiki API crawler
../scripts/data/raw/Scraped JSON output loaded by convertData.js

Architecture at a Glance โ€‹

text
Client (Fiori / REST / GraphQL)
        โ”‚
        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         CAP Service Layer (srv/)    โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚ *-service  โ”‚  โ”‚ *-fiori.cds   โ”‚  โ”‚
โ”‚  โ”‚   .cds     โ”‚  โ”‚  (UI annot.)  โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚  โ”‚  *.js handler lifecycle     โ”‚    โ”‚
โ”‚  โ”‚  before โ†’ on โ†’ after        โ”‚    โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚
        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         Domain Model (db/)          โ”‚
โ”‚  schema.cds + profile extensions    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚
        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Persistence (profile-selected at runtime) โ”‚
โ”‚  SQLite (dev) ยท SAP HANA (prod) ยท PG       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

See /architecture/ for the full annotated diagram.


Learning Tracks โ€‹

๐ŸŸข Beginner Track โ€‹

Goal: understand CDS modeling and how CAP exposes it automatically.

#TaskWhere to look
1Read db/schema.cds โ€” find entities, types, associationsdb/schema.cds
2Start the app (npm run sqlite) and browse /odata/v4/StarWarsPeople/Peoplepeople-service.cds
3Open Swagger UI at http://localhost:4004/api-docsserver.js
4Understand how @mandatory, @assert.range, @assert.format workdb/schema.cds
5Find the Episode entity and its parent Show โ€” notice the Composition of manydb/schema.cds
6Complete Lab 01 (add a new entity)labs/lab-01-model/
7Open the Fiori launchpad at http://localhost:4004/launchpadPage.html and explore all four appsapp/

๐ŸŸก Intermediate Track โ€‹

Goal: understand service handlers, events, and custom operations.

#TaskWhere to look
1Trace the full before โ†’ on โ†’ after handler lifecycle for Peoplepeople-service.js
2Call the rename bound action via HTTPpeople-service.cds
3Call the countByGender unbound functionpeople-service.cds
4Understand how notifications + domain events are emittedpeople-service.js
5Compare StarWarsEpisode (read-only, no .js handler) with StarWarsPeople (full lifecycle)episode-service.cds
6Complete Lab 03 (add your own hook)labs/lab-03-handler/

๐Ÿ”ด Advanced Track โ€‹

Goal: master authorization, testing by layer, and multi-profile deployment.

#TaskWhere to look
1Study the role matrix (Viewer / Editor / Admin)services-auth.cds
2Read handler-level tests and understand what each layer teststest/handler.test.js
3Compare SQLite vs HANA vs PG behavior/architecture/profiles
4Work through common pitfalls/reference/pitfalls
5Complete Lab 04 (add role-based auth)labs/lab-04-auth/

Quick Start โ€‹

bash
# Install dependencies
npm install

# Start with SQLite (no external services needed)
npm run sqlite

# Run all tests
npm run test

# Regenerate scraped Star Wars data (cache-first โ€” fast from committed cache files)
npm run scrape

# Load Star Wars data into SQLite
npm run load_sqlite

Browse to http://localhost:4004 to see the service index, Swagger UI, and Fiori preview.


Runtime Profiles โ€‹

ProfileCommandDatabaseUse when
sqlitenpm run sqliteSQLite (file)Local development, no external services
hybridnpm run watchSAP HANA HDIIntegrated local dev with HANA
pgnpm run pgPostgreSQLPostgreSQL-based environments
productioncds-serveSAP HANA HDIBTP production deployment

See /architecture/profiles for a full comparison of what changes between profiles.


CDS Configuration Notes โ€‹

  • cds.requires.queue: true โ€” enables the persistent outbox queue for reliable event delivery.
  • cds.requires.middlewares: true โ€” enables the full CAP middleware chain (CORS, authentication, etc.).
  • PostgreSQL credentials are intentionally not hardcoded; provide them via .env (see cap/.env).

Validation Commands โ€‹

bash
npm run test               # full model + handler test suite
npm run test:profile       # fast profile-scoping regression gate (use in CI)
npm run test:migration     # data conversion / migration tests

Learning Resources โ€‹

ResourceLink
CAP Architecture (this repo)/architecture/
Learning Path/guide/learning-path
CAP Cheat Sheet/reference/cheat-sheet
Profile Comparison/architecture/profiles
Common Pitfalls/reference/pitfalls
Hands-on Labs/labs/
Official CAP Docshttps://cap.cloud.sap/docs/

Upgrade Notes โ€‹

  • Breaking change: legacy value-help helper endpoints were removed in favor of *Values entities. Update using /reference/migration.