DEV Community

Cover image for How a Request Travels Through the ClassroomIO Public API
Hamzat Abdul-muizz
Hamzat Abdul-muizz

Posted on

How a Request Travels Through the ClassroomIO Public API

ClassroomIO is an LMS for companies that train people on their product: their customers, their partners and their own staff. It answers one question: how do I spend less time and money teaching customers how to use what I sell?

Think of a solar company teaching installers to fit and maintain its panels, a travel-tech company certifying agents on its booking system, or a hardware company that onboards every new customer with the same course instead of a live call. None of them are education companies, but education is part of what they sell.

This post is a technical walk-through of one part of ClassroomIO: the public API. If you'd rather skip the jargon, the help center shows how to use ClassroomIO without writing code.

What ClassroomIO is built with

ClassroomIO is open source, written in TypeScript and runs on Node.js. It's a monorepo: one repository that holds every app and the code they share, managed with pnpm workspaces and Turborepo.

  • apps/ holds what runs: the API server (built with Hono), the dashboard, the website, the docs, the help center and the jobs app for background work.
  • packages/ holds shared code: db (schema and queries, with Drizzle), core (business rules), utils (validation), mcp (our MCP server), email and more.

Behind the server sit Postgres for data, Redis for rate limits and caching, and S3-compatible storage for files (SeaweedFS when you self-host).

The API is a layered monolith: one server, where every request goes through a route, then a service, then a database query. The dashboard talks to it through Hono's typed RPC client. The dashboard, the public API and MCP all share the same services and queries underneath.

A request's journey

Take GET /public-api/v1/courses with an Authorization: Bearer cio_… header. Before any course code runs, it passes a chain of checks, and any of them can stop it:

  1. Mount. The server sends anything under /public-api/v1 to the public API router.
  2. CORS. Decides which websites a browser may call it from.
  3. Failed-login limiter. Slows down anyone guessing keys.
  4. Who are you? An API key is hashed and looked up; an OAuth token (how Claude connects through MCP) is checked against what the user approved. Neither: 401.
  5. What may you do? The route needs a scope, like course:read. No matching scope: 403. A route with no scope at all is refused too; that's called default deny.
  6. Rate limit per key. 100 requests a minute, then 429.
  7. MCP credits. Calls from AI tools use credits from the plan.
  8. Route. The input is checked against a schema; bad input gets a 400.
  9. Service. The same code the dashboard uses. It also checks the course belongs to your organization, so nobody can read another company's course by guessing its id.
  10. Response. The same { success, data } shape on every endpoint.

Step 5 in code. Each path maps to one scope, and a key passes with that scope or with the all-access public_api:*:

if (COHORT_PATH.test(path)) {
  return isRead ? 'cohort:read' : 'cohort:write';
}

const allowed =
  organizationApiKeyHasScopes(keyScopes, ['public_api:*']) ||
  (routeScope !== null && organizationApiKeyHasScopes(keyScopes, [routeScope]));
Enter fullscreen mode Exit fullscreen mode

That routeScope !== null is the default deny: a route nobody mapped needs the all-access key.

What surprised me

All of this lives in one file, routes/v1/index.ts: a simple chain of middleware. I expected a separate system for the public API. There isn't one. It's the same server and the same services as the dashboard. What changes is the path, and what each path trusts.

export const v1Router = new Hono()
  .use('*', publicApiCors)
  .use('*', createAuthenticationFailureRateLimiter({ /* … */ }))
  .use('*', automationKeyOrOAuthMiddleware)
  .use('*', publicApiScopesMiddleware)
  .use('*', createRateLimiter({ /* … */ }))
  .use('*', v1McpUsageMiddleware)
  .route('/courses', v1CoursesRouter)
  // … one .route() per resource
Enter fullscreen mode Exit fullscreen mode

Dashboard routes trust a login cookie, so their CORS only lets ClassroomIO's own sites (and verified custom domains) send that cookie from a browser. /public-api/v1 and /mcp allow any website, because they never use cookies: every call brings its own key or token, and the checks above decide what it can do. CORS on its own doesn't keep anyone out; it stops another website from using your logged-in browser against you. The key and scope checks are what protect the API.

// /public-api: any website, no cookies (/mcp has its own, the same way)
export const publicApiCors = cors({ ...sharedCorsOptions, origin: '*', credentials: false });

// dashboard routes: only trusted origins, cookies allowed
export const sessionCors = cors({
  ...sharedCorsOptions,
  origin: (origin) => resolveTrustedBrowserOriginForCors(origin),
  credentials: true
});
Enter fullscreen mode Exit fullscreen mode

Wrapping up

The public API is a thin front door on the same house: checks for who you are, what you may do and whose data you touch, then the same code the dashboard runs. A fix in one place reaches the dashboard, the API and MCP together.

Want to try it? Start with the API docs. Next week: the server itself, and how app.ts puts it all together.

If you're interested in learning more about how ClassroomIO helps you run training for your company or organization, check out classroomio.com/help.

If you found this helpful, don't forget to drop a like or a comment. See you in the next one!

Top comments (0)