Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI-Court System

A comprehensive legal technology platform that combines AI-powered dispute resolution with traditional court management systems.

πŸš€ Features

  • User Authentication: Secure JWT-based authentication with MongoDB
  • Role-based Access: Separate interfaces for users and court officials
  • AI-Powered Dispute Resolution: Intelligent case analysis and suggestions
  • Document Management: Secure file upload and management system
  • Case Tracking: Complete case lifecycle management
  • Real-time Chat: AI-powered legal assistance chatbot
  • Mediation Platform: Online dispute resolution tools

πŸ› οΈ Tech Stack

Backend

  • Node.js with Express.js

  • MongoDB with Mongoose ODM

  • JWT for session management

  • bcryptjs for password hashing

  • express-validator for input validation

Frontend

  • React with Vite

  • Axios for API communication

  • Context API for state management

πŸ“‹ Prerequisites

  • Node.js (v16 or higher)
  • MongoDB (v4.4 or higher)

πŸ”§ Installation & Setup

1. Clone the Repository

git clone <repository-url>
cd AI_Court

2. Backend Setup

cd backend
npm install

Environment Configuration

Create a .env file in the backend directory:

cp env.example .env

Edit the .env file with your configuration:

# Server Configuration
PORT=5000
NODE_ENV=development

# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/ai-court

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production



# Frontend URL for CORS
FRONTEND_URL=http://localhost:5173

3. Frontend Setup

cd frontend
npm install

Environment Configuration

Create a .env file in the frontend directory:

cp env.example .env

Edit the .env file with your configuration:

# Backend API URL
VITE_API_URL=http://localhost:5000/api

4. Database Setup

Ensure MongoDB is running:

# Start MongoDB (Ubuntu/Debian)
sudo systemctl start mongod

# Start MongoDB (macOS with Homebrew)
brew services start mongodb-community

# Start MongoDB (Windows)
net start MongoDB

5. Running the Application

Development Mode

Backend:

cd backend
npm run dev

Frontend:

cd frontend
npm run dev

Production Mode

Backend:

cd backend
npm start

Frontend:

cd frontend
npm run build
npm run preview

πŸ” Authentication Flow

The system uses JWT-based authentication:

  1. JWT Authentication: Primary authentication method for API access
  2. Session Management: Automatic token refresh and session validation

Authentication Endpoints

  • POST /api/auth/signup - User registration
  • POST /api/auth/login - User login
  • POST /api/auth/logout - User logout
  • GET /api/auth/profile - Get user profile
  • PUT /api/auth/profile - Update user profile
  • PUT /api/auth/change-password - Change password
  • POST /api/auth/verify - Verify JWT token

🚨 Troubleshooting

Common Issues

2. MongoDB Connection Failed

Symptoms: Database connection errors Solution:

  • Ensure MongoDB is running
  • Check MongoDB connection string
  • Verify network connectivity

3. JWT Token Issues

Symptoms: Authentication failures, 401 errors Solution:

  • Check JWT_SECRET environment variable
  • Ensure token is properly formatted
  • Verify token expiration

4. CORS Errors

Symptoms: Frontend can't connect to backend Solution:

  • Check FRONTEND_URL environment variable
  • Ensure CORS configuration matches frontend URL
  • Verify backend is running on correct port

Debug Mode

Enable debug logging by setting:

NODE_ENV=development
DEBUG=*

Logs

Check application logs for detailed error information:

# Backend logs
cd backend
npm run dev

# Frontend logs (in browser console)
F12 > Console

πŸ“ Project Structure

AI_Court/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ database.js      # MongoDB configuration

β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   └── auth.js          # Authentication middleware
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ User.js          # User model
β”‚   β”‚   └── Document.js      # Document model
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ auth.js          # Authentication routes
β”‚   β”‚   β”œβ”€β”€ cases.js         # Case management routes
β”‚   β”‚   └── documents.js     # Document management routes
β”‚   β”œβ”€β”€ scripts/
β”‚   β”‚   └── setup-demo.js    # Demo data setup
β”‚   β”œβ”€β”€ server.js            # Express server
β”‚   └── package.json
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/      # React components
β”‚   β”‚   β”œβ”€β”€ contexts/
β”‚   β”‚   β”‚   └── AuthContext.jsx  # Authentication context
β”‚   β”‚   β”œβ”€β”€ pages/           # Page components
β”‚   β”‚   β”œβ”€β”€ config/

β”‚   β”‚   └── main.jsx         # React entry point
β”‚   └── package.json
└── README.md

πŸ”’ Security Features

  • Password Hashing: bcrypt with salt rounds
  • JWT Token Security: Configurable expiration and secret
  • Input Validation: Comprehensive validation using express-validator
  • Rate Limiting: API rate limiting to prevent abuse
  • CORS Protection: Configured CORS for security
  • Helmet.js: Security headers middleware
  • Environment Variables: Secure configuration management

πŸ§ͺ Testing

Backend Testing

cd backend
npm test

Frontend Testing

cd frontend
npm test

πŸ“ API Documentation

Authentication

All protected routes require a valid JWT token in the Authorization header:

Authorization: Bearer <jwt-token>

Error Responses

Standard error response format:

{
  "error": "Error type",
  "message": "Human-readable error message",
  "details": [] // Optional validation errors
}

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.

πŸ†˜ Support

For support and questions:

  1. Check the troubleshooting section
  2. Review the logs for error details
  3. Create an issue with detailed error information
  4. Include environment details (without sensitive data)

πŸ”„ Updates

Recent Fixes

  • βœ… Improved JWT token handling
  • βœ… Enhanced error handling and validation
  • βœ… Added comprehensive authentication flow
  • βœ… Fixed CORS configuration
  • βœ… Improved database connection handling
  • βœ… Added security headers and rate limiting
  • βœ… Enhanced user model with better validation
  • βœ… Fixed frontend authentication context
  • βœ… Added proper environment variable handling

Releases

Packages

Contributors

Languages