A Next.js frontend application for the Kanoon Sathi legal AI assistant with comprehensive authentication and chat management.
- User Registration: Create new accounts with username, password, and optional email
- User Login: Secure JWT-based authentication
- Profile Management: Update username and email, view account details
- Guest Mode: Use the app without registration (with limited features)
- Persistent Sessions: User sessions persist across browser restarts
-
Authenticated Users:
- Chat history is saved to the database
- Access all previous conversations
- Create, rename, and delete chats
- Messages are synchronized across devices
-
Guest Users:
- Temporary chat sessions using GenKit Flow API
- Local conversation management
- Can upgrade to authenticated user to save history
- Responsive Design: Works on desktop and mobile devices
- Dark Theme: Modern dark UI optimized for extended use
- Real-time Chat: Instant message exchange with AI assistant
- Conversation Management: Easy navigation between different chat sessions
The application integrates with two API systems:
- REST API (
http://localhost:3001): User management and authenticated chat operations - GenKit Flow API (
http://localhost:7777): AI responses and guest chat functionality
app/
├── page.tsx # Main chat interface
├── login/page.tsx # User login page
├── register/page.tsx # User registration page
├── profile/page.tsx # User profile/settings page
└── layout.tsx # Root layout with AuthProvider
contexts/
└── auth-context.tsx # Authentication state management
lib/
├── chat-api.ts # API service for chat operations
└── utils.ts # Utility functions
components/
├── chat/ # Chat-related components
│ ├── chat-area.tsx
│ ├── chat-input.tsx
│ ├── chat-message.tsx
│ ├── chat-sidebar.tsx
│ └── conversation-list.tsx
└── ui/ # Reusable UI components
├── button.tsx
├── input.tsx
├── card.tsx
└── ...
types/
└── chat.ts # TypeScript type definitions
-
Install Dependencies:
npm install
-
Environment Setup: Make sure both backend services are running:
- REST API on
http://localhost:3001 - GenKit Flow API on
http://localhost:7777
- REST API on
-
Run Development Server:
npm run dev
-
Access the Application: Open http://localhost:3000 in your browser
- Visit the homepage
- Click "Sign Up" in the sidebar
- Create an account with username and password
- Start chatting with the AI assistant
- Click "Sign In" in the sidebar
- Enter your credentials
- Access your saved chat history
- Simply start typing in the chat interface
- Your conversation will be temporary
- Sign up anytime to save your chat history
graph TD
A[User visits app] --> B{Authenticated?}
B -->|Yes| C[Load user chats from database]
B -->|No| D[Show guest interface]
D --> E[User can chat temporarily]
E --> F[Option to sign up/in]
F --> G[Register/Login]
G --> C
C --> H[Full chat features available]
POST /api/auth/register- User registrationPOST /api/auth/login- User loginGET /api/auth/me- Get current userPUT /api/auth/profile- Update user profile
GET /api/chats- Get user's chatsPOST /api/chats- Create new chatGET /api/chats/:id- Get chat with messagesPUT /api/chats/:id- Update chat titleDELETE /api/chats/:id- Delete chatPOST /api/chats/:id/messages- Add message to chat
POST /autonomousAIFlow- Send message to AIGET /getChatHistory- Get chat history (guests)GET /getConversationList- Get conversation list (guests)
Manages global authentication state including:
- User information
- JWT token
- Login/logout functions
- Profile updates
Handles all API calls for:
- Chat CRUD operations
- Message management
- AI interactions
- Guest chat functions
- ChatSidebar: Navigation and user controls
- ChatArea: Message display with markdown support
- ChatInput: Message composition
- ConversationList: Chat history navigation
- JWT token-based authentication
- Secure password handling
- Input validation on both client and server
- Protected routes for authenticated features
- Automatic token refresh handling
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.