project-8f76630a

byNiru Singh

You are acting as a senior Python backend engineer building a portfolio-grade Retrieval-Augmented-Generation (RAG) API called LegalMind. Project Summary LegalMind lets authenticated users upload legal documents (contracts, court filings, agreements) and ask natural language questions about them. Every answer must include source citations pointing to the exact page/clause the information came from. This is API only — no frontend/UI . Tech Stack - FastAPI (async, Pydantic v2 models) - ChromaDB (vector store, one physical collection per user) - OpenAI API (embeddings + chat completion for answer synthesis) - SQLAlchemy (async) for relational metadata (users, documents, query logs) - Document parsing: PyMuPDF for PDFs, python-docx for Word files - Text chunking: LangChain text splitters or tiktoken-based custom chunker, chunk size ~500-800 tokens with overlap, must preserve page/clause metadata Multi-Tenancy & Security Requirements - Every request is authenticated via JWT; extract `user_id` from the token. - Each user gets their own physical ChromaDB collection (e.g. `collection_{user_id}`) — never a shared collection with a metadata filter. This is a hard isolation boundary, not a soft one. - All document metadata rows in the relational DB are scoped by `user_id` with row-level checks on every query — never trust a client-supplied user_id in the payload; always derive it from the verified JWT. - Write at least one test that proves user A cannot retrieve user B's data even with a crafted request. Core API Endpoints to Design 1. `POST /auth/token` — issue JWT (stub or real auth, your choice, but must embed `user_id` and `role` claims) 2. `POST /documents/upload` — accept PDF/DOCX, extract text with page numbers, chunk it, embed it, upsert into the user's Chroma collection, store document metadata (filename, upload date, page count) in the relational DB 3. `GET /documents` — list the current user's uploaded documents 4. `DELETE /documents/{document_id}` — remove a document and its vectors 5. `POST /query` — accept a natural-language question + optional `document_id` filter, retrieve top-k relevant chunks from the user's collection, call the LLM to synthesize an answer, and return the answer with a `citations` array (document name, page number, and the source text snippet for each cited chunk) RAG Pipeline Details - On upload: extract text page-by-page (never lose the page boundary), chunk with metadata `{document_id, page_number, chunk_index}`, embed with OpenAI `text-embedding-3-small` (or similar), upsert to Chroma with that metadata attached to every vector. - On query: embed the question, run similarity search (top_k configurable, default 5) against the user's collection only, pass retrieved chunks + question into a structured prompt that forces the LLM to cite which chunk each claim came from, and parse the response into `{answer: str, citations: [{document, page, snippet}]}`. - Include a basic guard against hallucinated citations: validate that every cited page/document actually exists in the retrieved chunk set before returning the response. Deliverables - Clean FastAPI project structure (routers/services/schemas/db separated) - `.env.example` with all required config keys - Dockerfile + docker-compose (API + Chroma persistent volume) - README with setup, architecture diagram description, and example curl requests for each endpoint - Basic pytest suite covering auth, upload, query, and the tenant-isolation test above Constraints - Keep this POC-scoped: no Kubernetes, no complex orchestration frameworks (no LangGraph/Autogen needed here — this is intentionally simpler than a multi-agent system). - Favor clarity and correctness over cleverness; this is a portfolio piece meant to demonstrate solid RAG + multi-tenant API design to interviewers. Start by proposing the folder structure and the SQLAlchemy models, then wait for confirmation before writing endpoint code.

LandingLoginAuth
Landing

Comments (0)

No comments yet. Be the first!

Project Tasks24

#1

Initialize FastAPI Project

To Do

As a developer, I want to initialize a FastAPI project with a structured folder layout, logging infrastructure, and environment handling.

AI 80%
Human 20%
High Priority
1 day
Backend Developer
#10

Implement CTASection for Landing

To Do

As a frontend developer, implement the CTASection for the Landing page. This section includes a motion-animated card that appears when in view, featuring a title, description, and two call-to-action buttons linking to the Auth and APIDocs pages. Ensure animations trigger correctly using the useInView hook from motion/react. Page access: shared by all personas (Authenticated User, Developer).

AI 90%
Human 10%
High Priority
1 day
Frontend Developer
#15

Implement Navbar for Landing

To Do

As a frontend developer, implement the Navbar for the Landing page. This component includes a logo and a responsive navigation menu with links to various pages. Ensure that links to restricted pages like Auth and APIDocs are conditionally shown based on the user's persona. Implement a toggleable burger menu for mobile view. Page access: shared by all personas (Authenticated User, Developer).

AI 90%
Human 10%
High Priority
1 day
Frontend Developer
#2

Setup JWT Authentication

To Do

As a developer, I want to implement JWT authentication for user requests to ensure secure access.

Depends on:#1
Waiting for dependencies
AI 70%
Human 30%
High Priority
1.5 days
Backend Developer
#3

Implement Document Upload

To Do

As a developer, I want to implement document upload functionality with text extraction and embedding.

Depends on:#1
Waiting for dependencies
AI 75%
Human 25%
High Priority
2 days
Backend Developer
#6

Database Schema & Models

To Do

As a developer, I want to define the database schema and models for users and documents.

Depends on:#1
Waiting for dependencies
AI 60%
Human 40%
Medium Priority
1.5 days
Backend Developer
#9

Docker & Deployment Setup

To Do

As a DevOps engineer, I want to set up Docker and docker-compose for consistent deployment.

Depends on:#1
Waiting for dependencies
AI 60%
Human 40%
Medium Priority
1.5 days
DevOps Engineer
#11

Implement FeaturesSection for Landing

To Do

As a frontend developer, implement the FeaturesSection for the Landing page. This section displays a grid of feature cards, each with an icon, title, and description. Use motion animations to reveal each card as it comes into view, leveraging the useInView hook for smooth transitions. Page access: shared by all personas (Authenticated User, Developer).

Depends on:#10
Waiting for dependencies
AI 90%
Human 10%
High Priority
1.5 days
Frontend Developer
#12

Implement Footer for Landing

To Do

As a frontend developer, implement the Footer for the Landing page. This section includes navigation links to various pages, ensuring that links to restricted pages like Auth and APIDocs are conditionally shown based on the user's persona. The footer also displays a logo and copyright information. Page access: shared by all personas (Authenticated User, Developer).

Depends on:#10
Waiting for dependencies
AI 85%
Human 15%
Medium Priority
0.5 days
Frontend Developer
#13

Implement HeroSection for Landing

To Do

As a frontend developer, implement the HeroSection for the Landing page. This section features a prominent title, subtitle, and call-to-action buttons, with motion animations for text and SVG artwork. Use the useReducedMotion hook to accommodate users with motion sensitivity. Page access: shared by all personas (Authenticated User, Developer).

Depends on:#10
Waiting for dependencies
AI 90%
Human 10%
High Priority
2 days
Frontend Developer
#14

Implement HowItWorksSection for Landing

To Do

As a frontend developer, implement the HowItWorksSection for the Landing page. This section outlines the steps to use the LegalMind API, with each step animated into view using the useInView hook. Ensure the steps are clearly presented and visually engaging. Page access: shared by all personas (Authenticated User, Developer).

Depends on:#10
Waiting for dependencies
AI 90%
Human 10%
Medium Priority
1 day
Frontend Developer
#23

Define Database Schema

To Do

As a Backend Developer, I want to define the database schema and models for users and documents.

Depends on:#1
Waiting for dependencies
AI 60%
Human 40%
Medium Priority
1 day
Backend Developer
#4

Create Query Endpoint

To Do

As a developer, I want to implement a query endpoint that retrieves and synthesizes answers with citations.

Depends on:#3
Waiting for dependencies
AI 80%
Human 20%
High Priority
2.5 days
Backend Developer
#5

Setup Multi-Tenancy & Security

To Do

As a developer, I want to ensure multi-tenancy and security by isolating user data and verifying access through JWT authentication.

Depends on:#2
Waiting for dependencies
AI 70%
Human 30%
High Priority
2 days
Backend Developer
#7

Implement Document Management

To Do

As a developer, I want to implement endpoints to list and delete documents.

Depends on:#6
Waiting for dependencies
AI 70%
Human 30%
Medium Priority
1.5 days
Backend Developer
#16

Create Auth API Endpoints

To Do

As a Backend Developer, implement the authentication API endpoints including `POST /auth/token` for issuing JWT tokens. Ensure JWT tokens include `user_id` and `role` claims. Implement token verification for secured endpoints.

Depends on:#2
Waiting for dependencies
AI 0%
Human 100%
High Priority
2 days
Backend Developer
#17

Create Document API Endpoints

To Do

As a Backend Developer, implement the document management API endpoints including `POST /documents/upload`, `GET /documents`, and `DELETE /documents/{document_id}`. Ensure document uploads handle PDF/DOCX parsing and metadata storage.

Depends on:#3#6
Waiting for dependencies
AI 0%
Human 100%
High Priority
3 days
Backend Developer
#20

Implement Row-Level Security

To Do

As a Backend Developer, implement row-level security in the relational database to ensure user data isolation. Verify that all database queries are scoped by `user_id` extracted from JWT.

Depends on:#6
Waiting for dependencies
AI 0%
Human 100%
High Priority
2 days
Backend Developer
#24

Test JWT Authentication

To Do

As a QA Engineer, develop unit and integration tests for the JWT authentication process. Ensure that tokens are issued correctly and that secured endpoints validate tokens properly.

Depends on:#2
Waiting for dependencies
AI 0%
Human 100%
Medium Priority
1 day
QA Engineer
#8

Integration & QA Testing

To Do

As a QA engineer, I want to create automated tests for authentication, document management, and query functions.

Depends on:#3#4#7#2
Waiting for dependencies
AI 50%
Human 50%
Medium Priority
2 days
QA Engineer
#18

Create Query API Endpoint

To Do

As a Backend Developer, implement the query API endpoint `POST /query` to process natural language questions and return synthesized answers with citations. Ensure integration with OpenAI API for embeddings and answer synthesis.

Depends on:#4
Waiting for dependencies
AI 0%
Human 100%
High Priority
3 days
Backend Developer
#19

Setup ChromaDB Collections

To Do

As a Backend Developer, configure ChromaDB to create a separate collection for each user upon registration. Ensure collections are isolated and secure, with user-specific access controls.

Depends on:#5
Waiting for dependencies
AI 0%
Human 100%
Medium Priority
2 days
Backend Developer
#21

Integration Testing for APIs

To Do

As a QA Engineer, develop integration tests for all API endpoints to ensure they work together seamlessly. Include tests for authentication, document management, and query processing.

Depends on:#17#8#16#18
Waiting for dependencies
AI 0%
Human 100%
High Priority
2.5 days
QA Engineer
#22

Integrate Backend APIs

To Do

As a Tech Lead, verify the end-to-end integration between the backend API implementations for authentication, document management, and query processing. Ensure data flows correctly and all interactions work as expected.

Depends on:#17#16#18
Waiting for dependencies
AI 0%
Human 100%
High Priority
2 days
Tech Lead
Landing design preview
Landing: View Info
Login: Sign In
Documents: Upload Document
Documents: View List
Query: Ask Question
Query: View Answer
Query: Review Citations
Documents: Delete Document
Landing design preview
Landing: View Info
Login: Sign In
Documents: Upload Document
Documents: View List
Query: Ask Question
Query: View Answer
Query: Review Citations
Documents: Delete Document