Capstone requirements and architecture
What you will learn
Build a fictional multi-tenant catalog and inventory service for a small learning-store team. A successful reservation reduces available stock once; rejected reservations leave stock unchanged. Keep those rules visible before selecting frameworks.
- Define domain invariants and testable acceptance criteria.
- Compare a modular monolith with separated services.
- Separate domain policy from HTTP and persistence adapters.
Plain Java 21: save each example as Main.java in a fresh directory, compile with javac --release 21 Main.java, then run java Main. Trusted local fixtures only. No network or third-party dependency is needed.
Validate a domain quantity
public class Main { record Quantity(int value) { Quantity { if(value<1 || value>100) throw new IllegalArgumentException("quantity"); } } public static void main(String[] args) throws Exception { System.out.println(new Quantity(3).value()); }}Expected output:
3Validation happens at construction, not after state is modified.
Requirements and scope
A tenant may read and reserve only its own SKU. Quantity is an integer from 1 to 100. Stock never becomes negative. A successful command has a unique reservation identifier; repeating the same identifier and payload returns the prior result without another deduction. Reusing the identifier with a different payload is rejected. Unknown or unauthorized items return no stock information. Use synthetic data. No payment, personal data or external systems are needed.
ADR-001: choose one deployable application
Option A: modular monolith with catalog, reservation, persistence and delivery boundaries; a PostgreSQL transaction can protect the stock and idempotency records together. Option B: separate catalog and reservation services, with reservation owning stock and command state, catalog publishing descriptive data; separate deployments add network failure, eventual consistency, contract versioning and operational cost. Select A for this fictional small team. Revisit only when ownership or scaling evidence supports B. No cache or asynchronous job is necessary for the core transaction. An optional later catalog-read cache must be tenant-keyed and invalidated; an outbox is appropriate only if a downstream notification becomes a requirement.
Project layout and evidence
In lab-fixtures/projects/v57-capstone, starter provides an exercise skeleton, local provides a dependency-free domain and loopback HTTP adapter, and spring provides a Boot 4.0.10/JDBC/PostgreSQL source-reviewed alternative. The local reference uses in-memory state, not durable transactions. The service tests use synthetic bearer tokens that are fixed test-only credentials, not production authentication. A genuine deployment must replace them with verified identity and resource-level authorization. Keep the interface narrow and document exactly which path is executed.
Use a tenant-qualified key
public class Main { record Key(String tenant,String sku) {} public static void main(String[] args) throws Exception { var map=java.util.Map.of(new Key("alpha","PEN"),4,new Key("beta","PEN"),7); System.out.println(map.get(new Key("beta","PEN"))); }}Expected output:
7Equal SKU names do not identify the same tenant resource.
Express the port separately from its adapter
public class Main { interface Stock { int available(String sku); } public static void main(String[] args) throws Exception { Stock stock=sku -> sku.equals("PEN")?4:0; System.out.println(stock.available("PEN")); }}Expected output:
4The application can exercise a port without a server or database.
Common mistakes
Do not add a queue, distributed lock or cache merely to demonstrate a tool. Never let a user-supplied tenant field stand in for an authenticated identity.
Practice
Implement a Quantity record bounded from 1 through 100. Print 100 and reject 101.
Expected output:
100rejectedCompare with the manual review criteria.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Capstone requirements and architecture — knowledge check
Java enterprise capstone reasoning.
Two concurrent requests reserve the last available item. Which invariant must the catalog preserve?
Which tenant identifies a resource owner?
Why choose a modular monolith here?
When add asynchronous jobs?
What does a port isolate?