ERPClimb logoERPClimb
CAP project foundation
SAP Cloud Application Programming Modelbeginner 6 min read

CAP project foundation — SAP Guided Tutorial

Free sample lesson · open to everyone

Key takeaway

How a CAP project is laid out (db/, srv/, app/), how cds watch, profiles and cds env decide what actually runs, and how cds build turns your model into deployable modules — so a service that works locally also starts in test.

In this lessonShow sections

Visual overview

CAP project foundation — learning sheetFlow: cds init: db / srv / app → cds watch: SQLite + mocked auth → Profiles: development vs production → cds build: gen/ deployables. Key ideas: PROJECT SKELETON; WHAT CDS WATCH HIDES FROM YOU; PROFILES AND EFFECTIVE CONFIGURATION; BUILD OUTPUT. Watch out: Most "works on my machine" CAP failures are configuration drift between the development and production profile, not code bugs.ERPClimb.com / CAP / LESSON 1/12 / LEARNING SHEETCAP project foundation1 · HOW IT FLOWS1cds initdb / srv / app2cds watchSQLite + mocked auth3Profilesdevelopment vsproduction4cds buildgen/ deployables2 · KEY IDEAS EXPLAINEDProject Skeleton`npm i -g @sap/cds-dk` installs the CLI; `cds initbookshop` creates the skeleton.db/schema.cds — entities and types.srv/cat-service.cds — what you expose.srv/cat-service.js — optional handler with the…What CDS Watch Hides From YouDatabase: SQLite in memory, recreated on everyrestart; initial data from db/data/*.csv.Auth: mocked users (alice, bob…) with roles frompackage.json, no XSUAA token.Profiles And Effective Configuration`"cds": { "requires": {"[production]": { "db":"hana", "auth"…`cds env requires.db --profile production` printsexactly what the runtime will use. Compare it withthe development output before deploying.Build Output`cds build --production` compiles CDS to gen/srv(Node app with csn.json) and gen/db (HDI artefactsfor HANA).Read the build log: it lists every task and targetfolder. A missing gen/db means no HANA tables willbe deployed.3 · REMEMBER · WATCH OUTRememberA CAP project is three folders by convention: db/ (domain model), srv/(services + handlers), app/ (UIs). package.json holds the cds…`cds watch` is a development runtime: in-memory SQLite, mocked users,auto-reload. It is not what runs in test or production.Profiles ([development], [production], custom ones) switch databases,auth and remote bindings. `cds env` shows the effective result.!Watch outMost "works on my machine"CAP failures are configuration driftbetween the development andproduction profile, not code bugs.4 · IN A REAL PROJECTA bookshop service runs fine with `cds watch`. After `cf push`, the app crashes on start with a databaseconnection error and the Fiori app shows no data. `cds env --profile production` shows requires.db.kind =hana, but no HDI container was ever created or bound, and the gen/db module was never deployed because the…Original ERPClimb learning sheet • Verify against your SAP release and edition

The situation: a real project scenario

A bookshop service runs fine with cds watch. After cf push, the app crashes on start with a database connection error and the Fiori app shows no data. cds env --profile production shows requires.db.kind = hana, but no HDI container was ever created or bound, and the gen/db module was never deployed because the team pushed only gen/srv.

Explanation

A CAP project follows a simple folder convention: db/ holds the domain model, srv/ holds the services and their handlers, and app/ holds the UIs, with package.json carrying the CDS configuration that ties it all together.

npm i -g @sap/cds-dk installs the CLI, and cds init bookshop scaffolds the skeleton; later facets like HANA, XSUAA, or MTA support are added with cds add hana, cds add xsuaa, cds add mta, and similar, rather than copied in by hand from blog posts, which keeps the generated config consistent with your actual CAP version.

The thing to understand early is that cds watch, the everyday development command, is not a preview of production — it's a convenience layer that hides a lot.

It runs against an in-memory SQLite database that's recreated on every restart and seeded from db/data/*.csv; it authenticates with mocked users like "alice" and "bob" defined in package.json, with no real XSUAA token involved; and remote services can be mocked locally so a missing destination never surfaces as an error at development time.

The practical consequence is that a service which starts fine under cds watch can still fail in test or production on a database connection, token validation, or a missing service binding — none of which cds watch ever exercised.

Profiles are how CAP resolves this gap. Entries like "[development]" and "[production]" under cds.requires swap out implementations — SQLite versus HANA, mocked auth versus XSUAA — and cds env requires.db --profile production prints exactly what the runtime will actually use for a given profile, which is worth comparing against the development output before every deployment.

On Cloud Foundry, NODE_ENV=production is set automatically, so the production profile activates without extra configuration — but that also means configuration drift between profiles, not a code bug, is the most common cause of "works on my machine" CAP failures.

Finally, cds build --production compiles the CDS model into deployable artifacts: gen/srv for the Node.js application plus its compiled model (csn.json), and gen/db for the HANA deployment artifacts (HDI). The build log lists every task and its output folder, and a missing gen/db after a build is a strong sign that no HANA tables will be deployed at all. Separately, cds compile srv --to edmx prints the OData $metadata your service will actually publish, which is worth checking directly before assuming a UI problem is really a service problem.

To see this for yourself: run cds init bookshop && cd bookshop && cds add sample, then cds watch and open /odata/v4/catalog/$metadata; run cds env requires --profile development and again with --profile production and note what differs; run cds build --production and list what appears under gen/; then deliberately break the app by setting [production].requires.db to a kind with no binding and starting with NODE_ENV=production cds-serve to see the resulting error.

By the end, you should be able to explain, from cds env output rather than from memory, exactly which database, auth strategy, and remote bindings each profile in your own project uses.

Code example

ABAP Code
// package.json (excerpt){  "cds": {    "requires": {      "db":   { "[development]": { "kind": "sqlite", "credentials": { "url": ":memory:" } },                "[production]":  { "kind": "hana" } },      "auth": { "[development]": { "kind": "mocked" },                "[production]":  { "kind": "xsuaa" } }    }  }}// Verify before you deploy://   cds env requires.db --profile production//   cds build --production   -> gen/srv, gen/db

Watch out

Common mistakes

  • Treating cds watch success as proof the service will start on Cloud Foundry.
  • Hand-editing gen/ files — they are overwritten on the next build.
  • Committing credentials in package.json or default-env.json instead of using service bindings.
  • Pinning old @sap/cds versions across modules so db and srv run different compiler versions.

Do this

Best practices

  • Use cds add <facet> for HANA, XSUAA, MTA and multitenancy instead of copying config from blogs.
  • Check cds env per profile in code review whenever package.json cds settings change.
  • Keep a small hybrid profile (cds bind) so you can run locally against real HANA/XSUAA before deploying.

In the interview

Interview angle

Interviewers use this topic to separate people who have only run tutorials from people who have deployed CAP. Explain the folder conventions, then spend most of the answer on profiles: what cds watch mocks, how the production profile changes db and auth, and how you verify effective configuration with cds env before deploying.

Practice this lesson

Original educational case studies for SAP consultants, not official SAP certification exam questions. Verify product edition and implementation details against the current SAP documentation.

Quick check

0 of 4 questions attempted

Question 1 of 4

A CAP service starts with `cds watch` but crashes on Cloud Foundry with a database error. What is the most direct first check?

Practise this in an interview

Answer in your own words and get instant feedback, the way an interviewer would judge it.

1Your CAP app works with `cds watch` but fails after deployment to BTP Cloud Foundry. How do you approach it?

2How would you structure a new CAP project for a team of five developers?

Was this lesson helpful?

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.