AWS Builder Center
Building a Voice-First Legal Rights Assistant with AWS: From Voice & Documents to Secure Authentication

Building a Voice-First Legal Rights Assistant with AWS: From Voice & Documents to Secure Authentication

Learn how we built the AWS backend infrastructure for AdhikarAI, a voice-first legal rights assistant that combines speech, document processing, persistent sessions, and secure email OTP authentication using AWS serverless services.

Studying

Title:

Building AdhikarAI: A Voice-First Legal Rights Assistant Using AWS

Description:

How we built the AWS backend for AdhikarAI, a voice-first legal rights assistant that combines voice input, document processing, persistent data, voice responses, and secure email authentication using AWS serverless services.

Body:

Building AdhikarAI: A Voice-First Legal Rights Assistant Using AWS

When we started building AdhikarAI, our idea was simple: make it easier for people to explain a legal problem and understand the information they receive.
A user should not have to know complicated legal terminology just to ask a question. They should be able to describe their situation naturally, either by typing or speaking, and receive information in a way that is easier to understand.
That idea led us to build AdhikarAI, a voice-first legal rights assistant.
My main responsibility in the project was the AWS backend and infrastructure layer. I worked on the APIs, AWS service integrations, file handling, database operations, voice and document processing, authentication, and connecting the backend with the frontend.
This project also gave me hands-on experience with how multiple AWS services can work together to build a complete application.



The Architecture

We decided to use a serverless architecture instead of maintaining a traditional backend server.
The basic flow looks like:
Frontend → API Gateway → Lambda → AWS Services → Response
The main AWS services used in my part of the project were:
  • Amazon API Gateway for exposing backend APIs
  • AWS Lambda for running backend logic
  • Amazon S3 for storing uploaded audio and documents
  • Amazon DynamoDB for persistent application data
  • Amazon Transcribe for speech-to-text
  • Amazon Textract for extracting text from documents
  • Amazon Polly for text-to-speech
  • AWS SAM for infrastructure configuration and deployment
Each service has a specific responsibility, which keeps the backend modular and easier to manage.



Voice Input with Amazon Transcribe

One of the main features of AdhikarAI is that users don't have to type everything.
They can simply speak about their situation.
The backend flow is:
Voice Recording → S3 → Lambda → Amazon Transcribe → Text → AI Processing
I worked on handling the uploaded audio, storing it, preparing it for transcription, and connecting the transcription result with the rest of the application.
We also considered Indian language support. For example, the backend maps English and Hindi inputs to the appropriate Indian language codes.
This part of the project taught me that handling voice input involves more than simply calling a transcription API. Audio formats, language configuration, storage, API handling, and error handling all need to work together.



Processing Documents with Amazon Textract

Another important feature of AdhikarAI is document understanding.
A user may have an agreement, notice, or another legal document but may not understand what it means.
To support this workflow, we integrated Amazon Textract.
The flow is:
Document Upload → S3 → Lambda → Textract → Extracted Text → AI Processing
The backend validates uploaded files and manages the document-processing workflow.
Once Textract extracts the text, it can be passed to the application's AI layer for further processing and explanation.
This helped us turn an uploaded document into information that the user can actually interact with.



Voice Responses with Amazon Polly

We didn't want voice interaction to work only in one direction.
After the application generates a response, it can also convert that response into speech using Amazon Polly.
The complete flow becomes:
User Speech → Transcribe → AI Response → Polly → Audio Response
This makes the application more suitable for a voice-first experience, especially for users who may prefer listening rather than reading a long response.
Working on this workflow also helped me understand how multiple cloud services can work together to create what feels like one feature from the user's perspective.



Managing Application Data with DynamoDB

We use Amazon DynamoDB for persistent application data.
The backend manages information such as:
  • User sessions
  • Cases
  • Reminders
  • Authentication records
  • OTP records
For authentication, user and OTP records are logically separated using partition and sort keys.
DynamoDB TTL is also used for temporary OTP records so that expired authentication data can be cleaned up automatically.
Working with DynamoDB taught me the importance of thinking about data access patterns before deciding how records should be structured.



Cases and Reminders

We also wanted AdhikarAI to maintain information beyond a single question.
I implemented backend functionality for cases and reminders.
The backend supports operations such as:
  • Creating cases
  • Retrieving cases
  • Creating reminders
  • Retrieving reminders
  • Updating reminders
  • Deleting reminders
This information is persisted in DynamoDB and can be accessed through backend APIs.
This was useful because the application could now maintain information across different interactions instead of treating every request as completely independent.



Adding Email OTP Authentication

After implementing the core backend functionality, I also worked on a demo email-based authentication system.
For this implementation, we decided to use Resend for email OTPs instead of using Cognito or phone/SMS authentication.
The signup flow looks like:
Signup → Generate OTP → Send Email → Verify OTP → Activate Account
The backend supports:
  • Email signup
  • OTP verification
  • OTP resend
  • Sign-in
  • Forgot password
  • Password reset
The OTP system includes several protections:
  • Secure 6-digit OTP generation
  • 5-minute OTP expiry
  • Maximum 5 verification attempts
  • 60-second resend cooldown
  • OTP hashing before storage
  • DynamoDB TTL for temporary records
Passwords are also hashed using PBKDF2 rather than being stored as plain text.
One thing I paid particular attention to was keeping the Resend API key on the backend rather than exposing it through the frontend.



Infrastructure as Code with AWS SAM

Another important part of my work was defining the backend infrastructure using AWS SAM.
Instead of manually configuring every Lambda function and API route, the infrastructure is described in the SAM  template.yaml .
It defines resources and configuration such as:
  • Lambda functions
  • API Gateway routes
  • DynamoDB configuration
  • IAM permissions
  • Environment variables
  • CloudFormation outputs
Using infrastructure as code made the backend configuration easier to maintain and reproduce.
It also helped me understand the practical side of managing cloud infrastructure alongside application code.



Separating the Infrastructure and AI Layers

A key architectural decision in the project was keeping the AWS infrastructure layer separate from the AI layer.
My work focused on the infrastructure and integration side:
API Gateway → Lambda → S3 → DynamoDB → Transcribe → Textract → Polly
The AI layer handles the intelligence and response-generation part of the application.
Keeping these responsibilities separate allowed the team to work in parallel. I could focus on making the APIs, storage, authentication, and AWS integrations work while the AI functionality was developed independently.



Testing the Complete Backend

Once the different pieces were implemented, I tested the backend workflows instead of checking only individual functions.
The tests covered:
  • Signup and OTP verification
  • Invalid OTP attempts
  • OTP cooldown
  • Sign-in
  • Password reset
  • Session management
  • Text queries
  • Document processing
  • Voice processing
  • Letter generation
  • Cases
  • Reminders
The final backend test run completed with:
15 tests passed and 0 failed.
The frontend production build also completed successfully with 0 errors.
This was an important part of the project because getting one AWS service to work is very different from making the complete workflow work from the frontend to the backend and back.



What I Learned

The biggest thing I learned from this project was how different AWS services fit together to solve an actual problem.
Before working on AdhikarAI, services such as Lambda, S3, DynamoDB, Transcribe, and Textract could be understood individually.
While building the project, I started seeing them as different parts of one system.
For example, something as simple as document upload can involve:
Frontend → API Gateway → Lambda → S3 → Textract → AI Layer → Frontend
There are several moving parts behind what looks like one simple feature to the user.
I also learned the importance of keeping secrets outside the source code, designing APIs around clear responsibilities, handling errors between services, and testing complete workflows.



What's Next

AdhikarAI is currently an MVP, so there is still a lot that we can improve.
One area we plan to explore further is vector search and Retrieval-Augmented Generation (RAG).
The idea is to build a legal knowledge base, create embeddings for relevant information, retrieve the most relevant content for a user's query, and then use that retrieved context to generate a more grounded response.
We are also exploring the use of the Gemini API as part of this future AI workflow.
These are future improvements and are separate from the AWS backend implementation described in this article.



Final Thoughts

Building AdhikarAI gave me practical experience with AWS beyond simply learning individual services.
I worked on the infrastructure that connects APIs, storage, databases, speech processing, document processing, and authentication into one application.
The project showed me that building a cloud application isn't just about knowing what each AWS service does. The real challenge is understanding how those services communicate with each other and how they fit into the overall user experience.
That was probably my biggest takeaway from working on AdhikarAI.
Technologies used: Amazon API Gateway, AWS Lambda, Amazon S3, Amazon DynamoDB, Amazon Transcribe, Amazon Textract, Amazon Polly, AWS SAM, AWS CloudFormation, IAM, Node.js, React, TypeScript, and Resend.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article