Take control over your live stream video by running it yourself. Streaming + chat out of the box.
Owncast AI Agent Instructions
This is the single source of truth for agent instructions in this repository. CLAUDE.md and .github/copilot-instructions.md point here.
Owncast is a self-hosted live streaming server: a Go backend plus a React/Next.js frontend. One frontend project builds two apps, the public viewer page and the admin at /admin, and the Go binary serves both. The backend exposes internal APIs for those apps plus a documented public API that third-party clients depend on.
Quick Reference
| Task | Command |
|---|---|
| Build backend | go build -o owncast . |
| Run backend | go run main.go |
| Run frontend dev server | cd web && npm run dev |
| Run Go tests | go test ./... |
| Run JS tests | cd web && npm test |
| Lint Go | make lint |
| Format Go | make fmt |
| Lint JS/CSS | cd web && npm run lint |
| Format JS/CSS | cd web && npm run format |
| Typecheck frontend | cd web && npm run typecheck |
| Full web CI check | cd web && npm run check |
| Build Storybook | cd web && npm run build-storybook |
| Generate API code | make api-generate |
| Generate DB code | make sqlc |
| Install dev tools | make install-tools |
| Install git hooks | make install-hooks |
| Start test stream | ./test/ocTestStream.sh |
Working Agreements
- Commit messages follow Conventional Commits (
type(scope): summary). Thecommit-msghook rejects anything else. Allowed types:build,chore,ci,docs,feat,fix,perf,refactor,revert,style,test. - No emoji in code, comments, or commit messages.
- Run
make install-hooksonce and lefthook covers the pre-commit gate: gofumpt, golangci-lint, eslint, prettier, stylelint, knip, and the Go and JS tests. Without hooks, runmake fmt,make lint, andcd web && npm run lint && npm run formatby hand before committing. developis the development branch and moves fast (automated bundle and translation commits land often); rebase before pushing.masteris the release branch.
Development Flow
- Backend:
go build -o owncast .,go test ./...,make lint. - Frontend:
cd web && npm run typecheckfor fast feedback.npm run checkis the full CI-equivalent gate (lint, format, typecheck, knip, tests, build). - Never copy frontend build output into
static/web/and never commit that directory. It is generated during release builds; local development uses the dev server. - UI work: components stay standalone and reusable with a story beside them, and
npm run build-storybookmust keep passing. Pattern guide:web/components/_COMPONENT_HOW_TO.md. - APIs: edit
openapi.yamlfirst, then runmake api-generate(wrapsbuild/gen-api.sh, which needsnpm install -g @redocly/cli). It regenerateswebserver/handlers/generated/; never hand-edit generated files, implement the stubs inwebserver/handlers/. - Database: schema changes are new numbered goose migrations in
persistence/migrations/, and a migration that has shipped is never edited. Queries live indb/query.sql; runmake sqlcafter changing either, and don't hand-write SQL in Go. Adding a migration also means updating the pinned assertions inpersistence/migrations/migrations_test.go. Walkthrough:db/README.md. - Tests: Go tests beside the code, JS unit tests via
npm test, API integration tests intest/automated/api/, browser flows intest/automated/browser/. Other suites live undertest/automated/(activitypub/,auth/,hls/,plugins/,upgrades/).
Testing the Web Frontend
Run the backend and the frontend dev server together: go run main.go in the repo root, cd web && npm run dev, then use http://localhost:3000.
Do not test against http://localhost:8080. That serves the web bundle embedded in the binary at compile time, not your working tree, so changes appear to have no effect.
./test/ocTestStream.sh starts a real stream against the local server when live-stream state is needed. Admin dev credentials are admin / abc123 over HTTP Basic Auth; the admin UI is at /admin.
Repository Structure
- Root of the repo: Go source for the backend.
web/: the React frontend (viewer page, admin, embeds).static/web/: generated web bundle. Never edit or commit it.test/automated/: integration, browser, and protocol test suites.build/: build and code generation scripts.docs/: internal design and reference docs (backend.md,plugins.md,product-definition.md,Release.md).
Backend Structure
main.go: entry point and composition root. Initializes logging, database, config, core services, and metrics, then constructs every migrated service fromservices/and injects them into the HTTP router and other consumers. See "Service migration pattern" below.webserver/router/: Chi (v5) HTTP router with HTTP/2 support. Routes under/api/,/api/admin/, federation endpoints,/hls/, and/ws.webserver/handlers/: request handlers for web, admin, static files, HLS, moderation, auth.webserver/handlers/generated/: auto-generated API types and Chi server stubs from the OpenAPI spec. Do not hand-edit.webserver/router/middleware/: authentication (RequireAdminAuth()for admin endpoints via HTTP Basic Auth) and ActivityPub content negotiation.persistence/: repository implementations (config, user, chat message, webhook, auth, federated servers, notifications) plus goose migrations. All database access goes through these.db/: sqlc-generated type-safe database code. Queries indb/query.sql; the schema comes from the migrations, there is noschema.sql. Runmake sqlcafter changes.services/: constructor-injected services (stream, chat, transcoder, storage, rtmp, activitypub, plugins, webhooks, notifications, geoip, cache, datastore, dispatcher).services/activitypub/: federation (controllers, inbox/outbox, HTTP signatures, WebFinger, NodeInfo, delivery queue).pluginhost/: plugin host surface (auth gates, chat bots, plugin events, per-plugin SQLite storage insqlite.go) on top ofservices/plugins/.models/: shared data models.config/: defaults and constants.auth/: IndieAuth and Fediverse chat auth.yp/: directory registration.utils/,logging/,metrics/,notifications/: supporting packages.tools/: separatego.modfor dev tool pins, installed to./bin/.
Service migration pattern
Owncast is being moved off package-level singletons toward constructor-injected services. New code and migrated services follow these rules:
A migrated service lives in
services/<domain>/and exposesNew(Deps) *Service. Services with a lifecycle also exposeStart(ctx) error/Stop(ctx) error. The package has no package-level state and noGet()(or equivalent) accessor.main.gois the composition root. It's the only place that callsservices/*.New(...). Other code receives services via constructor injection. New deps appear in aDepsstruct on each service or consumer.Existing
<pkg>.Get()accessors (inpersistence/) are deprecated and exist only until their callers migrate. New code never callsGet(). PRs may reduceGet()callers; PRs must not add them.
When a service publishes events to multiple listeners, model the listeners as injected interfaces (type StreamLifecycleListener interface { ... }) and iterate them in the publisher. Don't introduce a generic event bus; explicit calls make stack traces, grep, and tests work the way the rest of the codebase expects.
services/cache/ is the reference shape for a service, and the *Handlers struct in webserver/handlers/handlers.go is the reference pattern for consumers of injected services.
Frontend Structure
web/pages/: Next.js pages router with static export (viewer,admin/,embed/).web/components/: React components by domain (admin/,chat/,common/,layouts/,modals/,ui/,video/,action-buttons/,theme/).web/components/stores/: jotai state and the client config/status stores.web/components/theme/: Ant Design token theming (AntdProvider.tsx).web/interfaces/: TypeScript interfaces.web/i18n/: localization files (next-export-i18n).web/style-definitions/: design token definitions.
Key Technical Details
- Go version: see
go.mod(currently 1.26). - Database: SQLite, single file, no external DB server.
- Frontend: Next.js 16 (pages router, static export), React 18, TypeScript.
- UI library: Ant Design v6. Tokens are themed in
web/components/theme/AntdProvider.tsxand component CSS is pre-extracted toweb/styles/antd.cssvianpm run antd:extract. - State management: jotai.
- Styling: SCSS with component-scoped files.
- API spec: OpenAPI 3.1 in
openapi.yaml. - Go linting: golangci-lint with cyclop (max complexity 15), dupl (threshold 200), gosec, gocritic, forbidigo (no
fmt.Print*,print,println, orpanic), and others. Full config in.golangci.yml. - JS linting: ESLint with airbnb config, Prettier, Stylelint, and knip for unused code detection.
- CI: GitHub Actions for Go tests, JS lint/test, browser tests, Storybook builds, Chromatic visual regression, CodeQL.
- Makefile: common tasks for building, testing, linting, code generation, and installing dev tools and hooks.
make helplists them.
Guidelines
- All user-facing UI strings must be localizable. Prefer the
Translationcomponent because it carries default text; usenext-export-i18n'st()only for strings built at runtime. Test with?lang=de(untranslated strings won't visibly change, but previously translated ones must not regress). Reference: https://docs.owncast.dev/web-translations web/i18n/*/translation.jsonfiles are tab-indented and outside prettier's config. Add keys with a tab-preserving edit; running prettier on them rewrites the entire file.- UI components use Ant Design v6. When you use an antd component that isn't already in the build, add it to the manifest in
web/build-scripts/extract-antd-styles.jsand runnpm run antd:extract. - All database access goes through the
persistence/repositories. - Substantial Federation or ActivityPub changes must be reflected in
FEDERATION.md, which documents only the peer-visible protocol contract, not internal implementation. - Public API changes (config, status, HLS, directory, auth, payload shapes) affect downstream native clients (
owncast/owncasts-ios,owncast/roku). Call that out in the PR.
Pull Requests
- UI changes: include before and after screenshots, plus the Chromatic Storybook link from the PR's Chromatic job.
- API changes: include before and after example responses.
- Backend changes: include before and after log output demonstrating the change.
- Take screenshots from Storybook for standalone components (hide unrelated controls), or from the dev server at
http://localhost:3000for anything that isn't in Storybook, which is most of the admin. Embed them inline in the PR, not as attachments. - Keep screenshot scripts and images in
/tmp. Never commit them.
References
- Operator documentation: https://owncast.online/docs/
- Component library and design docs (Storybook): https://owncast.online/components
- Development guide: https://docs.owncast.dev/development
- Frontend component guide:
web/components/_COMPONENT_HOW_TO.mdand https://docs.owncast.dev/develop-frontend-components - API and web routing: https://docs.owncast.dev/api-web-routing
- Contributor guide: https://docs.owncast.dev/contributor-guide
- Public API reference: https://owncast.online/docs/api/ (the spec of record is
openapi.yaml) - Federation protocol:
FEDERATION.md - Database workflow:
db/README.md