Repository Structure and Application Foundation

A repository organized by business capability, why a modular monolith comes first, the engineering standards to agree early, and a reproducible local environment.

  • Advanced
  • About 14 minutes
  • Includes an exercise and a knowledge check

The concept Structure by capability, not by layer

A project structure should make responsibilities easy to find. Many applications start with four folders: controllers, services, repositories and models. As they grow, business rules scatter across all four, and one change to payments touches every folder. A better structure follows business capabilities and the architecture’s boundaries.

On the left, a photo of a workshop pegboard where every tool hangs in its own place. In the middle, packaging by layer: controllers, services, repositories and models folders, so payments are spread over four folders and rules leak into controllers. On the right, packaging by capability: payment, settlement, reconciliation, exception case, audit, security and shared, with payment holding api, application, domain and infrastructure. Everything about payments lives in the payment folder.
A place for every tool. Everything about payments lives in the payment folder.

textA starting repository structure for Apex

apex-reconciliation/
├── backend/
│   ├── src/main/java/com/apex/reconciliation/
│   │   ├── payment/          api/ application/ domain/ infrastructure/
│   │   ├── settlement/       api/ application/ domain/ infrastructure/
│   │   ├── reconciliation/   application/ domain/ infrastructure/
│   │   ├── exceptioncase/    api/ application/ domain/ infrastructure/
│   │   ├── audit/
│   │   ├── security/
│   │   └── shared/
│   ├── src/main/resources/
│   │   ├── db/migration/
│   │   └── application.yml
│   └── src/test/
├── frontend/
│   └── src/
│       ├── features/         dashboard/ payments/ reconciliation/ exceptions/ audit/
│       ├── components/
│       ├── api/
│       └── types/
├── infrastructure/           local/ aws/
├── docs/                     architecture/ adr/ api/ operations/
└── README.md

This is a starting structure, not a universal standard. Inside each capability, api holds the HTTP boundary, application the workflows, domain the business rules and infrastructure the database and messaging code. The domain depends on nothing outside itself.

Decision A modular monolith first

Start with one modular Spring Boot application. Apex has not shown a need for independently deployed services for every capability. A modular monolith gives clear business boundaries, easy local development, simple database transactions, low operational overhead and faster first delivery. Separate a service later, when workload, scaling, team ownership or reliability needs justify it, as Module 06 recorded in its ADR.

Agree early Engineering standards

StandardAn example decision for Apex
Java and Spring Boot versionsA current long-term-support Java release and a supported Spring Boot line, pinned in the build file
Dependency managementOne build file with versions managed in one place
FormattingOne formatter, enforced in the build
Error response formaterrorCode, message and correlationId, for every error
LoggingStructured JSON logs with correlation IDs; never secrets or raw payloads
Test namingNamed after the business behavior, for example rejectsSameTransactionIdWithDifferentAmount
Database migrationsNumbered, reviewed migration files; never hand edits in shared databases
API versioning/api/v1 in the path; additive changes only within a version
Configuration and secretsProfiles per environment; secrets from a secret store, never from Git

Reproducible The local development environment

Another engineer should be able to clone the repository, follow the README and run everything without configuring a cloud account: the Spring Boot backend, PostgreSQL, the message broker or a local substitute, the React development server and the test tools. A container compose file usually starts the infrastructure with one command. Add a health endpoint on day one (Spring Boot Actuator provides liveness and readiness checks) so every environment can prove it is up.

Practice Establish the foundation

Practical exercise

Exercise 02: a reproducible development environment

Set up the project so a new engineer is productive on day one.

  1. Create the backend and frontend projects.
  2. Start PostgreSQL locally and add configuration profiles.
  3. Set up database migrations.
  4. Write a README with startup instructions.
  5. Add a health endpoint and one command that runs all tests.
Show a sample README checklist
  • Prerequisites: a Java LTS JDK, Node LTS, a container runtime.
  • Start infrastructure: one compose command starts PostgreSQL and the broker.
  • Run backend: the build tool’s run command with the local profile; migrations run on startup.
  • Check: GET /actuator/health returns UP.
  • Run all tests: one command; integration tests use a real PostgreSQL container.

2 questions

Check your understanding

1. What is the main advantage of a modular monolith for the first Apex version?
2. Where should the matching rules live?
Answer every question to submit.

What you can do now

  • Structure a repository by business capability.
  • Justify a modular monolith and keep its boundaries enforced.
  • List the engineering standards to agree early.
  • Make the local environment reproducible.