This is the backend system for CIVIS AI Policy Document Analysis — built with FastAPI, SQLAlchemy, Alembic, and modern tooling using uv
for dependency management.
Make sure Python 3.10+ is installed.
Install uv
(package manager + virtualenv):
curl -LsSf https://astral.sh/uv/install.sh | sh
Install WeasyPrint WeasyPrint depends on some system libraries to render fonts, images, and CSS properly.
brew install cairo pango gdk-pixbuf libffi
git clone https://github.com/civis-vote/draft-analyzer-be.git
cd civis-backend-policy-analyser
Create a .env file
# example .env
# Database settings
DB_USER=username
DB_PASSWORD=password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=db-name
# Azure DeepSeek settings
AZURE_DEEPSEEK_API_KEY=your-api-key
AZURE_DEEPSEEK_ENDPOINT=https://your-resource.endpoint
AZURE_DEEPSEEK_MODEL=your-model-name
AZURE_DEEPSEEK_DEPLOYMENT_NAME=your-deployment-name
AZURE_OPENAI_API_VERSION=your-api-version
LLM_CLIENT=ollama
make setup
This will:
- Create
.venv
- Install base + AI + test dependencies
- Lock dependencies
- Generate
requirements.txt
make run
Visit:
- Swagger UI: http://localhost:8000/api/docs
- ReDoc: http://localhost:8000/redoc
make test
make cov
make lint
make fix
make db-build
make db-up
- Initialize alembic (first time only):
alembic init -t async src/civis_backend_policy_analyser/alembic
- Create a revision:
alembic revision --autogenerate -m "Initial schema"
- Apply migration:
alembic upgrade head
make db-logs # View logs
make db-psql # Open psql shell
make db-down # Stop and remove container
make seed
This runs seed_data.py
inside the virtual environment.
.
├── src/
│ └── civis_backend_policy_analyser/
│ ├── alembic/ # Alembic migrations
│ ├── api/ # FastAPI routes (entrypoints, routers)
│ ├── core/ # App config, DB setup, constants
│ ├── model/ # SQLAlchemy ORM models
│ ├── schemas/ # Pydantic schemas (request/response)
│ ├── utils/ # Helper functions, formatters, etc.
│ ├── views/ # Route logic (e.g., CRUD handlers)
│ └── __init__.py
├── pyproject.toml # Dependency & build config
├── Makefile # Task automation
├── requirements.txt # (auto-generated by uv)
├── seed_data.py # DB seeding script
└── README.md # Project documentation
uv
manages dependencies viapyproject.toml
with groups:[project]
,ai
,test
.- No manual activation of
.venv
is required when usinguv run
. - Prefer
make
targets for consistent workflows. make setup
is the fastest way to bootstrap everything from scratch.make quick-start
is for the quick start with sample data in database if docker running in local.
Command | Action |
---|---|
make quick-start |
Start full application with sample data |
make setup |
Full setup: venv + deps + lock + freeze |
make run |
Start FastAPI app |
make lint |
Run linter |
make fix |
Auto-fix lint issues |
make test |
Run unit tests |
make cov |
Run tests with coverage |
make revision |
Create alembic schema as per models |
make seed |
Seed initial data |
make db-up |
Start DB container |
make db-down |
Stop DB container |
make db-psql |
Open DB shell inside container |