Skip to content

Chamath-Adithya/Dayora-Audit-Man-Day-Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧮 Dayora - Audit Man-Day Calculator

Professional audit planning made simple
Calculate audit man-days instantly based on international standards (IAF MD 5:2019 and ISO/TS 22003:2022)

Audit Calculator TypeScript Tailwind CSS PostgreSQL Prisma License DOI

A modern, professional web application designed for certification professionals to streamline audit planning and resource allocation. Calculate audit man-days with precision using internationally recognized standards with proper database backend and accurate calculation methodology.

🚀 Quick Start

Prerequisites

  • Node.js 18+
  • PostgreSQL database (or use Supabase/Neon for free tier)

Installation

  1. Clone the repository

    git clone <repository-url>
    cd React-audit-man-day-calculator
  2. Install dependencies

    npm install
  3. Set up environment variables

    cp .env.example .env
    # Edit .env with your database URL and secrets
  4. Set up database

    # Generate Prisma client
    npm run db:generate
    
    # Push schema to database
    npm run db:push
    
    # Seed with default configuration
    npm run db:seed
  5. Start the development server

    npm run dev
  6. Open your browser Navigate to http://localhost:3000

✨ Features

🎯 Core Functionality

  • ✅ Accurate Calculations: Fixed calculation logic based on proper IAF MD 5:2019 standards
  • 🗄️ Database Backend: PostgreSQL with Prisma ORM for reliable data persistence
  • 📊 Multiple Standards: Support for QMS, EMS, EnMS, FSMS, and Cosmetics GMP
  • 🔍 Audit Types: Initial certification, surveillance, and recertification audits
  • 📈 Detailed Reports: Comprehensive calculation breakdowns with stage distribution
  • 📚 History Tracking: Searchable calculation history with proper data persistence
  • ⚙️ Admin Configuration: Customizable calculation parameters with database storage
  • 🔒 Audit Logging: Complete audit trail of all actions
  • 📤 Export Functionality: CSV export with filtering options
  • 🌐 Production Ready: Deployed on Vercel with proper environment configuration
  • 🔐 Authentication: Secure user authentication with NextAuth.js
  • 🌓 Theme Support: Beautiful light/dark mode with system preference detection

🎨 User Experience

  • 🌓 Light/Dark Mode: Elegant theme switching with persistence
  • 📱 Responsive Design: Works seamlessly on desktop, tablet, and mobile
  • ⚡ Real-Time Calculations: Instant results with detailed breakdowns
  • 🔍 Smart Search & Filtering: Find calculations quickly
  • 📊 Statistics Dashboard: Overview of calculation history and metrics

💾 Data Management

  • 📈 Calculation History: Save, view, and manage all calculations
  • 📁 Export Functionality: Download history as CSV files
  • 🔄 Auto-Save: Persistent storage with backend API
  • 📋 Detailed Reports: Comprehensive calculation breakdowns
  • 🗑️ Soft Delete: Archive calculations without permanent deletion
  • 🔍 Advanced Filtering: Filter by standard, audit type, date range

🏗️ Technical Features

  • 🔌 REST API: Complete backend with CRUD operations
  • 🎯 Type Safety: Full TypeScript implementation
  • ⚡ Performance: Optimized for speed and reliability
  • 🛡️ Error Handling: Graceful fallbacks and user feedback
  • 🔒 Data Validation: Zod schemas for type-safe validation
  • 🔐 Middleware Protection: Route-level authentication
  • 📊 Database Optimization: Efficient queries with Prisma

🛠️ Technology Stack

Frontend

Backend

  • Next.js API Routes - Serverless API endpoints
  • PostgreSQL - Reliable database with Prisma ORM
  • Prisma - Type-safe database access
  • Zod - Schema validation
  • TypeScript - End-to-end type safety

Development

  • ESLint - Code linting
  • PostCSS - CSS processing
  • Vercel Analytics - Performance monitoring
  • Prisma Studio - Database management UI

📖 Usage Guide

Creating a New Calculation

  1. Navigate to "New Calculation" in the sidebar

  2. Fill in Client Details:

    • Company name
    • Scope/Industry sector
  3. Configure Audit Parameters:

    • Select management system standard (QMS, EMS, EnMS, FSMS, Cosmetics)
    • Choose audit type (Initial, Surveillance, Recertification)
    • Pick appropriate category (AI, AII, BI, etc.)
  4. Enter Organization Details:

    • Number of employees
    • Number of sites
    • Risk/complexity level
    • HACCP studies (for FSMS only)
    • Integrated standards (optional)
  5. Calculate & Save: Get instant results with detailed breakdowns

Managing History

  • View All Calculations: Access complete history in the History section
  • Search & Filter: Find specific calculations by company, standard, or audit type
  • Export Data: Download filtered results as CSV
  • Detailed View: Click to see full calculation details
  • Archive/Restore: Soft delete calculations for better organization

🗂️ Project Structure

audit-calculator/
├── app/                          # Next.js App Router
│   ├── api/                      # API routes
│   │   ├── calculations/         # Calculation CRUD operations
│   │   ├── export/              # CSV export endpoint
│   │   └── stats/               # Statistics endpoint
│   ├── calculate/               # Calculation form page
│   ├── history/                 # History management page
│   ├── results/                 # Results display page
│   ├── admin/                   # Admin configuration page
│   ├── auth/                    # Authentication pages
│   ├── dashboard/               # Analytics dashboard
│   ├── globals.css              # Global styles
│   ├── layout.tsx               # Root layout
│   └── page.tsx                 # Home page
├── components/                   # React components
│   ├── ui/                      # Reusable UI components
│   ├── dashboard/               # Dashboard-specific components
│   ├── calculation-form-fixed.tsx # Fixed calculation form
│   ├── results-display.tsx      # Results presentation
│   ├── history-management.tsx   # History interface
│   ├── theme-provider.tsx       # Theme context
│   ├── theme-toggle.tsx         # Theme switch button
│   ├── sidebar-nav.tsx          # Navigation sidebar
│   ├── providers.tsx            # Context providers wrapper
│   └── main-layout.tsx          # Page layout wrapper
├── lib/                         # Utility libraries
│   ├── api-client.ts            # Backend API client
│   ├── audit-calculator-fixed.ts # Fixed calculation engine
│   ├── storage-db.ts            # Database storage layer
│   ├── database.ts              # Prisma client
│   ├── config.ts                # Configuration management
│   └── utils.ts                 # Helper functions
├── prisma/                      # Database schema and migrations
│   ├── schema.prisma            # Database schema
│   └── seed.ts                  # Database seeding
├── middleware.ts                # Next.js middleware for auth
├── public/                      # Static assets
└── styles/                      # Additional styles

🔌 API Reference

Calculations

Method Endpoint Description
GET /api/calculations Get all calculations
POST /api/calculations Save new calculation
GET /api/calculations/[id] Get specific calculation
PUT /api/calculations/[id] Update calculation
DELETE /api/calculations/[id] Delete calculation
DELETE /api/calculations Clear all calculations

Authentication

Method Endpoint Description
POST /api/auth/signin Sign in user
POST /api/auth/signout Sign out user
GET /api/auth/session Get current session

Statistics

Method Endpoint Description
GET /api/stats Get calculation statistics

Export

Method Endpoint Description
POST /api/export Export calculations as CSV

🎯 Supported Standards & Categories

Management Systems

  • QMS - Quality Management System (ISO 9001)
  • EMS - Environmental Management System (ISO 14001)
  • EnMS - Energy Management System (ISO 50001)
  • FSMS - Food Safety Management System (ISO 22000)
  • Cosmetics - Good Manufacturing Practice

Calculation Factors

  • Base Man-Days: IAF MD 5:2019 compliant base values
  • Employee Adjustments: Based on organization size
  • Risk Multipliers: Low (0.8x), Medium (1.0x), High (1.2x)
  • Multi-Site: Additional man-days for multiple locations
  • HACCP Studies: FSMS-specific adjustments
  • Integrated Systems: Reduction for multiple standards

Audit Types

  • Initial Certification: Stage 1 (30%) + Stage 2 (70%)
  • Surveillance: 33% of initial audit man-days
  • Recertification: 67% of initial audit man-days

🚀 Deployment

See DEPLOYMENT.md for detailed deployment instructions.

Quick Vercel Deployment

  1. Connect your GitHub repo to Vercel
  2. Set environment variables:
    • DATABASE_URL: Your PostgreSQL connection string
    • NEXTAUTH_SECRET: Random secret key
    • NEXTAUTH_URL: Your Vercel app URL
  3. Deploy and run database setup
  4. Run migrations: npm run db:deploy
  5. Seed database: npm run db:seed

🛠️ Development

Available Scripts

# Database operations
npm run db:generate    # Generate Prisma client
npm run db:push        # Push schema to database
npm run db:migrate     # Create and run migrations
npm run db:deploy      # Deploy migrations to production
npm run db:studio      # Open Prisma Studio
npm run db:seed        # Seed database with default data
npm run db:reset       # Reset database (development only)

# Development
npm run dev           # Start development server
npm run build         # Build for production
npm run start         # Start production server
npm run lint          # Run ESLint

Environment Variables

Create a .env file:

# Database
DATABASE_URL="postgresql://username:password@localhost:5432/audit_calculator"

# NextAuth.js
NEXTAUTH_SECRET="your-secret-key-here"
NEXTAUTH_URL="http://localhost:3000"

# Optional: Analytics
NEXT_PUBLIC_VERCEL_ANALYTICS_ID=your_analytics_id

📊 Calculation Methodology

The calculator implements the following international standards:

  • IAF MD 5:2019: International Accreditation Forum Mandatory Document
  • ISO/TS 22003:2022: Requirements for bodies providing audit and certification

Key Calculation Factors

  1. Base Man-Days: Determined by organization category (IAF MD 5:2019 compliant)
  2. Employee Adjustments: Scaling based on workforce size
  3. Multi-Site Factors: Additional time for multiple locations
  4. Risk Multipliers: Complexity adjustments (Low: 0.8x, Medium: 1.0x, High: 1.2x)
  5. Integrated System Efficiency: Reduction for multiple standards (10% savings per standard)
  6. Stage Distribution: 30% Stage 1, 70% Stage 2 (for initial audits)
  7. HACCP Studies: FSMS-specific adjustments (0.5 man-days per study)

🔒 Security & Privacy

  • Data Validation: Zod schemas for input validation
  • Audit Logging: Complete trail of all actions
  • Database Security: Proper connection handling and SSL
  • API Security: Input sanitization and error handling
  • No External Tracking: Privacy-focused implementation

🐛 Troubleshooting

Common Issues

  1. Database Connection: Verify DATABASE_URL and SSL settings
  2. Build Failures: Ensure Prisma client is generated
  3. Calculation Errors: Check input validation and standards

Getting Help

  1. Migration Issues: Run npm run db:reset in development
  • Review Vercel function logs
  • Verify database connectivity and schema
  • Use npm run db:studio to inspect database

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Support

  • Documentation: Check this README and DEPLOYMENT.md
  • Issues: Report bugs via GitHub Issues
  • Community: Join discussions in GitHub Discussions

🎯 Roadmap

  • ✅ Fixed calculation methodology
  • ✅ Database backend with Prisma
  • ✅ Proper data validation
  • ✅ Audit logging
  • ✅ Production deployment
  • ✅ User authentication system
  • ✅ Theme system with persistence
  • ✅ Advanced filtering and search
  • PDF report generation
  • Multi-language support
  • Advanced analytics dashboard
  • API rate limiting
  • Email notifications
  • Bulk import/export
  • Custom branding options

Built with ❤️ for certification professionals worldwide

Streamline your audit planning process with precision and confidence.