Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

matquest's avatar

Deciding Where To Place Reusable Code

I'm keeping track of photographs stored in Amazon S3 buckets. I have a Photo model that allows for storing information like which product style and color the photos belong to, dimensions, display order etc.

I'm having a hard time deciding where to put some of the re-usable code for storing new photos. When storing a new photo, I create a bunch of different sized versions of it and store each of them on S3 with the appropriate local Photo object stored for each. Normally I'd just place this in the controller that accepts the photo upload request but photos can also be created from commands that run on a schedule, getting data from external api's.

So if I have this photo (uploaded file or url) that needs to be resized and have many versions stored on s3 and tracked locally, where would I put this method that could be called from both a controller and command? I almost created a repository class for Photos and put it in there but that didn't feel right to me, it also didn't seem like a good "helper" method... I feel like I'm missing a key part of the architecture here as I really don't know where it should go, where would you guys put it?

Thanks in advance for any input/insights you may have.

0 likes
2 replies
martinbean's avatar
Level 80

@matquest Creating thumbnails is a “task”, so I’d dispatch a job whenever a Photo model instance is created, whether that be from the web or the command line.

matquest's avatar

@martinbean Interesting, I wasn't looking at it that way. I'll probably create a model for full/original size photos that get stored on aws glacier and then have a job that creates all the size variations, sends them off to s3 and stores the data for them in a regular photo model. Thanks for the input, I was starting to suffer from analysis paralysis on this.

Please or to participate in this conversation.