NyayaCop is an AI-powered legal assistance platform designed to help victims easily file complaints with police departments and navigate the legal system in India. The platform leverages artificial intelligence to classify complaints, suggest relevant IPC sections, and guide users through the complaint filing process, all while ensuring the integrity and security of data through blockchain verification.
- Technology Stack
- Architecture
- Features
- Project Structure
- Frontend
- Backend
- AI Integration
- Blockchain Component
- Database Structure
- Deployment
- APIs
- Security Features
- Testing
- Future Enhancements
- Troubleshooting
- Credits and Contributors
- Presentation Resources
- Framework: React with TypeScript
- Styling: Styled Components & CSS
- State Management: React Context API
- Routing: React Router v6
- HTTP Client: Axios
- Build Tool: Vite
- Map Integration: Leaflet.js
- Framework: Flask (Python)
- Authentication: JWT (JSON Web Tokens)
- Database: MongoDB
- SMS Notifications: Twilio API
- API Documentation: Swagger
- Language Model: Google Gemini API
- Text Analysis: Custom NLP models
- Legal Classification: Supervised learning on IPC sections
- Framework: Truffle Suite
- Network: Ethereum (Ganache for development)
- Smart Contract: Solidity
- Web3 Interface: Web3.js
- Frontend: Vercel
- Backend: Render
- Database: MongoDB Atlas
- CI/CD: GitHub Actions
NyayaCop follows a modern microservices architecture with the following components:
The architecture includes:
- A React-based frontend deployed on Vercel
- A Flask-based backend API deployed on Render
- MongoDB Atlas for database storage
- Ethereum blockchain for data integrity verification
- Google Gemini API for AI-powered legal analysis
The components work together to provide a seamless experience for both victims filing complaints and police officers managing cases.
- Phone number-based authentication with OTP
- File complaints in multiple languages
- AI-powered legal guidance
- Real-time tracking of complaint status
- Location-based police station finder
- SMS notifications for status updates
- Legal guides and resources
- Secure login with email and password
- Dashboard to manage and update complaints
- AI assistance for legal classification of complaints
- Tools to add case notes and update status
- Blockchain verification of complaint integrity
- Pre-registration of victims from in-person complaints
The project is organized into three main components:
- frontend/: React frontend application
- backend/: Flask backend API server
- blockchain_dev/: Blockchain integration components
The frontend is built with React and TypeScript using Vite as the build tool. It provides interfaces for both victims and police officers with different features for each user role.
-
Authentication
- OTP-based authentication for victims
- Email/password authentication for police
- JWT token management
-
Complaint Filing
- Multi-step form with language selection
- Location detection and police station mapping
- Real-time AI feedback on legal classification
-
Dashboard
- Status tracking for victims
- Complaint management for police officers
- Case notes and updates interface
-
Legal Resources
- IPC sections library
- Legal guides and FAQs
- Legal rights information
The backend is built with Flask and interacts with MongoDB for data storage. It handles authentication, complaint management, and integration with external services.
-
Authentication System
- JWT token generation and verification
- OTP generation and verification for victims
- Password hashing for police accounts
-
Complaint Management
- Creation, retrieval, and updates of complaints
- Status tracking and notifications
- Integration with AI for classification
-
Police Interface
- Case management and updates
- Victim pre-registration system
- Note-taking and status updates
-
Notification System
- Twilio integration for SMS notifications
- Event-based notifications for status changes
- Fallback mechanisms for development
SAARTHI integrates with Google's Gemini API to provide intelligent legal assistance. The AI component performs several key functions:
-
Legal Classification
- Analyzes complaint text to identify relevant IPC sections
- Determines if the offense is cognizable or non-cognizable
- Provides confidence scores for suggested sections
-
Summary Generation
- Creates concise summaries of lengthy complaints
- Extracts key information for police review
- Identifies important details like dates, locations, and parties involved
-
Multilingual Support
- Processes complaints in multiple Indian languages
- Translates and preserves context for legal analysis
- Provides responses in the user's preferred language
The blockchain component ensures the integrity and immutability of filed complaints. It uses Ethereum smart contracts to store hashes of complaint data.
-
Smart Contract
- Stores hashes of complaint data on the blockchain
- Provides verification methods to check data integrity
- Implements proper access control
-
Integration with MongoDB
- Hashes complaint data from MongoDB
- Stores the hash on the blockchain
- Records the transaction hash and block information
-
Verification System
- Allows verification of complaint integrity
- Provides proof of when a complaint was filed
- Ensures no tampering of complaint data
SAARTHI uses MongoDB with the following collections:
-
victims
- User accounts for complaint filers
- Authentication information
- Personal details
-
police
- Police officer accounts
- Authentication credentials
- Station assignments
-
complaints
- Complaint text and details
- Status and updates
- References to victims and police officers
- Blockchain verification data
-
pre_registered_victims
- Victims registered by police officers
- Temporary accounts until OTP verification
- Associated complaint references
-
case_notes
- Investigation updates
- Timeline of actions
- Visibility settings (public/private)
-
notifications
- SMS notification history
- Delivery status
- Message content
SAARTHI uses a modern CI/CD pipeline for deployment:
- Connect GitHub repository to Vercel
- Configure build settings
- Set environment variables
- Handle SPA routing with
vercel.json
- Connect GitHub repository to Render
- Configure build settings
- Set environment variables
- Ensure CORS is properly configured
- Create a MongoDB Atlas cluster
- Configure network access for Render and development environments
- Set up database user credentials
- Initialize collections and indexes
For the hackathon, we used Ganache for local blockchain development. In production, this would be deployed to a testnet or mainnet.
SAARTHI exposes several REST APIs:
POST /api/auth/send-otp- Send OTP for victim authenticationPOST /api/auth/verify-otp- Verify OTP and authenticate victimPOST /api/auth/police/login- Police officer loginPOST /api/auth/police/register- Register new police officerGET /api/auth/verify-token- Verify JWT token validityGET /api/auth/user- Get current user details
POST /api/complaints- File a new complaintGET /api/complaints- List complaints (filtered by role)GET /api/complaints/:id- Get a specific complaintPATCH /api/complaints/:id- Update complaint statusPOST /api/complaints/analyze- Analyze complaint text with AIPOST /api/complaints/:id/notes- Add case notesGET /api/complaints/:id/notes- Get case notes
GET /api/police/stations- List police stationsGET /api/police/ipc-sections- Get IPC sectionsPOST /api/auth/police/register-victim- Pre-register a victim
SAARTHI implements several security measures:
-
Authentication
- JWT-based authentication with proper expiration
- OTP-based verification for victims
- Password hashing using Werkzeug's generate_password_hash
-
Data Protection
- MongoDB connection secured with SRV protocol
- Sensitive data stored with proper encryption
- Blockchain verification for data integrity
-
API Security
- CORS properly configured for production
- Rate limiting on sensitive endpoints
- Input validation and sanitization
-
Access Control
- Role-based access control (RBAC)
- Proper authorization checks on all endpoints
- Visibility controls for case notes
The project includes several testing components:
-
Frontend Testing
- Component testing with React Testing Library
- End-to-end testing with Cypress
-
Backend Testing
- Unit tests for API endpoints
- Integration tests for database operations
-
Blockchain Testing
- Smart contract tests with Truffle
- Integration tests for blockchain storage and verification
Planned future enhancements include:
-
Advanced AI Features
- Sentiment analysis for urgency detection
- Evidence classification and organization
- Prediction of case outcomes based on historical data
-
Mobile Application
- Native mobile apps for Android and iOS
- Offline complaint drafting
- Push notifications for updates
-
Integration with Government Systems
- CCTNS (Crime and Criminal Tracking Network and Systems) integration
- e-Courts integration for case tracking
- Digital evidence management
-
Enhanced Security
- Multi-factor authentication for police
- End-to-end encryption for sensitive communications
- Advanced anomaly detection for fraud prevention
-
CORS Errors
- Ensure
FRONTEND_URLSin backend environment variables includes your frontend URL - Check that
app.pyhas proper CORS configuration - Verify API requests include proper headers
- Ensure
-
Authentication Issues
- Check JWT token expiration and validation
- Ensure proper token storage in localStorage
- Verify OTP generation and validation flow
-
Blockchain Integration
- Ensure Ganache is running for local development
- Check MongoDB connection for blockchain data storage
- Verify smart contract deployment and ABI configuration
-
Deployment Issues
- Verify environment variables in production
- Check build commands and output directories
- Ensure database connection strings are correct
SAARTHI was built as part of a hackathon project by:
- Frontend Development: [Your Name]
- Backend Development: [Your Name]
- Blockchain Integration: [Your Name]
- AI Implementation: [Your Name]
- UI/UX Design: [Your Name]
For hackathon presentations, we've prepared:
- Demo Video: [Link to video demonstration]
- Slide Deck: [Link to presentation slides]
- Live Demo: [Link to deployed application]
- Source Code: [GitHub repository link]
- Node.js (v16+)
- Python (v3.9+)
- MongoDB
- Truffle Suite
- Google Gemini API key
- Clone the repository
- Set up the backend with required environment variables
- Set up the frontend with required environment variables
- Set up the blockchain component
- Run the application (backend and frontend)
- Open your browser and navigate to the frontend URL
- Bhaskar Ojha [Backend]
- Anushka Dubey [Frontend]
- S Dhanush [Blockchain]