How opsway-io/backend works
Project type and purpose
• This is a Go-based monorepo for the “opsway” backend. It exposes a REST API (cmd/api.go), a probe runner (cmd/prober.go), and CLI commands (cmd/seed.go, etc.) for data seeding.
• Purpose: manage uptime monitoring (“probes”), incidents, maintenance windows, reporting, teams/users, billing, authentication, and notifications.
File structure
• Top-level executables under cmd/: API server, probe runner, CLI seeds.
• internal/: core business logic, broken out by domain (authentication, billing, changelog, check, incident, maintenance, monitor, report, team, user).
• internal/connectors/: database/queue clients for Postgres, ClickHouse, Redis.
• internal/rest/: HTTP layer—controllers, handlers, middleware.
• internal/notification/email/: email-templating and senders.
• internal/probes/http/: HTTP probe asserters.
• internal/event/: event publishing service.
• internal/storage/: object storage abstraction.
• Configuration and Docker artefacts in root (Dockerfile, docker-compose.yaml, .github/workflows/).
Extract key architecture insights from README
• Entirely dockerized, hot-reloaded Go code, automatic migrations.
• External dependencies spun up via Docker-Compose (Postgres, Redis, ClickHouse, SendGrid or SMTP).
Main components & interactions
a. Components
1. API Server (REST)
2. Probe Runner (background worker)
3. CLI Seeder
4. Domain Services (Authentication, Billing, Monitor, Incident, etc.)
5. Repositories / Connectors (Postgres, ClickHouse, Redis)
6. Event Bus / Publisher
7. Notification Service (Email via Console or SendGrid)
8. Object Storage (S3-compatible or similar)
9. External Clients: Users → HTTP(S), SMTP/SendGrid
10. Docker-Compose network
b. Relationships & data flow
• User → HTTP REST API → Controllers → Handlers → Services → Repositories → Databases
• Services publish domain events to Event Bus → Event Service subscribers (e.g., Notification)
• Probe Runner reads monitor definitions from DB → executes checks via internal/probes → writes results to ClickHouse (for metrics) and Postgres (for status) → may trigger incidents/events
• Notification Service subscribes to events → renders templates → sends emails via SMTP/SendGrid
• Object Storage used by API for avatars or report exports
• CLI Seeder writes seed data directly to DB via repositories
c. Architectural patterns & principles
• Layered (Controller → Service → Repository → Connector)
• Domain-driven: each domain has its own package under internal/
• Single binary for API, separate binary for worker (prober)
• Event-driven notifications
• Infrastructure as code via Docker Compose
d. Technologies & frameworks
• Go modules, Gin or standard net/http (in internal/rest/server.go)
• PostgreSQL (primary OLTP)
• ClickHouse (time-series metrics storage)
• Redis (caching, locks, rate limits)
• SendGrid or SMTP for email
• Docker, Docker Compose, GitHub Actions
2. Inside the API Server block, subdivide into: REST Controllers, Handlers, Service Layer, Repositories, Connectors.
3. Inside the Probe Runner block, show Monitor definitions → Probe Engine → Results → Storage (ClickHouse & Postgres)
4. Event Bus between Service Layer and Notification Service.
5. Notification Service rendering templates and sending via SMTP/SendGrid.
6. Technologies at each boundary (e.g., “Postgres via internal/connectors/postgres/client.go”).