The Digital Darkroom (Part 1): Architecting for Memories
Designing a system that treats your photos as precious artifacts using Spring Modulith.
The Moment
There is a certain magic to photography. The way light hits the sensor, the decision to press the shutter, the anticipation of seeing the result. In the analog world, this magic continues in the darkroom. The smell of chemicals, the dim red light, the meticulous process of developing a print.
But in the digital age? Our photos are dumped into /DCIM/100ND850 and forgotten. We scroll past them. We lose them in the cloud.
I wanted to bring the reverence of the darkroom back. To build a Digital Darkroom that treats every file as a memory to be curated, analyzed, and preserved.
The Experiment
I've been building Spring applications for years, usually defaulting to the classic "Layered Architecture" (Controller -> Service -> Repository). It works, but it inevitably turns into a "Big Ball of Mud" where everything depends on everything else.
For this project, a photo management system with AI integration, I wanted something different. I wanted the strict boundaries of microservices without the operational nightmare of managing 15 Docker containers for a simple app.
Enter Spring Modulith.
The Setup: Defining the Domain
The goal was simple regarding requirements but complex in execution:
- Ingestion Module: Watch a folder, detect new images, and shout "New File!" to the rest of the system.
- Image Module: Hear that shout, grab the file, extract EXIF data, and save it.
- Classification Module: New Image!! Lets extract details with a vision model.
- Publishing Module: Lets make a story and publish it to the web.
In a standard monolith, it becomes easy to have the god class with tightly couple services. But Modulith forces you to think cleanly without splitting the project into endless maven modules.
The Power of internal
The first thing I really liked is the internal concept which is enforced by Modulith. By structuring my packages like this:
my.digital.darkroom
├── ingestion
│ ├── FileIngestedEvent (public)
│ └── internal
│ └── FileWatcherService
└── image
├── Image (public entity)
└── internal
├── ImageRepository
└── ImageIngestionListener
I physically cannot accidentally use ImageRepository inside the ingestion module. The tests fail which helps enforce decoupling. This may feel restrictive at first, but its power quickly becomes apparent in the age of AI. I don't have to worry about side effects because the API surface area is small deliberate and enforceable and helps prevent AI code sprawl.
The Learning Curve: Events & Transactions
The steepest part of the journey wasn't learning a new API, but the fundamental shift in how I defined transactional boundaries. In a traditional monolith, the default is often a single, sweeping @Transactional block that spans multiple domains. Modulith challenges this by treating module interactions as first-class architectural citizens rather than mere method calls.
By leveraging @ApplicationModuleListener and the Event Publication Registry, you are forced to design for eventual consistency even within a single JVM. This decouples the lifecycle of an ingestion event from the lifecycle of metadata extraction. It ensures that the "Ingestion" module remains focused and resilient; a failure in the "Classification" module shouldn't cause the entire process to roll back. This architectural discipline turns the application into a collection of predictable, high-integrity components that communicate through well-defined, persistent events, ensuring that the system remains robust as it grows.
Testing in Isolation
In a standard Spring Boot application, integration tests often require loading the entire application context or managing a fragile web of mocks. This makes tests slow and brittle and painful to maintain.
Spring Modulith's @ApplicationModuleTest changes this by bootstrapping only the module under test. When I test the image module, I don't need to mock the ingestion service or the classification engine. I simply publish a FileIngestedEvent and verify the module's internal state.
@ApplicationModuleTest
class ImageModuleTests {
@Test
fun `listens to file ingestion and persists image`(scenario: Scenario) {
scenario.publish(FileIngestedEvent("path/to/file.jpg", "TEST"))
.andWaitForStateChange { imageRepository.count() }
.andVerify { count -> count > 0 }
}
}
This isolation makes it easy to test scenarios specific to the module's responsibility without the overhead of the rest of the system. It turns integration testing into something that feels as lightweight as unit testing, but with the confidence of a real database and event flow.
Developing the Future
Just like a print slowly appearing in the tray, our system is coming into focus. We have ingestion working. Metadata is extracted. The foundation is laid.
But the real magic is next. We will integrate AI vision models to "see" the photos, to describe the scene, the mood, the subjects. To turn a file named IMG_9823.JPG into "Sunset over the mountains, with a hint of melancholy."
Stay tuned. The red light is on.