Skip to content

amitlyzr/policy-generation-app-os

Repository files navigation

Lyzr Logo

HR Policy Generation Agent

AI-powered platform for creating, managing, and maintaining compliant HR policies

Next.js TypeScript Lyzr AI License

DemoDocumentationReport Bug


Overview

The HR Policy Generation Agent is an intelligent platform that leverages AI to streamline the creation, updating, and management of HR policies for organizations. Built with Next.js and powered by Lyzr AI agents, it provides an intuitive interface for generating compliant, country-specific HR policies through conversational AI.

Key Features

  • AI-Powered Policy Generation - Create comprehensive HR policies through natural conversation with specialized AI agents
  • Multi-Country Compliance - Generate policies compliant with regulations across multiple jurisdictions (US, Canada, UK, Germany, France, India, Australia)
  • Intelligent Policy Updates - Update existing policies with AI-assisted compliance checking and version control
  • PDF Upload & Analysis - Upload existing policy documents for analysis, parsing, and conversion to editable format
  • Policy Database - Centralized repository for storing, viewing, and managing all organizational policies
  • Real-time Research - Integrated Perplexity AI agent for up-to-date legal and compliance research
  • Rich Text Editing - Professional editor with formatting, highlighting, and markdown support
  • Version Control - Track policy changes with versioning and status management (Draft, In Review, Approved, Published, Archived)
  • Dark Mode Support - Comfortable viewing experience with theme toggling

Architecture

The application is built using a modern stack with AI agents at its core:

┌─────────────────────────────────────────────────────────────┐
│                      Next.js Frontend                        │
│  (React 19, TypeScript, Tailwind CSS, shadcn/ui)           │
└───────────────────┬─────────────────────────────────────────┘
                    │
┌───────────────────┴─────────────────────────────────────────┐
│                   API Routes Layer                           │
│  (/api/chat, /api/policies, /api/upload-pdf, etc.)         │
└───────────────────┬─────────────────────────────────────────┘
                    │
        ┌───────────┴───────────┐
        │                       │
┌───────┴────────┐     ┌────────┴─────────┐
│   Lyzr AI      │     │    MongoDB        │
│   Agents       │     │    (Prisma)       │
│                │     │                   │
│ • Chat Agent   │     │ • Users           │
│ • Perplexity   │     │ • Policies        │
│ • Compliance   │     │ • Sessions        │
│ • Law Updates  │     └───────────────────┘
└────────────────┘

Getting Started

Prerequisites

  • Node.js 18+
  • npm, yarn, pnpm, or bun
  • MongoDB database
  • Lyzr AI API key (Get one here)

Installation

  1. Clone the repository
git clone https://github.com/amitlyzr/policy-generation-app.git
cd policy-generation-app
  1. Install dependencies
npm install
# or
yarn install
# or
pnpm install
  1. Set up environment variables

Create a .env.local file in the root directory:

# Database
DATABASE_URL="your_mongodb_connection_string"

# Lyzr AI Configuration
LYZR_API_KEY="your_lyzr_api_key"

# Agent IDs (obtain from Lyzr dashboard)
NEXT_PUBLIC_CHAT_AGENT_ID="your_chat_agent_id"
NEXT_PUBLIC_PERPLEXITY_AGENT_ID="your_perplexity_agent_id"
NEXT_PUBLIC_COMPLIANCE_AGENT_ID="your_compliance_agent_id"
NEXT_PUBLIC_LAW_AGENT_ID="your_law_agent_id"

Note

You can find a template in .env.example. Copy it and fill in your values.

  1. Set up the database
npx prisma generate
npx prisma db push
  1. Run the development server
npm run dev
# or
yarn dev
# or
pnpm dev

Open http://localhost:3000 to see the application.

Usage

Creating a New Policy

  1. Navigate to Create New Policy from the sidebar
  2. Start a conversation with the AI agent about the policy you need
  3. Specify the policy type (e.g., Remote Work, PTO, Code of Conduct)
  4. Select applicable countries for compliance
  5. Review and refine the generated policy through conversation
  6. Save the policy to your database

Uploading Existing Policies

  1. Go to Upload Policy section
  2. Drag and drop or select a PDF file
  3. Add a policy name and select applicable countries
  4. The system will parse and convert the PDF to editable markdown format
  5. Review and save to your policy database

Updating Policies

  1. Navigate to Compliance Test section
  2. Select a policy from your database
  3. Describe the changes needed or compliance requirements
  4. The AI will analyze and suggest updates
  5. Review changes and save new version

Managing Policy Database

  1. Access Policy Database to view all policies
  2. Filter by status, country, or search by name
  3. View, edit, or archive policies as needed
  4. Track version history and status changes

Technology Stack

Frontend

  • Next.js 15.5 - React framework with App Router
  • React 19 - UI library
  • TypeScript - Type safety
  • Tailwind CSS 4 - Utility-first CSS
  • shadcn/ui - Component library
  • Radix UI - Unstyled accessible components

AI & Processing

  • Lyzr AI SDK - Multi-agent orchestration
  • Tiptap - Rich text editor
  • pdf2md - PDF parsing
  • Marked - Markdown processing
  • Streamdown - Streaming markdown renderer

Backend & Database

  • Prisma - Database ORM
  • MongoDB - Document database
  • Next.js API Routes - Backend API

State Management & Auth

  • Zustand - Lightweight state management
  • Lyzr Auth - Authentication provider
  • js-cookie - Cookie management

Project Structure

policy-generation-agent/
├── prisma/
│   └── schema.prisma           # Database schema
├── public/                     # Static assets
├── src/
│   ├── app/
│   │   ├── api/               # API routes
│   │   │   ├── chat/          # Chat agent endpoint
│   │   │   ├── policies/      # Policy CRUD operations
│   │   │   ├── upload-pdf/    # PDF processing
│   │   │   └── research-policy/ # Research agent endpoint
│   │   ├── create-policy/     # Policy creation page
│   │   ├── update-policy/     # Policy update page
│   │   ├── upload-policy/     # Policy upload page
│   │   ├── policy-db/         # Policy database page
│   │   ├── layout.tsx         # Root layout
│   │   └── page.tsx           # Dashboard
│   ├── components/
│   │   ├── custom/            # Custom components
│   │   │   ├── policy-conversation.tsx
│   │   │   ├── policy-database.tsx
│   │   │   ├── policy-uploader.tsx
│   │   │   └── ...
│   │   ├── providers/         # Context providers
│   │   └── ui/                # Reusable UI components
│   ├── lib/
│   │   ├── lyzr.ts           # Lyzr AI integration
│   │   ├── prisma.ts         # Prisma client
│   │   ├── file-utils.ts     # File processing utilities
│   │   └── utils.ts          # General utilities
│   └── stores/
│       └── policy-store.ts   # Zustand state management
├── .env.example              # Environment variables template
├── package.json
└── README.md

API Documentation

Chat Endpoint

POST /api/chat
{
  "message": "Create a remote work policy",
  "sessionId": "session_xyz",
  "agentId": "chat_agent_id",
  "userId": "user_123"
}

Policy Management

// Get all policies for a user
GET /api/policies?userId=user_123

// Create new policy
POST /api/policies
{
  "name": "Remote Work Policy",
  "content": "...",
  "countries": ["United States", "Canada"],
  "userId": "user_123"
}

// Update policy
PUT /api/policies?policyId=policy_123

// Delete policy
DELETE /api/policies?policyId=policy_123

PDF Upload

POST /api/upload-pdf
Content-Type: multipart/form-data
{
  "file": <PDF file>,
  "userId": "user_123"
}

Configuration

Lyzr AI Agents

The application uses multiple specialized AI agents:

  • Chat Agent - Main conversational interface for policy generation
  • Perplexity Agent - Real-time research for legal and compliance information
  • Compliance Agent - Validates policies against regulatory requirements
  • Law Agent - Provides updates on legal changes and requirements

Configure these agents in the Lyzr dashboard and add their IDs to your environment variables.

Database Schema

model User {
  id        String   @id @default(auto()) @map("_id") @db.ObjectId
  email     String   @unique
  userId    String   @unique
  orgId     String
  policies  Policy[]
}

model Policy {
  id          String       @id @default(auto()) @map("_id") @db.ObjectId
  policyId    String       @unique
  name        String
  content     String
  countries   String[]
  status      PolicyStatus @default(DRAFT)
  version     Int          @default(1)
  userId      String       @db.ObjectId
  user        User         @relation(fields: [userId], references: [id])
}

enum PolicyStatus {
  DRAFT
  IN_REVIEW
  APPROVED
  PUBLISHED
  ARCHIVED
}

Development

Running Tests

npm test

Building for Production

npm run build
npm start

Linting

npm run lint

Deployment

Vercel (Recommended)

The easiest way to deploy is using Vercel:

Deploy with Vercel

  1. Push your code to GitHub
  2. Import project to Vercel
  3. Add environment variables
  4. Deploy

Other Platforms

The application can be deployed to any platform that supports Next.js:

  • AWS Amplify
  • Netlify
  • Railway
  • DigitalOcean App Platform

Ensure environment variables are properly configured in your deployment platform.

Troubleshooting

Common Issues

Database Connection Errors

  • Verify your DATABASE_URL is correctly formatted
  • Ensure MongoDB is accessible from your deployment environment
  • Run npx prisma generate after schema changes

AI Agent Errors

  • Verify your LYZR_API_KEY is valid
  • Check that all agent IDs are correctly configured
  • Ensure you have sufficient credits in your Lyzr account

PDF Upload Issues

  • Check file size (max 10MB by default)
  • Verify PDF is not password-protected
  • Ensure proper file permissions

Support

Acknowledgments


Made with ❤️ by the Lyzr team
Empowering organizations with AI-driven HR policy management

About

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published