---
title: "Deploy Pakistan-Legal-Assistant-RAG"
description: "Multi-Agent RAG based AI Legal Assistant for Pakistan Law"
category: "Other"
url: https://railway.com/deploy/pakistan-legal-assistant-rag
---

# Deploy Pakistan-Legal-Assistant-RAG

Multi-Agent RAG based AI Legal Assistant for Pakistan Law

**[Deploy Pakistan-Legal-Assistant-RAG on Railway](https://railway.com/template/pakistan-legal-assistant-rag)**

- **Category:** Other

## Template content

### Backend

- **Source:** https://github.com/arloodots/Pakistan-Legal-Assistant-RAG
- **Start command:** `uvicorn app:app --host 0.0.0.0 --port $PORT`
- **Public domain:** Yes

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

### Frontend

- **Source:** https://github.com/arloodots/Pakistan-Legal-Assistant-RAG
- **Public domain:** Yes

## Documentation

# Deploy and Host Pakistan-Legal-Assistant-RAG on Railway

Pakistan-Legal-Assistant-RAG is a full-stack AI legal assistant designed to answer questions about Pakistani law using Retrieval-Augmented Generation (RAG). It combines a FastAPI backend, LangGraph multi-agent workflow, Qdrant vector search, PostgreSQL conversation persistence, and a Next.js frontend. The system retrieves relevant legal passages from sources such as the Constitution of Pakistan, Pakistan Penal Code (PPC), and Criminal Procedure Code (CrPC), then generates grounded answers with legal citations. It also includes conversation memory, voice interaction, monitoring with LangSmith, and evaluation capabilities.

## About Hosting Pakistan-Legal-Assistant-RAG

Hosting Pakistan-Legal-Assistant-RAG on Railway involves deploying the application as a full-stack service with separate frontend and backend services. The backend runs FastAPI, LangGraph, the RAG pipeline, legal-agent workflow, and voice functionality, while the Next.js application provides the user interface. PostgreSQL can be deployed directly on Railway for persistent chat and application data. Qdrant Cloud remains an external managed vector database containing the legal document embeddings. The application also connects to external AI services such as Groq and Hugging Face, while LangSmith can be configured for tracing and monitoring. Railway manages the application deployments, networking, environment variables, and scaling.

## Common Use Cases

* AI-powered legal question answering for Pakistani constitutional and criminal law.
* Retrieval-Augmented Generation over the Constitution of Pakistan, PPC, and CrPC with source citations.
* Demonstration and evaluation of a production-style multi-agent legal AI system with LangGraph, Qdrant, and LangSmith.

## Dependencies for Pakistan-Legal-Assistant-RAG Hosting

* **Railway** — hosts the frontend, backend, and PostgreSQL services.
* **PostgreSQL** — stores persistent application and conversation data.
* **Qdrant Cloud** — provides the persistent vector database and semantic retrieval layer.
* **Groq API** — provides the LLM used by the application's agents.
* **Hugging Face** — provides the embedding/inference API used by the RAG pipeline.
* **LangSmith** — provides tracing and monitoring for the LangGraph/LLM workflow.
* **Python 3.11+** — required for the FastAPI backend and RAG stack.
* **Node.js / Next.js** — required for the frontend.
* **faster-whisper** — provides local speech-to-text functionality when voice input is enabled.

### Deployment Dependencies

**Railway**

[Railway Documentation](https://docs.railway.com/?utm_source=chatgpt.com)

Railway supports deploying separate services from an isolated monorepo by configuring each service's root directory. For this project, the backend and frontend can be deployed independently from the same repository.

**PostgreSQL**

[Railway PostgreSQL Documentation](https://docs.railway.com/databases/postgresql?utm_source=chatgpt.com)

Railway provides PostgreSQL with connection variables including `DATABASE_URL`, `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD`, and `PGDATABASE`.

**Qdrant Cloud**

[Qdrant Cloud Documentation](https://qdrant.tech/documentation/cloud/?utm_source=chatgpt.com)

The application uses Qdrant Cloud as its managed vector database. Create a Qdrant cluster and configure its URL and API key as backend environment variables.

**Groq**

[Groq API Documentation](https://console.groq.com/docs/api-reference?utm_source=chatgpt.com)

The backend uses Groq for LLM inference through the application's LangChain/LangGraph agent workflow.

### Implementation Details

The repository is structured as an isolated full-stack monorepo:

```text
hamid7242-pakistan-legal-assistant-rag/
├── app.py
├── requirements.txt
├── backend/
│   ├── agents/
│   ├── api/
│   ├── core/
│   ├── persistence/
│   ├── rag/
│   ├── utils/
│   └── voice/
└── frontend/
    ├── package.json
    ├── next.config.mjs
    └── app/
```

Deploy the backend and frontend as separate Railway services.

**Backend**

```text
Root Directory: /
Build: pip install -r requirements.txt
Start: uvicorn app:app --host 0.0.0.0 --port $PORT
```

**Frontend**

```text
Root Directory: /frontend
Build: npm run build
Start: npm run start
```

Railway supports root-directory configuration for isolated monorepos, allowing the frontend and backend to be deployed as separate services from the same repository.

Connect the backend to Railway PostgreSQL using a Railway reference variable:

```text
DATABASE_URL=${{Postgres.DATABASE_URL}}
```

Railway reference variables allow one service to consume variables from another service, and PostgreSQL exposes `DATABASE_URL` automatically.

The frontend should use the public backend domain as its API endpoint. Railway provides `RAILWAY_PUBLIC_DOMAIN` for deployed services, which can be used when constructing service-to-service configuration.

The backend should listen on Railway's dynamically assigned `$PORT`:

```bash
uvicorn app:app --host 0.0.0.0 --port $PORT
```

Railway automatically builds and deploys repository-based services and starts them using the detected or configured start command.

For the voice-enabled deployment, the backend may require system dependencies for `faster-whisper`/PyAV. A Dockerfile can be used when those native multimedia dependencies are required.

## Why Deploy Pakistan-Legal-Assistant-RAG on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Pakistan-Legal-Assistant-RAG on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

Railway's service model supports application services, databases, environment variables, deployments, and monorepo configurations in the same project.


## Similar templates

- [Rocky Linux](https://railway.com/deploy/rocky-linux) — [Jul'26] Hosted Rocky Linux 9 workspace with SSH and persistent storage. 🚀
- [Foundry Virtual Tabletop](https://railway.com/deploy/X5tR6G) — A Self-Hosted & Modern Roleplaying Platform
- [Letta Code Remote](https://railway.com/deploy/letta-code-remote) — Run a Letta Code agent 24/7. No inbound ports, just deploy.

Open this page in a browser: https://railway.com/deploy/pakistan-legal-assistant-rag
