Skip to content

Nakul-Jaglan/ai-document-frontend

Repository files navigation

Document Portal - AI-Powered Document Analysis

A Next.js application that allows users to upload, manage, and ask questions about PDF documents using AI-powered analysis with the Gemini API.

πŸš€ Features

  • Secure Authentication: JWT-based user authentication and authorization
  • Document Management: Upload, view, and organize PDF, DOC, and DOCX files
  • AI-Powered Q&A: Ask questions about uploaded documents and get intelligent answers
  • Real-time Interaction: Interactive chat interface for document queries
  • Responsive Design: Mobile-friendly interface built with Tailwind CSS
  • Server Status Monitoring: Smart server startup notifications for cold starts

πŸ› οΈ Tech Stack

  • Framework: Next.js 15 with App Router
  • Styling: Tailwind CSS
  • Authentication: JWT tokens with automatic refresh
  • HTTP Client: Axios for API communication
  • UI Components: Custom React components
  • Date Handling: date-fns for date formatting
  • Deployment: Optimized for Vercel deployment

πŸ“‹ Prerequisites

Before running this application, ensure you have:

  • Node.js 18+ installed
  • npm or yarn package manager
  • A backend API server running (Django backend recommended)
  • Gemini API access for document analysis

πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/Nakul-Jaglan/ai-document-frontend.git
cd ai-document-frontend

2. Install Dependencies

npm install
# or
yarn install

3. Environment Configuration

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

NEXT_PUBLIC_API_URL=http://localhost:8000

Replace the API URL with your backend server URL.

4. Run the Development Server

npm run dev
# or
yarn dev

Open http://localhost:3000 in your browser.

5. Build for Production

npm run build
npm start

πŸ“ Project Structure

β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ dashboard/
β”‚   β”‚   └── page.js                 # Main dashboard page
β”‚   β”œβ”€β”€ document/
β”‚   β”‚   └── [id]/
β”‚   β”‚       └── question/
β”‚   β”‚           └── page.js         # Document Q&A page
β”‚   β”œβ”€β”€ login/
β”‚   β”‚   └── page.js                 # Login page
β”‚   β”œβ”€β”€ register/
β”‚   β”‚   └── page.js                 # Registration page
β”‚   β”œβ”€β”€ globals.css                 # Global styles
β”‚   β”œβ”€β”€ layout.js                   # Root layout with AuthProvider
β”‚   └── page.js                     # Home page (redirects)
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ DocumentCard.js             # Document display component
β”‚   β”œβ”€β”€ Navbar.js                   # Navigation component
β”‚   β”œβ”€β”€ PrivateRoute.js             # Route protection
β”‚   β”œβ”€β”€ ProtectedRoute.js           # Alternative route protection
β”‚   └── UploadModal.js              # File upload modal
β”œβ”€β”€ contexts/
β”‚   └── AuthContext.js              # Authentication context
β”œβ”€β”€ lib/
β”‚   └── api.js                      # API client and endpoints
└── public/                         # Static assets

πŸ” Authentication Flow

  1. Registration/Login: Users create accounts or sign in
  2. JWT Tokens: Access and refresh tokens for secure API calls
  3. Automatic Refresh: Seamless token renewal on expiration
  4. Route Protection: Private routes require authentication
  5. Logout: Secure session termination

πŸ“„ Document Management

Supported File Types

  • PDF documents
  • Microsoft Word (.doc, .docx)

Features

  • Drag-and-drop file upload
  • Document metadata management
  • File preview and organization
  • Secure document storage

πŸ€– AI-Powered Q&A

  • Ask natural language questions about document content
  • Get intelligent, context-aware responses
  • Conversation history tracking
  • Real-time answer generation

🎨 UI/UX Features

  • Responsive Design: Works on desktop, tablet, and mobile
  • Loading States: Smooth loading indicators
  • Error Handling: User-friendly error messages
  • Server Status: Cold start notifications with countdown timer
  • Accessibility: Screen reader friendly components

πŸ”§ Configuration

Environment Variables

Variable Description Example
NEXT_PUBLIC_API_URL Backend API base URL http://localhost:8000

API Endpoints

The application expects the following backend endpoints:

  • POST /api/auth/login/ - User authentication
  • POST /api/auth/register/ - User registration
  • POST /api/auth/refresh/ - Token refresh
  • GET /api/documents/ - List user documents
  • POST /api/documents/ - Upload new document
  • GET /api/documents/{id}/ - Get document details
  • DELETE /api/documents/{id}/ - Delete document
  • POST /api/documents/{id}/ask/ - Ask question about document

πŸš€ Deployment

Vercel (Recommended)

  1. Connect your GitHub repository to Vercel
  2. Configure environment variables in Vercel dashboard:
    • Add NEXT_PUBLIC_API_URL with your backend URL
  3. Deploy automatically on push to main branch

Note: The project includes a vercel.json configuration file to ensure proper deployment.

Manual Deployment

npm run build
npm start

πŸ”§ Development

Available Scripts

  • npm run dev - Start development server
  • npm run build - Create production build
  • npm run start - Start production server
  • npm run lint - Run ESLint

Code Style

  • Uses ESLint for code quality
  • Follows Next.js best practices
  • Component-based architecture
  • Tailwind CSS for styling

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ‘¨β€πŸ’» Author

Nakul Jaglan

πŸ™ Acknowledgments


For questions or support, please open an issue on GitHub or contact the author.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published