A Next.js application that provides AI-powered legal consultation using Grok API and OneDrive file management.
- 🤖 AI-Powered Chat: Real-time legal consultation with Grok 4
- 💬 Chat Interface: Modern chat UI
- 💎 Subscription Tiers: Silver, Gold, and Platinum plans
- 🔒 Chat Limits: Free tier with upgrade prompts
- 📱 Responsive Design: Works on all devices
- 📁 OneDrive Integration: Browse and manage OneDrive files
- 🔍 File Search: Search through OneDrive files
- 📥 File Download: Download files from OneDrive
- 🗂️ Folder Navigation: Navigate through OneDrive folders
- 🎯 Legal Analysis: AI-powered legal document analysis
- 🔍 Smart Recommendations: Intelligent legal insights and recommendations
npm installCreate a .env.local file in the root directory:
# Grok API Configuration
GROK_API_KEY=your_actual_grok_api_key_here
# Microsoft Graph Configuration for OneDrive
AZURE_AD_CLIENT_ID=your_AZURE_AD_CLIENT_ID
AZURE_AD_CLIENT_SECRET=your_AZURE_AD_CLIENT_SECRET
AZURE_AD_TENANT_ID=your_AZURE_AD_TENANT_ID
# NextAuth Configuration
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=supersecretstringTo get your Microsoft Graph API credentials:
-
Register an Azure AD Application:
- Go to Azure Portal
- Navigate to "Azure Active Directory" > "App registrations"
- Click "New registration"
- Name your application (e.g., "AI Wizard OneDrive")
- Select "Accounts in any organizational directory and personal Microsoft accounts"
- Set redirect URI to
http://localhost:3000 - Click "Register"
-
Configure API Permissions:
- In your app registration, go to "API permissions"
- Click "Add a permission"
- Select "Microsoft Graph"
- Choose "Delegated permissions"
- Add the following permissions:
Files.ReadWrite.All(for full file access including downloads)User.Read(for user profile information)
- Click "Grant admin consent"
-
Get Client Credentials:
- Go to "Certificates & secrets"
- Click "New client secret"
- Add a description and set expiration
- Copy the generated secret value
- Go to "Overview" and copy the "Application (client) ID"
-
Configure Environment Variables:
- Set
AZURE_AD_CLIENT_IDto your Application (client) ID - Set
AZURE_AD_CLIENT_SECRETto your client secret - Set
AZURE_AD_TENANT_IDto your tenant ID (or "common" for multi-tenant)
- Set
To get your Grok API key:
- Visit https://console.x.ai/
- Sign up or log in to your account
- Navigate to API keys section
- Create a new API key
- Copy the key and paste it in your
.env.localfile
npm run devOpen http://localhost:3000 in your browser.
- Real-time Chat: Chat with AI assistant for legal guidance
- Document Analysis: Upload and analyze legal documents
- Legal Insights: Get AI-powered legal insights and recommendations
- Smart Recommendations: Intelligent suggestions based on your legal situation
- File Browsing: Navigate through OneDrive folders
- File Search: Search for files across OneDrive
- File Download: Download files directly from OneDrive
- File Metadata: View file size, type, and last modified date
- Folder Navigation: Navigate through folder hierarchy
- File Actions: Download, share, and manage files
- Modern Design: Clean, responsive interface
- Chat Interface: Real-time chat with AI assistant
- Consultation Forms: Streamlined legal consultation process
- Results Display: Clear presentation of analysis results
- Microsoft Authentication: Secure login with Microsoft accounts
- Session Management: Persistent user sessions
- User Profiles: User profile management
The application uses a layered architecture (Controller → Service → Repository) for API endpoints.
📚 For complete API documentation, see API_ARCHITECTURE.md
⚡ For quick reference, see API_QUICK_REFERENCE.md
The APIs are organized by user roles:
- Client APIs (
/api/client/): Customer functionality - Attorney APIs (
/api/attorney/): Legal professional features - Admin APIs (
/api/admin/): System administration - Guest/Demo APIs (
/api/guest/,/api/demo/): Public demos - Auth APIs (
/api/auth/): Authentication
- OpenRouter API: AI model access for legal research
- Stripe API: Payment processing
- OneDrive API: File management
- NextAuth: Session management
AI-wizard/
├── src/
│ ├── app/
│ │ ├── api/
│ │ │ ├── auth/ # Authentication endpoints
│ │ │ ├── chat/ # Chat API endpoint
│ │ │ ├── legal-analysis/ # Legal analysis API endpoint
│ │ │ └── onedrive/ # OneDrive API endpoint
│ │ ├── auth/ # Authentication pages
│ │ ├── chat/ # Chat interface
│ │ ├── components/ # Reusable components
│ │ ├── wizard/ # AI wizard interface
│ │ └── page.tsx # Home page
│ ├── middleware.ts # Authentication middleware
│ └── lib/ # Utility functions
├── public/ # Static assets
└── README.md # Project documentation
- Start a Consultation: Navigate to the home page to begin a legal consultation
- Chat with AI: Use the chat interface to ask legal questions
- Get Analysis: Receive AI-powered legal analysis and recommendations
- View Results: Review detailed analysis results and insights
- OneDrive Integration: Access and manage your OneDrive files through the wizard interface
- Node.js 18+
- npm or yarn
- Microsoft Azure AD application
- Grok API key
- Clone the repository
- Install dependencies:
npm install - Set up environment variables
- Run development server:
npm run dev - Open http://localhost:3000
npm run build
npm start- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the MIT License.