Skip to content

Conversation

hellosunghyun
Copy link

Summary

This PR completes the API-only mode implementation for Invidious, allowing it to be built and run without GUI/frontend components. This significantly reduces the binary size and dependencies, making it ideal for API-focused deployments.

Motivation

The API-only mode was partially implemented but had several missing pieces that prevented it from working correctly. This PR fills those gaps and ensures the API-only build works seamlessly.

Changes

  • Added conditional compilation flags ({% if flag?(:api_only) %}) throughout the codebase to exclude frontend-specific code
  • Created stub implementations for database operations in API-only mode (DummyDB, VideoNotification, etc.)
  • Updated Docker configurations to support API-only builds with proper build arguments
  • Refactored require statements into a dedicated requires.cr file for better modularity
  • Fixed route handlers to work correctly without frontend dependencies
  • Added proper error handling for API-only mode

How to use

Using Crystal directly:

crystal build src/invidious.cr -Dapi_only --release

Using Make:

make API_ONLY=1

Using Docker:

# For AMD64
docker build --build-arg release=1 --build-arg api_only=1 -t invidious-api-only .

# For ARM64
docker build --platform linux/arm64 --build-arg release=1 --build-arg api_only=1 -f docker/Dockerfile.arm64 -t invidious-api-only:arm64 .

Benefits

  • Reduced binary size: The API-only binary is significantly smaller without frontend assets and dependencies
  • Lower resource usage: Less memory and CPU usage due to excluded frontend components
  • Faster startup: Quicker initialization without frontend-related setup
  • Microservice friendly: Perfect for API-only deployments in microservice architectures
  • Container optimization: Smaller Docker images for cloud deployments

Testing

  • Built and tested API-only mode on both AMD64 and ARM64 architectures
  • Verified all API endpoints work correctly without frontend dependencies
  • Confirmed database stubs work as expected in API-only mode
  • Tested Docker builds with the new build arguments

Breaking changes

None. This change is fully backward compatible. The default build still includes all frontend components.

This commit completes the API-only mode feature that allows Invidious to be built and run without GUI/frontend components, significantly reducing the binary size and dependencies.

Changes include:
- Add conditional compilation flags throughout the codebase to exclude frontend-specific code
- Create stub implementations for database operations in API-only mode
- Update Docker configurations to support API-only builds
- Refactor require statements for better modularity
- Add DummyDB and stub types for API-only mode
- Ensure all routes work correctly without frontend dependencies

The API-only mode can be enabled by:
- Using -Dapi_only flag during compilation
- Setting API_ONLY=1 when using make
- Using --build-arg api_only=1 with Docker builds

This is particularly useful for:
- Microservice architectures where only the API is needed
- Reducing resource usage in containerized environments
- Creating lightweight API servers for mobile/desktop applications
@SamantazFox
Copy link
Member

SamantazFox commented Aug 4, 2025

What you propose here is much more than an "API only" mode. It's a whole "no database" and "no users" mode. Be aware that the API-only mode is meant to be a clipious/freetube backend (primarily a cloud account server) rather than a pure content proxy (for scrapping, yt-dlp might be more adapted).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants