These walkthroughs map directly to the production code so you can jump from
“what happens?” to “where is it implemented?” without chasing Slack threads.
Authenticated API call
Request enters Hono
server.ts applies hono/logger, CORS, and the request-ID middleware before
your handler runs. The UUID is stored in c.get('requestId') and appended to
every successResponse/errorResponse.Authentication & context
auth0JwtMiddleware verifies the RS256 JWT using Auth0’s JWKS, looks up (or
auto-creates) the Mongo user via userRepository, and injects userId,
roles, permissions, and the raw payload into the request context. Routes
that accept anonymous traffic use optionalAuth0JwtMiddleware.Chat orchestration & memory
Conversation bootstrap
ChatOrchestrationService.processChat/processStreamingChat find or create
a conversation via ConversationRepository, persist the user message (plus
attachments), and schedule background title generation. When creating a new
conversation, the service automatically stores metadata including the
pre-prompt key (if used) and input type (text, file, or voice based
on whether attachments are present).Context hydration
The service resolves preprompts (
prePromptService), loads prior messages,
merges SuperMemory context via MemoryService, and stitches inline/remote
attachments using file-attachment.helper.ts. The resolved pre-prompt’s
masked value is injected into the conversation while the public key is
stored in the conversation document for analytics.LLM call + tracking
llmService fans out to the configured provider, Langfuse spans are emitted
(thanks to instrumentation.ts), and usageTrackingService increments the
user’s quota. Assistant messages are saved back through
MessageRepository, ensuring transcripts stay consistent with the
Conversations API.Retrieval-augmented answers
Query planning
The RAG controller receives the user query, normalizes filters, and calls
the query generator (
services/ai/services/query-generator.service.ts) to
determine intent and required tools.Vector + memory fetch
Depending on
ai.config.ts, the service queries Pinecone, SuperMemory, or
both. redisCache short-circuits hot lookups and stores serialized chunks
with TTLs.App launch bootstrap
Device handshake
/app/launch reads x-device-id, x-platform, and optional user hints,
then fetches the user/profile record if available.Context assembly
appController.launch merges profile data, onboarding state, usage limits,
social/system URLs, and cached feature flags so the mobile client knows what
to show.Preprompt + Langfuse sync
Authoring
CRUD endpoints under
/api/v1/preprompts/* write to Mongo with immutable
versions and optional public flags.Distribution
prePromptService resolves keys inside the chat orchestrator so each
conversation can pin a stable system prompt, while
src/shared/promptManager pushes updates to Langfuse.File attachments & uploads
Upload
/api/v1/files/upload validates MIME/size, stores the object in Google
Cloud Storage (when configured), and returns a signed reference ID.Attachment resolution
The chat service calls
resolveAttachmentsForUser to fetch metadata,
generate temporary download URLs, and hydrate the message payload before it
hits the LLM.Conversation sharing & analytics
Share creation
/api/v1/share/create stores a snapshot of selected messages plus
redaction metadata via ShareRepository.Public access
/api/v1/public/share/:slug validates the signed token from
share.config.ts, hydrates the sanitized transcript, and records view
analytics.Operational guardrails
startupConfigblocks boot when Mongo or Redis are unhealthy and prints a structured readiness report (also surfaced via/api/v1/health).usageTrackingServicerecords every chat/app launch to enforce free-tier thresholds—tie into it when adding new consumption surfaces.redisCache+redisOpsprovide a consistent way to memoize heavy queries, issue distributed locks, and expire counters.Langfusetracing is mandatory for AI changes; include prompt labels andrequestIdso traces connect back to logs.docs/cicdpipeline.mdxcovers the GitHub Actions workflows (Claim Dev,Deploy to Dev,Release Dev). Reference it whenever you add migrations or new secrets.