How davidsugianto/sentinel-incident works
1. System shape
- This is a Go-based HTTP incident-management service.
- The architecture is layered: cmd/http bootstraps the app, internal/handler/http exposes endpoints, internal/usecase contains business rules, and internal/repository integrates with storage and external services.
2. Entry point and wiring
- cmd/http/main.go and server.go are the composition root.
- They load config, initialize logging, database access, and route handlers, then start the Gin server.
- The init.go files under repositories/usecases/handlers suggest constructor-style dependency wiring by package.
3. Request ingress and HTTP boundary
- All external interaction enters through Gin routes in internal/handler/http.
- The documented API is small: GET /v1/ping for health and POST /v1/incidents for incident creation.
- Responses are standardized through internal/pkg/response.
4. Middleware and cross-cutting concerns
- HTTP middleware includes request ID injection, structured logging, and auth.
- Auth appears JWT-based from the README/config structure.
- This layer handles request-scoped concerns before control reaches business logic.
5. Business logic layer
- internal/usecase/incident is the main orchestration layer.
- It likely coordinates incident creation, persistence, and outbound notifications.
- internal/usecase/oncall handles on-call related workflows, probably around escalation or lookup.
6. Persistence and external integration boundaries
- internal/repository/incident is the database-backed persistence layer, using the shared DB package.
- internal/repository/oncall is the PagerDuty integration boundary.
- internal/repository/alert is the outbound alerting boundary for Slack and Lark.
- These repositories isolate infrastructure concerns from use cases.
7. Data flow for incident creation
- A request hits the HTTP handler, passes middleware, and enters the incident usecase.
- The usecase validates/coordinates the incident workflow, persists incident state through the incident repository, and triggers alert/on-call integrations through the alert and oncall repositories.
- The response is returned back through the HTTP layer in a uniform format.
8. Domain model boundaries
- Domain types are split by concern under internal/model: alert, incident, oncall, and team.
- These types define the shapes shared across handlers, use cases, and repositories, keeping the layers decoupled from transport and storage details.
9. Infrastructure and shared utilities
- internal/pkg/config loads YAML config with environment overrides.
- internal/pkg/db manages PostgreSQL connectivity and migrations.
- internal/pkg/logger centralizes structured logging.
- internal/pkg/slack, internal/pkg/lark, and internal/pkg/pagerduty are platform clients used by repositories.
10. Operational and development support
- The repo includes Docker, docker-compose, and Air hot-reload support for local development.
- Swagger/OpenAPI docs live under docs/, indicating the API surface is documented and likely intended for external consumption.
- CI is present via GitHub Actions, with Go tests and repository-local unit tests/mocks supporting the incident usecase and repositories.
Main entry points: server.go Server · incident Incidents · http Routes · oncall On-call
Components 20
Entry point
Process bootstrap and server composition.
HTTP boundary
Gin routes, middleware, and response shaping.
- Routes · Exposes the API endpoints for ping and incident creation.
internal/handler/http - Middleware · Request ID, structured logging, and auth around incoming requests.
internal/handler/http/middleware - Responses · Standardizes HTTP response payloads and error handling.
internal/pkg/response/response.go
Business logic
Incident and on-call orchestration.
Integrations
Persistence and external service adapters.
- Incident store · Persists incident state in PostgreSQL through the shared DB package.
internal/repository/incident - Alerts · Sends outbound alerts through Slack and Lark integrations.
internal/repository/alert - PagerDuty · Integrates with PagerDuty for on-call access and escalation data.
internal/repository/oncall
Domain models
Shared business entities and type definitions.
- Incident · Incident entity and related shared types.
internal/model/incident/type.go - Alert · Alert entity and message shape shared across layers.
internal/model/alert/type.go - On-call · On-call entity and escalation-related types.
internal/model/oncall/type.go - Team · Team entity shared by the incident and on-call flows.
internal/model/team/type.go
Shared infra
Configuration, logging, DB, and provider clients.
- Config · Loads YAML configuration with environment overrides.
internal/pkg/config/config.go - Database · Manages PostgreSQL connectivity and migrations.
internal/pkg/db/db.go - Logger · Centralized logging setup used across the service.
internal/pkg/logger/logger.go - Slack client · Slack API client used by alerting integrations.
internal/pkg/slack/client.go - Lark client · Lark API client used by alerting integrations.
internal/pkg/lark/client.go - PagerDuty client · PagerDuty API client used by on-call integrations.
internal/pkg/pagerduty/client.go
Connections 25
- Main → Server: launches · Main delegates application setup to the server composition root.
- Server → Config: loads · Configuration is loaded during startup.
- Server → Logger: initializes · Structured logging is configured before serving requests.
- Server → Database: connects · Server wiring creates database access and migrations.
- Server → Routes: wires · Handlers are assembled into the HTTP router.
- Server → Middleware: adds · Cross-cutting middleware is attached to the Gin stack.
- Server → Responses: uses · Server-level wiring relies on standardized response helpers.
- Routes → Middleware: passes through · Requests flow through auth, request ID, and logging middleware.
- Routes → Responses: formats · Handlers return responses via the shared response package.
- Routes → Incidents: calls · Incident creation requests are delegated to business logic.
- Routes → On-call: calls · On-call related endpoints delegate to on-call workflows.
- Incidents → Incident store: persists · Incident orchestration stores state through the incident repository.
- Incidents → Alerts: notifies · Incident workflow triggers outbound alerting.
- Incidents → PagerDuty: escalates · Incident workflow consults on-call integrations when needed.
- On-call → PagerDuty: queries · On-call business logic relies on PagerDuty-backed data.
- Alerts → Slack client: uses · Slack is one of the outbound alert channels.
- Alerts → Lark client: uses · Lark is one of the outbound alert channels.
- PagerDuty → PagerDuty client: uses · PagerDuty client powers on-call integration calls.
- Incident store → Database: uses · Incident persistence is backed by the shared database layer.
- Incidents → Incident: shares · Incident use cases operate on incident domain types.
- Incidents → Alert: shares · Incident orchestration exchanges alert domain types.
- Incidents → On-call: shares · Incident orchestration exchanges on-call domain types.
- On-call → On-call: shares · On-call workflows use on-call domain types.
- On-call → Team: shares · Team data is part of on-call and incident coordination.
- Routes → Incident: binds · HTTP layer maps incident payloads to domain models.