# hrtsegv/flagship architecture

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

- Interactive diagram: https://gitdiagram.com/hrtsegv/flagship
- Repository: https://github.com/hrtsegv/flagship

## Overview

Flagship is a self-hosted feature-flag control plane plus a Go SDK. The main workflow is project → environment → boolean-flag management over HTTP, followed by SDK configuration recovery and live synchronization; applications evaluate flags locally. The server wires use-case services to PostgreSQL, with in-memory repositories also available. The README documents broader roadmap capabilities, including targeting, rollouts, audit history, authentication, and a dashboard, but these are not implemented in the sampled source. Evidence for SDK behavior and some unsampled integrations is limited to README statements.

Main entry points: [`internal/httpapi/server.go`](https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/server.go) (HTTP API), [`sync.go`](https://github.com/hrtsegv/flagship/blob/main/sync.go) (Stream synchronization), [`internal/app/flag_service.go`](https://github.com/hrtsegv/flagship/blob/main/internal/app/flag_service.go) (Flag and configuration use cases), [`internal/postgres`](https://github.com/hrtsegv/flagship/tree/main/internal/postgres) (PostgreSQL repositories)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Control plane"]
  node_http["HTTP API<br/>[server.go]"]
  node_project_handlers["Project routes"]
  node_environment_handlers["Environment routes"]
  node_flag_handlers["Flag and sync routes<br/>[flag_handlers.go]"]
  node_health["Health probes<br/>[health.go]"]
  node_server["Server assembly<br/>[main.go]"]
  node_sse["SSE transport<br/>[sse.go]"]
end

subgraph group_usecases["Management services"]
  node_project_service["Project management<br/>[project_service.go]"]
  node_environment_service["Environment management"]
  node_flag_service["Flag and configuration use cases<br/>[flag_service.go]"]
  node_domain["Domain model and validation<br/>[validation.go]"]
end

subgraph group_storage["Persistence"]
  node_postgres["PostgreSQL repositories"]
  node_memory["In-memory repositories"]
end

subgraph group_sdk["Go SDK"]
  node_client["Local flag client<br/>[client.go]"]
  node_snapshot["Versioned snapshot<br/>[snapshot.go]"]
  node_fetch["Snapshot recovery<br/>[fetch.go]"]
  node_sync["Stream synchronization<br/>[sync.go]"]
  node_events["Configuration events<br/>[event.go]"]
  node_backoff["Reconnect backoff<br/>[backoff.go]"]
end

node_team(("Team / operator"))
node_application(("Application"))
node_database[("PostgreSQL")]

node_team -->|"manages resources"| node_http
node_http -->|"routes requests"| node_project_handlers
node_http -->|"routes requests"| node_environment_handlers
node_http -->|"routes requests"| node_flag_handlers
node_http -->|"routes probes"| node_health
node_project_handlers -->|"calls"| node_project_service
node_environment_handlers -->|"calls"| node_environment_service
node_flag_handlers -->|"calls"| node_flag_service
node_project_service -->|"validates"| node_domain
node_environment_service -->|"validates"| node_domain
node_flag_service -->|"validates"| node_domain
node_server -->|"constructs"| node_http
node_server -->|"configures repositories"| node_postgres
node_server -->|"connects"| node_database
node_project_service -->|"stores projects"| node_postgres
node_environment_service -->|"stores environments"| node_postgres
node_flag_service -->|"stores flags and events"| node_postgres
node_flag_service -.->|"uses repository interface"| node_memory
node_application -->|"evaluates flags"| node_client
node_client -->|"reads configuration"| node_snapshot
node_client -->|"applies updates"| node_events
node_application -->|"starts sync"| node_sync
node_sync -->|"connects to stream"| node_sse
node_sync -->|"recovers snapshot"| node_fetch
node_fetch -->|"installs snapshot"| node_snapshot
node_sync -->|"applies stream events"| node_events
node_sync -->|"retries with"| node_backoff
node_sse -->|"serves event stream"| node_flag_handlers

click node_http "https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/server.go"
click node_project_handlers "https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/project_handlers.go"
click node_environment_handlers "https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/environment_handlers.go"
click node_flag_handlers "https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/flag_handlers.go"
click node_health "https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/health.go"
click node_project_service "https://github.com/hrtsegv/flagship/blob/main/internal/app/project_service.go"
click node_environment_service "https://github.com/hrtsegv/flagship/blob/main/internal/app/environment_service.go"
click node_flag_service "https://github.com/hrtsegv/flagship/blob/main/internal/app/flag_service.go"
click node_domain "https://github.com/hrtsegv/flagship/blob/main/internal/domain/validation.go"
click node_postgres "https://github.com/hrtsegv/flagship/tree/main/internal/postgres"
click node_memory "https://github.com/hrtsegv/flagship/tree/main/internal/memory"
click node_server "https://github.com/hrtsegv/flagship/blob/main/cmd/flagship/main.go"
click node_client "https://github.com/hrtsegv/flagship/blob/main/client.go"
click node_snapshot "https://github.com/hrtsegv/flagship/blob/main/snapshot.go"
click node_fetch "https://github.com/hrtsegv/flagship/blob/main/fetch.go"
click node_sync "https://github.com/hrtsegv/flagship/blob/main/sync.go"
click node_sse "https://github.com/hrtsegv/flagship/blob/main/sse.go"
click node_events "https://github.com/hrtsegv/flagship/blob/main/event.go"
click node_backoff "https://github.com/hrtsegv/flagship/blob/main/backoff.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_http,node_project_handlers,node_environment_handlers,node_flag_handlers,node_health,node_server,node_sse toneBlue
class node_project_service,node_environment_service,node_flag_service,node_domain,node_database toneAmber
class node_postgres,node_memory toneMint
class node_client,node_snapshot,node_fetch,node_sync,node_events,node_backoff toneRose
class node_team,node_application toneIndigo
```

## Components

### Control plane

- [HTTP API](https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/server.go): `internal/httpapi/server.go`
- [Project routes](https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/project_handlers.go): `internal/httpapi/project_handlers.go`
- [Environment routes](https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/environment_handlers.go): `internal/httpapi/environment_handlers.go`
- [Flag and sync routes](https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/flag_handlers.go): `internal/httpapi/flag_handlers.go`
- [Health probes](https://github.com/hrtsegv/flagship/blob/main/internal/httpapi/health.go): `internal/httpapi/health.go`
- [Server assembly](https://github.com/hrtsegv/flagship/blob/main/cmd/flagship/main.go): `cmd/flagship/main.go`
- [SSE transport](https://github.com/hrtsegv/flagship/blob/main/sse.go): `sse.go`

### Management services

- [Project management](https://github.com/hrtsegv/flagship/blob/main/internal/app/project_service.go): `internal/app/project_service.go`
- [Environment management](https://github.com/hrtsegv/flagship/blob/main/internal/app/environment_service.go): `internal/app/environment_service.go`
- [Flag and configuration use cases](https://github.com/hrtsegv/flagship/blob/main/internal/app/flag_service.go): `internal/app/flag_service.go`
- [Domain model and validation](https://github.com/hrtsegv/flagship/blob/main/internal/domain/validation.go): `internal/domain/validation.go`

### Persistence

- [PostgreSQL repositories](https://github.com/hrtsegv/flagship/tree/main/internal/postgres): `internal/postgres`
- [In-memory repositories](https://github.com/hrtsegv/flagship/tree/main/internal/memory): `internal/memory`

### Go SDK

- [Local flag client](https://github.com/hrtsegv/flagship/blob/main/client.go): `client.go`
- [Versioned snapshot](https://github.com/hrtsegv/flagship/blob/main/snapshot.go): `snapshot.go`
- [Snapshot recovery](https://github.com/hrtsegv/flagship/blob/main/fetch.go): `fetch.go`
- [Stream synchronization](https://github.com/hrtsegv/flagship/blob/main/sync.go): `sync.go`
- [Configuration events](https://github.com/hrtsegv/flagship/blob/main/event.go): `event.go`
- [Reconnect backoff](https://github.com/hrtsegv/flagship/blob/main/backoff.go): `backoff.go`

### Other components

- **Team / operator**
- **Application**
- **PostgreSQL**

## Connections

- Team / operator → HTTP API: manages resources (evidence: `README.md`)
- HTTP API → Project routes: routes requests (evidence: `internal/httpapi/server.go`)
- HTTP API → Environment routes: routes requests (evidence: `internal/httpapi/server.go`)
- HTTP API → Flag and sync routes: routes requests (evidence: `internal/httpapi/server.go`)
- HTTP API → Health probes: routes probes (evidence: `internal/httpapi/server.go`)
- Project routes → Project management: calls (evidence: `internal/httpapi/project_handlers.go`)
- Environment routes → Environment management: calls (evidence: `internal/httpapi/environment_handlers.go`)
- Flag and sync routes → Flag and configuration use cases: calls (evidence: `internal/httpapi/flag_handlers.go`)
- Project management → Domain model and validation: validates (evidence: `internal/app/project_service.go`)
- Environment management → Domain model and validation: validates (evidence: `internal/app/environment_service.go`)
- Flag and configuration use cases → Domain model and validation: validates (evidence: `internal/app/flag_service.go`)
- Server assembly → HTTP API: constructs (evidence: `cmd/flagship/main.go`)
- Server assembly → PostgreSQL repositories: configures repositories (evidence: `cmd/flagship/main.go`)
- Server assembly → PostgreSQL: connects (evidence: `cmd/flagship/main.go`)
- Project management → PostgreSQL repositories: stores projects
- Environment management → PostgreSQL repositories: stores environments
- Flag and configuration use cases → PostgreSQL repositories: stores flags and events
- Flag and configuration use cases → In-memory repositories: uses repository interface (evidence: `README.md`)
- Application → Local flag client: evaluates flags (evidence: `README.md`)
- Local flag client → Versioned snapshot: reads configuration (evidence: `README.md`)
- Local flag client → Configuration events: applies updates (evidence: `README.md`)
- Application → Stream synchronization: starts sync (evidence: `README.md`)
- Stream synchronization → SSE transport: connects to stream (evidence: `README.md`)
- Stream synchronization → Snapshot recovery: recovers snapshot (evidence: `README.md`)
- Snapshot recovery → Versioned snapshot: installs snapshot (evidence: `README.md`)
- Stream synchronization → Configuration events: applies stream events (evidence: `README.md`)
- Stream synchronization → Reconnect backoff: retries with (evidence: `README.md`)
- SSE transport → Flag and sync routes: serves event stream (evidence: `internal/httpapi/flag_handlers.go`)
