# davidsugianto/sentinel-incident architecture

> Architecture diagram of the GitHub repository davidsugianto/sentinel-incident, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/davidsugianto/sentinel-incident
- Repository: https://github.com/davidsugianto/sentinel-incident

## Overview

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: [`cmd/http/server.go`](https://github.com/davidsugianto/sentinel-incident/blob/master/cmd/http/server.go) (Server), [`internal/usecase/incident`](https://github.com/davidsugianto/sentinel-incident/tree/master/internal/usecase/incident) (Incidents), [`internal/handler/http`](https://github.com/davidsugianto/sentinel-incident/tree/master/internal/handler/http) (Routes), [`internal/usecase/oncall`](https://github.com/davidsugianto/sentinel-incident/tree/master/internal/usecase/oncall) (On-call)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_cmd["Entry point"]
  node_n_main(("Main<br/>bootstrap<br/>[main.go]"))
  node_n_server["Server<br/>composition root<br/>[server.go]"]
end

subgraph group_grp_http["HTTP boundary"]
  node_n_routes["Routes<br/>HTTP handlers"]
  node_n_mw["Middleware<br/>HTTP cross-cutting"]
  node_n_resp["Responses<br/>response formatting<br/>[response.go]"]
end

subgraph group_grp_usecase["Business logic"]
  node_n_inc_usecase["Incidents<br/>usecase orchestration"]
  node_n_oncall_usecase["On-call<br/>usecase workflow"]
end

subgraph group_grp_repo["Integrations"]
  node_n_inc_repo[("Incident store<br/>DB repository")]
  node_n_alert_repo["Alerts<br/>notification adapter"]
  node_n_oncall_repo["PagerDuty<br/>external adapter"]
end

subgraph group_grp_model["Domain models"]
  node_n_inc_model["Incident<br/>domain model<br/>[type.go]"]
  node_n_alert_model["Alert<br/>domain model<br/>[type.go]"]
  node_n_oncall_model["On-call<br/>domain model<br/>[type.go]"]
  node_n_team_model["Team<br/>domain model<br/>[type.go]"]
end

subgraph group_grp_pkg["Shared infra"]
  node_n_config["Config<br/>settings loader<br/>[config.go]"]
  node_n_db[("Database<br/>postgres + migrate<br/>[db.go]")]
  node_n_logger["Logger<br/>structured logging<br/>[logger.go]"]
  node_n_slack["Slack client<br/>platform client<br/>[client.go]"]
  node_n_lark["Lark client<br/>platform client<br/>[client.go]"]
  node_n_pd["PagerDuty client<br/>platform client<br/>[client.go]"]
end

node_n_main -->|"launches"| node_n_server
node_n_server -->|"loads"| node_n_config
node_n_server -->|"initializes"| node_n_logger
node_n_server -->|"connects"| node_n_db
node_n_server -->|"wires"| node_n_routes
node_n_server -->|"adds"| node_n_mw
node_n_server -->|"uses"| node_n_resp
node_n_routes -->|"passes through"| node_n_mw
node_n_routes -->|"formats"| node_n_resp
node_n_routes -->|"calls"| node_n_inc_usecase
node_n_routes -->|"calls"| node_n_oncall_usecase
node_n_inc_usecase -->|"persists"| node_n_inc_repo
node_n_inc_usecase -->|"notifies"| node_n_alert_repo
node_n_inc_usecase -->|"escalates"| node_n_oncall_repo
node_n_oncall_usecase -->|"queries"| node_n_oncall_repo
node_n_alert_repo -->|"uses"| node_n_slack
node_n_alert_repo -->|"uses"| node_n_lark
node_n_oncall_repo -->|"uses"| node_n_pd
node_n_inc_repo -->|"uses"| node_n_db
node_n_inc_usecase -->|"shares"| node_n_inc_model
node_n_inc_usecase -->|"shares"| node_n_alert_model
node_n_inc_usecase -->|"shares"| node_n_oncall_model
node_n_oncall_usecase -->|"shares"| node_n_oncall_model
node_n_oncall_usecase -->|"shares"| node_n_team_model
node_n_routes -->|"binds"| node_n_inc_model

click node_n_main "https://github.com/davidsugianto/sentinel-incident/blob/master/cmd/http/main.go"
click node_n_server "https://github.com/davidsugianto/sentinel-incident/blob/master/cmd/http/server.go"
click node_n_routes "https://github.com/davidsugianto/sentinel-incident/tree/master/internal/handler/http"
click node_n_mw "https://github.com/davidsugianto/sentinel-incident/tree/master/internal/handler/http/middleware"
click node_n_resp "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/response/response.go"
click node_n_inc_usecase "https://github.com/davidsugianto/sentinel-incident/tree/master/internal/usecase/incident"
click node_n_oncall_usecase "https://github.com/davidsugianto/sentinel-incident/tree/master/internal/usecase/oncall"
click node_n_inc_repo "https://github.com/davidsugianto/sentinel-incident/tree/master/internal/repository/incident"
click node_n_alert_repo "https://github.com/davidsugianto/sentinel-incident/tree/master/internal/repository/alert"
click node_n_oncall_repo "https://github.com/davidsugianto/sentinel-incident/tree/master/internal/repository/oncall"
click node_n_inc_model "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/model/incident/type.go"
click node_n_alert_model "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/model/alert/type.go"
click node_n_oncall_model "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/model/oncall/type.go"
click node_n_team_model "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/model/team/type.go"
click node_n_config "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/config/config.go"
click node_n_db "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/db/db.go"
click node_n_logger "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/logger/logger.go"
click node_n_slack "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/slack/client.go"
click node_n_lark "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/lark/client.go"
click node_n_pd "https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/pagerduty/client.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_main,node_n_server toneBlue
class node_n_routes,node_n_mw,node_n_resp toneAmber
class node_n_inc_usecase,node_n_oncall_usecase toneMint
class node_n_inc_repo,node_n_alert_repo,node_n_oncall_repo toneRose
class node_n_inc_model,node_n_alert_model,node_n_oncall_model,node_n_team_model toneIndigo
class node_n_config,node_n_db,node_n_logger,node_n_slack,node_n_lark,node_n_pd toneTeal
```

## Components

### Entry point

Process bootstrap and server composition.

- [Main](https://github.com/davidsugianto/sentinel-incident/blob/master/cmd/http/main.go): bootstrap · Starts the service process and delegates wiring to the server composition root. · `cmd/http/main.go`
- [Server](https://github.com/davidsugianto/sentinel-incident/blob/master/cmd/http/server.go): composition root · Builds the app, loads config, initializes dependencies, and starts Gin. · `cmd/http/server.go`

### HTTP boundary

Gin routes, middleware, and response shaping.

- [Routes](https://github.com/davidsugianto/sentinel-incident/tree/master/internal/handler/http): HTTP handlers · Exposes the API endpoints for ping and incident creation. · `internal/handler/http`
- [Middleware](https://github.com/davidsugianto/sentinel-incident/tree/master/internal/handler/http/middleware): HTTP cross-cutting · Request ID, structured logging, and auth around incoming requests. · `internal/handler/http/middleware`
- [Responses](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/response/response.go): response formatting · Standardizes HTTP response payloads and error handling. · `internal/pkg/response/response.go`

### Business logic

Incident and on-call orchestration.

- [Incidents](https://github.com/davidsugianto/sentinel-incident/tree/master/internal/usecase/incident): usecase orchestration · Coordinates incident creation, validation, persistence, and notifications. · `internal/usecase/incident`
- [On-call](https://github.com/davidsugianto/sentinel-incident/tree/master/internal/usecase/oncall): usecase workflow · Handles on-call related business flows and lookup/escalation coordination. · `internal/usecase/oncall`

### Integrations

Persistence and external service adapters.

- [Incident store](https://github.com/davidsugianto/sentinel-incident/tree/master/internal/repository/incident): DB repository · Persists incident state in PostgreSQL through the shared DB package. · `internal/repository/incident`
- [Alerts](https://github.com/davidsugianto/sentinel-incident/tree/master/internal/repository/alert): notification adapter · Sends outbound alerts through Slack and Lark integrations. · `internal/repository/alert`
- [PagerDuty](https://github.com/davidsugianto/sentinel-incident/tree/master/internal/repository/oncall): external adapter · Integrates with PagerDuty for on-call access and escalation data. · `internal/repository/oncall`

### Domain models

Shared business entities and type definitions.

- [Incident](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/model/incident/type.go): domain model · Incident entity and related shared types. · `internal/model/incident/type.go`
- [Alert](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/model/alert/type.go): domain model · Alert entity and message shape shared across layers. · `internal/model/alert/type.go`
- [On-call](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/model/oncall/type.go): domain model · On-call entity and escalation-related types. · `internal/model/oncall/type.go`
- [Team](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/model/team/type.go): domain model · Team entity shared by the incident and on-call flows. · `internal/model/team/type.go`

### Shared infra

Configuration, logging, DB, and provider clients.

- [Config](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/config/config.go): settings loader · Loads YAML configuration with environment overrides. · `internal/pkg/config/config.go`
- [Database](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/db/db.go): postgres + migrate · Manages PostgreSQL connectivity and migrations. · `internal/pkg/db/db.go`
- [Logger](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/logger/logger.go): structured logging · Centralized logging setup used across the service. · `internal/pkg/logger/logger.go`
- [Slack client](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/slack/client.go): platform client · Slack API client used by alerting integrations. · `internal/pkg/slack/client.go`
- [Lark client](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/lark/client.go): platform client · Lark API client used by alerting integrations. · `internal/pkg/lark/client.go`
- [PagerDuty client](https://github.com/davidsugianto/sentinel-incident/blob/master/internal/pkg/pagerduty/client.go): platform client · PagerDuty API client used by on-call integrations. · `internal/pkg/pagerduty/client.go`

## Connections

- 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.
