I am working on a program in golang, which I am sructuring based on Hexagonal Architecture. I think I have my head wrapped mostly around the idea, but there is something I just can't figure out.
The function of the program is to monitor multiple IP cameras for alarm events, which a receiver can receive a live stream of alarm events over a HTTP2.0 PUSH REQUEST. (Just in-case thats not the technical term, my service establishes a TCP/HTTP connection from a GET request and keeps it open, and when the cameras triggers an alarm event, the camera pushes it back to the services)
Layers of Architecture
Adaptors
- HTTP Handler
- In-memory JSON Store
Ports
- DeviceService Interface
- EventService Interface
- DeviceRepo Interface
- EventRepo Interface
Services
- DeviceService
- EventService
Domain
- DeviceDomain
- EventDomain
The user adds a device to the system via API, the request includes the desired monitoring schedule (When the receiver should start and stop daily) and url.
A scheduler is responsible to periodically checking if a receiver is meant to be started based on its schedule. If it's meant to be running for a device it starts a receiver for that device.
The receiver establishes connection to the IP camera and loops over the alarm event stream processing the alarm events and passing them to the EventService.
The EventService receives the event, and is responsible for handling the event, based on the domain logic, and decides to send an email or ignore it. It also saves all events to the eventrepo.
The two parts of code i'm not sure where they sit is the scheduler and receiver. So should they be; a. Both in the same package and placed at the Adaptors layer b. The receiver in the Adaptors layer and the scheduler in the Service layer c. Both scheduler and receivers in the Service layer?
I am just confused, as the receiver isn't started by the user directly, but started by a running loop which continually checks a condition. But I also might have different receivers for different brands of cameras. Which is an implementation detail, which means the receiver should be in the Adaptors layer. Which makes me think option b is best.
I'm possibly over thinking it, but let me know what you all think the best option is or suggest a better one.