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.
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
The Server operates as an Express.js application with several key components:
- API Server: Provides HTTP and WebSocket endpoints for client communication
- 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.
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/prebuilds/
: Prebuild functionalitysrc/billing/
: Billing and subscription managementsrc/github/
,src/gitlab/
,src/bitbucket/
: SCM integrations
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 definitions- Various other Gitpod component APIs
- 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
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
The Server exposes multiple API endpoints:
- User API: User management, authentication, and preferences
- 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
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, permissions, and access controls.
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
- 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
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
- 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