Building the foundation Claudi... Note

Building the foundation Claudius runs on

This article details the server-side setup for a Claude-based chatbot named Claudius, focusing on its identity system, service connectivity, and deployment realities. The identity system ensures that user roles, such as admin, member, or guest, are determined solely on the server and cannot be manipulated by the client. This is achieved using Auth.js with the Google provider and a MongoDB adapter, where roles are resolved based on admin email, an allowlist, or defaulting to guest. The resolved role is then embedded in a JWT for efficient access within the application. The provisioning process also sets default values for user-specific fields and ensures the role is recomputed each sign-in.Connectivity is validated through a health check route that pings MongoDB Atlas and, optionally, makes a small call to Bedrock's Claude Haiku model. This probe verifies that the application can successfully interact with its AI backend and token usage metadata is returned. The application also defines a catalog of AI models with their respective inference profile IDs and pricing information. Environment variables are validated iteratively as needed for each development phase, with the current set including authentication, database, and Bedrock credentials.Several critical issues, or "gotchas," were encountered and resolved during this setup phase. A significant problem involved ensuring the correct database was targeted by both the Auth.js adapter and the application's database helper, as a missing database path in the connection string defaulted to an inaccessible "test" database. Connection pooling was optimized by caching the MongoDB client globally. Dependency management within a monorepo required careful attention to runtime dependencies and the inclusion of platform-specific binaries in optional dependencies for deployment. The foundation for user identity and service interaction is now established, although the core chat functionality is yet to be implemented.