CoolFace
Apppublic

Tetteh-Apotey/Electrical-Proposal-Generator

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
App README

โšก AS/NZS 3000 Electrical Compliance & Estimating Platform

![CI/CD Pipeline](https://github.com/life2allsofts/Electrical-Proposal-Generator/actions/workflows/ci-cd.yml) ![Deployed on HF Spaces](https://huggingface.co/spaces/tetteh-apotey/Electrical-Proposal-Generator)

Live Demo: https://tetteh-apotey-Electrical-Proposal-Generator.hf.space/

๐Ÿ“‹ Overview

An advanced full-stack platform designed for senior Australian electrical engineers and registered contractors to draft, manage, refine, and export professional compliance-checked electrical engineering proposals.

The application streamlines form-driven capture of site variables, models core workscopes (such as Switchboard Upgrades, EV Charger installations, and Lighting Retrofits), verifies compliance with Australian Wiring Rules (AS/NZS 3000:2018), orchestrates prompt templates via an AI backend, tracks full local document iteration through Revision History, and exports blueprints to PDF and MS Word formats.


๐Ÿ—๏ธ Architecture Diagrams

System Architecture Flow

Below is the request-response and data orchestration lifecycle within the application:

mermaid
graph TD
    A[Contractor / Engineer] -->|HTTPS Requests| B[Express Server: Port 3000]
    B --> C[Full-Stack Node.js Server]

    subgraph Frontend [React SPA Client]
        D[App.tsx] --> E[Multi-Step Compliance Form]
        D --> F[Dashboard & Document Editor]
        D --> G[Theme & Config Controls]
    end

    subgraph Backend [Node.js / Express Server]
        C -->|Serves Static UI Assets| Frontend
        C -->|Proposals API /api/proposals| H[(proposals_db.json)]
        C -->|Auth API /api/auth| H
        C -->|Generate API /api/generate| I[Gemini API Client]
    end

    I -->|System Prompts & Workscopes| J[Google Gemini LLM]
    J -->|Structured Markdown Proposal| C
    C -->|PDF/Word Export| A

Data Flow: Proposal Generation

mermaid
sequenceDiagram
    participant U as User
    participant F as React Frontend
    participant E as Express Server
    participant G as Gemini API
    participant D as proposals_db.json

    U->>F: Fill 5-step form
    F->>E: POST /api/generate (form data)
    E->>G: Send prompt + examples
    G-->>E: Return Markdown proposal
    E->>D: Save proposal to database
    E-->>F: Return proposal + ID
    F-->>U: Display proposal preview
    U->>F: Click Export PDF/Word
    F->>E: GET /api/export/:id
    E->>D: Retrieve proposal
    E-->>F: Return generated file
    F-->>U: Download document

๐Ÿ“ Project Directory Structure

The workspace is a single-command full-stack application. It uses a modular Vite + React client inside /src, and an orchestrating Node.js Express server at server.ts that serves as a secure API gateway for Gemini AI integration and local state management.

text
โ”œโ”€โ”€ .env.example                # Sample environment configuration
โ”œโ”€โ”€ .gitignore                  # Untracked build artifacts
โ”œโ”€โ”€ index.html                  # HTML shell for React
โ”œโ”€โ”€ metadata.json               # Platform configuration metadata
โ”œโ”€โ”€ package.json                # Dependency manifest & scripts
โ”œโ”€โ”€ proposals_db.json           # JSON database (users + proposals)
โ”œโ”€โ”€ server.ts                   # Express backend & API gateway
โ”œโ”€โ”€ tsconfig.json               # TypeScript configuration
โ”œโ”€โ”€ vite.config.ts              # Vite bundler configuration
โ”‚
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ prompts.json            # Editable AI prompt templates
โ”‚
โ”œโ”€โ”€ assets/                     # Images and static resources
โ”‚
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ main.tsx                # React bootstrap
    โ”œโ”€โ”€ index.css               # Global Tailwind styles
    โ”œโ”€โ”€ index.tsx               # React DOM render
    โ”œโ”€โ”€ types.ts                # TypeScript interfaces
    โ”œโ”€โ”€ App.tsx                 # Main React application
    โ”‚
    โ””โ”€โ”€ components/
        โ”œโ”€โ”€ Login.tsx           # Authentication (register/sign-in)
        โ”œโ”€โ”€ ThemeToggle.tsx     # 4-color theme switcher
        โ”‚
        โ”œโ”€โ”€ MultiStepForm/
        โ”‚   โ”œโ”€โ”€ Step1_JobDetails.tsx
        โ”‚   โ”œโ”€โ”€ Step2_Materials.tsx
        โ”‚   โ”œโ”€โ”€ Step3_Labour.tsx
        โ”‚   โ”œโ”€โ”€ Step4_SiteConditions.tsx
        โ”‚   โ””โ”€โ”€ Step5_Review.tsx
        โ”‚
        โ””โ”€โ”€ Dashboard/
            โ”œโ”€โ”€ ProposalList.tsx
            โ””โ”€โ”€ ProposalEditor.tsx

๐Ÿ“ File Responsibility Dictionary

Root Configuration

FilePurpose
server.tsMain Express server. Handles user auth, proposal CRUD, Gemini API proxy, PDF/Word export, and serves static frontend files.
package.jsonDependencies: @google/genai, express, lucide-react, motion, plus build scripts for Vite + esbuild.
proposals_db.jsonLightweight JSON storage for user accounts and saved proposals. Persists across restarts.
vite.config.tsBundler configuration for React + TypeScript with HMR.

Frontend Application Layer

FilePurpose
src/types.tsGlobal TypeScript interfaces: Proposal, Revision, FormData, UserSession.
src/App.tsxMain state manager: tab navigation, form data buffer, authentication state, API coordination.
src/index.cssTailwind + 4 custom themes (Ambient Slate, Cyber Neon, Electric Volt, Monochrome).

React Components

ComponentPurpose
Login.tsxRegistration and sign-in forms. Stores JWT in localStorage.
ThemeToggle.tsxCycles through 4 color themes. Persists preference.
MultiStepForm/Five-step questionnaire: Job Details โ†’ Materials โ†’ Labour โ†’ Site Conditions โ†’ Review.
Dashboard/ProposalList.tsxDisplays saved proposals with search, filter, and duplicate actions.
Dashboard/ProposalEditor.tsxDual-view editor (Markdown preview / raw text) with Revision History panel and checkpoint system.

๐Ÿ› ๏ธ Setup Guide

1. Prerequisites

  • โ€”Node.js (v18.x or higher)
  • โ€”npm (v9.x or higher)

2. Environment Setup

Create a .env file at the project root:

bash
cp .env.example .env

Edit .env with your Gemini API key (the app works without it using a mock fallback):

env
GEMINI_API_KEY=your_google_gemini_api_key_here
PORT=3000
Get a free Gemini API key: Google AI Studio

3. Install Dependencies

bash
npm install

๐Ÿš€ Running the Platform

Development Mode (with Hot Reload)

bash
npm run dev

Open: http://localhost:3000

Production Mode

bash
npm run build
npm run start

The app runs on port 3000 (or your PORT environment variable).


๐Ÿง‘โ€๐Ÿ’ป How to Use the Platform

Step 1: Register & Login

  1. 1.Open http://localhost:3000
  2. 2.Click "Register a new account"
  3. 3.Enter email and password (e.g., contractor@firm.com.au / password123)
  4. 4.Click "Register Account"
  5. 5.Log in with your new credentials

Step 2: Create a Proposal

  1. 1.Go to the Compliance Form tab
  2. 2.Complete all 5 steps:
  3. 3.Step 1: Client name, site address, contact details
  4. 4.Step 2: Job category, materials, compliance notes
  5. 5.Step 3: Crew size, hours, hourly rate
  6. 6.Step 4: Access requirements, power shutdown needs, safety notes
  7. 7.Step 5: Review all inputs
  8. 8.Click "Draft Proposal with Gemini"
  9. 9.Wait 5โ€“10 seconds for AI generation

Step 3: Manage Proposals

  1. 1.Go to the Dashboard tab
  2. 2.Click "Inspect / Edit" on any proposal
  3. 3.Toggle between Document Preview and Raw Edit modes
  4. 4.Click Export PDF or Export Word to download

Step 4: Revision History

  1. 1.In the Proposal Editor, click the Revision History button (clock icon)
  2. 2.Click "Save Current Snapshot Checkpoint" to save a version
  3. 3.Click any checkpoint to preview
  4. 4.Click "Revert to This Version" to restore

Step 5: Change Theme

Click the Theme Toggle button in the header to cycle through:

ThemeDescription
Ambient SlateDefault โ€” clean white with blue accents
Cyber NeonDark mode with vibrant cyan highlights
Electric VoltHigh contrast blue + amber (brand colors)
MonochromeBlack and white (accessibility focused)

๐Ÿ”ง Configuration (No Coding Required)

Edit these JSON files to customize the app without touching code:

FileWhat it controls
config/prompts.jsonAI system prompt, tone, AS/NZS 3000 references, output format
config/questions.jsonForm field labels, order, validation rules

After editing, restart the server or click "Reload Config" in the admin panel.


๐Ÿ› Troubleshooting

IssueSolution
Blank screen after clicking "Draft Proposal"Open browser console (F12) and check for errors. Verify Gemini API key or mock fallback.
"Failed to fetch" errorEnsure backend is running: npm run dev and check terminal for errors.
PDF export shows only titleCheck that proposal has content. Try editing and saving again.
Login doesn't workDelete proposals_db.json and restart. New file will be created.
Port 3000 already in useChange PORT in .env to 3001 or 8080.

๐Ÿš€ Deployment to Hugging Face Spaces

Option 1: One-Click Deploy (Coming Soon)

Option 2: Manual Deploy with Docker

Create a Dockerfile at the project root:

dockerfile
FROM node:18-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
EXPOSE 7860
ENV PORT=7860
CMD ["npm", "run", "start"]

Create space/README.md:

markdown
---
title: Electrical Proposal Generator
emoji: โšก
colorFrom: blue
colorTo: yellow
sdk: docker
app_port: 7860
---

Push to Hugging Face Spaces:

bash
git remote add space https://huggingface.co/spaces/your-username/electrical-proposal-generator
git push space main

Option 3: GitHub Actions CI/CD

Create .github/workflows/deploy.yml:

yaml
name: Deploy to Hugging Face Spaces

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to HF Spaces
        uses: huggingface/actions/space-deploy@v1
        with:
          space: your-username/electrical-proposal-generator
          token: ${{ secrets.HF_ACCESS_TOKEN }}

๐Ÿ“„ License

MIT โ€” Free for use by Australian electrical contractors.


๐Ÿ™‹ Support

For questions or feature requests, contact the developer via GitHub Issues.


Built with โšก for Australian electrical contractors. Compliant with AS/NZS 3000:2018.