### Setting Up KlickerUZH Development Environment Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/CLAUDE.md This snippet provides essential commands to initialize the KlickerUZH development environment. It covers installing project dependencies, starting the full development stack with Doppler environment variables, and preparing production-like components such as the database, Redis, and reverse proxy. ```bash # Install dependencies pnpm install # Start development environment with Doppler environment variables pnpm dev # Start database, Redis, and reverse proxy only pnpm run dev:prepare-prod ``` -------------------------------- ### Project Setup Commands Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/analytics/README.md Essential commands for setting up the KlickerUZH Analytics project, covering dependency installation using Poetry and PNPM, Prisma schema synchronization, and explicit Python environment configuration. ```Shell poetry install ``` ```Shell pnpm install ``` ```Shell util/sync-schema.sh ``` ```Shell poetry env use /Users/.../bin/python ``` -------------------------------- ### Common Development Commands for Docusaurus Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/docs/CLAUDE.md These commands are used to manage the KlickerUZH documentation application, including installing dependencies, starting the development server, building for production, deploying, and serving the built site locally. ```bash # Install dependencies pnpm install # Start development server pnpm start # Build for production pnpm build # Deploy the docs site pnpm deploy # Serve the built site locally pnpm serve ``` -------------------------------- ### Frontend Management Application Development Commands (pnpm) Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/frontend-manage/CLAUDE.md This snippet provides a list of common 'pnpm' commands used for developing the KlickerUZH frontend-manage application. It covers essential operations such as installing dependencies, starting the development server (with an option for Doppler environment variables), building for production, performing type checks, linting, and starting the production server. These commands are fundamental for setting up and managing the development environment. ```bash # Install dependencies pnpm install # Start development server pnpm dev # Start with Doppler environment variables pnpm dev:doppler # Build for production pnpm build # Type checking pnpm check # Linting pnpm lint # Start production server pnpm start ``` -------------------------------- ### Development Workflow: Building and Running the Shared Components Package Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/shared-components/CLAUDE.md These commands outline the standard development workflow for the `shared-components` package. They cover installing project dependencies, starting a local development server with live CSS reloading, building the package for production, and performing type-checking. These steps are essential for local development and deployment preparation. ```bash # Install dependencies (from project root) pnpm install # Start development with live CSS reloading pnpm run dev # Build the package pnpm run build # Type-check the package pnpm run check ``` -------------------------------- ### Cypress Local Testing Environment Setup Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/cypress/CLAUDE.md This snippet provides command-line instructions for setting up and running Cypress tests locally. It covers installing project dependencies, opening the Cypress test runner for interactive development, and executing tests headlessly for continuous integration or batch runs. ```bash # Install dependencies cd cypress pnpm install # Open Cypress test runner pnpm cypress open # Run tests headlessly pnpm cypress run ``` -------------------------------- ### TypeScript JSDoc Function Documentation Example Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/CLAUDE.md An example demonstrating the required JSDoc comment structure for TypeScript functions, including descriptions for parameters and return values, ensuring clear API documentation. ```typescript /** * Brief summary. * * @param param1 - Description. * @returns Description. */ function example(param1: string): number { // implementation } ``` -------------------------------- ### Cypress User Workflow Test Example Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/cypress/CLAUDE.md This snippet demonstrates a typical Cypress test structure for a user workflow. It includes setup and cleanup using `before` and `after` hooks, data loading from fixtures with `beforeEach`, user login, performing actions, and asserting results using `data-cy` attributes and fixture data. ```typescript describe('User workflow', () => { before(() => cy.seed()) after(() => cy.cleanup()) beforeEach(function () { cy.fixture('fixture-name.json').then((data) => { this.data = data }) }) it('completes a workflow successfully', function () { // Login cy.loginLecturer() // Perform actions cy.get('[data-cy="element"]').click() // Assert results cy.get('[data-cy="result"]').should('contain', this.data.expectedValue) }) }) ``` -------------------------------- ### Install Node.js Dependencies Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/office-addin/README.md Installs all necessary Node.js packages for the KlickerUZH PowerPoint add-in. This command should be executed after cloning the repository to set up the project environment. ```sh npm install ``` -------------------------------- ### Python Function Docstring Example (Google Style) Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/CLAUDE.md This snippet demonstrates the recommended Google style for writing docstrings in Python functions. It includes sections for a brief summary, arguments (Args), and return types (Returns), ensuring clear and consistent documentation for functions. ```Python def example(): """ Brief summary. Args: param1 (type): Description. Returns: type: Description. """ ``` -------------------------------- ### Common Task: Implementing a New Feature Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/frontend-manage/CLAUDE.md Comprehensive guide for implementing a new feature, from planning component hierarchy and state management to GraphQL operations, UI development, custom hooks, validation, error handling, and cross-device testing. ```APIDOC 1. Plan the component hierarchy and state management approach 2. Create necessary GraphQL operations in the graphql package 3. Implement UI components in the appropriate directories 4. Create custom hooks for complex logic or data fetching 5. Add form validation if needed 6. Implement error handling and loading states 7. Test across different devices and scenarios ``` -------------------------------- ### Common Task: Adding a New Component Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/frontend-manage/CLAUDE.md Step-by-step guide for creating and integrating a new React component into the project, including prop typing, state management, internationalization, styling, and usage. ```APIDOC 1. Create a new component file in the appropriate feature directory 2. Define TypeScript interface for props 3. Implement the component with proper hooks and state management 4. Add internationalization using the messages from `@klicker-uzh/i18n` 5. Style using Tailwind classes 6. Import and use in parent components ``` -------------------------------- ### Common Task: Creating a New Page Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/frontend-manage/CLAUDE.md Instructions for adding a new page to the Next.js application, covering file structure, component imports, data fetching with Apollo Client or SWR, layout setup, and authentication/permissions. ```APIDOC 1. Add a new file in the `/src/pages/` directory following Next.js routing 2. Import necessary components and hooks 3. Implement data fetching using Apollo Client or SWR 4. Set up proper layouts and page structure 5. Handle authentication and permissions appropriately ``` -------------------------------- ### Start Development Server and Sideload Add-ins Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/office-addin/README.md Initiates the development server and automatically sideloads both KlickerUZH add-ins into PowerPoint. This command enables live development with auto-reloading of source code changes. ```sh npm run dev ``` -------------------------------- ### Building KlickerUZH for Production Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/CLAUDE.md This snippet contains commands for building the KlickerUZH project. It includes commands to build all packages and applications for a production release, as well as a specific command for building them for testing purposes, ensuring different build configurations are supported. ```bash # Build all packages and applications pnpm build # Build packages and applications for testing pnpm build:test ``` -------------------------------- ### TypeScript Examples for KlickerUZH Element Data Processing Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/util/CLAUDE.md These TypeScript examples illustrate the usage of core functions for handling and transforming element data within the KlickerUZH platform. They demonstrate how to convert raw database element objects into a frontend-ready format, and how to initialize data structures for new element instance results and statistics tracking, ensuring consistent data handling across the application. ```typescript // Transform a database element into frontend-ready data const elementData = processElementData(element) // Get initial results structure for a new element instance const results = getInitialInstanceResults(elementData) // Get initial statistics for a new element instance const statistics = getInitialInstanceStatistics(instanceType) ``` -------------------------------- ### Embed Microlearning Preparation Video Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/docs/docs/tutorials/microlearning.mdx This HTML snippet embeds a video tutorial from UZH MediaSpace, guiding users through the process of preparing a microlearning activity. It specifies the video source, dimensions, and various permissions for playback and interaction within the embedded frame. ```HTML ``` -------------------------------- ### Client-Side Response Validation Example Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/shared-components/CLAUDE.md Shows how to use a utility function for validating user responses based on the question type, typically used within component logic. ```tsx import { validateResponse } from '../utils/validateResponse' // In component const isValid = validateResponse(response, questionType) ``` -------------------------------- ### Managing KlickerUZH Database with Prisma Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/CLAUDE.md This snippet outlines commands for managing the KlickerUZH database using Prisma. It includes syncing the Prisma schema between packages, deploying schema changes to the database, browsing data with Prisma Studio, and creating new database migration files. ```bash # Sync Prisma schema between packages/prisma and apps/analytics ./util/sync-schema.sh # Deploy Prisma schema changes to the database pnpm run prisma:deploy # Run Prisma Studio to browse data pnpm run prisma:studio # Create a new Prisma migration pnpm run prisma:migrate ``` -------------------------------- ### Execute Database Schema Migration and Sync Commands Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/CLAUDE.md These commands are used to update the database schema after modifications to Prisma schema files. `pnpm run prisma:migrate` creates a new migration, and `./util/sync-schema.sh` synchronizes the schema across different packages. ```Shell pnpm run prisma:migrate ``` ```Shell ./util/sync-schema.sh ``` -------------------------------- ### Python Environment Setup and Module Imports Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/analytics/src/notebooks/aggregated_analytics.ipynb This code block sets up the Python environment by modifying the system path to allow module imports from a parent directory and imports all necessary libraries for database interaction, date manipulation, and the core analytics computation function. ```python import os import json from datetime import datetime from prisma import Prisma import pandas as pd # set the python path correctly for module imports to work import sys sys.path.append("../../") from src.modules.aggregated_analytics.compute_aggregated_analytics import ( compute_aggregated_analytics, ) ``` -------------------------------- ### TypeScript Examples for Recomputing Derived Permissions Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/util/CLAUDE.md These TypeScript code snippets demonstrate how to invoke the utility functions responsible for recomputing derived permissions within the KlickerUZH system. The examples show how to trigger a recomputation for a specific object (e.g., an element) or for a particular user's permissions on an element, typically after changes to direct permissions or object relationships. The `prisma` client is passed as a dependency for database operations. ```typescript // Recompute permissions for a specific object await recomputeDerivedPermissions({ elementId: 123 }, prisma) // Recompute permissions for a specific user on an object await recomputeElementPermissionsUser({ id: 123, userId: 'user-id' }, prisma) ``` -------------------------------- ### Managing KlickerUZH Releases Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/CLAUDE.md This snippet details commands for managing releases of the KlickerUZH project. It includes commands for creating standard releases, as well as specific commands for alpha, beta, and release candidate versions, facilitating a structured release process. ```bash # Create a new release pnpm release # Create an alpha release pnpm release:alpha # Create a beta release pnpm release:beta # Create a release candidate pnpm release:rc ``` -------------------------------- ### Configuring NextIntlClientProvider for i18n in Next.js Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/i18n/CLAUDE.md Shows the setup of `NextIntlClientProvider` in a Next.js application, integrating i18n messages, locale, and custom error handling functions for robust internationalization. ```typescript {/* Application content */} ``` -------------------------------- ### Implement Transactional Service Function Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/graphql/CLAUDE.md Example of an asynchronous service function demonstrating how to use a `PrismaTransactionContext` to ensure database operations are part of an atomic transaction. Operations performed via `ctx.prisma` will automatically be included in the transaction provided by the context. ```typescript export async function createObject( args: CreateObjectArgs, ctx: PrismaTransactionContext ): Promise { // Operations will be part of the transaction from the context return await ctx.prisma.object.create({ data: {...}, }) } ``` -------------------------------- ### Running KlickerUZH Tests Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/CLAUDE.md This snippet provides commands for executing tests within the KlickerUZH project. It covers running all tests, running tests in watch mode for continuous feedback during development, and specifically opening the Cypress E2E test runner for end-to-end testing. ```bash # Run all tests pnpm test:run # Run tests with watch mode pnpm test:watch # Run Cypress E2E tests cd cypress && pnpm cypress open ``` -------------------------------- ### Basic Markdown String Rendering Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/markdown/CLAUDE.md A simple example demonstrating the fundamental usage of the `Markdown` component. It takes a `markdownString` variable as its `content` prop, rendering the provided markdown directly into React components. This is the most straightforward way to integrate markdown content. ```tsx ``` -------------------------------- ### Extend Next.js Configuration with Custom Image Domains Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/next-config/CLAUDE.md Example of how to add custom image domains to the Next.js configuration while preserving the base image settings provided by `getNextBaseConfig`. It demonstrates spreading existing image domains and appending new ones to the `domains` array. ```javascript let nextConfig = { ...getNextBaseConfig({ BLOB_STORAGE_ACCOUNT_URL }), images: { ...getNextBaseConfig({ BLOB_STORAGE_ACCOUNT_URL }).images, domains: [ ...getNextBaseConfig({ BLOB_STORAGE_ACCOUNT_URL }).images.domains, 'custom-domain.com', ], }, } ``` -------------------------------- ### PNPM Service Management Commands Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/analytics/README.md A list of commands executable via PNPM to manage the KlickerUZH Analytics service. These commands facilitate Prisma client generation, running the main analytics service, and starting the service in development watch mode. ```Shell pnpm generate ``` ```Shell pnpm main ``` ```Shell pnpm dev ``` -------------------------------- ### Documenting JSON Fields in Prisma Models Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/prisma/CLAUDE.md This example illustrates the recommended practice for documenting JSON fields within Prisma models using JSDoc-style comments. This improves code readability and maintainability, especially for complex object structures, by providing inline documentation. ```TypeScript /// [PrismaElementOptions] ``` -------------------------------- ### Implement Object Activity Change Tracking System Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/CLAUDE.md This section describes the `object-changelog` branch's implementation of a change tracking system for application objects. It details the `ActivityLogEntry` model, its types (MESSAGE, MODIFICATION), polymorphic relations, and associated GraphQL operations for logging and retrieving changes. ```APIDOC ActivityLogEntry Model: - Types: MESSAGE, MODIFICATION - Relations: Polymorphic relations to elements, courses, quizzes, and other object types - Properties: message_content (string), user (string), timestamp (datetime) GraphQL Operations: - Retrieve activity log entries - Add activity log entries ``` -------------------------------- ### Cypress Component Functionality Test Example Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/cypress/CLAUDE.md This snippet illustrates a Cypress test focused on specific component functionality. It sets up the test environment by seeding data and navigating to a specific page, then performs actions on a component and asserts its existence. This structure is suitable for isolated component testing. ```typescript describe('Component functionality', () => { before(() => cy.seed()) after(() => cy.cleanup()) beforeEach(() => { cy.loginLecturer() cy.visit('/specific-page') }) it('performs specific function', () => { // Test specific functionality cy.get('[data-cy="component"]').click() cy.get('[data-cy="result"]').should('exist') }) }) ``` -------------------------------- ### Implement GraphQL Error Handling Pattern Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/graphql/CLAUDE.md Example of a service function demonstrating a common error handling pattern for GraphQL operations. It includes initial validation checks, a try-catch block for the main operation logic, robust error logging, and translation of specific Prisma client errors (e.g., unique constraint violations) into more generic, user-friendly `GraphQLError` instances. ```typescript export async function exampleOperation(args, ctx) { // Validation checks if (!args.requiredField) { throw new GraphQLError('REQUIRED_FIELD_MISSING') } try { // Operation logic } catch (error) { // Error logging console.error('Failed to perform operation', error) // Error translation if (error instanceof Prisma.PrismaClientKnownRequestError) { if (error.code === 'P2002') { throw new GraphQLError('DUPLICATE_ENTRY') } } // Generic error throw new GraphQLError('OPERATION_FAILED') } } ``` -------------------------------- ### Initialize Python Environment and Import Modules Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/apps/analytics/src/notebooks/activity_progress.ipynb This snippet sets up the Python environment by appending a parent directory to the system path, ensuring that custom modules can be imported. It then imports necessary libraries like `os`, `json`, `datetime`, `prisma`, `pandas`, `sys`, and several custom modules related to course analytics and activity progress. ```python import os import json from datetime import datetime from prisma import Prisma import pandas as pd import sys # set the python path correctly for module imports to work sys.path.append("../../") from src.modules.participant_course_analytics.get_running_past_courses import ( get_running_past_courses, ) from src.modules.activity_progress.get_course_progress_activities import ( get_course_progress_activities, ) from src.modules.activity_progress.compute_progress_counts import ( compute_progress_counts, ) from src.modules.activity_progress.save_practice_quiz_progress import ( save_practice_quiz_progress, ) from src.modules.activity_progress.save_microlearning_progress import ( save_microlearning_progress, ) ``` -------------------------------- ### Common Prisma Development Commands Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/prisma/CLAUDE.md A comprehensive list of `pnpm` commands used for various development tasks related to the Prisma database, including building the package, creating and applying migrations, resetting the database, seeding data, and opening Prisma Studio. ```bash # Build the package (generates Prisma client) pnpm run build # Create a new migration pnpm run prisma:migrate # Create a migration without applying it pnpm run prisma:migrate:create # Apply pending migrations pnpm run prisma:deploy # Reset database and apply all migrations pnpm run prisma:reset # Reset with confirmation bypass (for scripts) pnpm run prisma:reset:yes # Seed the database with test data pnpm run seed # Open Prisma Studio to browse/edit data pnpm run prisma:studio # Run a script with environment variables pnpm run script src/scripts/your-script.ts # Run database push (for development, skips migrations) pnpm run prisma:push ``` -------------------------------- ### Example: Using Tailwind-Merge with React Components Source: https://github.com/uzh-bf/klicker-uzh/blob/v3/packages/shared-components/CLAUDE.md This snippet demonstrates how to use `tailwind-merge` within a React component to conditionally apply and merge Tailwind CSS classes. It ensures that default styles are correctly combined with any additional classes passed via props, preventing conflicts and maintaining styling consistency. The example shows a simple `Button` component. ```tsx import { twMerge } from 'tailwind-merge' function Button({ className, ...props }) { return (