Skip to content

Brandon sprint1#20

Open
bdtran2002 wants to merge 11 commits intomainfrom
brandon_sprint1
Open

Brandon sprint1#20
bdtran2002 wants to merge 11 commits intomainfrom
brandon_sprint1

Conversation

@bdtran2002
Copy link
Contributor

@bdtran2002 bdtran2002 commented Mar 9, 2026

We movin fellas we making it out of chico w this one 🔥

READ THE README AND THIS CHANGELOG BEFORE MAKING CHANGES

Major Changes:

  • Docker & Infrastructure Overhaul
    • Migrated backend DB driver to mysqlclient for better compatibility and performance.
    • Improved healthcheck routines and container cleanup.
    • Switched default DB to MariaDB in Docker Compose, ensuring easier cross-platform spins.
  • Backend Improvements
    • Added or improved /api/health/ and /api/classes/ for better diagnostics and flexibility.
    • Bugfixes and improvements in LaTeX compilation and API endpoint stability.
    • Increase robustness in error and exception handling.
    • Keeps database flexible with SQLite fallback; prepares for future DB migrations.
  • Frontend Revamp
    • Modernized several UI elements for improved UX.
    • Refactored CSS: introduced and expanded CSS variable use for color theming (early dark mode), though some hardcoded colors remain and are known issues.
    • Added more robust structure for LaTeX previewing and handling PDF/TeX downloads.
    • Linted and updated NPM dependencies for reliability and security.
  • Updated Documentation
    • Streamlined and clarified the README.
      • "To-Do / Known Issues" and "Planned Features" sections now accurately reflect current work and roadmap (dark mode refactor, compile button issues, database plans, image support, LaTeX shortcut needs, and more).
      • Removed duplicate/obsolete items and categorized features with more actionable bullet points.
    • Clarified development setup and tech stack.

Bugfixes & Known Issues (added in this PR or roadmap)

  • Dark mode: Refactor still needed to fully remove hardcoded colors.
  • Compile button: Can break after certain changes—on the fix roadmap.
  • Database: Migration or replacement planned, especially for production.
  • Image Insertion: Planned—users will insert images, stored in DB, preserved in .tex and .pdf.
  • Custom LaTeX Syntax: Shortcuts and extensibility planned.
  • Formatting: More robust formatting options in future (columns, scaling, margins).

Documentation & Dev-Ex

  • Starter docs improved (API, folder structure, setup, and test instructions).
  • Clarified contributor workflow and major features.

Breaking/Deprecating

  • None, but developers must note switch to MariaDB in Docker Compose and use mysqlclient in backend requirements.
  • Some local environments may require updating or rebuilding containers and virtualenvs for smooth experience.

How to Review

  • Review Main features in README and updated To-Do section for clarity.
  • For infrastructure updates, verify Docker Compose brings up all services for both development and production/test configs.
  • Note planned but not-yet-implemented features at top of README.
  • For DB changes, ensure you test with both MariaDB (Docker) and SQLite (fallback) as needed.

BREAKING CHANGES:
- Rename formula selection to require class + category + formula
- API endpoint /api/generate-sheet/ now accepts formulas array

NEW FEATURES:
- 3-level formula selection: class → category → individual formulas
- Updated UI with class checkboxes and category dropdowns
- Added CRUD API endpoints for templates, cheatsheets, and problems
- Added /api/cheatsheets/from-template/ endpoint
- Added ruff and safety to requirements for linting/security

CLEANUP:
- Removed unused packages: axios, react-router-dom, eslint
- Renamed old formula_loader.py to .old
- Added AGENTS.md and session files to .gitignore
- Simplified CI workflow (removed ESLint step)
- Updated README with current dependencies

DATA:
- Added formula_data/ with 4 classes: PRE-ALGEBRA, ALGEBRA I, ALGEBRA II, GEOMETRY
- Each class organized by category with hardcoded formulas

FIXES:
- All 20 tests now pass
- Compile endpoint supports both content and cheat_sheet_id
- Fixed PDF generation with proper LaTeX template
Deleted ~206 lines of unused CSS classes that were remnants from
the old subject/category/formula tab interface:
- .subjects-container, .subject-tabs, .subject_tab
- .category-tabs, .category_tab, .formula_btn
- .selection_tree, .class_block, .class_header
- .category_list, .formula_list, and related styles

App.css reduced from 447 lines to 241 lines (~45% reduction).
- Update category selection to always-visible checkboxes, remove dropdowns and secondary scrollbars
- Maximize LaTeX and PDF panes, remove width/padding constraints
- Fix all race conditions (useRef locks, fresh LaTeX to compile)
- Button disabling is robust, no overlapping requests
- Add GitHub link to footer
- Update .gitignore for secrets, coverage, PDF/TeX, DB, and temp files
- Revise README and backend logic for new features and stability
Removed architecture diagram from the README.
…eanup frontend config

- backend: switch DB adapter from PyMySQL to mysqlclient for better native compatibility (requirements.txt, Dockerfile, .env.docker, __init__.py)
- docker-compose: add backend healthcheck, cleanup db service port/depends_on config
- frontend: remove unused deps (axios, react-router-dom, ESLint plugins) and trim package-lock.json
- general: remove dead or unneeded config/ports, reflect changes in compose and build scripts

BREAKING: MySQL backend now expects mysqlclient and native driver; PyMySQL removed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR advances the app from a basic cheat sheet editor toward a “cheat sheet generator” workflow by adding backend-driven formula selection, LaTeX generation, PDF compilation support, and a Docker/CI overhaul to support MariaDB + pytest tooling.

Changes:

  • Frontend: replaces hardcoded formula picker with a backend-driven class/category selection UI and adds PDF/TeX download + preview workflow.
  • Backend: adds formula data modules, new /api/classes/ + /api/generate-sheet/ endpoints, plus CRUD models/serializers/endpoints and pytest-based tests.
  • Infra/CI: introduces MariaDB in Compose, switches DB config to DATABASE_URL (dj-database-url), and updates CI to run ruff/safety/pytest.

Reviewed changes

Copilot reviewed 28 out of 31 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
frontend/vite.config.js Updates dev proxy target and binds dev server to 0.0.0.0.
frontend/src/components/CreateCheatSheet.jsx New generator UI: fetch classes, select categories, generate LaTeX, compile/preview, download.
frontend/src/App.jsx Updates app title and adds a GitHub footer link.
frontend/src/App.css Large styling refresh with CSS variables, new selection UI styles, and footer styles.
frontend/package.json Removes ESLint-related dev dependencies.
frontend/package-lock.json Lockfile updates reflecting dependency removals/updates.
docker-compose.yml Adds MariaDB service, wires backend DATABASE_URL, adds backend healthcheck and frontend dependency on healthy backend.
backend/requirements.txt Adds dj-database-url, mysqlclient, pytest tooling, ruff, safety.
backend/pytest.ini Configures pytest-django settings module and test discovery patterns.
backend/conftest.py Adds shared api_client pytest fixture.
backend/cheat_sheet/settings.py Switches DB config to dj_database_url with SQLite fallback; minor env parsing formatting.
backend/api/views.py Adds formula endpoints, LaTeX generation helper, compile enhancements, and CRUD endpoints.
backend/api/urls.py Registers new formula and CRUD routes.
backend/api/tests.py Adds pytest-based model/API tests.
backend/api/serializers.py Implements DRF serializers for new models and compile request validation serializer.
backend/api/models.py Adds Template/CheatSheet/PracticeProblem models and LaTeX assembly logic.
backend/api/migrations/0001_initial.py Initial schema migration for new models.
backend/api/formula_loader.py.old Adds a legacy/unused formula loader (backup-style file).
backend/api/formula_data/init.py Aggregates available classes and formula data helpers.
backend/api/formula_data/pre_algebra.py Adds PRE-ALGEBRA formula definitions.
backend/api/formula_data/algebra_i.py Adds ALGEBRA I formula definitions.
backend/api/formula_data/algebra_ii.py Adds ALGEBRA II formula definitions.
backend/api/formula_data/geometry.py Adds GEOMETRY formula definitions.
backend/api/apps.py Adds API app config.
backend/api/admin.py Adds (commented-out) Django admin registrations.
backend/Dockerfile Installs MySQL build deps and waits for MariaDB before starting Django.
backend/.env.docker Updates docker env defaults and adds DATABASE_URL.
README.md Rewrites docs to match generator workflow, endpoints, and setup guidance.
.gitignore Expands ignores for env/test artifacts and TeX/PDF build outputs.
.github/workflows/ci.yml Updates backend CI to run ruff/safety/pytest and simplifies frontend CI to build-only.
Files not reviewed (1)
  • frontend/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +36 to +46
const toggleClass = (className) => {
setSelectedClasses((prev) => {
const newSelected = { ...prev };
if (newSelected[className]) {
delete newSelected[className];
// Clear categories for this class
Object.keys(selectedCategories).forEach((key) => {
if (key.startsWith(className + ':')) {
delete newSelected[key];
}
});
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toggleClass tries to clear selected categories when a class is unchecked, but it deletes category keys from newSelected (which is the selected-classes map), so category selections are never removed. This also reads selectedCategories from the outer scope inside a state updater, which can be stale. Clear category keys via setSelectedCategories (using its own functional updater) when a class is deselected.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +52 to +63
### Backend Dependencies
- django>=6.0
- djangorestframework>=3.15
- django-cors-headers>=4.4
- python-dotenv>=1.0
- dj-database-url>=2.1
- pymysql>=1.1
- pytest>=8.0
- pytest-django>=4.8
- ruff>=0.4.0 (linting)
- safety>=2.0 (security)

Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README lists pymysql>=1.1 as a backend dependency, but the actual backend dependency in backend/requirements.txt is mysqlclient (and pymysql is not listed). Update the README dependency list to match the real requirements to avoid confusing setup/install instructions.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +40 to +45
<footer className="app-footer">
<a href="https://github.com/ChicoState/cheat-sheet" target="_blank" rel="noopener noreferrer" title="View on GitHub">
<svg height="24" viewBox="0 0 16 16" width="24" fill="currentColor">
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/>
</svg>
</a>
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The footer link is icon-only, so screen readers may not announce a meaningful name. Add an accessible label (e.g., aria-label="View on GitHub") and/or visually-hidden text so the link has a proper accessible name beyond the SVG.

Copilot uses AI. Check for mistakes.
Comment on lines 185 to +189
except subprocess.CalledProcessError as e:
return Response({"error": "Failed to compile LaTeX", "details": e.stderr}, status=400)

return Response(
{"error": "Failed to compile LaTeX", "details": e.stderr},
status=400,
)
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile_latex returns raw Tectonic stderr in the API response (details). This can leak internal paths/environment info and can also produce very large responses on compile failures. Consider logging stderr server-side and returning a shorter, user-friendly error message (optionally gated behind DEBUG).

Copilot uses AI. Check for mistakes.
import react from '@vitejs/plugin-react'

const backendTarget = process.env.BACKEND_URL || 'http://localhost:8000'
const backendTarget = process.env.BACKEND_URL || 'http://backend:8000'
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting BACKEND_URL to http://backend:8000 will break local (non-Docker) development where the Django server runs on localhost:8000 (per README). Consider defaulting to http://localhost:8000 and setting BACKEND_URL=http://backend:8000 in docker-compose for container runs (or otherwise detecting Docker env).

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +10 to +11
# ports: comment out for now we'e not using atm
# - "3306:3306"
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment we'e is a typo and should be we're.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +5 to +9
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: cheatsheet_db
MYSQL_USER: cheatsheet_user
MYSQL_PASSWORD: cheatsheet_pass
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Database credentials are hard-coded directly in docker-compose.yml (including the root password). Even if intended for local dev, this pattern makes it easy to accidentally reuse weak credentials elsewhere and encourages copying secrets into source control. Prefer using a .env file (not committed) or compose variable substitution with documented defaults for local development.

Copilot uses AI. Check for mistakes.
Comment on lines +164 to +177
### Frontend (ESLint)

```bash
cd frontend
npx eslint src/ # Lint source files
npx eslint --fix src/ # Auto-fix lint issues
```

### CI Pipeline

The project includes GitHub Actions CI that runs:
- Backend: Ruff linting, Safety security scan, pytest
- Frontend: ESLint, build verification
- Docker: Image build verification
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README states the CI pipeline and local instructions use ESLint (npx eslint …) and that CI runs ESLint, but the workflow currently only runs npm run build and eslint packages were removed from frontend/package.json. Either re-add/configure ESLint (and a CI lint step) or update the README section to reflect the current tooling.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

Comment on lines +320 to +328
<button
type="button"
onClick={handlePreview}
className="btn compile-circle"
disabled={isCompiling || !content}
title={isCompiling ? 'Compiling...' : 'Compile & Preview'}
>
{isCompiling ? '...' : '↻'}
</button>
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compile/preview button uses only the character as its visible label. For accessibility, add an aria-label (or include visually-hidden text) so screen readers can announce the button purpose.

Copilot uses AI. Check for mistakes.
EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
CMD ["sh", "-c", "until mysqladmin ping -hdb -ucheatsheet_user -pcheatsheet_pass --silent; do sleep 2; done && python manage.py runserver 0.0.0.0:8000"]
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Docker CMD hard-codes DB credentials in the image (mysqladmin ping ... -ucheatsheet_user -pcheatsheet_pass). This leaks credentials into the image history and process list. Prefer reading credentials from environment variables (or relying on DATABASE_URL) when waiting for DB readiness.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

@thejoeyluu thejoeyluu self-assigned this Mar 9, 2026
Copy link
Contributor

Copilot AI commented Mar 9, 2026

@bdtran2002 I've opened a new pull request, #21, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 9, 2026

@bdtran2002 I've opened a new pull request, #22, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 9, 2026

@bdtran2002 I've opened a new pull request, #23, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 9, 2026

@bdtran2002 I've opened a new pull request, #24, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 9, 2026

@bdtran2002 I've opened a new pull request, #25, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 9, 2026

@bdtran2002 I've opened a new pull request, #26, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Mar 9, 2026

@bdtran2002 I've opened a new pull request, #27, to work on those changes. Once the pull request is ready, I'll request review from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants