core

πŸ“˜ Core Service – Devex Cloud IDE Backend

The core/ service is the main backend API server responsible for:
  • β€’Handling GitHub OAuth2.0 login
  • β€’Managing REPL sessions and their lifecycles
  • β€’Creating & deleting Kubernetes workloads for REPLs
  • β€’Interacting with S3 and Redis
It is written in Go and designed as a lightweight API service for managing REPL infrastructure.

You can Checkout how this server is deployed at DEPLOYMENT.

πŸ“ Directory Structure

PathDescription
cmd/Entry point, route definitions, middleware
internal/k8s/Kubernetes resource creation and cleanup
internal/s3/S3 file operations
internal/redis/Redis store logic
services/auth/githubGitHub OAuth2.0 login handler
services/repl/REPL session routes and logic
models/Shared data structures for REPLs and Auth
pkg/Utilities like JSON and env file loading

🌐 API Endpoints

POST /auth/github

Handles GitHub OAuth2.0 login. After successful login, the user session is managed via cookies or JWT.

POST /api/repl/... (Protected Route)

These routes require a valid authenticated user session.

Protected via Middleware

The middleware verifies the user's session using cookies or headers, and passes the request if authenticated.

🧠 Core Concepts

πŸ—ƒοΈ S3 – Code Storage

All REPL files are stored in S3 under:

username/repl-id/

On REPL creation:
  • β€’A folder is created
  • β€’Template files are copied from the /templates directory
Code Reference: internal/s3/s3.go

☸️ Kubernetes – Dynamic REPLs

When a REPL is started, the backend dynamically creates:
  1. β€’A Deployment
  2. β€’A Service
  3. β€’An Ingress
These allow the user to access their running REPL via:

[https://repl.parthkapoor.me/repl-id/](https://repl.parthkapoor.me/repl-id/)<subpath>

REPL Creation Logic

  • β€’Files are pulled from S3 via an InitContainer
  • β€’The main container (Runner) connects to frontend over WebSocket
πŸ“ Code:

REPL Deletion Logic

When a REPL session ends:
  • β€’An ephemeral container is injected into the pod
  • β€’Files are pushed back to S3
  • β€’The Deployment, Service, and Ingress are deleted
πŸ“ Code:

πŸ’Ύ Redis – In-memory Session State

We use Redis as a lightweight store to manage:
  • β€’activeSession:{replId} β†’ user’s active REPL session
  • β€’userRepls:{userId} β†’ all REPL IDs owned by the user
  • β€’replMeta:{replId} β†’ metadata like name, template, etc.
No traditional SQL DB is needed as:
  • β€’User data comes directly from GitHub
  • β€’Code is stored in S3
πŸ“ Redis Store Logic: internal/redis/store.go

πŸ”§ Internal Utilities

PathPurpose
cmd/api/api.goSets up the routes and API server
cmd/middleware/middleware.goMiddleware for session protection
models/repl.goREPL struct used across the app
pkg/dotenv/env.goLoads environment variables
pkg/json/json.goJSON encoder/decoder helpers

πŸ§ͺ Sample Flow

  1. β€’User logs in via /auth/github
  2. β€’Frontend calls /api/repl/create with template + name
  3. β€’Backend:
    • β€’Creates S3 folder and copies template files
    • β€’Creates K8s Deployment + Service + Ingress
    • β€’Returns access path
  4. β€’User writes code, interacts via WebSocket
  5. β€’On close:
    • β€’Ephemeral container syncs files β†’ S3
    • β€’K8s resources cleaned up

πŸ“¦ Future Improvements

  • β€’Add metrics and logging
  • β€’Add support for multiple languages and templates
  • β€’Optional: move metadata from Redis to Postgres

🧭 Next Docs

πŸ‘‰ Want to understand how the REPL container works? Check out the runner/ docs.
Need help setting up the cluster? Head to k8s/.