Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:ALwrity ALwrity initialize onboarding

From Leeroopedia
Knowledge Sources
Domains Onboarding, API
Last Updated 2026-10-24 00:00 GMT

Overview

Concrete tool for initialising and reconciling a user's onboarding session state provided by the ALwrity backend.

Description

The initialize_onboarding endpoint is the first call a frontend makes when a user enters the ALwrity onboarding flow. It reads the authenticated Clerk user, loads the existing onboarding session from the per-user SQLite database via OnboardingProgressService, reconciles completion flags against the actual artefacts present in the database, and returns a structured payload describing the 6-step onboarding state. If all required artefacts (API keys, website analysis, research preferences, persona) exist but the session was not marked complete, the function performs a one-time reconciliation that marks onboarding complete.

Usage

Import this endpoint when:

  • A user first lands on the onboarding page and the frontend needs to know which step to show.
  • A returning user resumes onboarding and the frontend must determine the next incomplete step.
  • A frontend reconciliation pass needs to confirm onboarding completion from existing artefacts.

Code Reference

Source Location

  • Repository: ALwrity
  • File: backend/api/onboarding_utils/endpoints_core.py (re-exported via backend/api/onboarding_endpoints.py)

Signature

async def initialize_onboarding(
    current_user: Dict[str, Any] = Depends(get_current_user),
) -> Dict[str, Any]:
    """
    Initialize or resume a user's onboarding session.

    Args:
        current_user: Authenticated Clerk user payload (id, email, clerk_user_id).

    Returns:
        Dict with 'user', 'onboarding' (steps, current_step, completion_percentage,
        next_step, is_completed), and 'session' metadata.

    Raises:
        HTTPException 401: User not authenticated.
        HTTPException 500: Failed to initialize onboarding.
    """

Import

from api.onboarding_endpoints import initialize_onboarding

I/O Contract

Inputs

Name Type Required Description
current_user Dict[str, Any] Yes Clerk JWT payload injected by auth middleware

Outputs

Name Type Description
return Dict[str, Any] Nested dict: user info, onboarding state (6 steps with status), session metadata
side effect DB Reconciles onboarding completion if all artefacts present

Usage Examples

FastAPI route registration

from fastapi import APIRouter, Depends
from api.onboarding_endpoints import initialize_onboarding
from middleware.auth_middleware import get_current_user

router = APIRouter(prefix="/onboarding")

@router.get("/initialize")
async def init_endpoint(user: dict = Depends(get_current_user)):
    return await initialize_onboarding(user)

Returned payload shape

{
    "user": {"id": "clerk_user_123", "email": "user@example.com"},
    "onboarding": {
        "is_completed": False,
        "current_step": 3,
        "completion_percentage": 33.3,
        "next_step": 3,
        "steps": [
            {"step_number": 1, "status": "completed", ...},
            {"step_number": 2, "status": "completed", ...},
            {"step_number": 3, "status": "pending", ...},
        ],
    },
    "session": {"session_id": "clerk_user_123", ...},
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment