diff --git a/README.md b/README.md index ee074eff..bcd8e3a8 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,5934 @@ -# Quick Setup Locally +# daily-code Documentation -## Option 1: Using Docker +## Overview + +This documentation covers 150 files from the daily-code codebase. + +## Table of Contents + +### Root + +- [.eslintrc.js](#-eslintrc-js) + +### apps/web + +- [.eslintrc.js](#apps-web--eslintrc-js) +- [next-env.d.ts](#apps-web-next-env-d-ts) +- [next.config.js](#apps-web-next-config-js) +- [postcss.config.js](#apps-web-postcss-config-js) +- [tailwind.config.js](#apps-web-tailwind-config-js) + +### apps/web/app + +- [globals.css](#apps-web-app-globals-css) +- [layout.tsx](#apps-web-app-layout-tsx) +- [page.module.css](#apps-web-app-page-module-css) +- [page.tsx](#apps-web-app-page-tsx) + +### apps/web/app/(marketing) + +- [layout.tsx](#apps-web-app-(marketing)-layout-tsx) + +### apps/web/app/(marketing)/(policy)/privacy-policy + +- [page.tsx](#apps-web-app-(marketing)-(policy)-privacy-policy-page-tsx) + +### apps/web/app/(marketing)/tnc + +- [page.tsx](#apps-web-app-(marketing)-tnc-page-tsx) + +### apps/web/app/admin + +- [layout.tsx](#apps-web-app-admin-layout-tsx) +- [page.tsx](#apps-web-app-admin-page-tsx) + +### apps/web/app/api/AddTracks + +- [route.ts](#apps-web-app-api-addtracks-route-ts) + +### apps/web/app/api/auth/[...nextauth] + +- [route.ts](#apps-web-app-api-auth-[---nextauth]-route-ts) + +### apps/web/app/api/revalidate + +- [route.ts](#apps-web-app-api-revalidate-route-ts) + +### apps/web/app/auth + +- [page.tsx](#apps-web-app-auth-page-tsx) + +### apps/web/app/canva-track/[...trackIds] + +- [page.tsx](#apps-web-app-canva-track-[---trackids]-page-tsx) + +### apps/web/app/pdf/[...pdfId] + +- [page.tsx](#apps-web-app-pdf-[---pdfid]-page-tsx) + +### apps/web/app/profile + +- [layout.tsx](#apps-web-app-profile-layout-tsx) +- [page.tsx](#apps-web-app-profile-page-tsx) + +### apps/web/app/tracks/[...trackIds] + +- [page.tsx](#apps-web-app-tracks-[---trackids]-page-tsx) + +### apps/web/components + +- [Appbar.tsx](#apps-web-components-appbar-tsx) +- [AppbarClient.tsx](#apps-web-components-appbarclient-tsx) +- [Blog.tsx](#apps-web-components-blog-tsx) +- [BlogAppbar.tsx](#apps-web-components-blogappbar-tsx) +- [Categories.tsx](#apps-web-components-categories-tsx) +- [CodeBlock.tsx](#apps-web-components-codeblock-tsx) +- [ContentSearch.tsx](#apps-web-components-contentsearch-tsx) +- [CustomPagination.tsx](#apps-web-components-custompagination-tsx) +- [EditProblem.tsx](#apps-web-components-editproblem-tsx) +- [ErrorBoundary.tsx](#apps-web-components-errorboundary-tsx) +- [Hero.tsx](#apps-web-components-hero-tsx) +- [LessonView.tsx](#apps-web-components-lessonview-tsx) +- [Loader.tsx](#apps-web-components-loader-tsx) +- [ModeToggle.tsx](#apps-web-components-modetoggle-tsx) +- [MultipleOptionChip.tsx](#apps-web-components-multipleoptionchip-tsx) +- [NotionRenderer.tsx](#apps-web-components-notionrenderer-tsx) +- [PageToggle.tsx](#apps-web-components-pagetoggle-tsx) +- [Print.tsx](#apps-web-components-print-tsx) +- [ProfileChildren.tsx](#apps-web-components-profilechildren-tsx) +- [ProfileSidebar.tsx](#apps-web-components-profilesidebar-tsx) +- [Providers.tsx](#apps-web-components-providers-tsx) +- [RedirectToLastSolved.tsx](#apps-web-components-redirecttolastsolved-tsx) +- [RedirectToLoginCard.tsx](#apps-web-components-redirecttologincard-tsx) +- [ScrollToTopWrapper.tsx](#apps-web-components-scrolltotopwrapper-tsx) +- [SearchDialog.tsx](#apps-web-components-searchdialog-tsx) +- [Signin.tsx](#apps-web-components-signin-tsx) +- [TrackCard-2.tsx](#apps-web-components-trackcard-2-tsx) +- [TrackList.tsx](#apps-web-components-tracklist-tsx) +- [TrackPreview.tsx](#apps-web-components-trackpreview-tsx) +- [TrackTools.tsx](#apps-web-components-tracktools-tsx) +- [Tracks.tsx](#apps-web-components-tracks-tsx) +- [UserAccountDropDown.tsx](#apps-web-components-useraccountdropdown-tsx) +- [UserDetailForm.tsx](#apps-web-components-userdetailform-tsx) +- [UserImage.tsx](#apps-web-components-userimage-tsx) +- [card.tsx](#apps-web-components-card-tsx) +- [use-follow-pointer.ts](#apps-web-components-use-follow-pointer-ts) +- [utils.tsx](#apps-web-components-utils-tsx) + +### apps/web/components/admin + +- [AddProblemCard.tsx](#apps-web-components-admin-addproblemcard-tsx) +- [AddTrackCard.tsx](#apps-web-components-admin-addtrackcard-tsx) +- [AdminAddMCQ.tsx](#apps-web-components-admin-adminaddmcq-tsx) +- [AdminMCQ.tsx](#apps-web-components-admin-adminmcq-tsx) +- [AdminSearch.tsx](#apps-web-components-admin-adminsearch-tsx) +- [CompleteAddTracks.tsx](#apps-web-components-admin-completeaddtracks-tsx) +- [CompleteTrackCard.tsx](#apps-web-components-admin-completetrackcard-tsx) +- [EditCategories.tsx](#apps-web-components-admin-editcategories-tsx) +- [EditTrackCard.tsx](#apps-web-components-admin-edittrackcard-tsx) +- [LinkCard.tsx](#apps-web-components-admin-linkcard-tsx) +- [LinkProblems.tsx](#apps-web-components-admin-linkproblems-tsx) +- [ProblemCard.tsx](#apps-web-components-admin-problemcard-tsx) +- [ProblemEditor.tsx](#apps-web-components-admin-problemeditor-tsx) +- [TracksEditor.tsx](#apps-web-components-admin-trackseditor-tsx) + +### apps/web/components/mcq + +- [EditMCQ.tsx](#apps-web-components-mcq-editmcq-tsx) +- [MCQCard.tsx](#apps-web-components-mcq-mcqcard-tsx) +- [MCQPanel.tsx](#apps-web-components-mcq-mcqpanel-tsx) +- [MCQQuestion.tsx](#apps-web-components-mcq-mcqquestion-tsx) +- [MCQRenderer.tsx](#apps-web-components-mcq-mcqrenderer-tsx) +- [SubmissionMCQ.tsx](#apps-web-components-mcq-submissionmcq-tsx) + +### apps/web/components/privacy-policy + +- [privacy-policy.ts](#apps-web-components-privacy-policy-privacy-policy-ts) + +### apps/web/components/profile + +- [ProfileOptions.tsx](#apps-web-components-profile-profileoptions-tsx) + +### apps/web/components/tnc + +- [tnc-content.ts](#apps-web-components-tnc-tnc-content-ts) + +### apps/web/hooks + +- [useMountStatus.ts](#apps-web-hooks-usemountstatus-ts) + +### apps/web/lib + +- [auth.ts](#apps-web-lib-auth-ts) +- [search.ts](#apps-web-lib-search-ts) +- [utils.ts](#apps-web-lib-utils-ts) + +### apps/web/lib/cache + +- [cache.ts](#apps-web-lib-cache-cache-ts) +- [in-memory-cache.ts](#apps-web-lib-cache-in-memory-cache-ts) +- [redis-cache.ts](#apps-web-lib-cache-redis-cache-ts) + +### apps/web/screens + +- [Admin.tsx](#apps-web-screens-admin-tsx) +- [Landing.tsx](#apps-web-screens-landing-tsx) +- [footer-cta.tsx](#apps-web-screens-footer-cta-tsx) +- [footer.tsx](#apps-web-screens-footer-tsx) + +### packages/db + +- [Cache.ts](#packages-db-cache-ts) +- [setupDB.sh](#packages-db-setupdb-sh) + +### packages/db/prisma + +- [seed.ts](#packages-db-prisma-seed-ts) + +### packages/db/prisma/migrations/20240402204828_init + +- [migration.sql](#packages-db-prisma-migrations-20240402204828_init-migration-sql) + +### packages/db/prisma/migrations/20240403204246_added_mcq + +- [migration.sql](#packages-db-prisma-migrations-20240403204246_added_mcq-migration-sql) + +### packages/db/prisma/migrations/20240404031649_nextauth + +- [migration.sql](#packages-db-prisma-migrations-20240404031649_nextauth-migration-sql) + +### packages/db/prisma/migrations/20240407230643_adds + +- [migration.sql](#packages-db-prisma-migrations-20240407230643_adds-migration-sql) + +### packages/db/prisma/migrations/20240408080322_added_categories + +- [migration.sql](#packages-db-prisma-migrations-20240408080322_added_categories-migration-sql) + +### packages/db/prisma/migrations/20240411143941_added_admin + +- [migration.sql](#packages-db-prisma-migrations-20240411143941_added_admin-migration-sql) + +### packages/db/prisma/migrations/20240412144918_ + +- [migration.sql](#packages-db-prisma-migrations-20240412144918_-migration-sql) + +### packages/db/prisma/migrations/20240412224746_code_exec + +- [migration.sql](#packages-db-prisma-migrations-20240412224746_code_exec-migration-sql) + +### packages/db/prisma/migrations/20240416173507_added_search + +- [migration.sql](#packages-db-prisma-migrations-20240416173507_added_search-migration-sql) + +### packages/db/prisma/migrations/20240427131506_add_index + +- [migration.sql](#packages-db-prisma-migrations-20240427131506_add_index-migration-sql) + +### packages/db/prisma/migrations/20240430194543_added_mcq_submission + +- [migration.sql](#packages-db-prisma-migrations-20240430194543_added_mcq_submission-migration-sql) + +### packages/db/prisma/migrations/20240803144221_added_cohort + +- [migration.sql](#packages-db-prisma-migrations-20240803144221_added_cohort-migration-sql) + +### packages/db/prisma/migrations/20240809135031_removed_code + +- [migration.sql](#packages-db-prisma-migrations-20240809135031_removed_code-migration-sql) + +### packages/db/prisma/migrations/20241101231656_add_canva + +- [migration.sql](#packages-db-prisma-migrations-20241101231656_add_canva-migration-sql) + +### packages/db/src + +- [index.ts](#packages-db-src-index-ts) + +### packages/eslint-config + +- [library.js](#packages-eslint-config-library-js) +- [next.js](#packages-eslint-config-next-js) +- [react-internal.js](#packages-eslint-config-react-internal-js) + +### packages/store/src + +- [index.ts](#packages-store-src-index-ts) + +### packages/store/src/atoms + +- [filter.ts](#packages-store-src-atoms-filter-ts) +- [index.ts](#packages-store-src-atoms-index-ts) +- [profileSidebar.ts](#packages-store-src-atoms-profilesidebar-ts) +- [quiz.ts](#packages-store-src-atoms-quiz-ts) +- [view.ts](#packages-store-src-atoms-view-ts) + +### packages/ui + +- [.eslintrc.js](#packages-ui--eslintrc-js) +- [tailwind.config.js](#packages-ui-tailwind-config-js) + +### packages/ui/src + +- [index.ts](#packages-ui-src-index-ts) + +### packages/ui/src/lib + +- [utils.ts](#packages-ui-src-lib-utils-ts) + +### packages/ui/src/shad/ui + +- [badge.tsx](#packages-ui-src-shad-ui-badge-tsx) +- [button.tsx](#packages-ui-src-shad-ui-button-tsx) +- [card.tsx](#packages-ui-src-shad-ui-card-tsx) +- [checkbox.tsx](#packages-ui-src-shad-ui-checkbox-tsx) +- [dailog.tsx](#packages-ui-src-shad-ui-dailog-tsx) +- [dropdown-menu.tsx](#packages-ui-src-shad-ui-dropdown-menu-tsx) +- [input.tsx](#packages-ui-src-shad-ui-input-tsx) +- [label.tsx](#packages-ui-src-shad-ui-label-tsx) +- [pagination.tsx](#packages-ui-src-shad-ui-pagination-tsx) +- [resizable.tsx](#packages-ui-src-shad-ui-resizable-tsx) +- [scroll-area.tsx](#packages-ui-src-shad-ui-scroll-area-tsx) +- [select.tsx](#packages-ui-src-shad-ui-select-tsx) +- [separator.tsx](#packages-ui-src-shad-ui-separator-tsx) +- [sheet.tsx](#packages-ui-src-shad-ui-sheet-tsx) +- [skeleton.tsx](#packages-ui-src-shad-ui-skeleton-tsx) +- [spotlight.tsx](#packages-ui-src-shad-ui-spotlight-tsx) +- [switch.tsx](#packages-ui-src-shad-ui-switch-tsx) +- [table.tsx](#packages-ui-src-shad-ui-table-tsx) +- [tabs.tsx](#packages-ui-src-shad-ui-tabs-tsx) +- [textarea.tsx](#packages-ui-src-shad-ui-textarea-tsx) +- [toast.tsx](#packages-ui-src-shad-ui-toast-tsx) +- [toaster.tsx](#packages-ui-src-shad-ui-toaster-tsx) +- [tooltip.tsx](#packages-ui-src-shad-ui-tooltip-tsx) +- [use-toast.tsx](#packages-ui-src-shad-ui-use-toast-tsx) + +## File Documentation + +### Root + + + +#### .eslintrc.js + +*Path: .eslintrc.js* + +1. **Purpose:** This file defines the ESLint configuration for the root of the repository, specifically targeting the package manager's execution context. It sets up linting rules and configurations that apply only to files within the root, excluding subdirectories like "apps" and "packages." + +2. **Key Functionality:** + +- **`ignorePatterns: ["apps/**", "packages/**"]`**: This configuration instructs ESLint to ignore all files and subdirectories within the "apps" and "packages" directories. This is crucial for applying different linting rules to different parts of the project, allowing for more specific configurations within those subdirectories. + +- **`extends: ["@repo/eslint-config/library.js"]`**: This line extends the base ESLint configuration defined in the "@repo/eslint-config/library.js" file. This promotes consistency across the project by inheriting a shared set of rules and configurations. This indicates a dependency on an internal package or shared configuration file. + +- **`parser: "@typescript-eslint/parser"`**: Specifies the parser to be used by ESLint. "@typescript-eslint/parser" allows ESLint to understand TypeScript syntax. This implies the project uses TypeScript. + +- **`parserOptions: { project: true }`**: This option tells the TypeScript parser to look for a `tsconfig.json` file in the current directory or any parent directory. This allows ESLint to leverage TypeScript's type checking capabilities for more accurate linting. + +- **`rules: { ... }`**: This object allows overriding or extending specific rules inherited from the extended configuration. + + - **`"no-unused-vars": "off"`**: Disables the rule that warns about unused variables. This might be necessary due to specific coding patterns or tooling used in the root directory. + + - **`"no-redeclare": "off"`**: Disables the rule that prevents variable redeclaration. Similar to the above, this might be disabled for specific reasons within the root's context. + + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** This file implicitly depends on ESLint and the "@typescript-eslint/parser" package. It also depends on an internal ESLint configuration file located at "@repo/eslint-config/library.js". +- **Code Relationships:** This file serves as the base ESLint configuration for the root of the repository. It's likely that other ESLint configuration files within "apps" and "packages" will extend or modify this base configuration, creating a hierarchical structure of linting rules. + +4. **Usage Example:** N/A (Configuration file, not directly executed) + +5. **Technical Notes:** + +- The decision to ignore "apps" and "packages" suggests a multi-package or monorepo structure where different parts of the project have distinct linting needs. +- Disabling "no-unused-vars" and "no-redeclare" at the root level might indicate a need for more granular control over these rules within subdirectories. It's important to understand the rationale behind disabling these rules to avoid potential code quality issues. +- The use of a shared ESLint configuration ("@repo/eslint-config/library.js") promotes consistency and maintainability across the project. This shared configuration likely contains the core linting rules for the project. + +--- + +### apps/web + + + +#### .eslintrc.js + +*Path: apps/web/.eslintrc.js* + +1. **Purpose:** This file configures ESLint for the web application, ensuring code style and quality consistency. It extends a shared ESLint configuration and sets up TypeScript parsing. + +2. **Key Functionality:** + + - `root: true`: Prevents ESLint from searching up the directory tree for other configuration files. This ensures that the project's ESLint configuration is self-contained. + - `extends: ["@repo/eslint-config/next.js"]`: Extends a predefined ESLint configuration specifically designed for Next.js projects within the repository. This promotes consistency across different Next.js applications in the monorepo. + - `parser: "@typescript-eslint/parser"`: Specifies the parser to use for TypeScript files. This allows ESLint to understand TypeScript syntax and apply relevant linting rules. + - `parserOptions: { project: true }`: Tells the TypeScript parser to infer project settings from the `tsconfig.json` file. This enables type-aware linting and autocompletion. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `eslint` and `@typescript-eslint/parser`. It leverages the shared ESLint config `@repo/eslint-config/next.js`. + - **Code Relationships:** This file is essential for the development workflow, ensuring code quality and consistency across the web application. It's used by ESLint during code linting. + +4. **Usage Example:** ESLint automatically uses this configuration file when linting files within the `apps/web` directory. Developers can run ESLint manually using commands like `npx eslint .` or integrate it into their IDE for real-time linting. + +5. **Technical Notes:** Using a shared ESLint configuration (`@repo/eslint-config/next.js`) promotes maintainability and consistency across multiple projects within the repository. + +--- + + + +#### next-env.d.ts + +*Path: apps/web/next-env.d.ts* + +1. **Purpose:** This file provides TypeScript type definitions for Next.js and related libraries, allowing TypeScript to understand Next.js-specific APIs and components. + +2. **Key Functionality:** + + - `/// `: Includes type definitions for the core Next.js library. This provides type information for Next.js components, functions, and objects. + - `/// `: Includes type definitions for the Next.js Image component. This ensures type safety when using the Image component and its properties. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on the `@types/next` package, which provides TypeScript definitions for Next.js. + - **Code Relationships:** This file is crucial for TypeScript integration with Next.js. It ensures that TypeScript can correctly type-check code that uses Next.js APIs. + +4. **Usage Example:** This file is automatically used by TypeScript when compiling the Next.js application. It doesn't require explicit usage in the codebase. + +5. **Technical Notes:** This file is automatically generated by Next.js and should not be manually edited. + +--- + + + +#### next.config.js + +*Path: apps/web/next.config.js* + +1. **Purpose:** This file configures the Next.js application, including webpack settings, transpiled packages, and image optimization domains. + +2. **Key Functionality:** + + - `webpack`: Customizes the webpack configuration. It adds path aliases for easier imports and resolves a potential issue with the `keyv` package. + - `resolve.alias`: Creates aliases for paths like `@components` and `@styles`. + - `plugins`: Adds a `ContextReplacementPlugin` to handle the `keyv` package dependency. + - `transpilePackages`: Specifies packages that should be transpiled by Next.js. This is useful for packages that are not written in ES5 and need to be transpiled for browser compatibility. + - `images.domains`: Whitelists domains for image optimization. This allows Next.js to optimize images from these domains. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `next`, `path`, and `webpack`. + - **Code Relationships:** This file is crucial for configuring the build process of the Next.js application. It affects how webpack bundles the code, handles dependencies, and optimizes images. + +4. **Usage Example:** This file is automatically used by Next.js during the build process. + +5. **Technical Notes:** The `webpack` configuration modifications improve developer experience by simplifying imports and resolving potential dependency issues. The `transpilePackages` setting ensures compatibility with specific packages. + +--- + + + +#### postcss.config.js + +*Path: apps/web/postcss.config.js* + +1. **Purpose:** This file configures PostCSS plugins for the project, specifically Tailwind CSS and Autoprefixer. + +2. **Key Functionality:** + + - `plugins`: Defines the PostCSS plugins to use. + - `tailwindcss`: Enables Tailwind CSS for utility-first styling. + - `autoprefixer`: Automatically adds vendor prefixes to CSS rules, ensuring cross-browser compatibility. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `tailwindcss` and `autoprefixer`. + - **Code Relationships:** This file is essential for styling the application using Tailwind CSS and ensuring cross-browser compatibility. + +4. **Usage Example:** This configuration is automatically used by PostCSS during the build process. + +5. **Technical Notes:** Using Tailwind CSS and Autoprefixer simplifies styling and improves cross-browser compatibility. + +--- + + + +#### tailwind.config.js + +*Path: apps/web/tailwind.config.js* + +1. **Purpose:** This file configures Tailwind CSS for the project, defining design tokens, styles, and customizations. + +2. **Key Functionality:** + + - `darkMode`: Enables dark mode support. + - `content`: Specifies the files to scan for Tailwind CSS class usage. + - `theme`: Customizes the default Tailwind CSS theme, including fonts, colors, and breakpoints. + - `plugins`: Adds Tailwind CSS plugins, such as `tailwindcss-animate`. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `tailwindcss` and `tailwindcss-animate`. + - **Code Relationships:** This file is crucial for styling the application using Tailwind CSS. It defines the design system and custom styles. It uses the `@repo/ui` package, indicating a dependency on a shared UI component library. + +4. **Usage Example:** This configuration is automatically used by Tailwind CSS during the build process. + +5. **Technical Notes:** The `content` array ensures that Tailwind CSS only generates styles for classes used in the specified files, optimizing the final CSS size. The inclusion of `../../packages/ui/src/**/*.{ts,tsx}` suggests a monorepo structure where the UI components are shared across different applications. + +--- + +### apps/web/app + + + +#### globals.css + +*Path: apps/web/app/globals.css* + +1. **Purpose:** This file defines the global styles for the web application, including font imports, Tailwind CSS configuration, and custom styling rules. It sets up the base styles, dark mode variations, and utility classes. + +2. **Key Functionality:** + +- **Font Imports:** Imports the "Open Sans", "Poppins", and "Montserrat Alternates" fonts from Google Fonts. +- **Tailwind CSS Integration:** + - `@tailwind base;`: Includes Tailwind's base styles. + - `@tailwind components;`: Includes Tailwind's component styles. + - `@tailwind utilities;`: Includes Tailwind's utility classes. +- **Custom Styles:** + - Defines CSS variables for colors and border radius within the `:root` element. + - Implements dark mode styles within the `.dark` class, toggling color variables. + - Sets default styles for elements like `body` and `*` within the `@layer base` directive. + - Creates utility classes like `wrapper`, `flex-center`, and `flex-between` within the `@layer utilities` directive. + - Enforces "Poppins" as the default font family for all elements. + - Implements a `.no-scrollbar` class to hide scrollbars. + +3. **Dependencies and Relationships:** + +- **Dependencies:** Depends on Tailwind CSS for utility classes and base styles. Relies on Google Fonts for the specified fonts. +- **Relationships:** This file is imported into `layout.tsx` to apply the styles globally to the application. + +4. **Usage Example:** N/A (CSS file) + +5. **Technical Notes:** + +- The use of CSS variables allows for easy theming and switching between light and dark modes. +- Tailwind CSS provides a utility-first approach for styling, promoting consistency and reducing custom CSS. +- The `@layer` directive helps organize styles and ensures proper precedence. + +--- + + + +#### layout.tsx + +*Path: apps/web/app/layout.tsx* + +1. **Purpose:** This file defines the main layout of the web application. It sets up the global font, theme provider, top loader, and wraps the application content with necessary providers. + +2. **Key Functionality:** + +- **Font Integration:** Uses the `Poppins` font from `next/font/google`. +- **Theme Provider:** Wraps the application with `ThemeProvider` from `../components/Providers` to manage theme switching (light/dark mode). Uses the `attribute="class"` prop, indicating theme changes are handled by CSS classes (like the `.dark` class in `globals.css`). Sets the default theme to "system" and enables system theme preference detection. Disables transitions on theme change. +- **Top Loader:** Implements `NextTopLoader` for a visual loading indicator at the top of the page. +- **Providers:** Wraps the application content with `Providers` (likely for context and state management). +- **Toaster:** Includes a `Toaster` component from `@repo/ui` for displaying notifications. +- **Metadata:** Defines metadata like `title` and `description` for the application. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** Imports `globals.css` for styling, `Poppins` font, `cn` utility, `Providers` and `ThemeProvider` components, `NextTopLoader`, React Notion X styles, PrismJS styles, KaTeX styles, and `Toaster`. +- **Code Relationships:** This layout file wraps all other page content, making it the entry point for styling and provider setup. It uses the styles defined in `globals.css`. + +4. **Usage Example:** N/A (Layout file) + +5. **Technical Notes:** + +- `suppressHydrationWarning` is used on the `html` element. This might be necessary if there are known hydration mismatches between server and client rendering. Investigate if this is truly necessary and address the underlying hydration issues if possible. +- The use of a theme provider allows for dynamic theme switching. +- Importing CSS libraries directly into the layout ensures they are applied globally. + +--- + + + +#### page.module.css + +*Path: apps/web/app/page.module.css* + +1. **Purpose:** This file is intended for module-specific styles for the main application page. However, it's currently empty. + +2. **Key Functionality:** None. The file is empty. + +3. **Dependencies and Relationships:** Potentially used by `page.tsx` if it contained styles. + +4. **Usage Example:** N/A (Empty CSS file) + +5. **Technical Notes:** This file can be removed if not needed. + +--- + + + +#### page.tsx + +*Path: apps/web/app/page.tsx* + +1. **Purpose:** This file defines the main page content of the application, rendering the `Landing` component. + +2. **Key Functionality:** Renders the `Landing` component. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** Imports the `Landing` component from `../screens/Landing`. +- **Code Relationships:** This file is the entry point for the main page content and determines what is displayed on the root route. + +4. **Usage Example:** This file represents the root route of the application. When a user visits the base URL, this component is rendered. + +5. **Technical Notes:** The simplicity suggests the `Landing` component holds the primary logic and content for the main page. + + +**Overall System Architecture and Relationships:** + +- `globals.css` provides the global styles for the application. +- `layout.tsx` sets up the layout, including the theme provider, font, and global providers, and imports the styles from `globals.css`. +- `page.tsx` defines the content of the main application page, rendering the `Landing` component. +- `page.module.css` is currently unused but is intended for page-specific styles. + +The files work together to create a styled and structured web application. `layout.tsx` acts as a container for all page content, applying global styles and providing necessary context. `page.tsx` determines the specific content displayed on the root route. The system is designed with a clear separation of concerns: layout, styling, and page content. + +--- + +### apps/web/app/(marketing) + + + +#### layout.tsx + +*Path: apps/web/app/(marketing)/layout.tsx* + +1. **Purpose:** This file defines the `MarketingLayout` component, which provides a consistent layout structure for marketing pages within the web application. It wraps child components with a header (AppbarClient) and footer. + +2. **Key Functionality:** + +- **`MarketingLayout` Component:** + - **Parameters:** + - `children`: `React.ReactNode` - The content to be rendered within the layout. This allows any valid React component or JSX to be passed as children to the layout. + - **Return Type:** `JSX.Element` - Renders the layout structure containing the header, children, and footer. + - **Implementation:** The component uses a `main` element with styling for background and minimum height. It renders the `AppbarClient` component at the top, followed by the provided `children`, and finally the `Footer` component. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `React`: Used for JSX and component creation. + - `Footer`: Imports the `Footer` component, presumably from `../../screens/footer`. This suggests a directory structure where shared UI components are located in a `screens` or `components` directory. + - `AppbarClient`: Imports the `AppbarClient` component, likely a customized app bar for client-facing marketing pages, from `../../components/AppbarClient`. +- **Code Relationships:** This layout component is likely used within the marketing section of the web application, wrapping specific marketing pages to provide a consistent look and feel. It depends on the `Footer` and `AppbarClient` components. + +4. **Usage Example:** + +```tsx +// Inside a marketing page component, e.g., /pages/marketing/pricing.tsx +import MarketingLayout from "../(marketing)/layout"; + +const PricingPage = () => { + return ( + + {/* Pricing page content */} +

Pricing

+

Our pricing plans...

+
+ ); +}; + +export default PricingPage; + +``` + +This example demonstrates how a marketing page (`PricingPage`) uses the `MarketingLayout` to wrap its content. The `PricingPage` component's JSX is passed as the `children` prop to `MarketingLayout`, resulting in a consistent layout across marketing pages. + +5. **Technical Notes:** + +- The use of a dedicated layout component promotes reusability and maintainability by centralizing the layout structure. +- The relative import paths (`../../screens/footer`, `../../components/AppbarClient`) suggest a well-organized project structure. This structure likely uses a shared components directory and separates components by their function (e.g., client-facing vs. internal). +- The `className` attribute uses tailwind CSS classes (`min-h-screen`, `bg-background`, `antialiased`) for styling. This indicates the project likely uses Tailwind CSS for styling. + + +--- + + +There were no other files provided. If you provide more files, I can generate documentation for them. + +--- + +### apps/web/app/(marketing)/(policy)/privacy-policy + + + +#### page.tsx + +*Path: apps/web/app/(marketing)/(policy)/privacy-policy/page.tsx* + +1. **Purpose:** This file defines the `PrivacyPolicyPage` component, responsible for rendering the privacy policy content on the website's marketing section. It displays the privacy policy information fetched from a shared component. + +2. **Key Functionality:** + +- **`PrivacyPolicyPage` Component:** This functional component renders the privacy policy content. + - **Parameters:** None + - **Return Type:** `JSX.Element` + - **Implementation:** It iterates through the `privacyPolicyContent` array (imported from `../../../../components/privacy-policy/privacy-policy`) and renders each item's description within a `

` tag. The content is structured within a main container with styling for responsiveness. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** Imports `privacyPolicyContent` from `../../../../components/privacy-policy/privacy-policy`. This indicates a dependency on a shared component for the actual policy content. This structure suggests a separation of concerns, with the content managed centrally and reused across different parts of the application. +- **Code Relationships:** This component is likely routed within the application's routing configuration (e.g., using Next.js's file-based routing) to be accessible at the `/privacy-policy` route under the marketing section. + +4. **Usage Example:** + +This component would be rendered when a user navigates to the privacy policy page within the marketing section of the website. For example, in a Next.js application, the file's location in the `app` directory automatically handles routing. + +5. **Technical Notes:** + +- The component uses a simple mapping function to render the policy content. This assumes that `privacyPolicyContent` is an array of objects, each with an `id` and `description` property. +- The styling uses Tailwind CSS classes for layout and responsiveness. + +--- + +### apps/web/app/(marketing)/tnc + + + +#### page.tsx + +*Path: apps/web/app/(marketing)/tnc/page.tsx* + +1. **Purpose:** This file defines the `TermsAndConditionsPage` component, responsible for rendering the terms and conditions content on a web page. It dynamically displays the content from a data source. + +2. **Key Functionality:** + +- **`TermsAndConditionsPage` (functional component):** + - **Parameters:** None + - **Return Type:** `JSX.Element` (React component) + - **Implementation:** This component iterates through the `tncContent` array (imported from `../../../components/tnc/tnc-content`). It renders an `h1` element for the title and then maps over the `tncContent` array. For each item in the array, it renders a `div` containing a description paragraph and a nested loop to render a list of points associated with that item. Each point is rendered as a paragraph with an ID and description. + - **Error Handling/Fallback:** No explicit error handling is present. If `tncContent` is empty or undefined, the rendered output will simply contain the title and no content below it. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `tncContent` from `../../../components/tnc/tnc-content`: This import provides the data for the terms and conditions. The file structure suggests this is a relative import within the same project, indicating a close relationship between the components. +- **Code Relationships:** This component likely fits within a larger web application structure, potentially routed using a framework like Next.js. It depends on the `tncContent` data, suggesting a separation of content and presentation. + +4. **Usage Example:** + +This component would be used as a route within a web application. In a Next.js application, for example, it might be placed in the `pages` directory to be directly accessible via a URL. + +```javascript +// Example in a Next.js routes directory +// pages/terms.tsx +import TermsAndConditionsPage from './(marketing)/tnc/page'; + +export default TermsAndConditionsPage; +``` + +5. **Technical Notes:** + +- The component uses a simple mapping approach to render the content. For more complex terms and conditions with dynamic sections or interactive elements, a more structured approach with reusable sub-components might be beneficial for maintainability. +- The key prop is used correctly within the mapping functions, which is crucial for React's reconciliation process and performance. However, if the `item.id` and `point.id` are not guaranteed to be unique, this could lead to issues. A more robust approach might involve generating unique keys if they are not readily available. +- The relative import path `../../../components/tnc/tnc-content` suggests a specific project structure. While relative imports are common, deeply nested paths can sometimes indicate a need for refactoring to improve code organization. Consider evaluating if the project structure could be optimized for simpler import paths. + +--- + +### apps/web/app/admin + + + +#### layout.tsx + +*Path: apps/web/app/admin/layout.tsx* + +1. **Purpose:** This file defines the layout for the admin section of the web application. It primarily handles authentication and authorization, ensuring only authorized users can access admin pages. + +2. **Key Functionality:** + +- **`AdminLayout` (functional component):** + - **Parameters:** + - `children`: `ReactNode` - The content to be rendered within the layout. + - **Return Type:** `JSX.Element` or `null` + - **Implementation:** + - Uses `getServerSession(authOptions)` to retrieve the user's session from NextAuth.js. + - Checks `session?.user?.admin`. If false (user not logged in or not an admin), renders an "Access Denied" page with a link to the homepage. + - If true (user is an admin), renders the provided `children` within the layout. + - **Fallback Mechanism:** If the user is not authorized, a specific access denied page is displayed, guiding the user back to the homepage. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `getServerSession` from `next-auth`: Used for server-side authentication. + - `authOptions` from `../../lib/auth`: Configuration options for NextAuth.js. + - `Link` from `next/link`: Used for client-side navigation. + - `LockClosedIcon` from `@radix-ui/react-icons`: Used for the visual lock icon. + - `ReactNode` from `react`: Defines the type for React children. +- **Code Relationships:** This layout component is used to wrap any page within the admin section (e.g., `/admin`). It depends on the authentication logic defined in `../../lib/auth`. + +4. **Usage Example:** + +```tsx +// In a page within the admin section (e.g., /admin/dashboard) +import AdminLayout from './layout'; + +export default function DashboardPage() { + return ( + + {/* Admin-specific content */} + + ); +} +``` + +5. **Technical Notes:** + +- Server-side rendering with `getServerSession` ensures that authentication is handled before the page is sent to the client, improving security. +- The `authOptions` likely contain the configuration for connecting to the authentication provider. + +--- + + + +#### page.tsx + +*Path: apps/web/app/admin/page.tsx* + +1. **Purpose:** This file defines the main entry point for the admin section of the application. It renders the admin layout and the core admin content. + +2. **Key Functionality:** + +- **`AdminPage` (functional component):** + - **Parameters:** None + - **Return Type:** `JSX.Element` + - **Implementation:** Renders the `AppbarClient` component and the `Admin` component within the layout structure. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `AppbarClient` from `../../components/AppbarClient`: The application's app bar component, likely providing navigation and other UI elements. + - `Admin` from `../../screens/Admin`: The main content component for the admin section. +- **Code Relationships:** This page component uses the `AppbarClient` for consistent UI and the `Admin` component to display the admin-specific content. It is likely routed to the `/admin` path. It is wrapped by `layout.tsx`, which provides the authentication layer. + +4. **Usage Example:** This component is typically accessed by navigating to the `/admin` route. + +5. **Technical Notes:** + +- This file demonstrates a clear separation of concerns: `AdminPage` handles the page structure, `AppbarClient` handles the app bar, and `Admin` handles the specific admin content. +- This structure makes the code more modular and maintainable. The relationship between `page.tsx` and `layout.tsx` is crucial for securing the admin section of the application. `layout.tsx` acts as a gatekeeper, ensuring only authorized users can access the content rendered by `page.tsx`. + +--- + +### apps/web/app/api/AddTracks + + + +#### route.ts + +*Path: apps/web/app/api/AddTracks/route.ts* + +1. **Purpose:** This file defines the API endpoint `/api/AddTracks` which fetches track data from a Notion page given its ID. It's used to populate track information within the application. + +2. **Key Functionality:** + +- **`POST` handler:** + - **Parameters:** `req` (NextRequest) - The incoming request object. + - **Return Type:** `NextResponse` - The API response containing track data or an error. + - **Implementation:** + 1. Retrieves the user's session using `getServerSession(authOptions)`. + 2. Authorizes the request, allowing access only to admin users. Returns a 401 Unauthorized response if the user is not an admin. + 3. Parses the Notion page ID (`notionId`) from the request body. + 4. Initializes a `NotionAPI` client. + 5. Fetches the Notion page data using `notion.getPage(notionId)`. + 6. Processes the `recordMap` from the Notion API response, filtering out blocks with `role: "none"`. + 7. Transforms the remaining blocks into an array of objects, each containing the `notionDocId` and `title`. + 8. Removes the first and last elements of the array (assumed to be extraneous based on the provided code). + 9. Returns the processed track data as a JSON response. + 10. Handles potential errors during the Notion API call and returns the error as a JSON response. + - **Error Handling:** Uses a `try-catch` block to handle errors during the Notion API call. + - **Optimizations:** Filters and maps the Notion data directly to minimize unnecessary processing. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `getServerSession` from `next-auth`: Used for server-side authentication. + - `NextRequest`, `NextResponse` from `next/server`: Next.js API route handlers. + - `NotionAPI` from `notion-client`: Used to interact with the Notion API. + - `authOptions` from `../../../lib/auth`: Authentication configuration. +- **Code Relationships:** This file depends on the Notion API and the application's authentication mechanism. It likely interacts with other parts of the application that consume the returned track data. + +4. **Usage Example:** + +```javascript +// Frontend code +const response = await fetch('/api/AddTracks', { + method: 'POST', + body: JSON.stringify({ notionId: 'YOUR_NOTION_PAGE_ID' }), +}); +const tracks = await response.json(); +// Use the 'tracks' data +``` + +5. **Technical Notes:** + +- The code assumes a specific structure for the Notion page and removes the first and last elements of the processed data. This suggests a convention or template used for storing track information in Notion. +- The error handling could be more robust, providing specific error messages and status codes based on the type of error encountered. +- The authorization mechanism relies on the `admin` flag in the user's session. This implies a role-based access control system within the application. The `authOptions` from `../../../lib/auth` likely defines the authentication strategy and session management. The dependency on `next-auth` suggests a server-side authentication approach. This API endpoint interacts with the Notion API externally and internally with other modules that consume the track data it retrieves and processes. This file is crucial for populating track information within the application, bridging the gap between the Notion data source and the application's internal data structures. + +--- + +### apps/web/app/api/auth/[...nextauth] + + + +#### route.ts + +*Path: apps/web/app/api/auth/[...nextauth]/route.ts* + +1. **Purpose:** This file sets up the NextAuth.js authentication middleware for the web application. It handles authentication routes and integrates with the authentication options defined in `authOptions`. + +2. **Key Functionality:** + +- **`handler`:** This constant is an instance of the NextAuth middleware initialized with `authOptions`. + - **Parameters:** `authOptions` (object) - Configuration options for NextAuth.js, including providers, callbacks, and database adapter. + - **Return Type:** `NextAuth` instance - A middleware function that handles authentication requests. + - **Implementation:** It uses the `NextAuth` function from the `next-auth` library, passing in the `authOptions` object. This sets up the authentication routes and logic based on the provided configuration. +- **`GET` and `POST` handler exports:** These lines expose the `handler` function for both GET and POST requests to the `/api/auth/*` routes. This allows NextAuth.js to handle various authentication actions like sign-in, sign-out, and callbacks. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `next-auth`: Provides the core NextAuth.js functionality. + - `../../../../lib/auth`: Imports the `authOptions` object, which likely contains provider configurations (e.g., Google, GitHub), database adapter settings, and custom callbacks. +- **Code Relationships:** This file is the entry point for all authentication requests. It relies on the `authOptions` from the `lib/auth` module to configure the authentication behavior. It interacts with external authentication providers based on the `authOptions` configuration. + +4. **Usage Example:** + +A user navigating to `/api/auth/signin` will trigger this route. The `handler` will process the request based on the configured providers in `authOptions`. For example, if Google is configured as a provider, the user will be redirected to Google for authentication. Upon successful authentication, the callback defined in `authOptions` will be executed. + +5. **Technical Notes:** + +- The `[...nextauth]` dynamic route syntax is a Next.js feature that allows NextAuth.js to handle all sub-paths under `/api/auth/`. This simplifies the routing configuration for authentication. +- The location of `authOptions` in `lib/auth` suggests a centralized configuration approach, promoting maintainability and code reusability. This separation also keeps sensitive configuration details away from the route handler itself. +- The use of both `GET` and `POST` exports ensures that the handler can handle various authentication requests, including OAuth callbacks which might use POST. + + +--- + + +There are no other files provided, so no further file documentation can be generated. If you provide additional files, I can create documentation for them following the same structure. Remember to provide context about how the files relate to each other. + +--- + +### apps/web/app/api/revalidate + + + +#### route.ts + +*Path: apps/web/app/api/revalidate/route.ts* + +1. **Purpose:** This file defines an API endpoint for on-demand revalidation of Next.js cached pages. It allows external triggers to refresh specific page content, ensuring data consistency. + +2. **Key Functionality:** + +- **`GET(req: NextRequest)`:** + - **Parameters:** `req` (NextRequest) - The incoming request object containing query parameters. + - **Return Type:** `NextResponse` - The response object containing revalidation status or error information. + - **Implementation:** + - Retrieves the `secret` and `path` from the request query parameters. + - Validates the `secret` against the environment variable `MY_SECRET_TOKEN`. + - If the secret is valid and a `path` is provided, it calls `revalidatePath(path)` to trigger revalidation of the specified path. + - Returns a JSON response indicating success or failure. + - **Error Handling:** Returns a 401 error for invalid tokens and a 500 error for revalidation failures. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `next/cache`: Imports `revalidatePath` for interacting with Next.js's caching mechanism. + - `next/server`: Imports `NextRequest` and `NextResponse` for handling requests and responses in a Next.js API route. +- **Code Relationships:** This API endpoint is likely triggered by external systems (e.g., CMS webhooks) or internal processes that need to refresh specific pages after data updates. It directly interacts with the Next.js runtime to invalidate the cache. + +4. **Usage Example:** + +```bash +# Trigger revalidation of the '/products' page +curl -X GET "https://your-domain/api/revalidate?secret=YOUR_SECRET_TOKEN&path=/products" +``` + +5. **Technical Notes:** + +- **Security:** The `MY_SECRET_TOKEN` environment variable is crucial for securing this endpoint. Without proper validation, anyone could trigger revalidation, potentially leading to performance issues or unintended cache invalidation. +- **Performance:** On-demand revalidation offers granular control over cache refresh, improving performance compared to time-based invalidation, especially for infrequently updated content. However, excessive revalidation calls can negatively impact performance. +- **Edge Cases:** The code handles missing `path` parameters gracefully, but it might be beneficial to log invalid revalidation requests for debugging and security analysis. Consider adding rate limiting to prevent abuse. + +--- + +### apps/web/app/auth + + + +#### page.tsx + +*Path: apps/web/app/auth/page.tsx* + +1. **Purpose:** This file defines the `SigninPage` component, which renders the sign-in form for the web application. It serves as the entry point for user authentication. + +2. **Key Functionality:** + +- **`SigninPage` (functional component):** + - **Parameters:** None + - **Return Type:** `JSX.Element` (React component) + - **Implementation:** This component uses React's `Suspense` component to handle the asynchronous loading of the `Signin` component. This improves the perceived performance by displaying a fallback UI while the `Signin` component is being loaded. +- **`Signin` (imported component):** This component is assumed to contain the actual sign-in form logic and UI elements. Its specific implementation details are not available in this file. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `react`: Uses `Suspense` for asynchronous component loading. + - `../../components/Signin`: Imports the `Signin` component, which encapsulates the sign-in form. +- **Code Relationships:** This file is the entry point for the `/auth` route (implied). It depends on the `Signin` component for the actual sign-in functionality. + +4. **Usage Example:** + +This component would be rendered when a user navigates to the `/auth` route of the application. The Next.js router (implied) would match this route to this file and render the `SigninPage` component. + +5. **Technical Notes:** + +- The use of `Suspense` suggests that the `Signin` component might involve dynamic imports or other asynchronous operations, potentially for code splitting or lazy loading. This optimization can improve initial page load performance. + +--- + +### apps/web/app/canva-track/[...trackIds] + + + +#### page.tsx + +*Path: apps/web/app/canva-track/[...trackIds]/page.tsx* + +1. **Purpose:** This file renders a Canva presentation embedded within an iframe. It retrieves the Canva link and title from URL parameters and displays the presentation in a full-screen view. + +2. **Key Functionality:** + +- **`Header` Component:** + - Parameters: `title` (string) - The title of the Canva presentation. + - Return Type: `React.ReactElement` - Renders the header section of the page. + - Implementation: Displays the provided title and a link back to the home page with an image. Uses `motion.div` from `framer-motion` for animation effects. + +- **`CanvaTrack` Component (default export):** + - Parameters: None + - Return Type: `React.ReactElement` - Renders the entire page containing the embedded Canva presentation. + - Implementation: + - Uses `useSearchParams` from `next/navigation` to retrieve URL parameters (`canvaLink`, `title`). + - Constructs the `embedUrl` by appending `?embed` to the `canvaLink` if it's not already present. + - Renders a full-screen iframe with the `embedUrl` as its source, allowing fullscreen viewing. + - Includes error handling: If `embedUrl` is missing, it displays a "No Canva presentation link provided" message. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `React`: Core React library. + - `useSearchParams` (from `next/navigation`): For accessing URL query parameters. + - `motion` (from `framer-motion`): For animation effects. + - `Link` (from `next/link`): For client-side navigation. + - `Image` (from `next/image`): For optimized image rendering. + +- **Code Relationships:** This file is a standalone page component within a Next.js application. It likely interacts with other parts of the application through routing and potentially shared context or data fetching mechanisms (not shown in this file). + +4. **Usage Example:** + +Navigating to a URL like `/canva-track/123?canvaLink=https://www.canva.com/design/DAFadsf/view&title=My%20Presentation` would render this page with the specified Canva presentation embedded. The `[...trackIds]` dynamic route segment suggests that this page might handle multiple Canva presentations based on IDs, although this specific implementation only uses the query parameters. + +5. **Technical Notes:** + +- The use of `?embed` ensures that the Canva presentation is displayed in embed mode within the iframe. +- The `allowFullScreen` and `allow="fullscreen"` attributes enable fullscreen viewing of the embedded presentation. +- The conditional rendering based on `embedUrl` provides a basic error handling mechanism. +- The use of `framer-motion` adds subtle animations to the header, enhancing the user experience. The specific animation configuration (duration, ease, type, damping) could be adjusted for different effects. +- The `Image` component from `next/image` is used for optimized image loading and responsiveness. It's important to provide appropriate `width` and `height` props for optimal performance. + + +This documentation provides a comprehensive overview of the file's purpose, functionality, dependencies, and usage. It highlights key implementation details, error handling, and technical considerations, offering valuable insights into how this component integrates within a larger Next.js application. + +--- + +### apps/web/app/pdf/[...pdfId] + + + +#### page.tsx + +*Path: apps/web/app/pdf/[...pdfId]/page.tsx* + +1. **Purpose:** This file defines a dynamic route handler for rendering a printable lesson view based on a track ID and problem ID. It fetches data from a Notion API and renders the content using Next.js components. + +2. **Key Functionality:** + +- **`TrackComponent({ params })`:** + - **Parameters:** `params`: An object containing the dynamic route parameters. `params.pdfId` is an array where `pdfId[0]` is the `trackId` and `pdfId[1]` is the `problemId`. + - **Return Type:** JSX.Element (React component) + - **Implementation:** + - Extracts `trackId` and `problemId` from `params`. + - Redirects to a specific track if `trackId` matches a hardcoded value. + - Fetches problem and track details using `getProblem` and `getTrack`. + - If no `problemId` is provided, redirects to the last solved problem using `RedirectToLastSolved`. + - Fetches Notion page data for the problem and all problems in the track using `notion.getPage`. This fetches data for all problems in the track to allow printing of the entire track. + - Redirects to the login page if the user is not authenticated, preserving the intended download URL. + - Renders `LessonView` components for each problem in the track, passing the fetched data. + - Includes a `Print` component for printing functionality. + - **Fallback Mechanisms:** Redirects to login if no session exists. Handles missing `problemId` by redirecting to the last solved problem. + +- **Dependencies:** + - `RedirectToLastSolved`: Internal component for redirecting to the last solved problem. + - `NotionAPI`: External library for interacting with the Notion API. + - `redirect`: Next.js function for redirecting navigation. + - `Print`: Internal component for printing functionality. + - `getProblem`, `getTrack`: Internal utility functions for fetching problem and track details. + - `LessonView`: Internal component for displaying lesson content. + - `getServerSession`: NextAuth function for retrieving the server-side session. + - `authOptions`: NextAuth configuration options. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** Imports components, utility functions, and external libraries as described above. +- **Code Relationships:** This file depends on the `getProblem` and `getTrack` functions to fetch data. It uses the `LessonView` component to display the lesson content and the `Print` component for printing. It interacts with the authentication system through `getServerSession` and `authOptions`. + +4. **Usage Example:** Accessing the URL `/pdf/some-track-id/some-problem-id` will trigger this route handler. + +5. **Technical Notes:** + +- The code fetches Notion data for all problems in the track, even though only one problem is initially displayed. This is likely done to enable printing of the entire track at once. This could be optimized to fetch data on demand if performance becomes an issue. +- The hardcoded redirect for a specific `trackId` suggests a potential temporary workaround or a special case that needs to be addressed more systematically. +- The use of `Promise.all` for fetching Notion pages optimizes performance by fetching data concurrently. + + +--- + + +No other files were provided, so only File 1 is documented. If you provide additional files, I can generate documentation for them as well. Remember to provide context about how the files relate to each other. For example, if a file imports a function from another file, mention this relationship explicitly. This will help create a comprehensive and interconnected documentation set. + +--- + +### apps/web/app/profile + + + +#### layout.tsx + +*Path: apps/web/app/profile/layout.tsx* + +1. **Purpose:** This file defines the layout for the user profile page in a Next.js web application. It structures the profile section with a sidebar and content area. + +2. **Key Functionality:** + +- **`ProfileLayout` Function:** + - **Parameters:** `children: React.ReactNode` (The content to be rendered within the layout) + - **Return Type:** `JSX.Element` (The rendered layout component) + - **Implementation:** This function uses a grid layout to arrange the `ProfileSidebar` and `ProfileChilldren` components. It wraps the provided `children` within the `ProfileChilldren` component, placing it in the main content area. The `AppbarClient` component is rendered at the top. + - **Fallback Mechanisms:** No specific fallback mechanisms are implemented within this layout component. Error handling would be handled by parent components or error boundaries higher up in the component tree. + +- **`metadata` Constant:** + - **Type:** `Metadata` (Next.js metadata object) + - **Implementation:** Defines metadata for the page, including the title and description for SEO purposes. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `Metadata` from `next`: Used for defining page metadata. + - `AppbarClient` from `../../components/AppbarClient`: The application's app bar component. + - `ProfileSidebar` from `../../components/ProfileSidebar`: The sidebar component for the profile page. + - `ProfileChilldren` from `../../components/ProfileChildren`: A wrapper component for the dynamic content within the profile section. + +- **Code Relationships:** This layout is used by the `page.tsx` file within the same directory to structure the profile page content. It relies on the `AppbarClient`, `ProfileSidebar`, and `ProfileChildren` components. + +4. **Usage Example:** + +```tsx +// In page.tsx +import ProfileLayout from './layout'; + +export default function ProfilePage() { + return ( + + {/* Content specific to the profile page */} +

Profile content here
+ + ); +} +``` + +5. **Technical Notes:** + +- The use of a grid layout (`grid grid-cols-8`) provides a responsive structure for the profile page. +- The `ProfileChildren` component acts as a container for the dynamic content passed as children, ensuring consistent styling and positioning within the layout. + +--- + + + +#### page.tsx + +*Path: apps/web/app/profile/page.tsx* + +1. **Purpose:** This file defines the main content and logic for the user profile page. It handles authentication and renders the user's profile details. + +2. **Key Functionality:** + +- **`Profile` Function:** + - **Return Type:** `JSX.Element` (The rendered profile page component) + - **Implementation:** This function first checks for an active user session using `getServerSession`. If no session exists, it redirects the user to the authentication page (`/auth`). If a session exists, it renders the profile page content, including a header and the `UserDetailForm` component. + - **Fallback Mechanisms:** Redirects to `/auth` if no user session is found. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `getServerSession` from `next-auth`: Used for server-side authentication. + - `authOptions` from `../../lib/auth`: Authentication configuration. + - `redirect` from `next/navigation`: Used for client-side navigation. + - `UserRound` from `lucide-react`: Icon component. + - `UserDetailForm` from `../../components/UserDetailForm`: Component for displaying and editing user details. + +- **Code Relationships:** This page uses the `ProfileLayout` component from `layout.tsx` to structure its content. It depends on the `next-auth` library for authentication and utilizes the `UserDetailForm` component to display user details. + +4. **Usage Example:** This file represents a page route in the Next.js application and is accessed via the `/profile` URL. + +5. **Technical Notes:** + +- Server-side authentication ensures that sensitive user data is not exposed on the client-side. +- The use of `redirect` provides a seamless client-side transition to the login page if the user is not authenticated. +- This file depends on the `layout.tsx` file for its overall structure and layout. The `UserDetailForm` component, used within this page, likely receives the user data from the `session.user` object to pre-fill the form fields. This demonstrates a clear flow of data and dependencies between the files within the profile section of the application. + +--- + +### apps/web/app/tracks/[...trackIds] + + + +#### page.tsx + +*Path: apps/web/app/tracks/[...trackIds]/page.tsx* + +1. **Purpose:** This file defines a dynamic Next.js page component responsible for rendering individual lesson pages within a learning track. It fetches track and problem details and displays them using a `LessonView` component. + +2. **Key Functionality:** + +- **`generateMetadata({ params })`**: This asynchronous function generates dynamic metadata for the page based on the track ID. It fetches track details using `getTrack(trackId)` and returns an object containing the title, description, and open graph metadata. If the track is not found, it returns default metadata indicating a 404. + - **Parameters:** `params`: An object containing the route parameters, including `trackIds`. + - **Return Type:** An object containing metadata for the page. +- **`generateStaticParams()`**: This asynchronous function generates static parameters for pre-rendering. It fetches all tracks and their associated problems using `getAllTracks()` and `cache` (for memoization). It returns an array of objects, each representing a page to be pre-rendered. Error handling is included with a console log and an empty array return. + - **Return Type:** An array of objects representing static paths. +- **`TrackComponent({ params })`**: This is the main page component. It retrieves the `trackId` and `problemId` from the route parameters. It handles redirection for a specific track ID. It fetches problem and track details using `getProblem()` and `getTrack()`. If no `problemId` is provided, it redirects to the last solved problem in the track using `RedirectToLastSolved`. If a `notionDocId` exists for the problem, it fetches the Notion page content using `notion.getPage()`. Finally, it renders the `LessonView` component with the fetched data or returns a 404 if the data is not found. + - **Parameters:** `params`: An object containing the route parameters. + - **Return Type:** JSX to be rendered. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `RedirectToLastSolved`: Internal component for redirecting to the last solved problem. + - `NotionAPI` from `notion-client`: Used for fetching data from Notion. + - `redirect`, `notFound` from `next/navigation`: Next.js routing functions. + - `getAllTracks`, `getProblem`, `getTrack`: Internal utility functions for data fetching. + - `cache` from `react`: For memoizing the `getAllTracks` function. + - `LessonView`: Internal component for rendering the lesson content. +- **Code Relationships:** + - This file depends on the `components/utils.ts` file for data fetching functions (`getAllTracks`, `getProblem`, `getTrack`). + - It uses the `components/RedirectToLastSolved` component for handling redirection logic. + - It uses the `components/LessonView` component to display the lesson content. + +4. **Usage Example:** + +Navigating to `/tracks/some-track-id/some-problem-id` will render this page component. Next.js will use the `generateStaticParams` and `generateMetadata` functions at build time for pre-rendering and SEO. + +5. **Technical Notes:** + +- The use of `cache` around `getAllTracks` improves performance by memoizing the results. +- The fallback to a default thumbnail image in `generateMetadata` enhances robustness. +- The redirection logic for a specific track ID (`43XrfL4n0LgSnTkSB4rO`) suggests a potential migration or alias. +- The dynamic route `[...trackIds]` allows for flexible handling of both track and problem IDs within the URL. The code handles cases where only the `trackId` is present. + +--- + +### apps/web/components + + + +#### Appbar.tsx + +*Path: apps/web/components/Appbar.tsx* + +1. **Purpose:** This component renders the main application AppBar, providing navigation and user authentication controls for the web application. It displays the logo, a mode toggle, a login button (or user dropdown if logged in), and links to other parts of the application. + +2. **Key Functionality:** + +- **`Appbar`**: The main functional component. + - *Parameters:* None + - *Return type:* `JSX.Element` + - *Implementation:* Uses `next/link` for routing, `@repo/ui` for UI components, `next-auth/react` for authentication, and `framer-motion` for animations. It conditionally renders the login button or user dropdown based on the authentication status. + +- **Dependencies:** + - `next/link`: For navigation. + - `@repo/ui`: For UI components (Button). + - `next-auth/react`: For authentication (signIn, useSession). + - `./ModeToggle`: For toggling light/dark mode. + - `./UserAccountDropDown`: For displaying user account options. + - `next/image`: For displaying images. + - `framer-motion`: For animations. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports components from `next/link`, `@repo/ui`, `next-auth/react`, and other internal components. + - **Code Relationships:** This component is used by `AppbarClient.tsx` to provide a client-side rendered version of the AppBar. + +4. **Usage Example:** +```tsx + +``` +This component is typically used at the top level of the application layout. + +5. **Technical Notes:** + - Uses Framer Motion for subtle animations, enhancing user experience. + - Conditionally renders content based on user authentication status. + +--- + + + +#### AppbarClient.tsx + +*Path: apps/web/components/AppbarClient.tsx* + +1. **Purpose:** This component acts as a client-side wrapper for the `Appbar` component. This allows the AppBar to utilize client-side features and APIs. + +2. **Key Functionality:** + - **`AppbarClient`**: A simple functional component that renders the `Appbar` component. + - *Parameters:* None + - *Return type:* `JSX.Element` + - *Implementation:* Directly returns the `Appbar` component. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports the `Appbar` component from `./Appbar`. + - **Code Relationships:** This component is used wherever the `Appbar` is needed on client-side rendered pages. It ensures that the `Appbar` has access to the client-side context. + +4. **Usage Example:** This component is used directly in client components where the app bar is needed. + +5. **Technical Notes:** The `"use client"` directive at the top signifies that this is a client component. + +--- + + + +#### Blog.tsx + +*Path: apps/web/components/Blog.tsx* + +1. **Purpose:** This component renders blog content fetched from Notion, handles different view modes (legacy and new), and integrates with other components like `BlogAppbar`, `NotionRenderer`, and `TrackTools`. + +2. **Key Functionality:** + - **`Blog`**: The main functional component. + - *Parameters:* `problem` (Problem data with Notion record map), `track` (Track data), `showAppBar` (boolean), `showPagination` (boolean), `isPdfRequested` (boolean), `problemIndex` (number). + - *Return type:* `JSX.Element` + - *Implementation:* Conditionally renders based on `isLegacyMode` state from Recoil. Uses `NotionRenderer` to display Notion content and integrates with `BlogAppbar`, `TrackTools`, and `CustomPagination` for navigation and other functionalities. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports from `recoil`, `@prisma/client`, `@repo/store`, and other internal components. + - **Code Relationships:** This component uses `BlogAppbar` for the app bar specific to blog posts, `NotionRenderer` to render Notion content, `TrackTools` for track-related tools, and `CustomPagination` for pagination. + +4. **Usage Example:** This component is used to display individual blog posts within a track. + +5. **Technical Notes:** + - Uses Recoil for state management (`isLegacyViewMode`). + - Handles different view modes based on user preference. + +--- + + + +#### BlogAppbar.tsx + +*Path: apps/web/components/BlogAppbar.tsx* + +1. **Purpose:** This component renders the application bar specific to blog posts, providing navigation, user authentication, and UI mode toggling. It also handles scroll behavior and displays track information. + +2. **Key Functionality:** + - **`BlogAppbar`**: The main functional component. + - *Parameters:* `problem` (Problem data), `track` (Track data), `problemIndex` (number). + - *Return type:* `JSX.Element` + - *Implementation:* Uses `next/navigation` for routing, `next-auth/react` for authentication, `recoil` for state management, `framer-motion` for animations, and `@repo/ui` for UI components. Handles scroll behavior to hide/show the app bar and conditionally renders based on `isLegacyMode`. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports from various libraries like `next/link`, `next/navigation`, `next-auth/react`, `recoil`, `framer-motion`, `@repo/ui`, and internal components. + - **Code Relationships:** Uses `ModeToggle`, `UserAccountDropDown`, and `CustomPagination` components. Interacts with the `isLegacyViewMode` state in `@repo/store`. + +4. **Usage Example:** Used within the `Blog` component to provide context-specific navigation and controls. + +5. **Technical Notes:** + - Uses debouncing for scroll handling to optimize performance. + - Stores view mode preference in local storage. + - Uses keyboard navigation for next/previous problem navigation. + +--- + + + +#### Categories.tsx + +*Path: apps/web/components/Categories.tsx* + +1. **Purpose:** This component renders a category selection UI, allowing users to filter content based on categories. It provides both a select dropdown and button-based UI depending on screen size. + +2. **Key Functionality:** + - **`Categories`**: The main functional component. + - *Parameters:* `categories` (array of Category objects). + - *Return type:* `JSX.Element` + - *Implementation:* Uses `@repo/ui` components for the UI and `recoil` for state management. Conditionally renders `SelectCategory` or `ButtonCategory` based on screen size. + - **`SelectCategory`**: Renders a select dropdown for category selection. + - **`ButtonCategory`**: Renders buttons for category selection. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports from `recoil` and `@repo/ui`. + - **Code Relationships:** Uses the `category` state from `@repo/store`. + +4. **Usage Example:** Used wherever category filtering is required. + +5. **Technical Notes:** + - Uses Recoil for managing the selected category state. + - Provides different UI layouts for different screen sizes. + +--- + + + +#### CodeBlock.tsx + +*Path: apps/web/components/CodeBlock.tsx* + +1. **Purpose:** This component renders code blocks with syntax highlighting and a copy-to-clipboard functionality. + +2. **Key Functionality:** + - **`CodeBlock`**: The main functional component. + - *Parameters:* `block` (object containing code block properties). + - *Return type:* `JSX.Element` + - *Implementation:* Uses `highlight.js` for syntax highlighting and provides a copy button using `lucide-react` and `@repo/ui`. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports `highlight.js`, `@repo/ui`, and `lucide-react`. + +4. **Usage Example:** Used to display code snippets within blog posts or other content. + +5. **Technical Notes:** + - Uses `highlight.js` for syntax highlighting. + - Provides a user-friendly copy-to-clipboard feature. + +--- + + + +#### ContentSearch.tsx + +*Path: apps/web/components/ContentSearch.tsx* + +1. **Purpose:** This component provides a search dialog to search for content within the application, using Fuse.js for fuzzy searching. + +2. **Key Functionality:** + - **`ContentSearch`**: The main functional component. + - *Parameters:* `tracks` (array of TrackPros objects). + - *Return type:* `JSX.Element` + - *Implementation:* Uses `radix-ui` and `@repo/ui` for UI components, `fuse.js` for fuzzy searching, and `next/link` for navigation. Handles keyboard navigation for search results. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports from `next/link`, `radix-ui`, `@repo/ui`, and `fuse.js`. + +4. **Usage Example:** Used to provide a search interface within the application. + +5. **Technical Notes:** + - Uses Fuse.js for efficient fuzzy searching. + - Implements keyboard navigation for search results. + - Uses a deferred value for input to optimize search performance. + +--- + + + +#### CustomPagination.tsx + +*Path: apps/web/components/CustomPagination.tsx* + +1. **Purpose:** This component renders pagination controls for navigating between problems within a track. + +2. **Key Functionality:** + - **`CustomPagination`**: The main functional component. + - *Parameters:* `allProblems` (array of Problem objects), `isAtHeader` (boolean), `problemIndex` (number), `track` (Track object). + - *Return type:* `JSX.Element` + - *Implementation:* Uses `next/link` for navigation and `@repo/ui` for UI components. Provides "Previous" and "Next" buttons. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports from `next/link`, `@repo/ui`, `@prisma/client`, and `./PageToggle`. + - **Code Relationships:** Uses the `PageToggle` component. + +4. **Usage Example:** Used within the `Blog` and `BlogAppbar` components for navigation between problems. + +5. **Technical Notes:** + - Uses `next/link` prefetching for improved navigation performance. + +--- + + + +#### EditProblem.tsx + +*Path: apps/web/components/EditProblem.tsx* + +1. **Purpose:** This component provides an interface for editing problem details, including ID, title, and Notion Doc ID. + +2. **Key Functionality:** + - **`EditProblem`**: The main functional component. + - *Parameters:* `problem` (Problem data). + - *Return type:* `JSX.Element` + - *Implementation:* Uses state to manage editing mode and problem details. Uses `@repo/ui` components for the UI. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports from `@prisma/client` and `@repo/ui`. + +4. **Usage Example:** Used within an admin interface to edit problem details. + +--- + + + +#### ErrorBoundary.tsx + +*Path: apps/web/components/ErrorBoundary.tsx* + +1. **Purpose:** This component implements an error boundary to catch and handle errors during rendering, preventing the entire application from crashing. + +2. **Key Functionality:** + - **`ErrorBoundary`**: A class component extending `React.Component`. + - *Parameters:* `children` (ReactNode). + - *Return type:* `JSX.Element` or a fallback UI. + - *Implementation:* Uses `getDerivedStateFromError` and `componentDidCatch` lifecycle methods to catch and handle errors. + +3. **Dependencies and Relationships:** None + +4. **Usage Example:** Wrap components that might throw errors within this component. + +--- + + + +#### Hero.tsx + +*Path: apps/web/components/Hero.tsx* + +1. **Purpose:** This component renders the hero section of the landing page, including a parallax effect, title, description, and a search bar. + +2. **Key Functionality:** + - **`Hero`**: The main functional component. + - *Parameters:* `tracks` (array of TrackPros objects). + - *Return type:* `JSX.Element` + - *Implementation:* Uses `framer-motion` for animations and `@repo/ui` for UI components. Implements a parallax effect based on mouse position. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports from `framer-motion`, `@repo/ui`, and `./ContentSearch`. + - **Code Relationships:** Uses the `ContentSearch` component. + +4. **Usage Example:** Used on the landing page to create an engaging introduction. + +5. **Technical Notes:** + - Uses `framer-motion` for animations and parallax effect. + +--- + + + +#### LessonView.tsx + +*Path: apps/web/components/LessonView.tsx* + +1. **Purpose:** This component acts as a router for different lesson types (MCQ or Blog), rendering the appropriate component based on the problem type. It also handles authentication checks for premium content. + +2. **Key Functionality:** + - **`LessonView`**: An async functional component. + - *Parameters:* `problem` (Problem data), `track` (Track data), `showAppBar` (boolean), `showPagination` (boolean), `isPdfRequested` (boolean). + - *Return type:* `JSX.Element` + - *Implementation:* Checks user authentication status and renders either `MCQRenderer` or `Blog` component based on `problem.type`. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports from `next-auth`, `@prisma/client`, and internal components (`Blog`, `MCQRenderer`, `RedirectToLoginCard`, `AppbarClient`). + - **Code Relationships:** Uses `Blog`, `MCQRenderer`, `RedirectToLoginCard`, and `AppbarClient` components. + +4. **Usage Example:** Used to render individual lesson content within a track. + +5. **Technical Notes:** + - Handles authentication checks for premium content. + +--- + + + +#### Loader.tsx + +*Path: apps/web/components/Loader.tsx* + +1. **Purpose:** This component renders a loading spinner while content is being fetched or processed. + +2. **Key Functionality:** + - **`Loader`**: A simple functional component. + - *Parameters:* None + - *Return type:* `JSX.Element` + - *Implementation:* Returns an SVG spinner with animation. + +3. **Dependencies and Relationships:** None + +--- + + + +#### ModeToggle.tsx + +*Path: apps/web/components/ModeToggle.tsx* + +1. **Purpose:** This component renders a toggle switch for switching between light and dark modes. + +2. **Key Functionality:** + - **`ModeToggle`**: The main functional component. + - *Parameters:* None + - *Return type:* `JSX.Element` + - *Implementation:* Uses `next-themes` for managing the theme and `@repo/ui` for UI components. Conditionally renders different toggle styles based on `isLegacyViewMode`. + +3. **Dependencies and Relationships:** + - **Imports & Usage:** Imports from `next-themes`, `recoil`, `@repo/ui`, and `lucide-react`. + - **Code Relationships:** Uses the `isLegacyViewMode` state from `@repo/store`. + +4. **Usage Example:** Used in the `Appbar` and `BlogAppbar` components. + +5. **Technical Notes:** + - Uses `next-themes` for theme management. + +--- + + + +#### MultipleOptionChip.tsx + +*Path: apps/web/components/MultipleOptionChip.tsx* + +1. **Purpose:** This component renders a simple chip displaying a given value, typically used for displaying multiple options or tags. + +2. **Key Functionality:** + - **`MultipleOptionChip`**: The main functional component. + - *Parameters:* `value` (string). + - *Return type:* `JSX.Element` + - *Implementation:* Returns a styled div containing the value. + +3. **Dependencies and Relationships:** None + + +This documentation provides a comprehensive overview of each file's purpose, functionality, dependencies, and relationships within the project. It emphasizes how these files work together to create the web application, highlighting key technical decisions and considerations. This structured approach ensures clarity and maintainability for the project. + +--- + + + +#### NotionRenderer.tsx + +*Path: apps/web/components/NotionRenderer.tsx* + +1. **Purpose:** This component renders Notion content using `react-notion-x`, providing styling and custom components for specific Notion blocks like code blocks. It adapts to the current theme (light/dark) and rendering mode (legacy/new). + +2. **Key Functionality:** + + - **`NotionRenderer` (functional component):** + - **Parameters:** + - `recordMap`: (object) The Notion data structure representing the page content. + - **Return Type:** (JSX.Element) The rendered Notion content. + - **Implementation:** Uses `react-notion-x`'s `NotionRenderer` to render the `recordMap`. It conditionally applies styling based on `isLegacyMode` for backward compatibility. Custom components, like `CodeBlock`, are passed via the `components` prop to override default rendering for specific Notion block types. The `useTheme` hook provides the current theme for styling. `useRecoilValue(isLegacyViewMode)` determines the rendering mode. + - **Fallback Mechanisms:** No explicit fallback mechanisms are present. Errors during rendering might be handled by `react-notion-x` internally. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `react-notion-x`: For rendering Notion content. + - `next-themes`: For accessing the current theme. + - `recoil`: For state management (`isLegacyViewMode`). + - `./CodeBlock`: A custom component for rendering code blocks. + - **Code Relationships:** This component is used wherever Notion content needs to be displayed within the application. It depends on the `CodeBlock` component for customized code block rendering. The `isLegacyViewMode` state from `@repo/store` influences its rendering. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The conditional styling based on `isLegacyMode` suggests a transition phase between two rendering approaches. + - The `useMemo` hook optimizes the `components` prop, preventing unnecessary re-renders. + +--- + + + +#### PageToggle.tsx + +*Path: apps/web/components/PageToggle.tsx* + +1. **Purpose:** This component provides a dropdown menu to navigate between different problems within a track. + +2. **Key Functionality:** + + - **`PageToggle` (functional component):** + - **Parameters:** + - `allProblems`: (Array\) An array of all problems in the track. + - `isAtHeader`: (boolean, optional) Determines styling based on location. + - `track`: (Track) The current track object, including its problems. + - **Return Type:** (JSX.Element) The dropdown menu. + - **Implementation:** Uses `next/navigation`'s `useParams` to get the current track and problem IDs. It renders a `DropdownMenu` from `@repo/ui` with a list of `DropdownMenuItem`s. Each item links to a specific problem within the track. The `isLegacyViewMode` state from `@repo/store` influences styling. + - **Fallback Mechanisms:** No explicit fallback mechanisms. Disabled items prevent navigation to the current problem. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `next/navigation`: For routing and parameter access. + - `next/link`: For creating links. + - `recoil`: For state management (`isLegacyViewMode`). + - `@repo/ui`: For UI components (Button, DropdownMenu, etc.). + - `@prisma/client`: For Prisma types (Track, Problem). + - `@repo/ui/utils`: For utility functions (likely styling). + - `@repo/store`: For application state. + - **Code Relationships:** This component is used within track pages to provide navigation between problems. It depends on the `@repo/ui` library for its UI elements and `@repo/store` for state management. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The `prefetch={true}` prop on the `Link` components optimizes navigation by prefetching the linked pages. + +--- + + + +#### Print.tsx + +*Path: apps/web/components/Print.tsx* + +1. **Purpose:** This component handles printing the current page and automatically closing the print window after completion. + +2. **Key Functionality:** + + - **`Print` (functional component):** + - **Parameters:** None + - **Return Type:** `null` (renders nothing) + - **Implementation:** Uses `useEffect` to perform side effects related to printing. It opens all `
` elements on the page, adds an `afterprint` event listener to close the window after printing, and then triggers the `print()` function. The `useRouter` hook is likely used for cleanup after printing, potentially redirecting back to the original page. + - **Fallback Mechanisms:** No specific fallback mechanisms are implemented. Relies on browser's print functionality. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `react`: For `useEffect` hook. + - `next/navigation`: For `useRouter`. + - **Code Relationships:** This component is likely used within a page or layout that requires print functionality. It doesn't have direct dependencies on other components in the provided code snippets. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The `useEffect` hook ensures that the cleanup (removing the event listener) happens when the component unmounts, preventing memory leaks. + +--- + + + +#### ProfileChildren.tsx + +*Path: apps/web/components/ProfileChildren.tsx* + +1. **Purpose:** This component wraps the children components of the profile page, managing the sidebar toggle state and providing theme and context providers. + +2. **Key Functionality:** + + - **`ProfileChildren` (functional component):** + - **Parameters:** + - `children`: (React.ReactNode) The child components to be rendered. + - **Return Type:** (JSX.Element) The wrapped children. + - **Implementation:** Uses `useRecoilState(profileSidebar)` to manage the sidebar's open/close state. Provides `ThemeProvider` from `next-themes` and custom `Providers` (likely context providers) to its children. A hamburger menu icon is displayed for toggling the sidebar on smaller screens. + - **Fallback Mechanisms:** No explicit fallback mechanisms. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `react`: For JSX and component structure. + - `./Providers`: Custom context providers. + - `recoil`: For state management (`profileSidebar`). + - `lucide-react`: For the Menu icon. + - `next-themes`: For theme management. + - `@repo/store`: For application state. + - **Code Relationships:** This component wraps profile-related content and manages shared state and context. It depends on the `Providers` component and the `profileSidebar` state from `@repo/store`. + +4. **Usage Example:** + + ```tsx + + {/* Profile content */} + + ``` + +5. **Technical Notes:** + - The conditional className based on `sidebarToggle` controls the layout based on the sidebar's state. + +--- + + + +#### ProfileSidebar.tsx + +*Path: apps/web/components/ProfileSidebar.tsx* + +1. **Purpose:** This component renders the sidebar on the profile page, displaying user information and profile options. + +2. **Key Functionality:** + + - **`ProfileSidebar` (functional component):** + - **Parameters:** None + - **Return Type:** (JSX.Element) The sidebar content. + - **Implementation:** Uses `useRecoilValue(profileSidebar)` to determine visibility based on the sidebar toggle state. Displays user information (image, name, email) fetched from `next-auth/react`'s `useSession`. Includes the `ProfileOptions` component for profile-related actions. Conditional styling adapts the sidebar's appearance based on screen size and the `sidebarToggle` state. + - **Fallback Mechanisms:** Uses a placeholder icon if the user doesn't have a profile image. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `react`: For JSX and component structure. + - `./UserImage`: Component for displaying the user's image. + - `lucide-react`: For the UserRound icon. + - `./profile/ProfileOptions`: Component for profile options. + - `recoil`: For state management (`profileSidebar`). + - `next-auth/react`: For user authentication data. + - `@repo/store`: For application state. + - **Code Relationships:** This component is part of the profile page layout. It depends on the `UserImage`, `ProfileOptions` components, and the `profileSidebar` state from `@repo/store`. It also interacts with `next-auth/react` for user data. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The conditional styling based on `sidebarToggle` and screen size creates a responsive sidebar experience. + +--- + + + +#### Providers.tsx + +*Path: apps/web/components/Providers.tsx* + +1. **Purpose:** This file provides context providers for Recoil (state management), Next.js themes, and NextAuth.js sessions, wrapping the application's children components. It also includes a toaster for notifications. + +2. **Key Functionality:** + + - **`Providers` (functional component):** + - **Parameters:** + - `children`: (React.ReactNode) The application's content. + - **Return Type:** (JSX.Element) The wrapped content. + - **Implementation:** Wraps the children with `SessionProvider` (for NextAuth.js), `RecoilRoot` (for Recoil), and a `Toaster` component (likely for notifications). + - **Fallback Mechanisms:** No explicit fallback mechanisms. + + - **`ThemeProvider` (functional component):** + - **Parameters:** Standard `ThemeProviderProps` from `next-themes`. + - **Return Type:** (JSX.Element) The wrapped content. + - **Implementation:** A wrapper around `next-themes`'s `ThemeProvider`. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `recoil`: For state management. + - `react`: For JSX and component structure. + - `next-themes`: For theme management. + - `next-auth/react`: For authentication. + - `@repo/ui`: For the `Toaster` component. + - **Code Relationships:** This file is a crucial part of the application's setup, providing essential context providers. It's used at a high level in the component tree to make these contexts available throughout the app. + +4. **Usage Example:** + + ```tsx + + + + + ``` + +5. **Technical Notes:** + - Wrapping the application with these providers ensures consistent state management, theming, and session handling. + +--- + + + +#### RedirectToLastSolved.tsx + +*Path: apps/web/components/RedirectToLastSolved.tsx* + +1. **Purpose:** This component redirects the user to the last solved problem within a given track, or the first problem if none have been solved. + +2. **Key Functionality:** + + - **`RedirectToLastSolved` (functional component):** + - **Parameters:** + - `trackId`: (string) The ID of the track. + - **Return Type:** (JSX.Element) A loading indicator while redirecting. + - **Implementation:** Uses `useEffect` to call `getFirstProblemForTrack` (not shown in provided code) to get the appropriate problem ID. Then, uses `next/navigation`'s `router.replace` to redirect to the problem page. Displays a `Loader` component while fetching the problem ID and redirecting. + - **Fallback Mechanisms:** No explicit fallback mechanisms, but `getFirstProblemForTrack` likely handles cases where no problems exist or no progress has been made. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `./Loader`: A loading indicator component. + - `react`: For `useEffect` hook. + - `next/navigation`: For routing. + - `./utils`: For the `getFirstProblemForTrack` function. + - **Code Relationships:** This component is used to manage initial navigation within a track. It depends on the `Loader` component and the `getFirstProblemForTrack` utility function. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The `router.replace` method prevents adding a new entry to the browser history, creating a cleaner user experience. + +--- + + + +#### RedirectToLoginCard.tsx + +*Path: apps/web/components/RedirectToLoginCard.tsx* + +1. **Purpose:** This component displays a card prompting the user to log in and redirects them to the login page, storing the current URL for redirection after successful login. + +2. **Key Functionality:** + + - **`RedirectToLoginCard` (functional component):** + - **Parameters:** None + - **Return Type:** (JSX.Element) The login prompt card. + - **Implementation:** Uses `next/navigation`'s `useRouter` and `usePathname` to get the current route. Stores the current pathname in localStorage under the key "loginRedirectUrl". Renders a `Card` component from `@repo/ui` with a button that redirects to the `/auth` route. + - **Fallback Mechanisms:** No explicit fallback mechanisms. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `next/navigation`: For routing and pathname access. + - `@repo/ui`: For UI components (Card, Button, etc.). + - **Code Relationships:** This component is used to gate protected content and redirect unauthenticated users to the login page. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - Storing the redirect URL in localStorage allows redirecting the user back to the original page after login, even if the application is refreshed or closed during the login process. + +--- + + + +#### ScrollToTopWrapper.tsx + +*Path: apps/web/components/ScrollToTopWrapper.tsx* + +1. **Purpose:** This component wraps its children and provides a "Scroll to Top" button. + +2. **Key Functionality:** + + - **`ScrollToTopWrapper` (functional component):** + - **Parameters:** + - `children`: (React.ReactNode) The content to be wrapped. + - **Return Type:** (JSX.Element) The wrapped content with the scroll-to-top button. + - **Implementation:** Uses the `react-scroll-to-top` library to render a scroll-to-top button. The `useTheme` hook from `next-themes` is used, but the `resolvedTheme` value isn't actually used in the code. + - **Fallback Mechanisms:** No explicit fallback mechanisms. Relies on the `react-scroll-to-top` library's internal functionality. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `next-themes`: For theme access (although not used in the current implementation). + - `react`: For JSX and component structure. + - `react-scroll-to-top`: For the scroll-to-top button. + - **Code Relationships:** This component is a layout component that can be used to wrap any part of the application where a scroll-to-top functionality is desired. + +4. **Usage Example:** + + ```tsx + + {/* Page content */} + + ``` + +5. **Technical Notes:** + - The `resolvedTheme` from `next-themes` is currently unused. This might indicate future plans for theme-specific styling of the scroll-to-top button. + +--- + + + +#### SearchDialog.tsx + +*Path: apps/web/components/SearchDialog.tsx* + +1. **Purpose:** This component provides a searchable dialog for navigating to specific tracks and problems within the application. It also supports voice search. + +2. **Key Functionality:** + + - **`SearchDialog` (functional component):** + - **Parameters:** + - `tracks`: (Array\) An array of tracks and their associated problems. + - **Return Type:** (JSX.Element) The search dialog. + - **Implementation:** Uses a `Dialog` from `@repo/ui`. Allows searching by track title and description. Implements keyboard navigation (up/down arrows, enter) for selecting search results. Uses the Web Speech API for voice search. The `TrackList` component displays the search results. + - **Fallback Mechanisms:** No explicit fallback mechanisms, but handles empty search results gracefully. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `@radix-ui/react-icons`: For icons. + - `@repo/ui`: For UI components (Dialog, Button, Input). + - `react`: For hooks and component structure. + - `@prisma/client`: For Prisma types (Track, Problem). + - `./TrackList`: Component for displaying track lists. + - `next/link`: For navigation. + - **Code Relationships:** This component is used for site-wide search functionality. It depends on the `TrackList` component and interacts with the `@repo/ui` library for its UI elements. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The use of keyboard navigation and voice search enhances accessibility and user experience. + - The `ref` for the scrollable container is used to manage scrolling when navigating search results with the keyboard. + +--- + + + +#### Signin.tsx + +*Path: apps/web/components/Signin.tsx* + +1. **Purpose:** This component provides a sign-in page with options for Google and GitHub authentication. It handles redirection after successful login. + +2. **Key Functionality:** + + - **`Signin` (functional component):** + - **Parameters:** None + - **Return Type:** (JSX.Element) The sign-in page content. + - **Implementation:** Uses `next-auth/react`'s `signIn` and `useSession` for authentication. Provides buttons for signing in with Google and GitHub. After successful login, redirects the user to either a URL stored in localStorage ("loginRedirectUrl") or a "redirectUrl" query parameter, or to the homepage ("/") if no redirect URL is found. Uses `framer-motion` for animations. + - **Fallback Mechanisms:** Redirects to the homepage if no specific redirect URL is provided. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `next-auth/react`: For authentication. + - `react`: For hooks and component structure. + - `next/navigation`: For routing and query parameters. + - `next/image`: For displaying images. + - `@repo/ui`: For UI components (Button, Separator). + - `next/link`: For linking to other pages. + - `framer-motion`: For animations. + - **Code Relationships:** This component is the main entry point for user authentication. It interacts with `next-auth/react` for authentication logic. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The `useRef` hook is used to prevent multiple redirections after login. + - The component handles different redirect scenarios, providing flexibility in how it's used within the application. + +--- + + + +#### TrackCard-2.tsx + +*Path: apps/web/components/TrackCard-2.tsx* + +1. **Purpose:** This component displays a card representing a track, showing its image, title, categories, number of problems, and creation date. It also handles navigation to the track's content. + +2. **Key Functionality:** + + - **`TrackCard2` (functional component):** + - **Parameters:** + - `track`: (TrackCardProps) An object containing track details and associated problems and categories. + - **Return Type:** (JSX.Element) The track card. + - **Implementation:** Uses `framer-motion` for animations on card appearance. Displays track information and categories. Handles clicks on the card, navigating to either a Canva link (if `trackType` is "CANVA") or showing a `TrackPreview` component (for other track types). Uses `formatDistanceToNow` from `date-fns` to format the creation date. + - **Fallback Mechanisms:** No explicit fallback mechanisms. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `react`: For hooks and component structure. + - `framer-motion`: For animations. + - `@prisma/client`: For Prisma types (Track, Problem). + - `./TrackPreview`: Component for displaying a track preview. + - `date-fns`: For date formatting. + - `next/navigation`: For routing. + - **Code Relationships:** This component is used to display track information in a list or grid. It depends on the `TrackPreview` component and uses `date-fns` for date formatting. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The `IntersectionObserver` is used to trigger the animation when the card becomes visible in the viewport, optimizing performance. + - The component handles different track types ("CANVA" and others) with specific navigation logic. + +--- + + + +#### TrackList.tsx + +*Path: apps/web/components/TrackList.tsx* + +1. **Purpose:** This component renders a list item for a given track, displaying its image, title, and description, and linking to the first problem in the track. + +2. **Key Functionality:** + + - **`TrackList` (functional component):** + - **Parameters:** + - `track`: (Track & { problems: Problem[] }) An object containing track details and associated problems. + - **Return Type:** (JSX.Element) The track list item. + - **Implementation:** Renders a `Link` to the first problem of the track. Displays the track's image, title, and a truncated description. + - **Fallback Mechanisms:** No explicit fallback mechanisms. If the track has no problems, the link might not navigate anywhere. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `@prisma/client`: For Prisma types (Track, Problem). + - `next/link`: For navigation. + - **Code Relationships:** This component is used within the `SearchDialog` component to display search results. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The `truncate` class on the description ensures that long descriptions don't overflow the list item. + +--- + + + +#### TrackPreview.tsx + +*Path: apps/web/components/TrackPreview.tsx* + +1. **Purpose:** This component displays a detailed preview of a track, including its image, description, topics, and a "Start" button. + +2. **Key Functionality:** + + - **`TrackPreview` (functional component):** + - **Parameters:** + - `showPreview`: (boolean) Controls the visibility of the preview. + - `setShowPreview`: (function) Function to toggle the visibility of the preview. + - `track`: (object) The track data. + - **Return Type:** (JSX.Element) The track preview dialog. + - **Implementation:** Uses a `Dialog` from `@repo/ui` to display the preview. Shows the track's image, title, categories, description, a list of problems (topics), and a "Start" button that links to the first problem. Truncates the description on smaller screens. Uses `formatDistanceToNow` from `date-fns` to format the creation date. + - **Fallback Mechanisms:** No explicit fallback mechanisms. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `react`: For hooks and component structure. + - `next/link`: For navigation. + - `@repo/ui`: For UI components (Button, Dialog). + - `lucide-react`: For icons. + - `date-fns`: For date formatting. + - **Code Relationships:** This component is used by `TrackCard2` to display a detailed preview when the card is clicked. It uses `date-fns` for date formatting and `@repo/ui` for UI elements. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The component dynamically adjusts the description length based on screen size. + - The `e.stopPropagation()` on the "Start" button prevents the click from closing the dialog. + +--- + + + +#### TrackTools.tsx + +*Path: apps/web/components/TrackTools.tsx* + +1. **Purpose:** This component provides navigation tools within a track, including "Previous," "Next," "Back to Home," "Jump To" (problem selection), and "Go to Top" buttons. + +2. **Key Functionality:** + + - **`TrackTools` (functional component):** + - **Parameters:** + - `track`: (Track & { problems: Problem[] }) The current track and its problems. + - `problemIndex`: (number) The index of the current problem within the track. + - **Return Type:** (JSX.Element) The navigation tools. + - **Implementation:** Uses `next/link` for navigation between problems and back to the homepage. Includes the `PageToggle` component for jumping to specific problems. Provides a "Go to Top" button with smooth scrolling. Disables "Previous" and "Next" buttons when at the beginning or end of the track, respectively. Uses `framer-motion` for animations. + - **Fallback Mechanisms:** Disabled buttons prevent navigation outside the bounds of the track's problems. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `@prisma/client`: For Prisma types (Track, Problem). + - `./PageToggle`: Component for problem selection. + - `next/link`: For navigation. + - `@repo/ui`: For UI components (Button). + - `lucide-react`: For icons. + - `framer-motion`: For animations. + - **Code Relationships:** This component is used within track pages to provide navigation controls. It depends on the `PageToggle` component and uses `next/link` for routing. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - The `prefetch={true}` prop on the `Link` components optimizes navigation by prefetching the linked pages. + - The `scrollToTop` function provides a smooth scrolling experience. + + +Key Overall Relationships and Dependencies: + +- `@repo/ui`: This UI library is used extensively throughout the components for various UI elements. +- `@repo/store`: This module manages application state using Recoil, influencing rendering and behavior in several components. +- `next-auth/react`: Handles authentication and provides user session data. +- `next/navigation`: Used for routing and accessing route parameters. +- `prisma/client`: Provides Prisma types for database interactions. +- `react-notion-x`: Used for rendering Notion content. +- Several components have dependencies on utility functions located in `./utils` (not fully shown in the provided snippets). + + +This documentation provides a comprehensive overview of the provided code files, highlighting their purpose, functionality, dependencies, and relationships within the system. It emphasizes how the files work together and clarifies the flow of data and control between them. This structured approach facilitates understanding and maintainability of the codebase. + +--- + + + +#### Tracks.tsx + +*Path: apps/web/components/Tracks.tsx* + +1. **Purpose:** This component displays a list of tracks, allowing users to filter and sort them by category, cohort, and alphabetical/chronological order. It handles pagination for large lists of tracks. + +2. **Key Functionality:** + + - **`Tracks` Component:** + - `tracks`: (required) An array of `TrackPros` objects, representing the tracks to display. Each `TrackPros` object includes track details, associated problems, and categories. + - `categories`: (required) An array of category objects, each with `id` and `category` strings. Used for filtering tracks by category. + - Uses `useRecoilState` to manage the selected category state globally. + - Uses `useState` to manage filtering, sorting, pagination, loading state, and cohort selection. + - `filterTracks`: Filters tracks based on selected category and cohort. Resets pagination to the first page after filtering. + - `sortTracks`: Sorts tracks based on the selected sorting criteria (ascending, descending, newest, oldest). + - `handleCohortSelection`: Toggles cohort selection between cohort 2, cohort 3, and all cohorts. + - `trackAnimation`: Defines Framer Motion animation for track display. + - Renders a list of `TrackCard2` components, each representing a track. + - Implements pagination using `Pagination` components from `@repo/ui`. + - Displays skeletons while loading. + - Displays a message if no tracks match the filter criteria. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `TrackCard2`: Displays individual track information. + - `@repo/store`: For global state management using Recoil. + - `@prisma/client`: Prisma client for database interactions. + - `recoil`: Recoil library for state management. + - `@repo/ui`: UI components library. + - `framer-motion`: For animations. + - `next/navigation`: For client-side routing. + - **Code Relationships:** + - This component uses data fetched by server components or API routes and passed as props. + - It interacts with `TrackCard2` to display individual track details. + - It relies on `@repo/store` for global state management of the selected category. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + + - Uses Framer Motion for smooth animations. + - Pagination is implemented to handle large lists efficiently. + - Recoil is used for managing the selected category, ensuring consistency across the application. + - Cohort filtering provides a way to quickly view tracks specific to certain cohorts. + +--- + + + +#### UserAccountDropDown.tsx + +*Path: apps/web/components/UserAccountDropDown.tsx* + +1. **Purpose:** This component renders a user account dropdown menu, displaying user information and providing options like viewing the profile and logging out. + +2. **Key Functionality:** + + - `UserAccountDropDown` Component: + - Uses `next-auth/react` for session management and user authentication. + - Uses `useRouter` for client-side navigation. + - `dropDownData`: Array of objects defining dropdown items (currently only "Profile"). + - Renders a `DropdownMenu` from `@repo/ui`. + - Displays user image (using `UserImage` component) and name. + - Handles logout functionality using `signOut` from `next-auth/react`. + - Uses Framer Motion's `AnimatePresence` for smooth dropdown animations. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `@repo/ui`: UI components library. + - `next-auth/react`: Next.js authentication library. + - `lucide-react`: Icon library. + - `next/navigation`: Client-side routing. + - `UserImage`: Component to display user image. + - `framer-motion`: Animation library. + - **Code Relationships:** + - Uses `UserImage` to display the user's profile picture. + - Depends on `next-auth/react` for user authentication and session management. + +4. **Usage Example:** + + ```tsx + + ``` + +5. **Technical Notes:** + - Uses Framer Motion for smooth entry/exit animations of the dropdown content. + - The component conditionally renders based on user authentication status. + +--- + + + +#### UserDetailForm.tsx + +*Path: apps/web/components/UserDetailForm.tsx* + +1. **Purpose:** This component displays a form with user details, including profile picture, name, and email. The fields are currently disabled, suggesting a view-only purpose. + +2. **Key Functionality:** + + - `UserDetailForm` Component: + - `user`: (required) A `User` object from Prisma client, containing user details. + - Renders user's profile picture using the `UserImage` component. + - Displays user's name and email in disabled input fields. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `@repo/ui`: UI components library. + - `UserImage`: Component to display user image. + - `@prisma/client`: Prisma client for database models. + - **Code Relationships:** + - Uses `UserImage` to display the user's profile picture. + - Receives user data as props, likely fetched from a database or API route. + +4. **Usage Example:** + + ```tsx + + ``` + +--- + + + +#### UserImage.tsx + +*Path: apps/web/components/UserImage.tsx* + +1. **Purpose:** This component displays a user's profile image. + +2. **Key Functionality:** + + - `UserImage` Component: + - `image`: (required) The URL of the user's image. + - Renders an `img` element with the provided image URL. + - Sets default `width`, `height`, and `alt` attributes. + - Uses `referrerPolicy="no-referrer"` for privacy. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** None (besides React). + - **Code Relationships:** Used by other components (like `UserAccountDropDown` and `UserDetailForm`) to display user images. + +--- + + + +#### card.tsx + +*Path: apps/web/components/card.tsx* + +1. **Purpose:** This component renders a clickable card with a title and content, linking to an external resource. + +2. **Key Functionality:** + + - `Card` Component: + - `className`: Optional CSS class name for styling. + - `title`: (required) The title of the card. + - `children`: (required) The content of the card. + - `href`: (required) The URL the card links to. + - Renders an `a` tag with the provided `href`, opening in a new tab. + - Appends UTM parameters to the URL for tracking. + +3. **Dependencies and Relationships:** None (besides React). + +--- + + + +#### use-follow-pointer.ts + +*Path: apps/web/components/use-follow-pointer.ts* + +1. **Purpose:** This custom hook creates a smooth, spring-based animation that follows the user's pointer position. + +2. **Key Functionality:** + + - `useFollowPointer` hook: + - `ref`: (required) A ref to the element that should follow the pointer. + - Uses Framer Motion's `useMotionValue`, `useSpring`, and `frame` for animation. + - Calculates the x and y offsets based on pointer position and element position. + - Returns `x` and `y` motion values that can be used to animate an element's position. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** `framer-motion` for animation logic. + - **Code Relationships:** Intended to be used within a component to animate an element's position based on pointer movement. + +--- + + + +#### utils.tsx + +*Path: apps/web/components/utils.tsx* + +1. **Purpose:** This file contains server-side utility functions for interacting with the database, primarily related to tracks, problems, categories, and MCQ questions. It utilizes caching for performance optimization. + +2. **Key Functionality:** + + - Various asynchronous functions for database operations: + - `getProblem`, `getFirstProblemForTrack`, `getAllProblems`, `updateProblem`, `createProblem`, `createTrackProblems`, `getTrack`, `getAllTracks`, `createTrack`, `updateTrack`, `getAllCategories`, `getAllMCQs`, `getAllMCQQuestion`, `createMCQ`, `updateMCQ`, `deleteMCQ`, `getAllMCQsForProblem`, `createQuizScore`, `getQuizScore`, `getCategories`, `addCategory`, `deleteCategory`. + - These functions perform CRUD operations on different database entities. + - They use Prisma client for database interactions. + - Caching is implemented using a `cache` object to reduce database load. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** + - `@prisma/client`: Prisma client for database interactions. + - `@repo/db/client`: Database client instance. + - `@repo/db/Cache`: Caching mechanism. + - **Code Relationships:** + - Used by server components and API routes to fetch and manipulate data. + - The caching mechanism improves performance by storing frequently accessed data. + +5. **Technical Notes:** + + - Server-side functions improve security by handling sensitive database operations on the server. + - Caching significantly optimizes performance by reducing database queries. + - The code utilizes asynchronous functions for non-blocking database operations. + - Clear separation of concerns by grouping related database operations into a single utility file. + + +**Inter-file Relationships Summary:** + +- `Tracks.tsx` uses `TrackCard2.tsx` to display individual track information. +- `Tracks.tsx` relies on `@repo/store` (likely containing Recoil state) for managing selected category. +- `UserAccountDropDown.tsx` uses `UserImage.tsx` to display the user's profile picture. +- `UserDetailForm.tsx` uses `UserImage.tsx` to display the user's profile picture. +- Many components rely on `@repo/ui` for UI components. +- Server components/API routes use `utils.tsx` for database operations. +- `utils.tsx` uses `@prisma/client` and `@repo/db/client` for database access and `@repo/db/Cache` for caching. +- Several components use `framer-motion` for animations. +- `UserAccountDropDown.tsx` uses `next-auth/react` for authentication. + + +This documentation provides a comprehensive overview of the provided code files, their functionalities, dependencies, and relationships within the system. It emphasizes the technical aspects and clarifies how these files work together to achieve the application's goals. The use of caching in `utils.tsx` is a key performance optimization strategy. The consistent use of `@repo/ui` suggests a well-structured design system for UI components. The documentation also highlights the use of Framer Motion for animations, indicating a focus on user experience. The reliance on `next-auth/react` in `UserAccountDropDown.tsx` clarifies the authentication mechanism employed. Finally, the clear separation of concerns, particularly the server-side functions in `utils.tsx`, contributes to a maintainable and scalable architecture. + +--- + +### apps/web/components/admin + + + +#### AddProblemCard.tsx + +*Path: apps/web/components/admin/AddProblemCard.tsx* + +1. **Purpose:** This component provides a form for adding new problems to the system. It allows admins to input problem details like title, description, type, and Notion document ID. + +2. **Key Functionality:** + + - **`AddProblemCard` Component:** This functional component renders the problem creation form and manages the state of new problems. + - **`newProblems` (state):** An array of `Problem` objects representing newly added problems. + - **`title` (state):** The title of the problem. + - **`description` (state):** The description of the problem. + - **`notionDocId` (state):** The Notion document ID associated with the problem. + - **`type` (state):** The type of the problem (Blog or MCQ). + - **`handleCreateProblem`:** An async function that calls the `createProblem` utility function to create a new problem in the database. It uses the `toast` hook to provide feedback to the user. + - **JSX Structure:** The component renders a `Card` containing input fields for title, description, Notion ID, and a type selector. A button triggers `handleCreateProblem`. Newly added problems are displayed below the form in separate cards. + +3. **Dependencies and Relationships:** + + - **Imports:** `useState`, `Card`, `CardContent`, `CardDescription`, `CardHeader`, `CardTitle`, `Select`, `SelectContent`, `SelectItem`, `SelectTrigger`, `SelectValue`, `Input`, `Button`, `useToast` from `@repo/ui`; `ProblemType` from `@prisma/client`; `createProblem` from `../utils`. + - **Relationships:** This component uses the `createProblem` utility function to interact with the backend API. It depends on the `@repo/ui` library for UI components. + +4. **Usage Example:** + + ```typescript + + ``` + + This component is likely used within an admin dashboard page. + +5. **Technical Notes:** + + - The component uses client-side rendering (`"use client"`). + - Error handling is implemented using the `toast` notification. + - The `disabled` attribute on the button prevents submission if required fields are empty. + +--- + + + +#### AddTrackCard.tsx + +*Path: apps/web/components/admin/AddTrackCard.tsx* + +1. **Purpose:** This component provides a form for adding new tracks to the system. It allows admins to input track details like title, description, image, category, and visibility. + +2. **Key Functionality:** + + - **`AddTrackCard` Component:** This functional component renders the track creation form. + - **`newTracks` (state):** An array of `Track` objects representing newly added tracks. + - **`id`, `title`, `description`, `image`, `hidden`, `selectedCategory`, `cohort`, `canvaLink` (states):** Track properties managed by the component's state. + - **`handleFilterButton`:** A function to toggle category selection. + - **JSX Structure:** The component renders a `Card` containing input fields for track properties. A button triggers track creation. Newly added tracks are displayed below the form. + +3. **Dependencies and Relationships:** + + - **Imports:** `useState`, UI components from `@repo/ui`, `createTrack` from `../utils`, `Categories`, `Track` from `@prisma/client`. + - **Relationships:** This component uses the `createTrack` utility function to interact with the backend. It receives `categories` as a prop. + +4. **Usage Example:** + + ```typescript + + ``` + +5. **Technical Notes:** + + - Client-side rendering (`"use client"`). + - The `disabled` attribute prevents submission with empty required fields. + +--- + + + +#### AdminAddMCQ.tsx + +*Path: apps/web/components/admin/AdminAddMCQ.tsx* + +1. **Purpose:** This component allows admins to add or edit Multiple Choice Questions (MCQs) associated with a specific problem. + +2. **Key Functionality:** + + - **`AdminAddMCQ` Component:** Manages MCQ creation and editing. + - **`mcqs`, `ExistingMCQs`, `question`, `options`, `option`, `correctOption`, `isUpdate` (states):** Component's state for managing MCQs. + - `handleAddOption`, `handleRemoveOption`, `handleAddMCQ`, `handleRemoveMCQ`, `handleSubmit`, `handleRemoveExistingMCQs`: Functions to manage MCQ data. + - **JSX Structure:** Renders a sheet with input fields for question, options, and correct option. Displays existing MCQs and allows editing/removal. + +3. **Dependencies and Relationships:** + + - **Imports:** `useEffect`, `useState`, UI components from `@repo/ui`, `MCQQuestion`, `Problem` from `@prisma/client`, utility functions from `../utils`, `EditMCQ` component. + - **Relationships:** Uses utility functions to interact with the backend. `EditMCQ` component is used for editing existing MCQs. Receives `problem` as a prop. + +4. **Usage Example:** + + ```typescript + + ``` + +5. **Technical Notes:** + + - Uses `useEffect` to fetch and update MCQs. + +--- + + + +#### AdminMCQ.tsx + +*Path: apps/web/components/admin/AdminMCQ.tsx* + +1. **Purpose:** This component displays a list of problems and allows admins to manage their associated MCQs. + +2. **Key Functionality:** + + - **`AdminMCQ` Component:** Fetches and displays problems. + - **`Problems` (state):** State to store fetched problems. + - **JSX Structure:** Renders a list of cards, each representing a problem. Includes `AdminAddMCQ` component for managing MCQs for each problem. + +3. **Dependencies and Relationships:** + + - **Imports:** `useEffect`, `useState`, `getAllMCQs` from `../utils`, UI components from `@repo/ui`, `Problem`, `MCQQuestion` from `@prisma/client`, `AdminAddMCQ` component. + - **Relationships:** Uses `getAllMCQs` to fetch data. Renders `AdminAddMCQ` for each problem. + +4. **Usage Example:** + + ```typescript + + ``` + +5. **Technical Notes:** + + - Uses `useEffect` to fetch problems on mount. + +--- + + + +#### AdminSearch.tsx + +*Path: apps/web/components/admin/AdminSearch.tsx* + +1. **Purpose:** This component manages the search index for tracks. It allows admins to add tracks to the search index and create the search collection. + +2. **Key Functionality:** + + - **`AdminSearch` Component:** Handles search index operations. + - **`handleAddTracks`:** Adds tracks to the search index. + - **`handlecreateCollection`:** Creates the search collection. + - **JSX Structure:** Renders buttons for creating the collection and adding tracks to the index. Displays lists of tracks in and not in the search index. + +3. **Dependencies and Relationships:** + + - **Imports:** UI components from `@repo/ui`, `Track` from `@prisma/client`, `useState`, `createCollection`, `insertData` from `../../lib/search`. + - **Relationships:** Uses search functions from `../../lib/search`. Receives `TracksinSearch` and `TracksNotinSearch` as props. + +4. **Usage Example:** + + ```typescript + + ``` + +--- + + + +#### CompleteAddTracks.tsx + +*Path: apps/web/components/admin/CompleteAddTracks.tsx* + +1. **Purpose:** This component provides a form for adding tracks with associated problems fetched from Notion. + +2. **Key Functionality:** + + - **`CompleteAddTracks` Component:** Manages track creation with problems. + - State variables for track properties and selected categories. + - `handleFilterButton`: Toggles category selection. + - `useEffect`: Updates track data based on state changes. + - JSX Structure: Renders input fields for track details, category selection buttons, and the `CompleteTrackCard` component. + +3. **Dependencies and Relationships:** + + - **Imports:** `useEffect`, `useState`, UI components from `@repo/ui`, `Categories` from `@prisma/client`, `CompleteTrackCard`, `EditCategories`. + - **Relationships:** Receives `categories` as a prop. Uses `CompleteTrackCard` to handle problem fetching and track creation. Uses `EditCategories` to manage categories. + +4. **Usage Example:** + + ```typescript + + ``` + +--- + + + +#### CompleteTrackCard.tsx + +*Path: apps/web/components/admin/CompleteTrackCard.tsx* + +1. **Purpose:** This component fetches problem details from Notion and adds a new track with the fetched problems. + +2. **Key Functionality:** + + - **`CompleteTrackCard` Component:** Handles fetching problems from Notion and creating a track. + - `handleAddTrack`: Creates a track with the fetched problems. + - `useEffect`: Fetches problem data from Notion based on `notionId`. + - JSX Structure: Renders a sheet with track details and a list of `EditProblem` components for each fetched problem. Includes a button to trigger track creation. + +3. **Dependencies and Relationships:** + + - **Imports:** `useState`, `useEffect`, UI components from `@repo/ui`, `EditProblem`, `createTrack`, `insertData`. + - **Relationships:** Receives `notionId` and `TrackData` as props. Uses `createTrack` to create the track. Uses `insertData` to add the track to the search index. Renders `EditProblem` for each fetched problem. + +--- + + + +#### EditCategories.tsx + +*Path: apps/web/components/admin/EditCategories.tsx* + +1. **Purpose:** This component allows admins to edit existing categories and add new ones. + +2. **Key Functionality:** + + - **`EditCategories` Component:** Manages category editing and creation. + - `handleAddCategory`: Adds a new category. + - `handleDeleteCategory`: Deletes an existing category. + - JSX Structure: Renders a dialog with a list of existing categories and buttons for deleting them. Includes an input field and button for adding new categories. + +3. **Dependencies and Relationships:** + + - **Imports:** UI components from `@repo/ui`, `useState`, `addCategory`, `deleteCategory`, `useRouter`. + - **Relationships:** Uses `addCategory` and `deleteCategory` to interact with the backend. Uses `useRouter` to refresh the page after changes. Receives `categories` as a prop. + +--- + + + +#### EditTrackCard.tsx + +*Path: apps/web/components/admin/EditTrackCard.tsx* + +1. **Purpose:** This component allows admins to edit the details of an existing track. + +2. **Key Functionality:** + + - **`EditTrackCard` Component:** Manages track editing. + - State variables for track properties and selected categories. + - `handleEdit`: Updates the track in the database. + - `handleFilterButton`: Toggles category selection. + - `handleDiscardButton`: Resets the form to the original track data. + - JSX Structure: Renders a card with editable input fields for track properties and category selection buttons. + +3. **Dependencies and Relationships:** + + - **Imports:** `useState`, UI components from `@repo/ui`, `Track`, `Categories` from `@prisma/client`, `updateTrack`. + - **Relationships:** Receives `Track` and `categories` as props. Uses `updateTrack` to update the track in the database. + +--- + + + +#### LinkCard.tsx + +*Path: apps/web/components/admin/LinkCard.tsx* + +1. **Purpose:** This component allows admins to link problems to a specific track. + +2. **Key Functionality:** + + - **`LinkCard` Component:** Manages linking problems to a track. + - `handleAddProblem`: Links a problem to the track. + - JSX Structure: Renders a sheet with input fields for problem ID and sorting order. Displays existing linked problems using `ProblemCard`. + +3. **Dependencies and Relationships:** + + - **Imports:** UI components from `@repo/ui`, `TrackProblems`, `Track` from `@prisma/client`, `useState`, `createTrackProblems`, `ProblemCard`. + - **Relationships:** Receives `track` as a prop. Uses `createTrackProblems` to link problems. Renders `ProblemCard` for existing linked problems. + +--- + + + +#### LinkProblems.tsx + +*Path: apps/web/components/admin/LinkProblems.tsx* + +1. **Purpose:** This component displays a list of tracks and allows admins to manage the problems linked to each track. + +2. **Key Functionality:** + + - **`LinkProblems` Component:** Displays tracks and allows linking problems. + - `search`, `filteredTracks` (states): Manages search and filtering of tracks. + - `useEffect`: Filters tracks based on search input. + - JSX Structure: Renders a search input and a list of track cards. Includes `LinkCard` for managing linked problems. + +3. **Dependencies and Relationships:** + + - **Imports:** `ScrollArea`, `Track` from `@prisma/client`, `Input`, `MagnifyingGlassIcon`, `useEffect`, `useState`, UI components from `@repo/ui`, `LinkCard`. + - **Relationships:** Receives `tracks` as a prop. Renders `LinkCard` for each track. + +--- + + + +#### ProblemCard.tsx + +*Path: apps/web/components/admin/ProblemCard.tsx* + +1. **Purpose:** This component displays a problem's details and allows admins to edit them. + +2. **Key Functionality:** + + - **`ProblemCard` Component:** Manages display and editing of problem details. + - State variables for problem properties. + - `handleEdit`: Updates the problem in the database. + - `handleDiscardButton`: Resets the form to the original problem data. + - JSX Structure: Renders a card with editable input fields for problem properties. + +3. **Dependencies and Relationships:** + + - **Imports:** `useState`, UI components from `@repo/ui`, `Problem`, `ProblemType` from `@prisma/client`, `updateProblem`. + - **Relationships:** Receives `problem` as a prop. Uses `updateProblem` to update the problem in the database. + +--- + + + +#### ProblemEditor.tsx + +*Path: apps/web/components/admin/ProblemEditor.tsx* + +1. **Purpose:** This component displays a list of problems and allows admins to edit them or add new ones. + +2. **Key Functionality:** + + - **`ProblemEditor` Component:** Displays and manages problems. + - JSX Structure: Renders a scrollable area with a list of `ProblemCard` components and an `AddProblemCard` component. + +3. **Dependencies and Relationships:** + + - **Imports:** `Problem` from `@prisma/client`, `ScrollArea`, `ProblemCard`, `AddProblemCard`. + - **Relationships:** Receives `problems` as a prop. Renders `ProblemCard` for each problem and `AddProblemCard` for adding new problems. + +--- + + + +#### TracksEditor.tsx + +*Path: apps/web/components/admin/TracksEditor.tsx* + +1. **Purpose:** This component displays a list of tracks and allows admins to edit them or add new ones. + +2. **Key Functionality:** + + - **`TracksEditor` Component:** Displays and manages tracks. + - JSX Structure: Renders a scrollable area with a list of `EditTrackCard` components and an `AddTrackCard` component. + +3. **Dependencies and Relationships:** + + - **Imports:** `AddTrackCard`, `ScrollArea`, `Track` from `@prisma/client`, `EditTrackCard`, `getAllCategories`. + - **Relationships:** Receives `tracks` as a prop. Uses `getAllCategories` to fetch category data. Renders `EditTrackCard` for each track and `AddTrackCard` for adding new tracks. + + +These components work together to provide a complete admin interface for managing problems, tracks, MCQs, and categories. The `utils` file likely contains API interaction logic. The `@repo/ui` library provides reusable UI components. The `@prisma/client` library is used for database interactions. The search functionality relies on an external search service. The components are designed for client-side rendering and use state management for interactivity. They demonstrate clear separation of concerns and utilize best practices like input validation and error handling. + +--- + +### apps/web/components/mcq + + + +#### EditMCQ.tsx + +*Path: apps/web/components/mcq/EditMCQ.tsx* + +1. **Purpose:** This component provides an interface for editing existing Multiple Choice Questions (MCQs). It allows modifying the question text, options, and the correct answer. + +2. **Key Functionality:** + + - **`EditMCQ` (Component):** + - `mcq: MCQQuestion`: The MCQ object to be edited. + - `setIsUpdate: Dispatch>`: A function to control the visibility of the edit dialog. + - **Implementation:** Manages the state for question, options, and correct option. Uses a dialog to present the editing interface. + - **Fallback Mechanisms:** Uses asynchronous `updateMCQ` function for updates, implicitly handling potential errors within that function. + + - **`handleAddOption`:** + - **Implementation:** Adds new options to the MCQ. Allows multiple options separated by commas. + - **`handleRemoveOption(option: string)`:** + - **Implementation:** Removes the specified option from the MCQ. + - **`handleUpdate`:** + - **Implementation:** Updates the MCQ in the database using the `updateMCQ` utility function. Sets `isUpdating` state to manage UI during the update process. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `@repo/ui` for UI components, `react` for core React functionality, `@prisma/client` for Prisma types, and `../utils` for the `updateMCQ` function. + - **Code Relationships:** This component is used within the context of displaying and managing MCQs, likely within a parent component that lists MCQs and triggers the edit functionality. It interacts with the database via the `updateMCQ` utility function. + +4. **Usage Example:** + +```tsx +// Within a parent component that fetches and displays MCQs + +``` + +5. **Technical Notes:** + - The component relies on the `updateMCQ` utility function for database interaction. Error handling and data validation are assumed to be handled within that utility function. + +--- + + + +#### MCQCard.tsx + +*Path: apps/web/components/mcq/MCQCard.tsx* + +1. **Purpose:** This component displays a set of MCQ questions for a given problem, allows users to answer them, and handles quiz submission and score calculation. + +2. **Key Functionality:** + + - **`MCQCard` (Component):** + - `problem: Problem`: The problem object associated with the MCQs. + - **Implementation:** Fetches MCQ questions, manages user responses, calculates the score, and handles quiz submission. + - **Fallback Mechanisms:** Includes error handling within the `fetchQuestions` and `submitQuiz` functions. Uses toast notifications for user feedback. + + - **`handleResetScore`:** + - **Implementation:** Resets the quiz state, clearing user responses and score. + - **`handleSubmit`:** + - **Implementation:** Calculates the final score, submits the quiz results to the database, and provides feedback to the user. + - **`giveFeedback`:** + - **Implementation:** Generates feedback based on the user's score. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `@repo/ui` for UI components, `next-auth/react` for session management, `@prisma/client` for Prisma types, `./MCQQuestion` for rendering individual questions, and `../utils` for utility functions. + - **Code Relationships:** This component uses `MCQQuestion` to render individual questions. It interacts with the database via the `createQuizScore` and `getAllMCQsForProblem` utility functions. + +4. **Usage Example:** + +```tsx +// Within a component that displays problem details + +``` + +5. **Technical Notes:** + - The component relies on external utility functions for data fetching and submission. The `atempted` state tracks user responses using the question ID as the key. + +--- + + + +#### MCQPanel.tsx + +*Path: apps/web/components/mcq/MCQPanel.tsx* + +1. **Purpose:** This component provides a tabbed interface for displaying the description and submissions related to a specific MCQ problem. + +2. **Key Functionality:** + + - **`MCQPanel` (Component):** + - `problem: Problem & { notionRecordMap: any }`: The problem object, including its Notion record map for rendering the description. + - **Implementation:** Uses a tabbed interface to switch between the problem description and submission history. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `@repo/ui` for UI components, `../NotionRenderer` for rendering Notion content, `./SubmissionMCQ` for displaying submissions, and `@prisma/client` for Prisma types. + - **Code Relationships:** This component uses `NotionRenderer` to display the problem description and `SubmissionMCQ` to display the submission history. + +4. **Usage Example:** + +```tsx +// Within a component that displays problem details + +``` + +5. **Technical Notes:** + - Assumes the `problem` prop includes a `notionRecordMap` for rendering the description. + +--- + + + +#### MCQQuestion.tsx + +*Path: apps/web/components/mcq/MCQQuestion.tsx* + +1. **Purpose:** This component renders a single MCQ question with its options, handles user selection, and provides feedback on correctness. + +2. **Key Functionality:** + + - **`MCQQuestion` (Component):** + - `question: Question`: The MCQ question object. + - `setAtempted`: Function to update the parent component's state with the user's answer. + - `isReset`: Flag to indicate if the quiz has been reset. + - `isSubmitted`: Flag to indicate if the quiz has been submitted. + - `setisSubmitted`: Function to update the parent's submission state. + - **Implementation:** Renders the question and options, handles user selection, and displays feedback based on correctness. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `@repo/ui` for UI components, `react` for core React functionality, and `@prisma/client` for Prisma types. + - **Code Relationships:** This component is used by `MCQCard` to render individual questions. + +4. **Usage Example:** See `MCQCard.tsx` + +5. **Technical Notes:** + - Styling is applied based on user selection and submission status. + +--- + + + +#### MCQRenderer.tsx + +*Path: apps/web/components/mcq/MCQRenderer.tsx* + +1. **Purpose:** This component acts as the main entry point for rendering MCQ problems. It orchestrates the layout, including the problem description, question card, and app bar. + +2. **Key Functionality:** + + - **`MCQRenderer` (Component):** + - `problem`: The problem object. + - `track`: The track object the problem belongs to. + - `showAppBar`: Boolean to control app bar visibility. + - `problemIndex`: The index of the problem within the track. + - **Implementation:** Uses a resizable panel group to display the `MCQPanel` and `MCQQuestionCard` side-by-side. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `@repo/ui` for UI components, `next-auth/react` for session management, `./MCQCard` for rendering the question card, `./MCQPanel` for rendering the problem description and submissions, `@prisma/client` for Prisma types, and `../BlogAppbar` for the app bar. + - **Code Relationships:** This component uses `MCQPanel` and `MCQQuestionCard` to display the problem details and questions, respectively. It also uses `BlogAppbar` for navigation. + +4. **Usage Example:** + +```tsx +// Within a route or page component + +``` + +5. **Technical Notes:** + - Uses `ResizablePanelGroup` to allow users to adjust the width of the description and question panels. + +--- + + + +#### SubmissionMCQ.tsx + +*Path: apps/web/components/mcq/SubmissionMCQ.tsx* + +1. **Purpose:** This component displays the submission history for a given MCQ problem. + +2. **Key Functionality:** + + - **`SubmissionMCQ` (Component):** + - `problem: Problem`: The problem object. + - **Implementation:** Fetches and displays the user's quiz scores for the given problem. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `@repo/ui` for UI components, `next-auth/react` for session management, `@prisma/client` for Prisma types, and `../utils` for the `getQuizScore` utility function. + - **Code Relationships:** This component is used by `MCQPanel` to display the submission history. It interacts with the database via the `getQuizScore` utility function. + +4. **Usage Example:** See `MCQPanel.tsx` + +5. **Technical Notes:** + - Relies on the `getQuizScore` utility function for data fetching. Formats the submission timestamp for display. + + +**Overall System Architecture and Relationships:** + +The MCQ functionality is modularized into several components, promoting reusability and maintainability. `MCQRenderer` acts as the main container, orchestrating the layout and integrating the other components. `MCQPanel` handles the description and submission history, while `MCQCard` manages the display and interaction with the questions themselves. `MCQQuestion` renders individual questions, and `EditMCQ` provides editing capabilities. Utility functions in `../utils` handle database interactions. The system leverages Next.js features like client components and server sessions. Dependencies on external libraries like `@repo/ui`, `next-auth/react`, and `@prisma/client` are clearly defined. The components communicate primarily through props and callbacks. Error handling and data validation are distributed across components and utility functions. The use of a resizable panel in `MCQRenderer` enhances user experience. The system is designed to be scalable and maintainable, adhering to best practices for React development. + +--- + +### apps/web/components/privacy-policy + + + +#### privacy-policy.ts + +*Path: apps/web/components/privacy-policy/privacy-policy.ts* + +1. **Purpose:** This file defines the privacy policy content displayed on the website. It stores the policy as an array of objects, each containing a segment of the policy text. + +2. **Key Functionality:** + +- **`privacyPolicyContent`:** This constant array holds the privacy policy text. Each element in the array is an object with two properties: + - `id`: (number) A unique identifier for each section of the privacy policy. + - `description`: (string) The text content of the privacy policy section. + + The implementation is straightforward: a hardcoded array of objects. No functions or methods are present. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** This file has no external dependencies. +- **Code Relationships:** This file is likely imported by a component that renders the privacy policy on the website. The component would iterate through the `privacyPolicyContent` array and display each `description`. + +4. **Usage Example:** + +```typescript +// Example usage in a React component +import { privacyPolicyContent } from './privacy-policy'; + +const PrivacyPolicyComponent = () => { + return ( +
+ {privacyPolicyContent.map((section) => ( +

{section.description}

+ ))} +
+ ); +}; +``` + +5. **Technical Notes:** + +- The privacy policy is hardcoded. For maintainability, consider storing this content in a separate file (e.g., a markdown file or a database) and loading it dynamically. This would allow updating the policy without recompiling the application. This also opens possibilities for internationalization. +- The `id` field, while currently unused in the provided code, suggests potential future enhancements like linking to specific sections or implementing dynamic show/hide features. + +--- + +### apps/web/components/profile + + + +#### ProfileOptions.tsx + +*Path: apps/web/components/profile/ProfileOptions.tsx* + +1. **Purpose:** This React component renders a list of profile options (e.g., "Profile", "Submissions") with icons, allowing users to navigate between different sections of their profile. It highlights the currently active option based on the URL. + +2. **Key Functionality:** + +- **`ProfileOptions` (functional component):** + - **Parameters:** None + - **Return Type:** `JSX.Element` (React component) + - **Implementation:** Renders a vertical list of profile options. Uses `usePathname` from `next/navigation` to get the current URL path and `useRouter` to handle navigation. The `useEffect` hook updates the active option whenever the pathname changes. The `handleOptionClick` function updates the active state and navigates to the selected option's URL. + - **Fallback Mechanisms:** No explicit fallback mechanisms are implemented. If the pathname doesn't match any option, none will be highlighted. + +- **`optionsData` (array):** + - Contains the configuration for each profile option, including its name, icon (using `lucide-react`), and associated URL. + +- **`useState` (hook):** Manages the `activeOption` state, which tracks the currently selected option's index. Initialized based on the initial pathname. + +- **`useEffect` (hook):** Synchronizes the `activeOption` state with the current `pathname`. + +- **`handleOptionClick` (function):** + - **Parameters:** `index` (number), `href` (string) + - **Return Type:** `void` + - **Implementation:** Called when an option is clicked. Updates the `activeOption` state and uses the `router.push` method to navigate to the corresponding `href`. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `lucide-react`: Used for displaying icons. + - `next/navigation`: `usePathname` and `useRouter` are used for routing and determining the active section. + - `react`: Core React library for functional components, hooks, and JSX. + +- **Code Relationships:** This component is likely used within a larger profile page layout component. It relies on the Next.js routing system for navigation. + +4. **Usage Example:** + +```jsx +// Within a parent profile layout component + +``` + +This component would typically be placed within a sidebar or navigation section of a user's profile page. The parent component would handle fetching and displaying the main profile content based on the active option selected through this component. + +5. **Technical Notes:** + +- The component uses client-side routing provided by `next/navigation`. +- The initial active option is determined on the client-side using the `useState` hook with a functional initializer. This ensures the correct option is highlighted on the initial render. +- Styling is applied using Tailwind CSS classes. +- No specific error handling is implemented as the component primarily relies on Next.js routing, which handles navigation errors. More robust error handling might be needed if the `optionsData` were fetched dynamically. + + +--- + + +No other files were provided, so no further documentation could be generated. If you provide additional files, I can create documentation for them following the same structure. + +--- + +### apps/web/components/tnc + + + +#### tnc-content.ts + +*Path: apps/web/components/tnc/tnc-content.ts* + +1. **Purpose:** This file defines the terms and conditions content displayed on the 100xDevs website. It stores the content as a structured JavaScript array of objects, making it easy to manage and render in a component. + +2. **Key Functionality:** + +- **`tncContent` (constant):** This constant array holds the terms and conditions data. Each element in the array represents a section or paragraph of the T&C. The structure is as follows: + - `id` (number): A unique identifier for the section. + - `description` (string): The text content of the section. + - `points` (array, optional): An array of sub-points within a section. Each point has an `id` (number) and a `description` (string). + + The code simply defines the data structure. There's no complex logic or implementation details. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** This file has no external dependencies. +- **Code Relationships:** This file is likely imported and used by a React component responsible for displaying the terms and conditions on the website. The component would iterate through the `tncContent` array and render the `description` and `points` accordingly. + +4. **Usage Example:** + +```typescript +// Example usage in a React component (hypothetical) +import { tncContent } from './tnc-content'; + +const TermsAndConditions: React.FC = () => { + return ( +
+ {tncContent.map((section) => ( +
+

{section.description}

+ {section.points && ( +
    + {section.points.map((point) => ( +
  • {point.description}
  • + ))} +
+ )} +
+ ))} +
+ ); +}; + +export default TermsAndConditions; + +``` + +5. **Technical Notes:** + +- The data is hardcoded within the component. For larger or more dynamic T&C content, consider fetching the data from an external source (e.g., a CMS or database) to improve maintainability and allow for easier updates without code changes. This would also allow for internationalization. +- The current structure uses numerical IDs. While functional, using unique string IDs (UUIDs) is generally recommended for better scalability and flexibility, especially if the data will be managed externally. +- No specific error handling is needed in this file as it only defines data. Error handling (e.g., for fetching data if moved to an external source) would be implemented in the component that uses this data. + +--- + +### apps/web/hooks + + + +#### useMountStatus.ts + +*Path: apps/web/hooks/useMountStatus.ts* + +1. **Purpose:** This file provides a React Hook, `useMountStatus`, which tracks the mount status of a component. It allows other components to determine if they are currently mounted in the DOM. + +2. **Key Functionality:** + +- **`useMountStatus()`:** + - Parameters: None + - Return Type: `boolean` (true if mounted, false otherwise) + - Technical Explanation: This hook uses the `useState` hook to manage the `mounted` state variable. Initially set to `false`, the `useEffect` hook with an empty dependency array ensures that `setMounted(true)` is called only once after the initial render, effectively indicating that the component is mounted. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** This hook depends on React's core libraries (`react`) for `useEffect` and `useState`. +- **Code Relationships:** This hook is typically used within other React components to manage logic that should only execute when the component is mounted, preventing potential errors or memory leaks caused by state updates or DOM manipulations after a component has unmounted. + +4. **Usage Example:** + +```typescript +import useMountStatus from './useMountStatus'; + +const MyComponent: React.FC = () => { + const isMounted = useMountStatus(); + + useEffect(() => { + if (isMounted) { + // Perform actions that require the component to be mounted, + // such as subscribing to an event listener or fetching data. + } + + return () => { + // Cleanup logic if necessary (e.g., unsubscribe from event listeners) + }; + }, [isMounted]); + + return
My Component
; +}; +``` + +5. **Technical Notes:** + +- The empty dependency array in `useEffect` ensures the callback runs only once after the initial render, mimicking componentDidMount lifecycle behavior in class components. This is crucial for preventing unintended side effects or memory leaks. This hook provides a clean and efficient way to handle mount-related logic in functional components. + +--- + +### apps/web/lib + + + +#### auth.ts + +*Path: apps/web/lib/auth.ts* + +1. **Purpose:** This file configures authentication using NextAuth.js, integrating with GitHub and Google providers and using Prisma for database persistence. It also implements a rate limiting mechanism. + +2. **Key Functionality:** + +- **`authOptions` (object):** Configuration object for NextAuth.js. + - `adapter: PrismaAdapter(db)`: Uses Prisma to manage user data. + - `providers: [GithubProvider, GoogleProvider]` : Sets up authentication with GitHub and Google. Each provider requires `clientId` and `clientSecret` from environment variables. `allowDangerousEmailAccountLinking` is enabled (consider security implications). + - `secret`: Secret used to encrypt JWTs (should be a strong, randomly generated string). + - `pages`: Customizes sign-in page URL. + - `session`: Defines session strategy as JWT. + - `callbacks`: Contains functions to modify the JWT and session objects. + - `jwt({ token })`: Returns the token. + - `session({ session, token })`: Enriches the session object with user data from the database, including the `accessToken` and a custom `admin` flag. Retrieves user data based on `token.sub` (user ID). +- **`rateLimit(userId, rateLimitCount, rateLimitInterval)` (function):** Implements rate limiting for a given user. + - `userId (string)`: The ID of the user to rate limit. + - `rateLimitCount (number)`: The maximum number of requests allowed within the interval. + - `rateLimitInterval (number)`: The time interval (in milliseconds) for the rate limit. + - Returns `true` if the request is allowed, `false` otherwise. + - Implementation: Uses a `Map` to store user timestamps. Removes outdated timestamps based on `rateLimitInterval`. If the number of remaining timestamps exceeds `rateLimitCount`, returns `false`. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `next-auth`: Provides authentication functionalities. + - `next-auth/providers/{github, google}`: Providers for GitHub and Google authentication. + - `@auth/prisma-adapter`: Adapter for using Prisma with NextAuth.js. + - `@repo/db/client`: Prisma client instance. +- **Code Relationships:** This file is used by the NextAuth.js middleware to handle authentication. + +4. **Usage Example:** This configuration is used within the `[...nextauth].ts` file in the `pages/api` directory, which is the default NextAuth.js endpoint. + +5. **Technical Notes:** + - The `allowDangerousEmailAccountLinking` flag in the providers should be carefully considered as it poses security risks. + - The `secret` should be a strong, randomly generated value stored securely. + - The rate limiting mechanism is in-memory and won't scale across multiple server instances. Consider using a distributed cache like Redis for production. + +--- + + + +#### search.ts + +*Path: apps/web/lib/search.ts* + +1. **Purpose:** This file provides functionality for scraping data from Notion, embedding it using Google's Generative AI, storing it in Qdrant, and performing semantic search. + +2. **Key Functionality:** + +- **`scrapeData({ trackId })` (async function):** Scrapes data from Notion for a given track ID. + - `trackId (string)`: The ID of the track. + - Returns an array of problem objects with added `titles`, `trackId`, `trackTitle`, and `image` properties. + - Implementation: Uses `notion-client` to fetch page content. Extracts titles and source URLs from Notion blocks. Combines titles into a single string. +- **`createCollection()` (async function):** Creates a Qdrant collection named "DailyCode". Sets vector size and distance metric. +- **`insertData(trackId)` (async function):** Inserts scraped data into Qdrant. + - `trackId (string)`: The ID of the track. + - Implementation: Calls `scrapeData` to get the data. Embeds the `titles` string using Google's Generative AI. Upserts data into Qdrant with a random UUID, the generated vector, and a payload containing track and problem information. Updates the `track` record in the database to mark it as `inSearch: true`. +- **`getSearchResults(query)` (async function):** Performs a semantic search in Qdrant. + - `query (string)`: The search query. + - Returns an array of search results from Qdrant. + - Implementation: Embeds the query using Google's Generative AI. Queries Qdrant with the generated vector and returns the results. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `notion-client`: For interacting with the Notion API. + - `@google/generative-ai`: For generating embeddings. + - `@qdrant/js-client-rest`: For interacting with the Qdrant vector database. + - `crypto`: For generating UUIDs. + - `@repo/db/client`: Prisma client instance. + - `../components/utils`: Imports `getTrack`. +- **Code Relationships:** + - This file depends on environment variables for API keys and URLs. + - It interacts with Notion, Google AI, and Qdrant. + - It uses the `getTrack` function from another module. + - It updates the `track` data in the database using the Prisma client. + +4. **Usage Example:** This file's functions would be called from API routes to handle search requests and data ingestion. + +5. **Technical Notes:** + - The vector size is determined by the environment variable `VECTOR_SIZE` and defaults to 768. + - Error handling and retry mechanisms are missing and should be added for robustness. + +--- + + + +#### utils.ts + +*Path: apps/web/lib/utils.ts* + +1. **Purpose:** This file provides utility functions for working with Tailwind CSS and class names. + +2. **Key Functionality:** + +- **`cn(...inputs)` (function):** Merges Tailwind CSS classes using `clsx` and `tailwind-merge`. + - `inputs (ClassValue[])`: An array of class names or objects. + - Returns a merged string of class names. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `clsx`: For conditionally joining classNames together. + - `tailwind-merge`: For merging Tailwind CSS classes. + +4. **Usage Example:** +```typescript +
+``` + +5. **Technical Notes:** This function simplifies the process of composing Tailwind CSS classes, especially when dealing with conditional classes. + + +**Inter-file Relationships:** + +- `apps/web/lib/auth.ts` is independent and handles authentication. +- `apps/web/lib/search.ts` depends on `apps/web/components/utils` (for `getTrack`), `@repo/db/client` (for database interaction), and environment variables. +- `apps/web/lib/utils.ts` is a utility file used across the application, including potentially by the other two files. It has no direct dependencies on the other files. + +--- + +### apps/web/lib/cache + + + +#### cache.ts + +*Path: apps/web/lib/cache/cache.ts* + +1. **Purpose:** This file defines the `ICache` interface, which serves as a contract for all cache implementations. It ensures a consistent API for interacting with different caching mechanisms. + +2. **Key Functionality:** + +- **Interface `ICache`:** Defines the methods that any caching class must implement. + - `set(type: string, args: string[], value: any, expirySeconds: number): Promise`: Sets a value in the cache. `type` and `args` are used for key generation, `value` is the cached data, and `expirySeconds` determines the Time-To-Live (TTL). + - `get(type: string, args: string[]): Promise`: Retrieves a value from the cache based on the provided `type` and `args`. + - `evict(type: string, args: string[]): Promise`: Removes a value from the cache. + +3. **Dependencies and Relationships:** + +- This interface is used by `InMemoryCache` and `RedisCache` to ensure consistent implementation. + +4. **Usage Example:** + +```typescript +// Example usage with a hypothetical cache implementation +const cache: ICache = someCacheImplementation; +await cache.set('user', ['123'], { name: 'John Doe' }, 3600); +const user = await cache.get('user', ['123']); +``` + +5. **Technical Notes:** + +- The use of an interface promotes loose coupling and allows for easy swapping of caching strategies without modifying the consuming code. + +--- + + + +#### in-memory-cache.ts + +*Path: apps/web/lib/cache/in-memory-cache.ts* + +1. **Purpose:** This file implements the `ICache` interface using an in-memory map, providing a simple caching solution within the application's process. + +2. **Key Functionality:** + +- **Class `InMemoryCache`:** Implements the `ICache` interface. + - **`constructor()`:** Initializes the `inMemoryDb` as a `Map`. + - **`static getInstance()`:** Implements the Singleton pattern, ensuring only one instance of `InMemoryCache` exists. + - **`set(type: string, args: string[], value: any, expirySeconds: number)`:** Sets a cache entry with an expiry time. Uses `generateKey` to create a unique key. Default expiry is fetched from the `CACHE_EXPIRE` environment variable or defaults to 1800 seconds (30 minutes). + - **`get(type: string, args: string[]): Promise`:** Retrieves a cached value. Handles expired entries by removing them and returning `null`. + - **`evict(type: string, args: string[]): Promise`:** Removes a cache entry. + - **`private generateKey(type: string, args: string[]): string`:** Creates a cache key from the `type` and `args`. + +3. **Dependencies and Relationships:** + +- **Imports:** `ICache` from `./cache.ts`. +- **Relationships:** Implements the `ICache` interface, fulfilling the contract defined in `cache.ts`. + +4. **Usage Example:** + +```typescript +import { InMemoryCache } from './in-memory-cache'; + +const cache = InMemoryCache.getInstance(); +await cache.set('product', ['123'], { name: 'Awesome Product' }); +const product = await cache.get('product', ['123']); +``` + +5. **Technical Notes:** + +- The Singleton pattern ensures that only one in-memory cache exists, preventing data inconsistencies. +- The default expiry time is configurable via the `CACHE_EXPIRE` environment variable. + +--- + + + +#### redis-cache.ts + +*Path: apps/web/lib/cache/redis-cache.ts* + +1. **Purpose:** This file implements the `ICache` interface using Redis, providing a distributed caching solution. + +2. **Key Functionality:** + +- **Class `RedisCache`:** Implements the `ICache` interface. + - **`constructor(redisUrl: string)`:** Initializes a Redis client using the provided `redisUrl`. + - **`static getInstance(redisUrl: string)`:** Implements the Singleton pattern, ensuring only one instance of `RedisCache` exists per provided URL. + - **`set(type: string, args: string[], value: any, expirySeconds: number)`:** Sets a value in Redis with an optional expiry. Uses `generateKey` to create a unique key. Serializes the `value` using `JSON.stringify`. + - **`get(type: string, args: string[]): Promise`:** Retrieves a value from Redis. Deserializes the value using `JSON.parse`. + - **`evict(type: string, args: string[]): Promise`:** Deletes a key from Redis. + - **`private generateKey(type: string, args: string[]): string`:** Creates a cache key from the `type` and `args`. + +3. **Dependencies and Relationships:** + +- **Imports:** `Redis` from `ioredis`, `ICache` from `./cache.ts`. +- **Relationships:** Implements the `ICache` interface, fulfilling the contract defined in `cache.ts`. Uses the `ioredis` library to interact with a Redis instance. + +4. **Usage Example:** + +```typescript +import { RedisCache } from './redis-cache'; + +const cache = RedisCache.getInstance(process.env.REDIS_URL); +await cache.set('user', ['456'], { name: 'Jane Doe' }, 7200); +const user = await cache.get('user', ['456']); +``` + +5. **Technical Notes:** + +- The Singleton pattern ensures only one Redis client is created per Redis URL, optimizing resource usage. +- Uses `JSON.stringify` and `JSON.parse` for serialization and deserialization, making it compatible with various data types. + + +These three files work together to provide a flexible caching system. `cache.ts` defines the interface, while `in-memory-cache.ts` and `redis-cache.ts` provide concrete implementations. This allows the application to easily switch between in-memory and Redis caching based on configuration or deployment environment. The use of a shared interface ensures consistent interaction regardless of the chosen implementation. + +--- + +### apps/web/screens + + + +#### Admin.tsx + +*Path: apps/web/screens/Admin.tsx* + +1. **Purpose:** This file defines the Admin screen component, providing an interface for managing problems, tracks, categories, and search functionality within the application. It serves as a central hub for administrative tasks. + +2. **Key Functionality:** + +- **`Admin` (functional component):** + - **Parameters:** None + - **Return Type:** `JSX.Element` (React component) + - **Implementation:** Fetches data for problems, tracks, and categories using `getAllProblems`, `getAllTracks`, and `getCategories` respectively. It also fetches tracks based on their `inSearch` status from the database using Prisma Client queries. Renders a tabbed interface using the `Tabs` component from `@repo/ui`. Each tab provides specific admin functionality: managing complete tracks, problems, tracks, linking problems to tracks, managing search indexing, and MCQ functionality. The component leverages asynchronous operations for data fetching and displays a notification about the need for manual refresh to see changes reflected in the admin interface. + - **Fallback Mechanisms:** While there isn't explicit error handling shown, the asynchronous fetches should ideally be wrapped in `try...catch` blocks to handle potential network or database errors gracefully. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@repo/ui`: Uses components like `Tabs`, `TabsContent`, `TabsList`, and `TabsTrigger` for the tabbed interface. + - `../components/admin/*`: Imports various admin-related components for each tab's content. + - `../components/utils`: Imports utility functions `getAllProblems`, `getAllTracks`, and `getCategories` for data fetching. + - `@repo/db/client`: Imports the Prisma client `db` for database interactions. +- **Code Relationships:** + - This file acts as a container for various admin components, orchestrating their rendering and data flow. It depends on the utility functions for fetching data and the Prisma client for database access. It also relies on the `@repo/ui` library for UI components. + +4. **Usage Example:** This component would likely be routed to under an `/admin` path, accessible only to authorized users. + +5. **Technical Notes:** + - The note about manual refresh suggests that the application doesn't use real-time updates or server-side rendering for the admin interface. Consider implementing a mechanism for automatic updates to improve the user experience. + - The use of Prisma Client simplifies database interactions. + +--- + + + +#### Landing.tsx + +*Path: apps/web/screens/Landing.tsx* + +1. **Purpose:** This file defines the Landing page component, showcasing the main content of the application, including hero section, tracks, and footer elements. It serves as the entry point for users visiting the website. + +2. **Key Functionality:** + +- **`Landing` (functional component):** + - **Parameters:** None + - **Return Type:** `JSX.Element` (React component) + - **Implementation:** Fetches tracks and categories data using `getAllTracks` and `getAllCategories`. Renders the `AppbarClient`, `Hero`, `Tracks`, `FooterCTA`, and `Footer` components, passing the fetched data as props. + - **Fallback Mechanisms:** No explicit error handling is shown. Consider adding `try...catch` blocks around the asynchronous fetches to handle potential errors. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `../components/*`: Imports various components for rendering the landing page sections. + - `../components/utils`: Imports utility functions `getAllTracks` and `getAllCategories`. + - `./footer` and `./footer-cta`: Imports the footer components. +- **Code Relationships:** This file acts as a container, assembling the different sections of the landing page. It depends on the utility functions for data fetching and the individual components for rendering. + +4. **Usage Example:** This component would be routed to the root path ("/") of the application. + +5. **Technical Notes:** No critical technical notes. + +--- + + + +#### footer-cta.tsx + +*Path: apps/web/screens/footer-cta.tsx* + +1. **Purpose:** This file defines the Footer Call-to-Action (CTA) component, encouraging users to download the application and join the platform. + +2. **Key Functionality:** + +- **`FooterCTA` (functional component):** + - **Parameters:** None + - **Return Type:** `JSX.Element` (React component) + - **Implementation:** Renders a styled section with a gradient background, text content, and two buttons: one for downloading the app and another for joining the platform. Uses `lucide-react` for icons and `framer-motion` for animation of the mockup image. Links are implemented using `next/link`. + - **Fallback Mechanisms:** No specific fallback mechanisms are implemented. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@repo/ui`: Uses the `Button` component. + - `lucide-react`: Uses icons. + - `next/link`: Used for navigation links. + - `framer-motion`: Used for animation. + - `next/image`: Used for optimized image display. +- **Code Relationships:** This component is typically used within the `Footer` or other layout components to provide a prominent call to action. + +4. **Usage Example:** See usage in `File 2: apps/web/screens/Landing.tsx`. + +5. **Technical Notes:** The use of `framer-motion` adds a subtle animation to the mockup image, enhancing visual appeal. + +--- + + + +#### footer.tsx + +*Path: apps/web/screens/footer.tsx* + +1. **Purpose:** This file defines the Footer component, displaying information about the company, social media links, and legal links. + +2. **Key Functionality:** + +- **`Footer` (functional component):** + - **Parameters:** None + - **Return Type:** `JSX.Element` (React component) + - **Implementation:** Renders the footer section with the company logo, social media links, and links to legal pages (Terms & Conditions, Privacy Policy, Refund & Cancellation). Uses `next/link` for navigation and `next/image` for optimized image display. + - **Fallback Mechanisms:** No specific fallback mechanisms are implemented. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `next/link`: Used for navigation links. + - `next/image`: Used for optimized image display. + - `@repo/ui`: Uses the `Separator` component. +- **Code Relationships:** This component is a standard footer, typically used across the application. + +4. **Usage Example:** See usage in `File 2: apps/web/screens/Landing.tsx`. + +5. **Technical Notes:** No critical technical notes. + + +**Inter-file Relationships:** + +- `Landing.tsx` uses `Footer.tsx` and `FooterCTA.tsx` to compose the landing page. +- `Admin.tsx` uses components from `@repo/ui` and utility functions, potentially shared with other parts of the application. +- All files demonstrate a consistent use of React components and Next.js features. The use of a shared UI library (`@repo/ui`) and utility functions promotes code reusability and maintainability. The consistent use of `next/link` ensures optimized client-side navigation. The use of Prisma Client in `Admin.tsx` suggests a well-structured approach to database interactions. + +--- + +### packages/db + + + +#### Cache.ts + +*Path: packages/db/Cache.ts* + +1. **Purpose:** This file defines a `Cache` class that provides a unified interface for caching data, abstracting the underlying implementation (in-memory or Redis). It uses a singleton pattern to ensure only one instance of the cache exists. + +2. **Key Functionality:** + +- **`Cache` class:** Implements the `ICache` interface. Uses a strategy pattern to delegate to either `InMemoryCache` or `RedisCache`. + - **`constructor()`:** Private constructor to enforce singleton pattern. Initializes the `delegate` based on the presence of `REDIS_URL` environment variable. + - **`getInstance()`:** Static method that returns the singleton instance of `Cache`. Creates the instance if it doesn't exist. + - **`set(type: string, args: string[], value: any, expirySeconds: number)`:** Sets a cached value. + - `type`: A string representing the type of data being cached (e.g., "user"). + - `args`: An array of strings used to create a unique cache key (e.g., ["123"]). + - `value`: The value to be cached. + - `expirySeconds`: The time-to-live (TTL) for the cached entry. Defaults to 1800 seconds (30 minutes). + - Returns: `Promise`. + - Implementation: Delegates the `set` operation to the underlying `delegate` (either `InMemoryCache` or `RedisCache`). + - **`get(type: string, args: string[])`:** Retrieves a cached value. + - `type`: The type of data. + - `args`: The arguments used to create the cache key. + - Returns: `Promise`. The cached value or `null` if not found. + - Implementation: Delegates the `get` operation to the underlying `delegate`. + - **`evict(type: string, args: string[])`:** Removes a cached entry. + - `type`: The type of data. + - `args`: The arguments used to create the cache key. + - Returns: `Promise`. + - Implementation: Delegates the `evict` operation to the underlying `delegate`. + +- **`cache` constant:** An instance of the `Cache` class, readily available for use. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `ICache`: Interface defining the cache methods. + - `InMemoryCache`: In-memory caching implementation. + - `RedisCache`: Redis-based caching implementation. +- **Code Relationships:** This file is the central point of access for caching throughout the application. Other modules interact with this file to utilize caching functionality. It depends on the `InMemoryCache` and `RedisCache` modules for the actual caching implementation. + +4. **Usage Example:** + +```typescript +import { cache } from './Cache'; + +async function getUser(id: string) { + const cachedUser = await cache.get('user', [id]); + if (cachedUser) { + return cachedUser; + } + + // Fetch user from database + const user = await fetchUserFromDatabase(id); + + await cache.set('user', [id], user); + return user; +} +``` + +5. **Technical Notes:** + +- The use of the singleton pattern ensures that only one cache instance exists, preventing potential inconsistencies and resource wastage. +- The strategy pattern allows for easy switching between different caching implementations without modifying the consuming code. +- The `REDIS_URL` environment variable controls which caching implementation is used. If it's set, Redis is used; otherwise, the in-memory cache is used. + +--- + + + +#### setupDB.sh + +*Path: packages/db/setupDB.sh* + +1. **Purpose:** This shell script sets up the database for the application. It handles both local (Postgres or Docker) and cloud database setups, including migrations and seeding. + +2. **Key Functionality:** + +- **`migrate_seed_db()` function:** Handles database migrations and seeding. Checks if seeds have already been applied and skips seeding if they have. +- **Environment Variable Handling:** Checks for the existence of a `.env` file and copies `.env.example` if it doesn't exist. +- **Database Type Selection:** Prompts the user to choose between local and cloud database setups. +- **Local Database Setup:** + - Prompts for Postgres or Docker setup. + - If Postgres, prompts for database credentials. + - If Docker, sets up the `DATABASE_URL` for the Docker container. +- **Cloud Database Setup:** Prompts for the cloud database URI. +- **Docker Container Management:** Starts the Docker container if Docker is chosen and handles potential errors. +- **Migration and Seeding:** Calls the `migrate_seed_db` function to apply migrations and seed the database. + +3. **Dependencies and Relationships:** + +- **Dependencies:** `docker-compose`, `npx`, `prisma`. +- **Code Relationships:** This script is typically run during the application setup process. It interacts with the database (either local or cloud) and uses `prisma` for migrations and seeding. It sets the `DATABASE_URL` environment variable, which is used by `Cache.ts` (File 1) to determine the database connection for caching. + +4. **Usage Example:** ```bash -docker compose watch +./setupDB.sh +``` + +5. **Technical Notes:** + +- The script uses a series of prompts to guide the user through the setup process. +- Error handling is implemented for the Docker setup to ensure the container is running. +- The `migrate_seed_db` function prevents duplicate seeding. +- The script modifies the `.env` file, which is crucial for the application's database connection. + + +**Inter-file Relationships:** + +- `setupDB.sh` (File 2) sets the `DATABASE_URL` environment variable. This variable is used by `Cache.ts` (File 1) to determine whether to use Redis or in-memory caching. If `REDIS_URL` is set (indicating a likely cloud deployment where `setupDB.sh` would have configured a cloud database), Redis is used. Otherwise, in-memory caching is used, which is more suitable for local development setups where `setupDB.sh` might have configured a local Postgres or Docker database. This demonstrates a clear dependency and interaction between these two files, mediated by environment variables. This setup allows for flexible configuration based on the deployment environment. + +--- + +### packages/db/prisma + + + +#### seed.ts + +*Path: packages/db/prisma/seed.ts* + +1. **Purpose:** This file seeds the database with initial data for tracks and categories, establishing relationships between them. It's essential for setting up a development or testing environment with predefined data. + +2. **Key Functionality:** + +- **`main()`:** This asynchronous function orchestrates the seeding process. + - Parameters: None + - Return Type: `Promise` + - Implementation: + - Iterates through `seedsData` (imported from `./seedsData`). + - Uses a `hashID` array to prevent duplicate track entries. + - Checks if a track with the given ID already exists using `db.track.findUnique`. + - Creates a new track using `db.track.create` if it doesn't exist. + - Creates predefined categories using `db.categories.create`. + - Creates relationships between tracks and categories using `db.trackCategory.createMany`. + - Includes error handling with a `try...catch` block to log potential errors during track creation. +- **Fallback Mechanisms:** The `try...catch` block around the database operations catches and logs errors, preventing the seeding process from halting completely if a single operation fails. However, it doesn't implement retries or other sophisticated error recovery mechanisms. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `db` from `../src`: Imports the Prisma client instance, which is used to interact with the database. + - `seedsData` from `./seedsData`: Imports the seed data for tracks. +- **Code Relationships:** This file depends on the database schema defined in the Prisma schema file (likely `schema.prisma` in the same directory) and uses the Prisma client to interact with the database. It also relies on the `seedsData` file for the initial track data. + +4. **Usage Example:** This script is typically executed during development or testing setup using a command like `npx prisma db seed`. It populates the database with the initial data required for the application to function correctly. + +5. **Technical Notes:** + - The use of `findUnique` before `create` ensures idempotency of the seeding process, preventing duplicate entries if the script is run multiple times. + - The script directly interacts with the database using the Prisma client, making it dependent on a running database instance and correct Prisma setup. + - The error handling is basic and could be improved by implementing retries or more specific error handling logic. The lack of more robust error handling could lead to incomplete seeding if errors occur. + - The script assumes the `seedsData` is correctly formatted and contains valid data for the track model. There's no validation of the seed data before it's used. + +--- + +### packages/db/prisma/migrations/20240402204828_init + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240402204828_init/migration.sql* + +1. **Purpose:** This file defines the initial database schema for the application using Prisma migrations. It creates the necessary tables and enums for users, tracks, and problems, along with their relationships. + +2. **Key Functionality:** + +- **`CREATE TYPE "ProblemType" AS ENUM ('Blog', 'Code');`**: Defines an enum named `ProblemType` with possible values `Blog` and `Code`. This enum likely categorizes the type of problem. + +- **`CREATE TABLE "User"`**: Creates the `User` table with columns: + - `id` (TEXT, primary key): Unique identifier for the user. + - `username` (TEXT, not null): User's username. + - `password` (TEXT, not null): User's password. + +- **`CREATE TABLE "Track"`**: Creates the `Track` table with columns: + - `id` (TEXT, primary key): Unique identifier for the track. + - `title` (TEXT, not null): Title of the track. + - `description` (TEXT, not null): Description of the track. + - `image` (TEXT, not null): URL or path to an image representing the track. + - `hidden` (BOOLEAN, not null, default: false): Flag indicating if the track is hidden. + - `createdAt` (TIMESTAMP, not null, default: CURRENT_TIMESTAMP): Timestamp of track creation. + +- **`CREATE TABLE "Problem"`**: Creates the `Problem` table with columns: + - `id` (TEXT, primary key): Unique identifier for the problem. + - `title` (TEXT, not null): Title of the problem. + - `description` (TEXT, not null): Description of the problem. + - `notionDocId` (TEXT, not null): ID of the corresponding Notion document. + - `type` (`ProblemType`, not null): Type of the problem (Blog or Code). + +- **`CREATE TABLE "TrackProblems"`**: Creates a junction table `TrackProblems` to represent the many-to-many relationship between `Track` and `Problem`. It has columns: + - `trackId` (TEXT, not null, part of composite primary key, foreign key referencing `Track.id`): ID of the associated track. + - `problemId` (TEXT, not null, part of composite primary key, foreign key referencing `Problem.id`): ID of the associated problem. + +- **`ALTER TABLE "TrackProblems" ADD CONSTRAINT ...`**: These statements define foreign key constraints to enforce referential integrity between the `TrackProblems` table and the `Track` and `Problem` tables. `ON DELETE RESTRICT` ensures that a track or problem cannot be deleted if it's referenced in the `TrackProblems` table. `ON UPDATE CASCADE` ensures that if a `trackId` or `problemId` is updated in the parent table, the corresponding entries in `TrackProblems` are also updated. + +3. **Dependencies and Relationships:** + +- **Dependencies:** This file depends on the Prisma ORM and the underlying database system. +- **Relationships:** This migration script creates the initial schema. Subsequent application code will interact with these tables through the Prisma Client. The `TrackProblems` table establishes a many-to-many relationship between `Track` and `Problem`. + +4. **Usage Example:** This SQL script is executed by Prisma's migration engine as part of the database setup or upgrade process. It's not directly used by application code. + +5. **Technical Notes:** + +- The use of UUIDs (represented as TEXT) for primary keys is a common practice in distributed systems. +- The `ProblemType` enum provides type safety and clarity for categorizing problems. +- The `TrackProblems` junction table is a standard way to implement many-to-many relationships in relational databases. The choice of `RESTRICT` for `ON DELETE` behavior ensures data integrity by preventing accidental deletion of related records. The `CASCADE` behavior for `ON UPDATE` simplifies updates by automatically propagating changes in the parent tables to the junction table. + +--- + +### packages/db/prisma/migrations/20240403204246_added_mcq + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240403204246_added_mcq/migration.sql* + +1. **Purpose:** This migration script adds support for Multiple Choice Questions (MCQs) to the database schema. It introduces a new table for MCQ questions and extends the existing `ProblemType` enum. + +2. **Key Functionality:** + +- **`ALTER TYPE "ProblemType" ADD VALUE 'MCQ';`**: Extends the `ProblemType` enum by adding a new value 'MCQ'. This allows problems to be categorized as MCQs. No parameters or return values. + +- **`CREATE TABLE "MCQQuestion"`**: Creates a new table named `MCQQuestion` with the following columns: + - `id` (TEXT, PRIMARY KEY): Unique identifier for the MCQ question. + - `question` (TEXT, NOT NULL): The text of the MCQ question. + - `options` (TEXT[], array): An array of strings representing the answer options. + - `correctOption` (TEXT, NOT NULL): The correct answer option. + - `problemId` (TEXT, NOT NULL, FOREIGN KEY): Links the MCQ question to a `Problem` entry. + +- **`ALTER TABLE "MCQQuestion" ADD CONSTRAINT "MCQQuestion_problemId_fkey"`**: Creates a foreign key constraint between the `MCQQuestion` table and the `Problem` table. This ensures referential integrity and establishes a one-to-many relationship between `Problem` and `MCQQuestion` (one problem can have multiple MCQ questions). The `ON DELETE RESTRICT` clause prevents deletion of a `Problem` if it has associated `MCQQuestion` entries. The `ON UPDATE CASCADE` clause ensures that if a `Problem`'s `id` is updated, the corresponding `problemId` in `MCQQuestion` is also updated. + +3. **Dependencies and Relationships:** + +- **Dependencies:** This migration script depends on the Prisma ORM and the existing database schema, specifically the `Problem` table and the `ProblemType` enum. +- **Relationships:** This file modifies the database schema and is executed by Prisma's migration engine. It introduces the `MCQQuestion` table and links it to the `Problem` table, establishing a relationship where a problem can have multiple associated MCQ questions. + +4. **Usage Example:** This SQL script is executed as part of the database migration process using the Prisma CLI. For example: `npx prisma migrate deploy`. + +5. **Technical Notes:** + - The choice of `TEXT` for `id` aligns with Prisma's recommendation for UUIDs. + - The use of an array type for `options` provides a flexible way to store multiple answer choices. + - The foreign key constraint ensures data integrity and enforces the relationship between problems and their associated MCQ questions. The `ON DELETE RESTRICT` clause is a crucial data integrity measure. + + +--- + + +No other files were provided, so no further documentation could be generated. If you provide additional files, I can create documentation for them following the same structure and principles. Remember to provide context about how the files relate to each other within the project. + +--- + +### packages/db/prisma/migrations/20240404031649_nextauth + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240404031649_nextauth/migration.sql* + +1. **Purpose:** This SQL migration script modifies the database schema to integrate NextAuth.js for authentication. It alters the `User` table and introduces new tables for managing accounts, sessions, and verification tokens. + +2. **Key Functionality:** + + - **`ALTER TABLE "User"`:** Modifies the existing `User` table. + - `DROP COLUMN "password", DROP COLUMN "username"`: Removes the existing password and username columns. This suggests a move away from traditional username/password authentication. + - `ADD COLUMN "email" TEXT, ADD COLUMN "emailVerified" TIMESTAMP(3), ADD COLUMN "image" TEXT, ADD COLUMN "name" TEXT`: Adds columns for email-based authentication (email, emailVerified), user profile information (image, name). + + - **`CREATE TABLE "Account"`:** Creates a table to store user accounts linked to external providers (e.g., Google, GitHub). + - Columns like `provider`, `providerAccountId`, `access_token`, `refresh_token` facilitate OAuth flows. `expires_at`, `refresh_token_expires_in` manage token lifetimes. + + - **`CREATE TABLE "Session"`:** Creates a table to manage user sessions. + - `sessionToken` is used for session management. `expires` determines session validity. + + - **`CREATE TABLE "VerificationToken"`:** Creates a table for email verification tokens. + - `identifier` (likely email), `token`, and `expires` are used for the verification process. + + - **`CREATE UNIQUE INDEX ...`:** Creates unique indexes for efficient lookups and data integrity. These are crucial for performance on queries involving these fields. + + - **`CREATE INDEX ...`:** Creates indexes for efficient lookups and data integrity. + + - **`ADD CONSTRAINT ...`:** Adds foreign key constraints to enforce referential integrity between tables. `ON DELETE CASCADE` ensures dependent records are deleted when a related user is deleted. + +3. **Dependencies and Relationships:** + + - **Dependencies:** This migration depends on the Prisma ORM and the underlying database system. + - **Relationships:** The `Account` and `Session` tables have a foreign key relationship with the `User` table via `userId`. This establishes a one-to-many relationship (one user can have multiple accounts and sessions). + +4. **Usage Example:** This migration script is executed by Prisma's migration engine. It's typically run using a command like `npx prisma migrate deploy`. + +5. **Technical Notes:** + + - The migration reflects a shift to a social login/OAuth-based authentication strategy using NextAuth.js. + - The use of unique indexes is crucial for performance and data integrity, especially for authentication-related queries. + - The cascading foreign key constraints ensure data consistency across related tables. + +--- + +### packages/db/prisma/migrations/20240407230643_adds + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240407230643_adds/migration.sql* + +1. **Purpose:** This SQL migration script adds a new `sortingOrder` column to the `TrackProblems` table in the database. This likely allows for ordering problems associated with a track. + +2. **Key Functionality:** + +- `ALTER TABLE "TrackProblems" ADD COLUMN "sortingOrder" INTEGER NOT NULL;` + - This SQL statement adds a new column named `sortingOrder` to the `TrackProblems` table. + - The data type is set to `INTEGER`. + - The `NOT NULL` constraint ensures that every entry in the `TrackProblems` table must have a value for the `sortingOrder` column. + + - **Implementation and Optimizations:** This is a standard SQL `ALTER TABLE` command. Database performance during this migration will depend on the database engine and the size of the `TrackProblems` table. Adding a `NOT NULL` column to a non-empty table requires existing rows to be updated with a value for this new column. The migration script does not provide a default value, indicating a potential requirement for a separate data migration step to populate this column for existing records. + + - **Fallback Mechanisms:** Database migrations typically have transaction management built-in. If the migration fails for any reason (e.g., insufficient permissions, invalid data type), the transaction will be rolled back, leaving the database in its previous state. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** This migration script depends on the Prisma migration engine and the underlying database system. +- **Code Relationships:** This migration script modifies the database schema, which will affect any code that interacts with the `TrackProblems` table. This includes any application code that reads or writes to this table. + +4. **Usage Example (N/A):** Migration scripts are executed by the Prisma migration CLI. + +5. **Technical Notes:** + +- The `NOT NULL` constraint without a default value requires careful consideration. Since the table is not empty, applying this migration will fail unless all existing rows are first updated with a value for `sortingOrder`. This likely necessitates a separate data migration step before or after this schema migration to populate the `sortingOrder` column for existing records. A default value should be considered for future additions to avoid this issue. +- The choice of `INTEGER` for `sortingOrder` is appropriate for representing an ordinal ranking. Consider using a smaller integer type if the range of possible sorting orders is limited to conserve storage space. + + +--- + + +There are no other files provided, so analysis of inter-file dependencies and relationships is limited to the impact of this migration script on other parts of the application that interact with the database. Any code that uses the `TrackProblems` table will need to be aware of the new `sortingOrder` column and handle it appropriately. This might involve updating data models, queries, and user interfaces. + +--- + +### packages/db/prisma/migrations/20240408080322_added_categories + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240408080322_added_categories/migration.sql* + +1. **Purpose:** This SQL migration file adds a new table named "Categories" to the database and establishes a foreign key relationship with the "Track" table. It's part of the Prisma migration workflow, managing database schema changes. + +2. **Key Functionality:** + +- **`CREATE TABLE "Categories"`:** Creates the "Categories" table with the following columns: + - `id` (TEXT, NOT NULL, PRIMARY KEY): Unique identifier for each category. + - `category` (TEXT, NOT NULL): The name of the category. + - `trackId` (TEXT, NOT NULL): Foreign key referencing the "Track" table. + +- **`ALTER TABLE "Categories" ADD CONSTRAINT "Categories_trackId_fkey"`:** Adds a foreign key constraint to the "Categories" table. + - `Categories_trackId_fkey`: Name of the foreign key constraint. + - `REFERENCES "Track"("id")`: Specifies that the `trackId` column references the `id` column of the "Track" table. + - `ON DELETE RESTRICT`: Restricts deleting a record in the "Track" table if a corresponding record exists in the "Categories" table. + - `ON UPDATE CASCADE`: If the `id` of a "Track" is updated, the corresponding `trackId` in the "Categories" table will be updated automatically. + +3. **Dependencies and Relationships:** + +- **Dependencies:** This migration depends on the Prisma ORM and the underlying database system. It also implicitly depends on the existence of the "Track" table. +- **Relationships:** This file directly relates to the database schema and interacts with the "Track" table by establishing a foreign key relationship. It is part of the Prisma migrations, which are managed sequentially. This specific migration adds to the schema defined by previous migrations. + +4. **Usage Example:** This file is executed by Prisma's migration engine (e.g., `npx prisma migrate deploy`). It's not directly called by application code. + +5. **Technical Notes:** +- The `ON DELETE RESTRICT` policy ensures data integrity by preventing accidental deletion of tracks that have associated categories. +- The `ON UPDATE CASCADE` policy maintains referential integrity by automatically updating related records when a track's ID is changed. This choice simplifies application logic as it doesn't need to handle cascading updates manually. +- The choice of `TEXT` for the `id` and `trackId` suggests these are UUIDs or similar strings, which is a common practice in distributed systems. Using a dedicated UUID type if the database supports it would enhance type safety. + + +--- + + +No other files were provided, so no further documentation could be generated. If you provide additional files, I can create documentation for them following the same structure. Remember to provide context about how these files relate to each other within the project. + +--- + +### packages/db/prisma/migrations/20240411143941_added_admin + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240411143941_added_admin/migration.sql* + +1. **Purpose:** This SQL migration script adds an `admin` boolean column to the `User` table. This allows for differentiating between regular users and administrator users within the application. + +2. **Key Functionality:** + +- `ALTER TABLE "User" ADD COLUMN "admin" BOOLEAN NOT NULL DEFAULT false;` + - This SQL statement modifies the existing `User` table schema. + - It adds a new column named `admin` of type `BOOLEAN`. + - `NOT NULL` constraint ensures that every user record must have a value for the `admin` flag. + - `DEFAULT false` sets the default value of the `admin` flag to `false` for all existing and new users unless explicitly set to `true`. + +3. **Dependencies and Relationships:** + +- **Dependencies:** This migration depends on the Prisma ORM and the underlying database system (e.g., PostgreSQL, MySQL). It assumes a `User` table already exists in the database schema. +- **Code Relationships:** This migration script is part of the database migration history managed by Prisma. It's executed sequentially with other migration scripts to evolve the database schema over time. The application's data models (likely defined in a Prisma schema file) will need to be updated to reflect this change. + +4. **Usage Example (N/A):** Migration scripts are executed automatically by Prisma's migration engine. + +5. **Technical Notes:** + +- This migration is additive and non-destructive. It adds a new column without altering existing data. +- The default value of `false` ensures that existing users are not inadvertently granted administrator privileges after the migration. +- Prisma manages the execution order of migrations, ensuring that database schema changes are applied consistently across environments. + + +--- + + +There are no other files provided to document their interrelationships or dependencies. If other files like a Prisma schema or application code using the `User` model were provided, the documentation would detail how this migration affects those files and how they interact. For example, the Prisma schema would need to be updated to include the `admin` field in the `User` model definition, and application code could then use this field to implement authorization logic. + +--- + +### packages/db/prisma/migrations/20240412144918_ + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240412144918_/migration.sql* + +1. **Purpose:** This SQL migration script modifies the database schema by removing the `trackId` column from the `Categories` table and creating a new join table called `TrackCategory` to represent the many-to-many relationship between Tracks and Categories. This restructuring improves database normalization and allows for more flexible relationships between tracks and categories. + +2. **Key Functionality:** + +- **`ALTER TABLE "Categories" DROP CONSTRAINT "Categories_trackId_fkey";`**: Drops the foreign key constraint that previously linked the `Categories` table to the `Track` table via the `trackId` column. This is necessary before the `trackId` column can be removed. +- **`ALTER TABLE "Categories" DROP COLUMN "trackId";`**: Removes the `trackId` column from the `Categories` table. This eliminates the previous one-to-many relationship (or potentially incorrect one-to-one if enforced) where a category could only belong to one track. +- **`CREATE TABLE "TrackCategory" ( ... );`**: Creates the `TrackCategory` join table with two columns: `trackId` and `categoryId`, both of type `TEXT` and forming a composite primary key. This table will store the relationships between tracks and categories. +- **`ALTER TABLE "TrackCategory" ADD CONSTRAINT "TrackCategory_trackId_fkey" ... ;`**: Adds a foreign key constraint to the `TrackCategory` table, linking the `trackId` column to the `id` column of the `Track` table. `ON DELETE RESTRICT` ensures that a track cannot be deleted if it is referenced in the `TrackCategory` table. `ON UPDATE CASCADE` ensures that if a track's `id` is updated, the corresponding entries in `TrackCategory` are also updated. +- **`ALTER TABLE "TrackCategory" ADD CONSTRAINT "TrackCategory_categoryId_fkey" ... ;`**: Adds a foreign key constraint to the `TrackCategory` table, linking the `categoryId` column to the `id` column of the `Categories` table with similar `ON DELETE` and `ON UPDATE` cascade behavior. + +3. **Dependencies and Relationships:** + +- **Dependencies:** This migration script depends on the Prisma ORM and the underlying database system (e.g., PostgreSQL, MySQL). +- **Code Relationships:** This script modifies the database schema that is used by the application code. Any code that previously relied on the `trackId` column in the `Categories` table will need to be updated to use the new `TrackCategory` table. This likely involves changes to data access logic and potentially API endpoints related to tracks and categories. + +4. **Usage Example (N/A):** Migration scripts are executed by the Prisma CLI (`prisma migrate`) and are not directly called by the application code. + +5. **Technical Notes:** + +- This migration reflects a shift from a potentially less flexible database design to a more robust and scalable many-to-many relationship between Tracks and Categories. The use of a join table (`TrackCategory`) is a standard practice for representing many-to-many relationships in relational databases. The `ON DELETE RESTRICT` clause helps maintain data integrity by preventing the deletion of tracks or categories that are still referenced in the join table. Consider using `ON DELETE CASCADE` if the business logic requires deleting related entries in the `TrackCategory` table when a track or category is deleted. + +--- + +### packages/db/prisma/migrations/20240412224746_code_exec + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240412224746_code_exec/migration.sql* + +1. **Purpose:** This file defines the database schema for code execution, including tables for problem statements, test cases, code languages, and submissions. It establishes relationships between these entities to support the core functionality of the coding platform. + +2. **Key Functionality:** + + This SQL migration script creates the following tables and relationships: + + * **ProblemStatement:** Stores information about a coding problem. + * `id`: (TEXT, Primary Key) Unique identifier for the problem statement. + * `problemId`: (TEXT, Unique, Foreign Key referencing `Problem`) ID of the associated problem. + * `mainFuncName`: (TEXT) Name of the main function to be executed. + * `argumentNames`: (TEXT\[]) Array of argument names for the main function. + + * **TestCase:** Stores test cases for a problem statement. + * `id`: (TEXT, Primary Key) Unique identifier for the test case. + * `expectedOutput`: (TEXT) Expected output for the test case. + * `problemStatementId`: (TEXT, Foreign Key referencing `ProblemStatement`) ID of the associated problem statement. + * `inputs`: (TEXT\[]) Array of input values for the test case. + + * **CodeLanguage:** Stores supported programming languages. + * `id`: (INTEGER, Primary Key) Unique identifier for the code language. + * `value`: (TEXT) Value representing the language (e.g., "python", "javascript"). + * `label`: (TEXT) Human-readable label for the language (e.g., "Python", "JavaScript"). + + * **Submission:** Stores user code submissions. + * `id`: (TEXT, Primary Key) Unique identifier for the submission. + * `code`: (TEXT) Submitted code. + * `codeLanguageId`: (INTEGER, Foreign Key referencing `CodeLanguage`) ID of the used language. + * `statusId`: (INTEGER) Status code of the submission (e.g., success, failure). + * `statusDesc`: (TEXT) Description of the submission status. + * `runtime`: (INTEGER) Execution time in milliseconds. + * `memoryUsage`: (INTEGER) Memory usage in bytes. + * `errorMessage`: (TEXT) Error message if the submission failed. + * `testCasesPassed`: (INTEGER) Number of test cases passed. + * `problemStatementId`: (TEXT, Foreign Key referencing `ProblemStatement`) ID of the associated problem statement. + * `userId`: (TEXT, Foreign Key referencing `User`, nullable) ID of the submitting user. + * `createdAt`: (TIMESTAMP) Timestamp of submission creation. + * `lastTestCaseId`: (TEXT, Foreign Key referencing `TestCase`, nullable) ID of the last executed test case. + * `stdout`: (TEXT) Standard output of the code execution. + + * **\_CodeLanguageToProblemStatement:** A join table representing a many-to-many relationship between `CodeLanguage` and `ProblemStatement`. This allows a problem statement to be associated with multiple code languages. + + The script also creates indexes for performance optimization, especially for foreign key relationships and unique constraints. + +3. **Dependencies and Relationships:** + + * **Dependencies:** This migration script depends on the Prisma ORM and a database (e.g., PostgreSQL). It also implicitly depends on the existence of the `Problem` and `User` tables. + * **Relationships:** The tables are interconnected through foreign keys, establishing relationships between problem statements, test cases, code languages, and submissions. The `_CodeLanguageToProblemStatement` table manages the many-to-many relationship between `CodeLanguage` and `ProblemStatement`. + +4. **Usage Example:** + + This migration script is executed by the Prisma CLI during database migrations. It alters the database schema to include the defined tables and relationships. + + ```bash + npx prisma migrate deploy + ``` + +5. **Technical Notes:** + + * The use of UUIDs for primary keys (`id` fields) provides globally unique identifiers. + * The `argumentNames` and `inputs` fields are stored as arrays, allowing for flexible handling of function parameters and test case inputs. + * The `_CodeLanguageToProblemStatement` join table is a standard approach for managing many-to-many relationships in relational databases. + * Indices are created on foreign keys and unique fields to optimize query performance. The `problemId` unique index ensures that each problem has only one associated `ProblemStatement`. The index on `_CodeLanguageToProblemStatement` ensures efficient lookups for this many-to-many relationship. + + +This documentation provides a comprehensive overview of the database schema defined in the migration script. It highlights the purpose of each table, their relationships, and key technical considerations. This information is crucial for understanding the data model and how it supports the functionality of the coding platform. + +--- + +### packages/db/prisma/migrations/20240416173507_added_search + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240416173507_added_search/migration.sql* + +1. **Purpose:** This SQL migration script adds a new boolean column named `inSearch` to the `Track` table in the database. This likely supports a feature to mark specific tracks as included in a search index. + +2. **Key Functionality:** + +- `ALTER TABLE "Track" ADD COLUMN "inSearch" BOOLEAN NOT NULL DEFAULT false;` + - This SQL statement adds a new column to the existing `Track` table. + - `inSearch`: The name of the new column. + - `BOOLEAN`: The data type of the new column, indicating it stores true/false values. + - `NOT NULL`: A constraint ensuring that this column cannot have null values. + - `DEFAULT false`: Sets the default value of the new column to `false` for all existing rows. This ensures existing tracks are not immediately included in searches after the migration. + +3. **Dependencies and Relationships:** + +- **Dependencies:** This migration depends on the Prisma ORM (Object-Relational Mapper) and the underlying database system (e.g., PostgreSQL, MySQL). It assumes a `Track` table already exists in the database schema. +- **Code Relationships:** This migration script is part of the database migration history managed by Prisma. It will be executed sequentially with other migrations to evolve the database schema over time. It likely interacts with application code that queries and updates the `inSearch` field of the `Track` table. + +4. **Usage Example (N/A):** Migration scripts are executed by Prisma's migration engine, not directly by the application code. + +5. **Technical Notes:** + +- The `NOT NULL` constraint and `DEFAULT false` ensure data integrity by preventing null values in the `inSearch` column and providing a sensible default for existing records. +- This migration is likely related to a feature that allows users to search for tracks. The `inSearch` flag could be used to filter tracks that are included in the search index, optimizing search performance. This suggests a relationship with code that manages search indexing and querying. + +--- + +### packages/db/prisma/migrations/20240427131506_add_index + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240427131506_add_index/migration.sql* + +1. **Purpose:** This file represents a database migration script. It's responsible for adding an index to a database table, likely for performance optimization. This is part of the Prisma migration workflow. + +2. **Key Functionality:** + + - This file likely contains SQL commands (e.g., `CREATE INDEX`, `ALTER TABLE`) to add an index to a specific table and column. Since the file content is empty, no specific SQL commands are present. This suggests either a rollback or a placeholder migration. A typical `CREATE INDEX` command would look like this: + + ```sql + CREATE INDEX idx_table_column ON table_name (column_name); + ``` + + - **Parameters/Return Types:** SQL commands don't have parameters or return types in the same way functions in programming languages do. They operate directly on the database schema. + + - **Implementation/Optimizations:** Creating indexes generally improves the speed of lookups on the indexed column(s). The specific optimization depends on the type of index (B-tree, hash, etc.) and the database engine. + + - **Fallback Mechanisms:** Database migrations typically have transaction management built into the migration tool (like Prisma Migrate). If the SQL commands fail, the transaction is rolled back, preventing partial updates to the database schema. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** This file is implicitly used by the Prisma Migrate tool. It depends on the Prisma schema definition and the database engine being used. + - **Code Relationships:** This migration file is part of a sequence of migrations managed by Prisma. It builds upon the schema defined in previous migrations. + +4. **Usage Example:** This file is executed by the Prisma Migrate tool as part of the `prisma migrate deploy` or similar command. It's not directly called by application code. + +5. **Technical Notes:** + + - An empty migration file can be useful for creating a named migration point without actually changing the schema. This can be helpful for organizational purposes or for marking a specific point in the migration history. However, in most cases, an empty migration file indicates an error or an incomplete migration. It's crucial to review the migration history and ensure the database schema is in the expected state. + +--- + +### packages/db/prisma/migrations/20240430194543_added_mcq_submission + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240430194543_added_mcq_submission/migration.sql* + +1. **Purpose:** This file defines a database migration script to add the `QuizScore` table and its relationships to the existing `User` and `Problem` tables. This migration enables storing user scores for quiz problems. + +2. **Key Functionality:** + +- **`CREATE TABLE "QuizScore"`:** Creates the `QuizScore` table with the following columns: + - `id` (TEXT, PRIMARY KEY): Unique identifier for each quiz score entry. + - `score` (INTEGER): The score achieved by the user for the problem. + - `userId` (TEXT, FOREIGN KEY referencing `User.id`): The user who submitted the quiz. Allows null values (user deletion). Updates cascade. + - `problemId` (TEXT, FOREIGN KEY referencing `Problem.id`): The problem associated with the quiz score. Restricts deletion if related `QuizScore` entries exist. Updates cascade. + - `createdAt` (TIMESTAMP): Timestamp indicating when the score was recorded. Defaults to the current timestamp. + +- **`ALTER TABLE "QuizScore" ADD CONSTRAINT "QuizScore_userId_fkey"`:** Establishes a foreign key constraint between `QuizScore.userId` and `User.id`. `ON DELETE SET NULL` ensures that if a user is deleted, their associated `userId` in `QuizScore` is set to null instead of deleting the score entry. `ON UPDATE CASCADE` ensures that if a user's `id` is updated, the change is reflected in the `QuizScore` table. + +- **`ALTER TABLE "QuizScore" ADD CONSTRAINT "QuizScore_problemId_fkey"`:** Establishes a foreign key constraint between `QuizScore.problemId` and `Problem.id`. `ON DELETE RESTRICT` prevents deletion of a `Problem` if it has associated entries in `QuizScore`. `ON UPDATE CASCADE` ensures that if a problem's `id` is updated, the change is reflected in the `QuizScore` table. + + +3. **Dependencies and Relationships:** + +- **Dependencies:** This migration script depends on the Prisma ORM and the underlying database system. It also relies on the existence of the `User` and `Problem` tables, likely created in previous migrations. +- **Relationships:** This file directly interacts with the database schema. It creates the `QuizScore` table and establishes relationships with the `User` and `Problem` tables. This implies the existence of other files defining the schema for `User` and `Problem`. + +4. **Usage Example:** This SQL script is executed by a database migration tool (like Prisma Migrate) as part of the application's deployment process. It alters the database schema to accommodate the new `QuizScore` functionality. + +5. **Technical Notes:** + +- The `ON DELETE` and `ON UPDATE` clauses in the foreign key constraints define the referential integrity rules. The chosen settings (`SET NULL` for `userId` and `RESTRICT` for `problemId`) reflect the intended behavior when related records are deleted or updated. +- The use of `TEXT` for `id` fields suggests UUIDs are being used as primary keys, which is a common practice in distributed systems. +- The `createdAt` timestamp provides an audit trail for quiz submissions. + + +This migration script is a crucial part of the database evolution. It introduces the `QuizScore` table, allowing the application to track user performance in quizzes. The defined relationships ensure data consistency and integrity across the database. The choice of `RESTRICT` on `problemId` suggests that problems cannot be deleted if quiz scores are associated with them, maintaining data integrity for historical quiz results. The `SET NULL` on `userId` allows for user deletion while preserving quiz score data, potentially for analytical purposes. + +--- + +### packages/db/prisma/migrations/20240803144221_added_cohort + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240803144221_added_cohort/migration.sql* + +1. **Purpose:** This SQL migration script adds a new `cohort` column to the `Track` table in the database. This likely allows for grouping and filtering tracks based on a cohort identifier. + +2. **Key Functionality:** + +- `ALTER TABLE "Track" ADD COLUMN "cohort" INTEGER NOT NULL DEFAULT 0;` + - This SQL statement adds a new column named `cohort` to the `Track` table. + - The data type is set to `INTEGER`, meaning it will store integer values. + - `NOT NULL` constraint ensures that every track must have a cohort value assigned. + - `DEFAULT 0` sets the default value for the `cohort` column to 0 for existing tracks. New tracks will automatically be assigned a cohort of 0 unless explicitly specified otherwise. + +3. **Dependencies and Relationships:** + +- **Dependencies:** This migration script depends on the Prisma migration engine and the existing database schema. It assumes a `Track` table already exists. +- **Code Relationships:** This migration is part of the database schema evolution managed by Prisma. It alters the `Track` table, which is likely used by other parts of the application that interact with track data. + +4. **Usage Example (N/A):** Migration scripts are executed by the Prisma CLI (`prisma migrate deploy`) and are not directly used by the application code. + +5. **Technical Notes:** + - The default value of 0 for the `cohort` column ensures backward compatibility. Existing tracks will be assigned to cohort 0, preventing potential issues with null values. This suggests cohorts were not previously tracked and this migration introduces the concept. + - Using an integer for the `cohort` suggests a numerical representation for cohorts. This could be a sequential identifier, a year, or some other encoded value. A dedicated enum might be more descriptive if the possible cohort values are known and limited. + + +--- + + +There were no other files provided, so only File 1 was documented. If other files were provided, such as application code interacting with the database, the documentation would explain how those files use the `Track` table and the `cohort` column, demonstrating the relationships between the files. For example, it might show how a query filters tracks based on the `cohort` value or how a new track is created with a specific `cohort` assigned. This would illustrate the complete flow of data and interaction within the system. + +--- + +### packages/db/prisma/migrations/20240809135031_removed_code + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20240809135031_removed_code/migration.sql* + +1. **Purpose:** This SQL migration script removes database entities related to code challenges, including code languages, problem statements, submissions, test cases, and their relationships. It also modifies the `ProblemType` enum, removing the `Code` variant. + +2. **Key Functionality:** + + * **`ALTER TYPE ProblemType ...`**: Migrates the `ProblemType` enum by removing the `Code` option. It creates a new enum type, copies existing valid values, and renames the new type to the original name. This approach ensures minimal disruption to existing data. + * **`DROP TABLE ...`**: Removes tables `CodeLanguage`, `ProblemStatement`, `Submission`, `TestCase`, and `_CodeLanguageToProblemStatement`. This indicates a significant shift in the application's functionality, likely moving away from code-based challenges. + * **`DROP CONSTRAINT ...`**: Drops foreign key constraints before dropping tables to maintain database integrity. This ensures that no orphaned records are left behind. + * **`BEGIN; ... COMMIT;`**: Wraps the enum alteration within a transaction block. This ensures that either all changes are applied successfully, or none are, maintaining data consistency. + +3. **Dependencies and Relationships:** + + * **Dependencies:** This migration script depends on the Prisma ORM and the underlying database system (e.g., PostgreSQL). + * **Relationships:** This script impacts the `Problem` table by modifying its `type` enum. It also removes tables that were previously related to the `Problem` table and each other, indicating a decoupling of code challenge functionality. + +4. **Usage Example:** This script is executed by Prisma's migration engine as part of the database schema update process. Typically, this would be triggered by a command like `npx prisma migrate deploy`. + +5. **Technical Notes:** + + * The migration handles potential data loss by issuing warnings about the removal of enum values and tables. It's crucial to back up the database before applying this migration if the removed data is needed. + * The use of a temporary enum type (`ProblemType_new`) during the enum alteration is a best practice to avoid potential conflicts and ensure a smooth transition. + * The explicit dropping of foreign key constraints before dropping tables demonstrates careful attention to database integrity. + + +--- + + +There are no other files provided, so no further documentation can be generated. If you provide additional files, I can create documentation for them following the same structure. + +--- + +### packages/db/prisma/migrations/20241101231656_add_canva + + + +#### migration.sql + +*Path: packages/db/prisma/migrations/20241101231656_add_canva/migration.sql* + +1. **Purpose:** This migration script adds support for Canva links and a track type enum to the `Track` table in the database. It extends the existing `Track` entity to accommodate different content sources. + +2. **Key Functionality:** + +- **`CREATE TYPE "TrackType" AS ENUM ('NOTION', 'CANVA');`**: This statement defines a new enum type named `TrackType` with two possible values: `NOTION` and `CANVA`. This enum will be used to categorize the source of the track content. + +- **`ALTER TABLE "Track" ADD COLUMN "canvaLink" TEXT, ADD COLUMN "trackType" "TrackType" NOT NULL DEFAULT 'NOTION';`**: This statement alters the existing `Track` table by adding two new columns: + - `canvaLink`: A `TEXT` field to store the URL of a Canva design. This allows associating Canva designs with tracks. + - `trackType`: A column of type `TrackType` (the previously defined enum). It is set as `NOT NULL` with a default value of `NOTION`. This ensures that all existing tracks are marked as originating from Notion by default, maintaining backward compatibility. + +3. **Dependencies and Relationships:** + +- **Dependencies:** This migration script depends on the Prisma migration engine and the underlying database system. It assumes the existence of a `Track` table. +- **Relationships:** This migration directly modifies the `Track` table schema. Any code interacting with the `Track` table will be affected by these changes and might need adjustments to handle the new fields. This change likely relates to other parts of the application that handle track creation, display, and editing, potentially including frontend components and backend API endpoints. + +4. **Usage Example (N/A):** Migration scripts are executed by the Prisma CLI and are not directly used by the application code. + +5. **Technical Notes:** + +- The default value of `'NOTION'` for the `trackType` column ensures a smooth transition for existing data. New tracks can be explicitly assigned the `CANVA` type when created. +- The choice of `TEXT` for `canvaLink` provides flexibility for storing URLs of varying lengths. + +--- + +### packages/db/src + + + +#### index.ts + +*Path: packages/db/src/index.ts* + +1. **Purpose:** This file initializes and exports a Prisma client instance, ensuring a single instance is used throughout the application, especially crucial in development or serverless environments. It provides a standardized way to interact with the database. + +2. **Key Functionality:** + +- **`prismaClientSingleton()`:** + - Parameters: None + - Return Type: `PrismaClient` instance + - Implementation: Creates a new `PrismaClient` instance from the `@prisma/client` library. This function encapsulates the instantiation logic. + +- **`globalForPrisma`:** + - Type: `GlobalThis` augmented with an optional `prisma` property of type `PrismaClientSingleton`. + - Implementation: Leverages `globalThis` to store the Prisma client instance, preventing re-instantiation across hot reloads in development and ensuring a single instance in serverless functions. The type augmentation ensures type safety. + +- **`prisma`:** + - Type: `PrismaClientSingleton` + - Implementation: This is the exported Prisma client instance. It either retrieves an existing instance from `globalForPrisma` or creates a new one using `prismaClientSingleton()`. + +- **`if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;`:** + - Implementation: This condition ensures that the Prisma client is only stored in `globalThis` during development (non-production environments). This is crucial for preventing issues with multiple Prisma client instances in serverless functions and hot reloading. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** Depends on the `@prisma/client` library, which provides the Prisma client for database interactions. +- **Code Relationships:** This file is the central point of access for database operations. Any other file interacting with the database will import and use the `prisma` instance exported from this file. + +4. **Usage Example:** + +```typescript +import prisma from './db'; // Assuming this file is in the same directory + +async function getUser(id: number) { + const user = await prisma.user.findUnique({ where: { id } }); + return user; +} +``` + +5. **Technical Notes:** + +- The use of `globalThis` and the conditional assignment based on `NODE_ENV` are critical for optimizing performance and preventing issues in development and serverless deployments. This pattern ensures a single Prisma client instance, avoiding potential connection leaks and improving efficiency. +- The `PrismaClient` is initialized only once, promoting efficient resource utilization. This singleton pattern is essential for maintaining database connection consistency and preventing performance bottlenecks. This is particularly important in serverless environments where cold starts can be impacted by redundant initializations. +- The file structure and naming conventions adhere to best practices, making the codebase maintainable and easy to understand. The clear separation of concerns ensures that database initialization is handled in a dedicated module. + +--- + +### packages/eslint-config + + + +#### library.js + +*Path: packages/eslint-config/library.js* + +1. **Purpose:** This file defines the base ESLint configuration for JavaScript/TypeScript libraries within a project, ensuring code style and quality consistency. It serves as a foundation for other ESLint configurations. + +2. **Key Functionality:** + +- **`module.exports`**: Exports the ESLint configuration object. + - **Parameters:** None + - **Return Type:** `import("eslint").Linter.Config` + - **Implementation:** Defines the ESLint rules, plugins, environment settings, and other configurations. It extends the recommended ESLint rules, prettier formatting rules, and the `eslint-config-turbo` configuration. The `only-warn` plugin changes all errors to warnings. It sets up the environment for Node.js and defines global variables `React` and `JSX`. Importantly, it configures the `import/resolver` to use TypeScript's `tsconfig.json` for resolving module imports. It also ignores specific files and folders like dotfiles, `node_modules/`, and `dist/`. Finally, it overrides settings for files matching `*.js?(x)` and `*.ts?(x)`. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `node:path`: Used for path resolution with `resolve(process.cwd(), "tsconfig.json")` to locate the project's `tsconfig.json`. + - `eslint`: The core ESLint library, providing the configuration interface. + - `prettier`: For code formatting consistency. + - `eslint-config-turbo`: Extends a pre-configured set of ESLint rules optimized for performance. + - `only-warn`: An ESLint plugin that converts all errors to warnings. +- **Code Relationships:** This file serves as the base configuration for other ESLint configuration files, like `next.js` and `react-internal.js`, which extend it. + +4. **Usage Example:** This file is used by including it in the `extends` array of a project's `.eslintrc.js` file. + +5. **Technical Notes:** + - The use of `resolve(process.cwd(), "tsconfig.json")` dynamically locates the `tsconfig.json` based on the current working directory, making the configuration portable across different project setups. + - Extending `eslint-config-turbo` optimizes ESLint's performance. + - The `only-warn` plugin is used to prevent ESLint from throwing errors, which can be useful in certain development workflows. + +--- + + + +#### next.js + +*Path: packages/eslint-config/next.js* + +1. **Purpose:** This file provides an ESLint configuration specifically tailored for Next.js projects. It builds upon the base `library.js` configuration. + +2. **Key Functionality:** + +- **`module.exports`**: Exports the ESLint configuration object. + - **Parameters:** None + - **Return Type:** `import("eslint").Linter.Config` + - **Implementation:** Extends the base configuration from `library.js` and adds Next.js specific rules from `@vercel/style-guide/eslint/next`. It also sets the environment to include `browser` in addition to `node`. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `node:path`: For path resolution. + - `eslint`: The core ESLint library. + - `prettier`: For code formatting consistency. + - `@vercel/style-guide/eslint/next`: Provides Next.js specific ESLint rules. + - `eslint-config-turbo`: For performance optimization. + - `only-warn`: ESLint plugin to convert errors to warnings. + - `./library.js`: Inherits and extends the base ESLint configuration. +- **Code Relationships:** This file depends on `library.js` for its base configuration, specializing it for Next.js projects. + +4. **Usage Example:** This file is used by including it in the `extends` array of a project's `.eslintrc.js` file within a Next.js project. + +5. **Technical Notes:** Extending the base configuration from `library.js` promotes consistency and reduces redundancy in ESLint configurations across different project types. + +--- + + + +#### react-internal.js + +*Path: packages/eslint-config/react-internal.js* + +1. **Purpose:** This file defines an ESLint configuration for internal React libraries bundled by their consumer. It provides a tailored configuration for this specific use case, building upon the base configuration. + +2. **Key Functionality:** + +- **`module.exports`**: Exports the ESLint configuration object. + - **Parameters:** None + - **Return Type:** `import("eslint").Linter.Config` + - **Implementation:** Extends the base configuration from `library.js`. Sets the environment to `browser`. Includes the `only-warn` plugin. Configures the `import/resolver` to use TypeScript. Ignores specific files and folders. Overrides settings for files matching `*.js?(x)` and `*.ts?(x)`. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `node:path`: For path resolution. + - `eslint`: The core ESLint library. + - `prettier`: For code formatting consistency. + - `eslint-config-turbo`: For performance optimization. + - `only-warn`: ESLint plugin to convert errors to warnings. + - `./library.js`: Inherits and extends the base ESLint configuration. +- **Code Relationships:** This file depends on `library.js` for its base configuration, specializing it for internal React libraries. + +4. **Usage Example:** This file is used by including it in the `extends` array of a project's `.eslintrc.js` file within an internal React library project. + +5. **Technical Notes:** The configuration is specifically designed for internal React libraries bundled by their consumer, indicating a focus on projects where the library is not published as a standalone package. Extending the base configuration ensures consistency with other project types. + +--- + +### packages/store/src + + + +#### index.ts + +*Path: packages/store/src/index.ts* + +1. **Purpose:** This file serves as the main entry point for the `store` package, re-exporting all named exports from the `./atoms` module. This simplifies importing atoms into other parts of the application. + +2. **Key Functionality:** This file doesn't contain any functions or classes. Its sole purpose is to re-export the contents of `./atoms`. This allows consumers to import atoms directly from the `store` package without needing to specify the `atoms` submodule. For example, if `./atoms` exports `userAtom` and `productAtom`, this file makes both available through `store`. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `./atoms` and re-exports all its named exports. + - **Code Relationships:** This file acts as a facade for the `atoms` module, making it the central access point for state management within the application. Other modules needing to interact with application state will likely import from this index file. + +4. **Usage Example:** + +```typescript +// In a component or other module: +import { userAtom, productAtom } from 'store'; + +// Use the imported atoms with a state management library like Recoil or Zustand. +``` + +5. **Technical Notes:** Using a barrel file (index.ts) like this improves developer experience by reducing import path complexity and providing a single, well-defined entry point for the package's functionality. This pattern promotes better code organization and maintainability. It also allows for internal restructuring of the `atoms` module without affecting how consuming modules import its exports. + +--- + +### packages/store/src/atoms + + + +#### filter.ts + +*Path: packages/store/src/atoms/filter.ts* + +1. **Purpose:** This file defines a Recoil atom named `category` to manage the filtering category within the application's state. It provides a centralized state management solution for filtering data. + +2. **Key Functionality:** + +- `category`: A Recoil atom. + - **Key:** "category" (unique identifier for the atom). + - **Default Value:** "" (empty string). + - **Implementation:** Uses `atom` from the `recoil` library to create a piece of state. This atom stores the currently selected category for filtering. Components can subscribe to this atom to react to changes in the filter category. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** Imports `atom` from `recoil`. +- **Code Relationships:** This atom is likely used by components that display filterable content. Other modules might update this atom to trigger filtering logic. It's exported through the `index.ts` file (File 2) to make it accessible throughout the application. + +4. **Usage Example:** + +```typescript +import { useRecoilState } from 'recoil'; +import { category } from 'packages/store/src/atoms/filter'; + +function MyComponent() { + const [selectedCategory, setSelectedCategory] = useRecoilState(category); + + const handleCategoryChange = (newCategory: string) => { + setSelectedCategory(newCategory); + }; + + return ( + // ... JSX to display filter options and update selectedCategory ... + ); +} +``` + +5. **Technical Notes:** Using Recoil for state management simplifies state sharing and synchronization across components. + +--- + + + +#### index.ts + +*Path: packages/store/src/atoms/index.ts* + +1. **Purpose:** This file acts as a central export point for all Recoil atoms defined within the `atoms` directory. This improves code organization and simplifies imports in other parts of the application. + +2. **Key Functionality:** Re-exports atoms from other files using `export * from ...`. This makes all atoms available through a single import. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** Imports and re-exports atoms from `./filter`, `./profileSidebar`, `./quiz`, and `./view`. +- **Code Relationships:** This file serves as the main access point for all atoms in the store. It connects the individual atom definitions to the rest of the application. + +4. **Usage Example:** + +```typescript +import { category, profileSidebar, scoreState, isLegacyViewMode } from 'packages/store/src/atoms'; +``` + +5. **Technical Notes:** Centralized exports improve maintainability and reduce import path complexity. + +--- + + + +#### profileSidebar.ts + +*Path: packages/store/src/atoms/profileSidebar.ts* + +1. **Purpose:** Defines a Recoil atom named `profileSidebar` to manage the visibility state of a profile sidebar. + +2. **Key Functionality:** + +- `profileSidebar`: A Recoil atom. + - **Key:** "profileSidebar" + - **Default Value:** `false` (sidebar initially hidden) + - **Implementation:** Uses `atom` from `recoil` to store a boolean value indicating whether the profile sidebar is visible. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** Imports `atom` from `recoil`. +- **Code Relationships:** Exported through the `index.ts` (File 2). Components can use this atom to control the rendering and behavior of the profile sidebar. + +4. **Usage Example:** Similar to File 1, using `useRecoilState` to access and update the `profileSidebar` atom. + +--- + + + +#### quiz.ts + +*Path: packages/store/src/atoms/quiz.ts* + +1. **Purpose:** Defines a Recoil atom to manage the score in a quiz context. + +2. **Key Functionality:** + +- `scoreState`: A Recoil atom. + - **Key:** "scoreState" + - **Default Value:** 0 + - **Implementation:** Stores the current quiz score. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** Imports `atom` from `recoil`. +- **Code Relationships:** Exported through `index.ts` (File 2). Quiz components will likely use this atom to display and update the score. + +--- + + + +#### view.ts + +*Path: packages/store/src/atoms/view.ts* + +1. **Purpose:** Defines a Recoil atom to manage the view mode of the application (legacy or not). + +2. **Key Functionality:** + +- `isLegacyViewMode`: A Recoil atom. + - **Key:** "isLegacyViewMode" + - **Default Value:** `false` + - **Implementation:** Stores a boolean indicating whether the application is in legacy view mode. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** Imports `atom` from `recoil`. +- **Code Relationships:** Exported through `index.ts` (File 2). Components can use this atom to conditionally render different UI elements based on the view mode. + + +All these files work together to provide a centralized state management solution using Recoil. File 2 (`index.ts`) plays a crucial role in connecting the individual atom definitions to the rest of the application. Components can import and use these atoms to manage various aspects of the application's state, such as filtering, sidebar visibility, quiz scores, and view modes. This modular approach promotes code reusability and maintainability. + +--- + +### packages/ui + + + +#### .eslintrc.js + +*Path: packages/ui/.eslintrc.js* + +1. **Purpose:** This file configures ESLint for the UI package, ensuring code style and quality consistency within the React project. It extends a shared ESLint configuration and specifies project-specific settings. + +2. **Key Functionality:** + + - **`module.exports`**: Exports the ESLint configuration object. + - **`root: true`**: Indicates this is the root ESLint configuration file, preventing ESLint from searching up the directory tree for other configuration files. This improves performance and avoids unintended inheritance. + - **`extends: ["@repo/eslint-config/react-internal.js"]`**: Extends a shared ESLint configuration located at `@repo/eslint-config/react-internal.js`. This promotes consistency across multiple projects or packages within the repository. + - **`parser: "@typescript-eslint/parser"`**: Specifies the parser to use for TypeScript files. This allows ESLint to understand TypeScript syntax. + - **`parserOptions`**: Options for the TypeScript parser. + - **`project: "./tsconfig.lint.json"`**: Points to the TypeScript configuration file specifically for linting. This file likely contains type information and compiler options relevant to static analysis. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `eslint`, `@typescript-eslint/parser`, and the shared ESLint config `@repo/eslint-config/react-internal.js`. + - **Code Relationships:** This file is the root ESLint configuration for the `packages/ui` directory. It's used by ESLint when linting files within this directory and its subdirectories. + +4. **Usage Example:** ESLint automatically uses this configuration file when run within the `packages/ui` directory. For example: `npx eslint src/**/*.ts`. + +5. **Technical Notes:** Using a shared ESLint configuration (`@repo/eslint-config/react-internal.js`) promotes maintainability and consistency across projects. The `tsconfig.lint.json` file likely excludes test files and other non-production code from type checking during linting to improve performance. + +--- + + + +#### tailwind.config.js + +*Path: packages/ui/tailwind.config.js* + +1. **Purpose:** This file configures Tailwind CSS for the UI package, defining the design system and styling rules for the project's components. It customizes colors, border radii, animations, and other styling aspects. + +2. **Key Functionality:** + + - **`module.exports`**: Exports the Tailwind CSS configuration object. + - **`darkMode: ["class"]`**: Enables dark mode based on the presence of a specific class (likely `dark`) on the `html` or `body` element. + - **`content`**: Specifies the files to scan for Tailwind CSS class usage. This ensures that only used styles are included in the final build, optimizing performance. + - **`prefix`**: Configures an optional prefix for generated utility classes. An empty string means no prefix is used. + - **`theme`**: Customizes the default Tailwind theme. + - `container`: Defines default container styles. + - `extend`: Extends the default theme with custom colors, border radii, keyframes, and animations. Uses CSS variables (e.g., `hsl(var(--primary))`) for dynamic theming. + - **`plugins`**: Includes the `tailwindcss-animate` plugin for utility-first animations. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** Depends on `tailwindcss` and `tailwindcss-animate`. + - **Code Relationships:** This file is the central configuration for Tailwind CSS within the `packages/ui` directory. It's used by the Tailwind CLI during build time to generate the CSS stylesheet. It interacts with the files listed in the `content` array, as Tailwind scans these files to determine which styles are actually used in the project. It also relies on the `.eslintrc.js` file (File 1) indirectly, as ESLint helps maintain code quality within the project, including the components that use Tailwind classes. + +4. **Usage Example:** Tailwind CLI uses this configuration file during the build process. For example: `npx tailwindcss -i ./src/input.css -o ./dist/output.css --config ./tailwind.config.js`. + +5. **Technical Notes:** The use of CSS variables for colors allows for dynamic theming. The `content` array is crucial for purging unused styles and optimizing the final CSS bundle size. The dependency on `tailwindcss-animate` provides pre-built animation utilities. The connection between this file and `.eslintrc.js` highlights the importance of consistent code style and quality across the project, even in configuration files. + +--- + +### packages/ui/src + + + +#### index.ts + +*Path: packages/ui/src/index.ts* + +1. **Purpose:** This file serves as the main entry point for the UI component library, exporting all available components for easy access and integration. It acts as a central hub for distributing UI elements throughout the application. + +2. **Key Functionality:** This file re-exports components from various modules within the `shad/ui` directory. It doesn't contain any functions or classes itself, but rather aggregates and exposes the UI components. There are no parameters, return types, or implementation details specific to this file as it primarily focuses on exporting modules. + +3. **Dependencies and Relationships:** + + - **Imports & Usage:** This file imports and re-exports components from other files within the `shad/ui` directory. Each `export * from './shad/ui/{component}';` statement imports all exported members from the specified component module and re-exports them from this index file. + - **Code Relationships:** This file is the central point of access for all UI components. Any other module in the application that needs to use these components will import them from this file. This creates a dependency between consuming modules and this index file, ensuring a single source of truth for UI component imports. + +4. **Usage Example:** + +```typescript +// In another component or module: +import { Button, Card } from '@shadcn/ui'; // Assuming '@shadcn/ui' resolves to this index file + +function MyComponent() { + return ( + + + + ); +} +``` + +5. **Technical Notes:** + +- This barrel export pattern simplifies importing components and promotes maintainability by centralizing the export location. It avoids deep imports and keeps the component usage concise. +- The `@shadcn/ui` alias in the usage example assumes that the UI library is packaged and published as a separate package, and this alias is configured in the build process. This is a common practice for sharing UI components across multiple projects. This structure allows for independent versioning and updates of the UI library. + + +--- + + +There are no other files provided to document. If you provide additional files, I can generate documentation for them following the same structure and guidelines. + +--- + +### packages/ui/src/lib + + + +#### utils.ts + +*Path: packages/ui/src/lib/utils.ts* + +1. **Purpose:** This file provides utility functions for working with CSS classes, specifically for merging and combining Tailwind CSS classes with other class values. It centralizes class manipulation logic for the UI package. + +2. **Key Functionality:** + +- **`cn(...inputs: ClassValue[])`**: + - **Parameters:** `inputs` (an array of `ClassValue` which can be strings, arrays, or objects representing CSS classes). + - **Return Type:** `string` (a merged string of CSS classes). + - **Implementation:** This function utilizes `clsx` to handle conditional class merging and `tailwind-merge` to merge Tailwind CSS classes effectively, ensuring proper ordering and deduplication. It simplifies the process of combining CSS classes from different sources within the UI components. + - **Error Handling:** `clsx` and `tailwind-merge` handle invalid input gracefully, typically by ignoring non-string values or returning an empty string if no valid classes are provided. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `clsx`: A utility for constructing `className` strings conditionally. Used for combining and toggling CSS classes based on conditions. + - `tailwind-merge`: A utility specifically designed for merging Tailwind CSS classes correctly. Ensures proper order and avoids conflicts. +- **Code Relationships:** This utility function is intended to be used within UI components across the `packages/ui` directory to manage CSS classes effectively. + +4. **Usage Example:** + +```typescript +import { cn } from "./lib/utils"; + +const MyComponent = ({ isActive }: { isActive: boolean }) => ( +
+ {/* ... component content ... */} +
+); +``` + +5. **Technical Notes:** + +- The use of `tailwind-merge` is crucial for correctly handling the complexities of Tailwind CSS class merging, ensuring that classes are applied in the correct order and avoiding conflicts. This choice improves maintainability and reduces potential styling issues. +- This utility promotes consistency in how CSS classes are managed across the UI components, simplifying development and reducing code duplication. + +--- + +### packages/ui/src/shad/ui + + + +#### badge.tsx + +*Path: packages/ui/src/shad/ui/badge.tsx* + +1. **Purpose:** This file defines a reusable Badge component for displaying small status labels or indicators. It leverages class-variance-authority (cva) for managing styles. + +2. **Key Functionality:** + +- **`badgeVariants`:** A cva function that defines the styling variants for the badge. + - **Parameters:** An object with a `variant` property (default, secondary, destructive, outline). + - **Returns:** A string of CSS classes. + - **Implementation:** Uses cva to generate CSS classes based on the chosen variant. Provides default styles for common badge appearances. +- **`Badge`:** The React component for rendering the badge. + - **Parameters:** + - `className` (optional): Additional CSS classes. + - `variant` (optional): The style variant to apply (default, secondary, destructive, outline). + - `...props`: Any other HTML attributes for the `
` element. + - **Returns:** A React component representing the badge. + - **Implementation:** Renders a `
` with the appropriate CSS classes based on the `variant` prop and any provided `className`. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `React`: For creating the functional component. + - `cva`: For managing style variants. + - `cn`: A utility function (likely from a shared utility module) for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is likely used by other components in the repository to display badges. + +4. **Usage Example:** + +```tsx +import { Badge } from "@repo/ui/badge"; + +function MyComponent() { + return New; +} +``` + +5. **Technical Notes:** + - The use of `cva` promotes maintainability and consistency in styling. + +--- + + + +#### button.tsx + +*Path: packages/ui/src/shad/ui/button.tsx* + +1. **Purpose:** Defines a reusable Button component with various style variants and sizes. Uses `radix-ui/react-slot` for rendering flexibility. + +2. **Key Functionality:** + +- **`buttonVariants`:** A cva function that defines the styling variants for the button. + - **Parameters:** An object with `variant` (default, destructive, outline, secondary, ghost, link, explore) and `size` (default, sm, lg, icon) properties. + - **Returns:** A string of CSS classes. + - **Implementation:** Uses cva to generate CSS classes based on the chosen variant and size. Provides default styles for common button appearances. +- **`Button`:** The React component for rendering the button. + - **Parameters:** + - `className` (optional): Additional CSS classes. + - `variant` (optional): The style variant to apply. + - `size` (optional): The size of the button. + - `asChild` (optional): Boolean indicating whether to render as a `Slot` (for advanced composition). Defaults to `false`. + - `...props`: Any other HTML attributes for the button element. + - **Returns:** A React component representing the button. + - **Implementation:** Renders either a `; +} +``` + +5. **Technical Notes:** + - The use of `radix-ui/react-slot` allows for more complex composition scenarios where the button might wrap other elements. + - `forwardRef` ensures that refs are passed correctly to the underlying button element. + +--- + + + +#### card.tsx + +*Path: packages/ui/src/shad/ui/card.tsx* + +1. **Purpose:** Defines a Card component and its sub-components (CardHeader, CardTitle, CardDescription, CardContent, CardFooter) for creating visually distinct sections within the UI. + +2. **Key Functionality:** + +- **`Card`**: The main card container. + - **Implementation:** A simple `div` with styling for rounded corners, border, background, text color, and shadow. +- **`CardHeader`**: Container for the card's header section. + - **Implementation:** A `div` with flexbox styling for layout. +- **`CardTitle`**: Displays the card's title. + - **Implementation:** An `h3` with styling for font weight, line height, and letter spacing. +- **`CardDescription`**: Displays a short description for the card. + - **Implementation:** A `div` with styling for smaller text and muted color. +- **`CardContent`**: Container for the main content of the card. + - **Implementation:** A `div` with padding. +- **`CardFooter`**: Container for the card's footer section. + - **Implementation:** A `div` with flexbox styling for layout. + +All components use `forwardRef` for better composability. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `forwardRef`: From React, for ref forwarding. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is likely used to structure content in various parts of the application. The sub-components are meant to be used within the `Card` component. + +4. **Usage Example:** + +```tsx +import { Card, CardHeader, CardTitle, CardContent, CardFooter, CardDescription } from "@repo/ui/card"; + +function MyComponent() { + return ( + + + Card Title + Card Description + + Card Content + Card Footer + + ); +} +``` + +5. **Technical Notes:** + - The consistent use of `forwardRef` ensures that refs can be passed to the underlying DOM elements. + +--- + + + +#### checkbox.tsx + +*Path: packages/ui/src/shad/ui/checkbox.tsx* + +1. **Purpose:** Defines a Checkbox component using `@radix-ui/react-checkbox`. + +2. **Key Functionality:** + +- **`Checkbox`:** The checkbox component. + - **Implementation:** Wraps `CheckboxPrimitive.Root` from Radix UI and applies custom styling. Includes a `CheckIcon` from Radix UI for the checked state. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@radix-ui/react-checkbox`: Provides the underlying checkbox functionality. + - `@radix-ui/react-icons`: For the checkmark icon. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is a basic UI element likely used in forms and other interactive components. + +4. **Usage Example:** + +```tsx +import { Checkbox } from "@repo/ui/checkbox"; + +function MyComponent() { + const [checked, setChecked] = React.useState(false); + return ; +} +``` + +5. **Technical Notes:** + - Using Radix UI provides accessibility and styling benefits. + +--- + + + +#### dailog.tsx + +*Path: packages/ui/src/shad/ui/dailog.tsx* + +1. **Purpose:** Defines a Dialog component and related sub-components using `@radix-ui/react-dialog`. + +2. **Key Functionality:** + +- **`Dialog`:** The root dialog component. +- **`DialogTrigger`:** The element that triggers the dialog to open. +- **`DialogPortal`:** A portal for rendering the dialog outside the normal DOM hierarchy. +- **`DialogClose`:** A button or element that closes the dialog. +- **`DialogOverlay`:** A backdrop behind the dialog. +- **`DialogContent`:** The main container for the dialog's content. +- **`DialogHeader`**: Container for the dialog's header. +- **`DialogFooter`**: Container for the dialog's footer. +- **`DialogTitle`:** Displays the dialog's title. +- **`DialogDescription`**: Displays a description for the dialog. + +All components except `Dialog`, `DialogTrigger`, `DialogPortal`, and `DialogClose` are custom wrappers around Radix UI primitives, adding styling and layout. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@radix-ui/react-dialog`: Provides the core dialog functionality. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is used to display modal dialogs in the application. + +4. **Usage Example:** + +```tsx +import { + Dialog, + DialogTrigger, + DialogContent, + DialogTitle, + DialogDescription, + DialogClose, +} from "@repo/ui/dialog"; + +function MyComponent() { + return ( + + Open Dialog + + Dialog Title + Dialog description. + Close + + + ); +} ``` -## Option 2: Manual Setup +5. **Technical Notes:** + - Using Radix UI provides accessibility and animation features. -### 1. Install Dependencies -```bash -cd daily-code -yarn install +--- + + + +#### dropdown-menu.tsx + +*Path: packages/ui/src/shad/ui/dropdown-menu.tsx* + +1. **Purpose:** Defines a DropdownMenu component and related sub-components using `@radix-ui/react-dropdown-menu`. + +2. **Key Functionality:** + +- **Wrappers around Radix UI primitives:** `DropdownMenu`, `DropdownMenuTrigger`, `DropdownMenuGroup`, `DropdownMenuPortal`, `DropdownMenuSub`, `DropdownMenuRadioGroup`, `DropdownMenuSubTrigger`, `DropdownMenuSubContent`, `DropdownMenuContent`, `DropdownMenuItem`, `DropdownMenuCheckboxItem`, `DropdownMenuRadioItem`, `DropdownMenuLabel`, `DropdownMenuSeparator`. +- **`DropdownMenuShortcut`**: A custom component for displaying keyboard shortcuts. + +These components provide the structure and functionality for dropdown menus, including submenus, checkboxes, radio buttons, and keyboard shortcuts. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@radix-ui/react-dropdown-menu`: Provides the core dropdown menu functionality. + - `@radix-ui/react-icons`: For icons used within the dropdown. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is used for dropdown menus throughout the application. + +4. **Usage Example:** + +```tsx +import { + DropdownMenu, + DropdownMenuTrigger, + DropdownMenuContent, + DropdownMenuItem, +} from "@repo/ui/dropdown-menu"; + +function MyComponent() { + return ( + + Open Menu + + Item 1 + Item 2 + + + ); +} ``` -### 2. Setup Database +5. **Technical Notes:** + - Using Radix UI provides accessibility and animation features. -#### For Mac and Linux users -```bash -cd packages/db -chmod +x ./setupDB.sh -./setupDB.sh +--- + + + +#### input.tsx + +*Path: packages/ui/src/shad/ui/input.tsx* + +1. **Purpose:** Defines a basic Input component. + +2. **Key Functionality:** + +- **`Input`:** The input component. + - **Implementation:** A simple `` element with styling for common input appearances. Uses `forwardRef` for ref forwarding. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. + - `React.forwardRef`: For ref forwarding. +- **Code Relationships:** This component is a basic UI element likely used in forms and other interactive components. + +4. **Usage Example:** + +```tsx +import { Input } from "@repo/ui/input"; + +function MyComponent() { + return ; +} ``` -#### For Windows users -```bash -cd packages/db -copy .env.example .env -docker-compose up +5. **Technical Notes:** + - The component handles different input types through the `type` prop. + +--- + + + +#### label.tsx + +*Path: packages/ui/src/shad/ui/label.tsx* -# Configure the database connection -# Add your connection string to DATABASE_URL +1. **Purpose:** Defines a Label component using `@radix-ui/react-label`. -yarn prisma migrate dev -yarn prisma db seed +2. **Key Functionality:** + +- **`Label`:** The label component. + - **Implementation:** Wraps `LabelPrimitive.Root` from Radix UI and applies custom styling using `cva`. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@radix-ui/react-label`: Provides the underlying label functionality. + - `cva`: For managing style variants. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is used to label form elements and other interactive components. + +4. **Usage Example:** + +```tsx +import { Label } from "@repo/ui/label"; +import { Input } from "@repo/ui/input"; + +function MyComponent() { + return ( +
+ + +
+ ); +} ``` -### 3. Run Locally -```bash -cd ../.. -yarn run dev +5. **Technical Notes:** + - Using Radix UI provides accessibility benefits. + +--- + + + +#### pagination.tsx + +*Path: packages/ui/src/shad/ui/pagination.tsx* + +1. **Purpose:** Defines a Pagination component and related sub-components for navigating paginated content. + +2. **Key Functionality:** + +- **`Pagination`:** The main pagination container. +- **`PaginationContent`:** A `ul` element to hold the pagination items. +- **`PaginationItem`:** An `li` element to wrap each pagination item. +- **`PaginationLink`:** An `a` element for navigating to different pages. +- **`PaginationPrevious`:** A button for going to the previous page. +- **`PaginationNext`:** A button for going to the next page. +- **`PaginationEllipsis`:** A visual indicator for omitted pages. + +These components work together to create a pagination control. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@radix-ui/react-icons`: For icons used in the previous and next buttons. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. + - `buttonVariants` and `ButtonProps` from `./button`: Uses button styling for the pagination links. +- **Code Relationships:** This component is used to display pagination controls in the application. It depends on the `Button` component for styling. + +4. **Usage Example:** + +```tsx +import { + Pagination, + PaginationContent, + PaginationItem, + PaginationLink, + PaginationPrevious, + PaginationNext, + PaginationEllipsis, +} from "@repo/ui/pagination"; + +function MyComponent() { + return ( + + + + + 1 + + + + + + ); +} +``` + +5. **Technical Notes:** + - The component uses ARIA attributes for accessibility. + +--- + + + +#### resizable.tsx + +*Path: packages/ui/src/shad/ui/resizable.tsx* + +1. **Purpose:** Defines components for creating resizable panels using `react-resizable-panels`. + +2. **Key Functionality:** + +- **`ResizablePanelGroup`:** A container for resizable panels. +- **`ResizablePanel`:** An individual resizable panel. +- **`ResizableHandle`:** The draggable handle for resizing panels. + +These components provide the structure and functionality for creating resizable layouts. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `react-resizable-panels`: Provides the core resizing functionality. + - `@radix-ui/react-icons`: For the drag handle icon. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is used for creating resizable layouts within the application. + +4. **Usage Example:** + +```tsx +import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from "@repo/ui/resizable"; + +function MyComponent() { + return ( + + Panel 1 + + Panel 2 + + ); +} +``` + +5. **Technical Notes:** + - The `withHandle` prop on `ResizableHandle` controls whether a visual drag handle is displayed. + +--- + + + +#### scroll-area.tsx + +*Path: packages/ui/src/shad/ui/scroll-area.tsx* + +1. **Purpose:** Defines a ScrollArea component using `@radix-ui/react-scroll-area`. + +2. **Key Functionality:** + +- **`ScrollArea`:** The main scroll area container. +- **`ScrollBar`:** The custom scrollbar component. + +These components provide a customizable scroll area with a custom scrollbar. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@radix-ui/react-scroll-area`: Provides the core scroll area functionality. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is used to create scrollable areas within the application. + +4. **Usage Example:** + +```tsx +import { ScrollArea } from "@repo/ui/scroll-area"; + +function MyComponent() { + return ( + +
+ {/* Content that scrolls */} +
+
+ ); +} +``` + +5. **Technical Notes:** + - Using Radix UI provides accessibility and styling benefits. + +--- + + + +#### select.tsx + +*Path: packages/ui/src/shad/ui/select.tsx* + +1. **Purpose:** Defines a Select component using `@radix-ui/react-select`. + +2. **Key Functionality:** + +- **Wrappers around Radix UI primitives:** `Select`, `SelectGroup`, `SelectValue`, `SelectTrigger`, `SelectScrollUpButton`, `SelectScrollDownButton`, `SelectContent`, `SelectLabel`, `SelectItem`, `SelectSeparator`. +These components provide the structure and functionality for a select dropdown, including grouping, labels, and separators. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@radix-ui/react-select`: Provides the core select functionality. + - `@radix-ui/react-icons`: For icons used within the select. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is used for select dropdowns throughout the application. + +4. **Usage Example:** + +```tsx +import { + Select, + SelectTrigger, + SelectContent, + SelectItem, +} from "@repo/ui/select"; + +function MyComponent() { + return ( + + ); +} +``` + +5. **Technical Notes:** + - Using Radix UI provides accessibility and animation features. + +--- + + + +#### separator.tsx + +*Path: packages/ui/src/shad/ui/separator.tsx* + +1. **Purpose:** Defines a Separator component using `@radix-ui/react-separator`. + +2. **Key Functionality:** + +- **`Separator`:** The separator component. + - **Implementation:** Wraps `SeparatorPrimitive.Root` from Radix UI and applies custom styling. Supports horizontal and vertical orientation. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@radix-ui/react-separator`: Provides the underlying separator functionality. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is used to visually separate content within the application. + +4. **Usage Example:** + +```tsx +import { Separator } from "@repo/ui/separator"; + +function MyComponent() { + return ( +
+
Section 1
+ +
Section 2
+
+ ); +} +``` + +5. **Technical Notes:** + - Using Radix UI provides styling and accessibility benefits. + +--- + + + +#### sheet.tsx + +*Path: packages/ui/src/shad/ui/sheet.tsx* + +1. **Purpose:** Defines a Sheet component using `@radix-ui/react-dialog`. This is a type of modal dialog that slides in from the side of the viewport. + +2. **Key Functionality:** + +- **Wrappers around Radix UI primitives:** `Sheet`, `SheetTrigger`, `SheetClose`, `SheetPortal`, `SheetOverlay`, `SheetContent`, `SheetHeader`, `SheetFooter`, `SheetTitle`, `SheetDescription`. +These components provide the structure and functionality for a sheet dialog, including header, footer, title, and description. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@radix-ui/react-dialog`: Provides the core dialog functionality. + - `@radix-ui/react-icons`: For the close icon. + - `cva`: For managing style variants. + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is used to display sheet dialogs in the application. + +4. **Usage Example:** + +```tsx +import { + Sheet, + SheetTrigger, + SheetContent, + SheetTitle, + SheetDescription, + SheetClose, +} from "@repo/ui/sheet"; + +function MyComponent() { + return ( + + Open Sheet + + Sheet Title + Sheet description. + + + + + + ); +} +``` + +5. **Technical Notes:** + - Using Radix UI provides accessibility and animation features. + +--- + + + +#### skeleton.tsx + +*Path: packages/ui/src/shad/ui/skeleton.tsx* + +1. **Purpose:** Defines a Skeleton component for displaying placeholder content while data is loading. + +2. **Key Functionality:** + +- **`Skeleton`:** The skeleton component. + - **Implementation:** A simple `div` with styling for a loading animation (pulse) and rounded corners. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `cn`: Utility function for combining CSS classes. Located at `@repo/ui/utils`. +- **Code Relationships:** This component is used as a placeholder for content that is still loading. + +4. **Usage Example:** + +```tsx +import { Skeleton } from "@repo/ui/skeleton"; + +function MyComponent() { + return ; +} +``` + +5. **Technical Notes:** + - The component uses CSS animations for the loading effect. + +**Overall System Design:** + +The `@repo/ui` library provides a collection of reusable UI components built primarily with React and Radix UI. It leverages `cva` for managing style variants and a custom `cn` utility function (presumably located in `@repo/ui/utils`) for combining CSS classes. The heavy reliance on Radix UI suggests a focus on accessibility and polished animations. The components are designed to be composable and flexible, allowing for customization and integration into various parts of the application. The clear separation of concerns and consistent use of patterns like `forwardRef` contribute to the maintainability and scalability of the UI codebase. + +--- + + + +#### spotlight.tsx + +*Path: packages/ui/src/shad/ui/spotlight.tsx* + +1. **Purpose:** This file defines a React component called `Spotlight` that renders an animated spotlight effect using an SVG. It's likely used to highlight specific areas or elements on the screen. + +2. **Key Functionality:** + +- **`Spotlight` (functional component):** + - **Parameters:** + - `className` (optional, string): Additional CSS classes to apply to the SVG. + - `fill` (optional, string): Color of the spotlight. Defaults to white. + - **Return Type:** `JSX.Element` (the SVG element). + - **Implementation:** Renders an SVG ellipse with a Gaussian blur filter applied to create a soft spotlight effect. The `animate-spotlight` class suggests an animation is applied externally (likely via CSS). The component uses `cn` from `@repo/ui/utils` for convenient class name concatenation. + - **Fallback Mechanisms:** No explicit error handling or fallbacks are present. Relies on standard React error boundaries. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `react`: Used for JSX and component creation. + - `cn` from `@repo/ui/utils`: Utility for combining CSS class names. +- **Code Relationships:** This component is likely used by other components in the UI library to add the spotlight effect. The animation is likely defined in a separate CSS file. + +4. **Usage Example:** + +```tsx + +``` + +5. **Technical Notes:** The spotlight's size and position are controlled via CSS classes and transformations applied to the SVG element. The `pointer-events-none` attribute ensures the spotlight doesn't interfere with mouse interactions on underlying elements. + +--- + + + +#### switch.tsx + +*Path: packages/ui/src/shad/ui/switch.tsx* + +1. **Purpose:** This file defines a custom `Switch` component using Radix UI's `react-switch` library. It provides a styled toggle switch for user interaction. + +2. **Key Functionality:** + +- **`Switch` (functional component, forwardRef):** + - **Parameters:** Inherits props from `@radix-ui/react-switch`. Includes `className` for custom styling. + - **Return Type:** `JSX.Element` (the switch component). + - **Implementation:** Wraps `SwitchPrimitives.Root` and `SwitchPrimitives.Thumb` from Radix UI to provide styling and accessibility features. Uses `cn` for class name management. + - **Fallback Mechanisms:** Relies on Radix UI's internal error handling and accessibility features. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `react`: For JSX and component creation. + - `@radix-ui/react-switch`: Provides the underlying switch functionality. + - `cn` from `@repo/ui/utils`: Utility for combining CSS class names. +- **Code Relationships:** This component is a standalone UI element that can be used within other components. + +4. **Usage Example:** + +```tsx + +``` + +5. **Technical Notes:** The `forwardRef` allows external components to access the underlying switch element for focus management and other DOM manipulations. Leveraging Radix UI ensures accessibility and consistent behavior across browsers. + +--- + + + +#### table.tsx + +*Path: packages/ui/src/shad/ui/table.tsx* + +1. **Purpose:** This file defines a set of React components for creating accessible and styled tables. It provides components for table structure (`Table`, `TableHeader`, `TableBody`, `TableFooter`), rows (`TableRow`), cells (`TableHead`, `TableCell`), and captions (`TableCaption`). + +2. **Key Functionality:** + +- **`Table`, `TableHeader`, `TableBody`, `TableFooter`, `TableRow`, `TableHead`, `TableCell`, `TableCaption` (functional components, forwardRef):** + - **Parameters:** Accept standard HTML attributes for their respective elements, including `className`. + - **Return Type:** `JSX.Element` (the corresponding table element). + - **Implementation:** Each component renders its corresponding HTML element with pre-defined styling and accessibility features using `cn` for class name management. + - **Fallback Mechanisms:** Relies on standard HTML table behavior and React error boundaries. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `react`: For JSX and component creation. + - `cn` from `@repo/ui/utils`: Utility for combining CSS class names. +- **Code Relationships:** These components are designed to be used together to construct a complete table. + +4. **Usage Example:** + +```tsx + + + + Column 1 + Column 2 + + + + + Data 1 + Data 2 + + +
+``` + +5. **Technical Notes:** The `forwardRef` allows access to the underlying DOM elements. Styling is applied via Tailwind CSS classes using the `cn` utility. The components include basic styling for hover and selected states. + +--- + + + +#### tabs.tsx + +*Path: packages/ui/src/shad/ui/tabs.tsx* + +1. **Purpose:** This file defines a set of React components for creating accessible and styled tabs using Radix UI's `react-tabs` library. + +2. **Key Functionality:** + +- **`Tabs`, `TabsList`, `TabsTrigger`, `TabsContent` (functional components, forwardRef):** + - **Parameters:** Inherit props from `@radix-ui/react-tabs`. Include `className` for custom styling. + - **Return Type:** `JSX.Element` (the corresponding tab element). + - **Implementation:** Wraps components from `@radix-ui/react-tabs` to provide styling and accessibility. Uses `cn` for class name management. + - **Fallback Mechanisms:** Relies on Radix UI's internal error handling and accessibility features. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `@radix-ui/react-tabs`: Provides the underlying tab functionality. + - `cn` from `@repo/ui/utils`: Utility for combining CSS class names. + - `react`: For JSX and component creation. +- **Code Relationships:** These components are designed to be used together to create a tabbed interface. + +4. **Usage Example:** + +```tsx + + + Tab 1 + Tab 2 + + Content 1 + Content 2 + ``` + +5. **Technical Notes:** Leveraging Radix UI ensures accessibility and consistent behavior. The `forwardRef` allows access to the underlying DOM elements. + +--- + + + +#### textarea.tsx + +*Path: packages/ui/src/shad/ui/textarea.tsx* + +1. **Purpose:** This file defines a styled `Textarea` component. + +2. **Key Functionality:** + +- **`Textarea` (functional component, forwardRef):** + - **Parameters:** Inherits props from `React.TextareaHTMLAttributes`, including `className`. + - **Return Type:** `JSX.Element` (the textarea element). + - **Implementation:** Renders a standard HTML `textarea` with pre-defined styling using `cn` for class name management. + - **Fallback Mechanisms:** Relies on standard `textarea` behavior and React error boundaries. + +3. **Dependencies and Relationships:** + +- **Imports & Usage:** + - `react`: For JSX and component creation. + - `cn` from `@repo/ui/utils`: Utility for combining CSS class names. +- **Code Relationships:** This component is a standalone UI element that can be used within other components. + +4. **Usage Example:** + +```tsx +