Server Component
Overview
The Server is a central component in Gitpod that serves as the main backend service, handling API requests, authentication, user management, workspace operations, and integration with various source code management systems. It acts as the core orchestrator for the Gitpod platform, connecting various components and providing a unified API for clients.
Purpose
The primary purposes of the Server component are:
Provide API endpoints for client applications (dashboard, IDE, CLI)
Handle user authentication and session management
Manage user accounts and preferences
Coordinate workspace creation and management
Integrate with source code management systems (GitHub, GitLab, Bitbucket)
Process webhooks for prebuilds and other automated operations
Manage billing and subscription information
Provide real-time communication via WebSockets
Coordinate with other Gitpod components
Architecture
The Server operates as an Express.js application with several key components:
API Server: Provides HTTP and WebSocket endpoints for client communication. It also directly hosts and implements
gitpod.v1
gRPC services (defined in.proto
files withincomponents/public-api/
) for programmatic access.Authentication System: Handles user authentication and session management
Database Interface: Interacts with the database for persistent storage
WebSocket Manager: Manages real-time communication with clients
SCM Integrations: Connects with GitHub, GitLab, Bitbucket, and other platforms
Workspace Coordinator: Manages workspace lifecycle in coordination with ws-manager
Monitoring Endpoints: Provides health checks and metrics
The server is designed as a modular application using dependency injection (Inversify) to manage components and their dependencies.
Key Files and Structure
main.ts
: Entry point that initializes the container and starts the serverinit.ts
: Handles server initialization and setupserver.ts
: Core server implementationsrc/api/
: API endpoints and handlerssrc/auth/
: Authentication and authorizationsrc/workspace/
: Workspace managementsrc/user/
: User managementsrc/orgs/
: Organization managementsrc/prebuilds/
: Prebuild functionalitysrc/billing/
: Billing and subscription managementsrc/github/
,src/gitlab/
,src/bitbucket/
: SCM integrations
Dependencies
Internal Dependencies
components/gitpod-db
: Database access layercomponents/gitpod-protocol
: Shared protocol definitionscomponents/content-service-api
: Content service API definitionscomponents/ws-manager-api
: Workspace manager API definitionscomponents/image-builder-api
: Image builder API definitionsVarious other Gitpod component APIs
External Dependencies
Express.js for HTTP server
WebSocket for real-time communication
Inversify for dependency injection
TypeORM for database access
Redis for caching and pub/sub
Prometheus for metrics
Various SCM platform SDKs
Configuration
The Server is configured via environment variables and configuration files, including:
Server address and port
Database connection details
Authentication providers
SCM integration settings
Feature flags
Monitoring and logging settings
API Services
The Server exposes multiple API endpoints:
User API: User management, authentication, and preferences
Organization API: Handles organization creation, settings, member management, and administrative functions like maintenance mode.
Workspace API: Workspace creation, management, and access
SCM Integration APIs: GitHub, GitLab, Bitbucket webhooks and OAuth
Billing API: Subscription and payment management
WebSocket API: Real-time communication with clients
Health and Metrics API: System health and monitoring
Authentication and Authorization
The Server supports multiple authentication methods:
Session-based Authentication: For web clients
Bearer Token Authentication: For API access
OAuth Integration: With GitHub, GitLab, Bitbucket, etc.
Personal Access Tokens: For programmatic access
Authorization is handled through a combination of user roles and permissions, leveraging SpiceDB for fine-grained access control checks within its service implementations (including for gRPC services).
Integration Points
The Server integrates with:
Database: For persistent storage
Redis: For caching and pub/sub messaging
Workspace Manager: For workspace lifecycle management
Image Builder: For custom workspace images
Content Service: For workspace content management
SCM Platforms: For repository access and webhooks
Payment Providers: For billing and subscriptions
Security Considerations
Implements CSRF protection for WebSocket connections
Handles authentication and session management securely
Validates and sanitizes user input
Implements proper error handling and logging
Uses HTTPS for secure communication
Manages sensitive data securely
Uses
safeFragmentRedirect()
for all HTTP redirects to prevent OAuth token inheritance attacks
Common Usage Patterns
The Server is typically used to:
Handle API requests from the dashboard and IDE
Process authentication and session management
Coordinate workspace creation and management
Handle webhooks from SCM platforms
Manage user accounts and preferences
Process billing and subscription information
Related Components
Dashboard: Frontend interface that communicates with the server
Workspace Manager: Manages workspace instances
Content Service: Manages workspace content
Image Builder: Builds custom workspace images
Database: Stores persistent data
IDE Service: Provides IDE configuration