Skip to content

Codebase cleanup: deduplicate, remove dead code, fix structure#97

Merged
nv78 merged 2 commits intomainfrom
codebase-cleanup
Mar 24, 2026
Merged

Codebase cleanup: deduplicate, remove dead code, fix structure#97
nv78 merged 2 commits intomainfrom
codebase-cleanup

Conversation

@nv78
Copy link
Member

@nv78 nv78 commented Mar 24, 2026

Summary

Language endpoints (~500 lines → thin wrappers)

  • Extracted shared extract_text_from_file() and all chat handler logic into a single language_chat.py with a make_language_blueprint() factory
  • Each language file (arabic, spanish, chinese, japanese, korean, gtm) is now a one-liner that passes its model ID, system prompt, and language-specific strings to the factory
  • Eliminates ~500 lines of copy-paste code

financeGPT/chatbot_endpoints.py

  • Removed 18 pass-through wrapper functions (e.g. add_message_to_db, retrieve_chats_from_db) that did nothing but delegate to database.db
  • Replaced with direct re-export aliases — same public API, zero redundant code
  • Removed unused service function re-assignments that were never consumed within the module

Dead code removed from app.py

  • /process-message-pdf-demo, /ingest-pdf-demo, /download-chat-history-demo endpoints and their global state
  • Commented-out /reset-chat-demo block
  • /temp-test development endpoint
  • Stale TODO: COMMENT OUT WHEN DEPLOY TO PROD comment

Package structure

  • Added missing __init__.py to 13 backend packages so they are importable as proper Python packages

Docker

  • backend/Dockerfile: combined two separate apt-get RUN layers into one (fewer image layers, faster builds), removed redundant separate pip install tokenizers anthropic step, upgraded to python:3.12-slim
  • frontend/Dockerfile: removed npm install --force (no longer needed), upgraded to node:22-alpine

Redux

  • Removed unused lastFetchTime state and selectLastFetchTime selector from ChatSlice

Test plan

  • docker compose up --build succeeds with new Dockerfiles
  • All 5 language chat endpoints respond correctly (/api/chat/arabic, /api/chat/spanish, etc.)
  • CI passes: Ruff lint, MyPy, pytest (≥92% coverage), frontend build

🤖 Generated with Claude Code

nv78 and others added 2 commits March 23, 2026 22:04
Language endpoints:
- Extract shared extract_text_from_file() and chat handler logic into
  language_chat.py; reduce 5 near-identical files (~500 lines) to thin
  one-liners via make_language_blueprint() factory
- Apply same pattern to gtm.py

financeGPT/chatbot_endpoints.py:
- Remove 18 pass-through wrapper functions (e.g. add_message_to_db,
  retrieve_chats_from_db) and replace with direct re-export aliases
- Remove redundant service function re-assignments that were never
  used within the module

backend/app.py:
- Remove demo-only endpoints: /process-message-pdf-demo,
  /ingest-pdf-demo, /download-chat-history-demo and their global state
- Remove commented-out /reset-chat-demo block
- Remove /temp-test development endpoint
- Remove stale TODO comment

Package structure:
- Add missing __init__.py to 13 backend packages so they are
  importable as proper Python packages

Docker:
- backend/Dockerfile: combine two apt-get RUN layers into one,
  remove redundant separate tokenizers/anthropic pip install
  (already covered by requirements.txt), upgrade to python:3.12-slim
- frontend/Dockerfile: remove npm install --force (no longer needed),
  upgrade to node:22-alpine

Redux:
- Remove unused lastFetchTime state and selectLastFetchTime selector
  from ChatSlice

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Deletes test_demo_routes_work, test_demo_download_route_error_branch,
and the /temp-test assertion from test_add_model_key_and_temp_test
(renamed to test_add_model_key) since those endpoints were removed
in the codebase cleanup commit.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@nv78 nv78 merged commit 706b849 into main Mar 24, 2026
5 checks passed
@nv78 nv78 deleted the codebase-cleanup branch March 24, 2026 02:22
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.

1 participant