A robust GraphQL API built with Go for real-time collaborative drawing applications. This backend powers the collab-draw platform, handling workspace management, project persistence, and live synchronization using GraphQL subscriptions.
- Language: Go 1.25+
- GraphQL Engine: gqlgen
- Database: MongoDB (via official mongo-driver/v2)
- Authentication: Clerk (Clerk SDK for Go)
- Real-time: Gorilla WebSockets for GraphQL Subscriptions
- Router: Chi
graph/: GraphQL schema definitions (.graphqls) and generated code.resolvers/: Implementation of GraphQL queries, mutations, and subscriptions.
internal/: Core business logic and infrastructure.auth/: Clerk middleware for session verification.db/: MongoDB connection management.models/: BSON-tagged Go structs for database entities.repository/: Data access layer (Repository Pattern) for Projects and Workspaces.
server.go: Application entry point and server configuration.
- Go 1.25 or higher
- MongoDB instance (local or Atlas)
- Clerk account and API keys
Create a .env file in the root directory:
PORT=8080
MONGO_URI=mongodb://localhost:27017
DATABASE_NAME=collab-draw
CLERK_SECRET_KEY=sk_test_...-
Install dependencies:
go mod download
-
Run the server:
go run server.go
The GraphQL playground will be available at http://localhost:8080/.
The backend uses GraphQL Subscriptions to sync drawing elements across clients.
- Mutation:
updateProjectupdates the drawing state in MongoDB and broadcasts to subscribers. - Subscription:
project(id: ID!)allows clients to receive live updates.
For more details, see SUBSCRIPTION_GUIDE.md.
All requests (except the playground in dev mode) require a valid Clerk session token passed in the Authorization header:
Authorization: Bearer <your_session_token>