Skip to content

devftrejo/CodeFit_AI.js

Repository files navigation

Project - CodeFit_AI.js

Purpose

To serve as ${DarkMode} Devs company online AI bootcamp, as such, it will always be under development.

Only ${DarkMode} Devs company developers are authorized to use this code for the sole purpose of maintaining and updating this project for the benefit of the company - ${DarkMode} Devs.

Built With

Frontend

Backend

NOTE: This can change at any time during the project's growth and development.

Repository Layout

This repo is an npm workspace with two packages:

client/      Vite MPA — vanilla JS ES modules, CodeMirror 6 + marked + DOMPurify + Font Awesome (all bundled from npm)
functions/   Cloud Functions for Firebase (v2, ESM) — the `chat` handler (auth, OpenAI streaming, Firestore persistence) plus the voice endpoints `transcribe`/`speak` (OpenAI STT/TTS). Shared auth + rate-limit guards live in `shared.js`.

Most dependencies hoist to a single root node_modules/, so you install once at the repo root. (A few functions/ deps stay local under functions/node_modules/ because of npm version-resolution rules — that's normal and works both locally and on Firebase deploys.)

Firebase configuration lives at the repo root: firebase.json, .firebaserc, firestore.rules, firestore.indexes.json.

The client ships five pages:

  • / — landing
  • /app.html — the chat + code-sandbox app (gated on sign-in)
  • /about.html — about
  • /contact.html — contact
  • /sign-in.html — sign-in / create-account (Email/Password + Google)

All five share a top-bar nav. The shared <head> and top-bar markup are authored once as Handlebars partials in client/src/partials/ and included into each page via vite-plugin-handlebars (rendered at build time), so they aren't copy-pasted across pages. The chat app additionally has an off-canvas navbar for the Snippets, Curriculum, and AI Roles menus.

The app supports optional turn-based voice chat (speak a question, hear the reply back). Voice is off by default and lives behind a voice-mode toggle: turning it on plays a short spoken greeting that explains how to use the mic, then lets you talk to the AI; with it off, chat stays text-only. The app is also mobile-responsive: the top bar and marketing pages adapt at a 1024px breakpoint, and under 1024px the app becomes a chat-only tutor (the CodeMirror editor is desktop-only and isn't even loaded on phones).

Getting Started

Prerequisites

Make sure a current Node.js LTS and npm are available:

node -v
npm -v

If either is missing or out of date, install or update Node from nodejs.org.

Initial Setup

  1. Clone the repository:

    git clone "repository-url"

    (replace "repository-url" with the actual URL).

  2. Install dependencies from the repo root — one command installs both packages:

    npm install
  3. Add your environment files:

    • functions/.secret.localrequired for local chat. Holds OPENAI_API_KEY=sk-... for the Functions emulator (gitignored). The deployed function reads the key from Secret Manager instead.

      OPENAI_API_KEY=sk-...
      
    • client/.env — optional. VITE_API_URL overrides the chat endpoint; not needed for normal dev (defaults to /api/chat → emulator) or prod (set in client/.env.production). See client/.env.example.

  4. Firebase setup (the Firebase CLI runs the emulators for local dev and performs deploys):

    • Install the Firebase CLI globally:

      npm install -g firebase-tools
    • Authenticate with the Google account that has access to the project:

      firebase login
    • Verify the project alias resolves (should print codefit-ai-js):

      firebase use
    • For deployed Cloud Functions, the OpenAI key is stored as a Secret Manager secret (the deployed analog of functions/.secret.local):

      firebase functions:secrets:set OPENAI_API_KEY

      ⚠️ On Windows, don't pipe the value through PowerShell stdin — it injects a UTF-8 BOM that corrupts the key (the OpenAI call then 500s). Paste it when prompted, or use --data-file <ascii-file>.

    • Plan requirement: Cloud Functions calling external APIs (like OpenAI) requires the project to be on the Blaze (pay-as-you-go) plan. Spark/free tier covers Hosting and basic Firestore but not the chat function. Upgrade before the first deploy.

Day-to-Day Development

Always pull before starting work:

git pull

Start the Vite client (port 8080) and the Firebase emulators — Functions (5001), Auth (9099), Firestore (8085) — with a single command from the repo root. The Firestore emulator needs a JDK installed.

npm run dev

To run only one piece:

npm run dev -w client      # Vite client only
npm run emulators          # Firebase emulator suite only

Testing

Tests run on Vitest from the repo root:

npm test          # run the suite once
npm run test:watch  # watch mode

Tests are colocated as *.test.js next to the code they cover, and run in Node (no browser/jsdom) with Firebase and OpenAI stubbed, so no emulators or API key are needed. The current suite is a focused hardening layer — the topic-scoped prompt builder, the per-user rate-limit cost guard, the App Check + auth request gate, and the client's streaming/error-mapping — not full end-to-end coverage.

Formatting, Linting & Code Health

Prettier, ESLint, knip, and jscpd are wired up at the repo root. Run before committing:

npm run format         # write formatting changes
npm run format:check   # check without writing
npm run lint           # ESLint (incl. duplicate/dead-code rules) over client/ and functions/
npm run knip           # report unused files, exports, and dependencies
npm run jscpd          # report copy-pasted code blocks across JS/CSS/HTML

ESLint (with eslint-plugin-sonarjs), knip, and jscpd together catch dead/unused and duplicated code. The latter three are report-only — they surface findings but don't fail the build.

Production Build & Preview

npm run build     # builds client/ to client/dist/
npm run preview   # serves the built client locally

Firebase Deploy

The app is live at https://codefit-ai-js.web.app. One command builds the client and deploys Hosting + Functions + Firestore rules:

npm run firebase:deploy

One-time setup before the first deploy (Firebase / Cloud console):

  • Project on the Blaze plan (Cloud Functions requirement).
  • OpenAI secret set: firebase functions:secrets:set OPENAI_API_KEY (mind the Windows BOM caveat above). The key's account must be on an OpenAI usage tier that supports the configured models — gpt-5.4-mini for chat (needs Tier 1+; the Free tier can't call it) plus the gpt-4o-mini audio models for voice.
  • If a function URL returns a Google 403 after deploying, enable Cloud Run → Allow unauthenticated invocations for each function the client calls directly (chat, transcribe, speak) — auth is still enforced in-function via the Firebase token.
  • Email/Password + Google enabled under Authentication → Sign-in method.
  • App Check (reCAPTCHA v3) registered under Project settings → App Check, and the generated site key pasted into RECAPTCHA_SITE_KEY in client/src/js/firebase.js (public, safe to commit) before building/deploying. The functions verify an App Check token in prod, so the client must send one — deploy the client (with the key) and the functions together. App Check is enforced in prod only; local dev (emulators) skips it.

Prod streaming note: the production client calls the Cloud Function directly (via VITE_API_URL in client/.env.production), not the /api/chat Hosting rewrite, because Hosting buffers Server-Sent Events. The function sets restricted CORS + no-transform so the stream isn't gzip-buffered by Google's frontend.

Pushing changes: use your preferred Git workflow (VSCode UI or CLI).

Usage Instructions

This repository contains proprietary code belonging to ${DarkMode} Devs. Access is limited to the company's full-stack engineers, who are authorized to further develop the project in alignment with the company's interests.

Author

Fernando Trejo / DevFTrejo / NaNTheProgrammer

License

No License - see License tab for details.

Useful Links

Choose A License

Markdown

Badges

Authors/Contributors and Acknowledgements

${DarkMode} Devs and its team of full-stack software engineers have developed this project. External acknowledgements - N/A.

Project Status

Active and Under Development.

Contact Information

For any questions, or for more information, please reach out via our company's Gmail or Discord server.

Dev Jokes - Because, why not?!

Jokes Card

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors