From dca9a354f6be489c0a55dcfe5d72dd1610a86b05 Mon Sep 17 00:00:00 2001 From: Pablo Occhiuzzi <104530403+opablon@users.noreply.github.com> Date: Tue, 5 Aug 2025 12:19:26 +0000 Subject: [PATCH 1/8] refactor: implement best practices for scalability, maintainability and performance - Add modular architecture with organized folder structure - Implement custom hooks (useAutoencoder, useErrorHandler) - Add centralized configuration and utilities - Optimize performance with lazy loading, throttling, and memory management - Add comprehensive error handling with ErrorBoundary - Improve accessibility with ARIA attributes and semantic HTML - Optimize build configuration with code splitting and minification - Add ESLint configuration and code quality tools - Enhance CI/CD pipeline with quality gates - Improve SEO with meta tags and structured HTML --- .eslintrc.cjs | 43 ++++ .github/workflows/deploy.yml | 46 +++- .gitignore | 102 +++++++- index.html | 40 ++- package-lock.json | 60 +++++ package.json | 5 +- postcss.config.js | 2 - src/App.jsx | 90 +++++-- src/components/ControlPanel.jsx | 96 ++++++-- src/components/ErrorBoundary.jsx | 85 +++++++ src/components/GeneratedCharacter.jsx | 6 +- src/components/Header.jsx | 2 - src/components/LatentSpacePlot.jsx | 227 ++++++++++------- src/components/Spinner.jsx | 2 - src/components/TheorySection.jsx | 1 - src/config/constants.js | 57 +++++ src/hooks/useAutoencoder.js | 341 ++++++++++---------------- src/hooks/useErrorHandler.js | 59 +++++ src/main.jsx | 5 +- src/utils/math.js | 76 ++++++ src/utils/performance.js | 82 +++++++ src/utils/validation.js | 54 ++++ vite.config.js | 20 ++ 23 files changed, 1141 insertions(+), 360 deletions(-) create mode 100644 .eslintrc.cjs create mode 100644 src/components/ErrorBoundary.jsx create mode 100644 src/config/constants.js create mode 100644 src/hooks/useErrorHandler.js create mode 100644 src/utils/math.js create mode 100644 src/utils/performance.js create mode 100644 src/utils/validation.js diff --git a/.eslintrc.cjs b/.eslintrc.cjs new file mode 100644 index 0000000..855b9b3 --- /dev/null +++ b/.eslintrc.cjs @@ -0,0 +1,43 @@ +module.exports = { + root: true, + env: { browser: true, es2020: true, node: true }, + globals: { + process: 'readonly', + tf: 'readonly' + }, + extends: [ + 'eslint:recommended', + 'plugin:react/recommended', + 'plugin:react/jsx-runtime', + 'plugin:react-hooks/recommended', + ], + ignorePatterns: ['dist', '.eslintrc.cjs'], + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + ecmaFeatures: { + jsx: true + } + }, + plugins: ['react-refresh'], + rules: { + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + 'react/prop-types': 'off', + 'no-unused-vars': ['error', { argsIgnorePattern: '^_' }], + 'no-console': 'warn', + 'prefer-const': 'error', + 'no-var': 'error', + 'react/jsx-key': 'error', + 'react-hooks/exhaustive-deps': 'warn', + 'react/no-unescaped-entities': 'off', + 'react/display-name': 'off' + }, + settings: { + react: { + version: 'detect', + }, + }, +} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 65cf716..9c67ba4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,40 +2,62 @@ name: Deploy to GitHub Pages on: push: - branches: - - main + branches: [ main ] + pull_request: + branches: [ main ] +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages permissions: contents: read pages: write id-token: write +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + jobs: - build-and-deploy: + # Build job + build: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - + - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '18' - + cache: 'npm' + - name: Install dependencies - run: npm install - - - name: Build + run: npm ci + + - name: Lint code + run: npm run lint + + - name: Build for production run: npm run build - + - name: Setup Pages uses: actions/configure-pages@v5 - + - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: - path: './dist' - + path: ./dist + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + if: github.ref == 'refs/heads/main' + steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 diff --git a/.gitignore b/.gitignore index 3c3629e..5ddd652 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,101 @@ -node_modules +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.local +.env.development.local +.env.test.local +.env.production.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Vite build output +dist +dist-ssr +*.local + +# Rollup build output +build/ + +# Webpack build output +/dist/ + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +# OS generated files +Thumbs.db +.DS_Store? +ehthumbs.db +Icon? + +# Temporary files +tmp/ +temp/ + +# IDE files +*.swp +*.swo +*~ + +# Storybook build outputs +storybook-static diff --git a/index.html b/index.html index ebbf157..4d5df57 100644 --- a/index.html +++ b/index.html @@ -3,10 +3,48 @@
-