# eshaanpra/grantops architecture

> Architecture diagram of the GitHub repository eshaanpra/grantops, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/eshaanpra/grantops
- Repository: https://github.com/eshaanpra/grantops

## Overview

##### Request path from UI to backend
The web app renders the user-facing workflows for grants, matches, pipeline, review, organization analysis, and workspaces. UI components call the API through a small client layer in `apps/web/lib/api.ts`, and most pages map directly to major product areas such as `/grants`, `/matches`, `/pipeline`, `/review`, `/organization`, and `/workspaces/{id}`.

##### API layer and domain boundaries
The FastAPI app exposes versioned endpoints under `apps/api/app/api/v1`. These endpoints are grouped by domain: auth, dashboard, grants, grantors, IRS 990, matches, orgs, pipeline, review, snapshots, sources, workspaces, and applicants. This is the main synchronous boundary for reads, writes, and action-triggered state changes.

##### Core business services
The API is structured around a service layer in `apps/api/app/services` rather than placing logic in endpoints. Key service clusters include:
- **Ingestion** for external data collection and source discovery
- **Matching** for grant-to-organization fit evaluation
- **Parsing / extraction** for turning documents into structured evidence
- **Organization model analysis** for uploaded org documents and boilerplate support
- **Grant summaries** and **grantor verification** for opportunity normalization and validation
- **Audit** and **applicant profile** support for workflow history and org profile data

##### Data model and persistence
The backend uses a relational database with Alembic migrations in `apps/api/alembic`. Models are split by domain in `apps/api/app/models` and include grants, applicants, IRS 990 data, matching, pipeline, sources, tenancy/workspaces, and shared enums/mixins. The presence of versioned migrations shows the schema is a first-class part of the architecture, with multi-step evolution already tracked.

##### Asynchronous processing
Background work is handled by Celery. The worker package contains tasks for ingestion, matching, applicant processing, and alerts. Redis is the broker/result backend in the default local stack, and Celery beat schedules recurring jobs such as IRS 990 intelligence refresh. This is the main async boundary between user actions and slow or periodic processing.

##### External data ingestion pipeline
A major subsystem ingests grant-related data from external/public sources. The repository includes adapters and registry logic for sources like **Grants.gov** and **SAM assistance**, plus IRS 990 ingestion and non-government source handling. Discovery logic promotes credible funders and then searches for official grant pages. This ingestion pipeline feeds the grant/source tables and downstream matching and review flows.

##### Document parsing and extraction
Uploaded or fetched documents pass through parsing and extraction services. There are dedicated PDF and HTML parsers, plus normalization and rule-based extraction components. This supports evidence-backed claim generation, confidence-aware review, and snapshot/history behavior rather than treating extracted text as raw blobs.

##### Organization analysis and local model integration
Organization document analysis is a specialized flow used by the `/organization` area. The repo explicitly supports a local LLM runtime via **Docker Model Runner** and a configurable model URL. Uploaded evidence documents are analyzed asynchronously, and the model produces concise evidence bullets while the human-edited boilerplate remains separate and user-owned.

##### Storage and identity backends
The system is designed with pluggable infrastructure. Auth can run either through a local JWT flow or **Supabase Auth**, while storage can use **S3/MinIO** or **Supabase Storage**. The API enforces org-level RBAC regardless of auth provider, using membership data in the application database.

##### Workspace and pipeline workflow
The product’s operational core is the grant-writing workspace and pipeline. Users start from matches or grants, create a reusable workspace for an organization/grant pair, then manage tasks, drafts, budget, attachments, review, submission, and award states. Pipeline stages are action-driven and can be moved by explicit workflow events like eligibility checks, sending to review, approving, submitting, or archiving.

##### Frontend stateful surfaces
The web app is not just a static viewer; it contains interactive surfaces for dashboard summaries, match triage, pipeline drag/drop, review queues, workspace detail views, rich text editing, and source monitoring. Several components have tests alongside them, suggesting the frontend includes meaningful client-side business logic.

##### Infrastructure and deployment
Local development uses Docker Compose with separate containers for API, web, worker, scheduler, Postgres, Redis, and MinIO. Production supports both **Supabase-backed** and **AWS ECS/Terraform-backed** deployments. The infra folder also includes bootstrap state setup, Dockerfiles for each app, and seed scripts for curated non-government grant data.

##### Testing and quality boundaries
The repository includes backend E2E and service tests, frontend component tests, and CI workflows. That indicates the key architecture boundaries are enforced at multiple layers: API contracts, matching/extraction logic, ingestion adapters, and UI behavior.

Main entry points: [`apps/api/app/services`](https://github.com/eshaanpra/grantops/tree/main/apps/api/app/services) (Services), [`apps/worker/tasks`](https://github.com/eshaanpra/grantops/tree/main/apps/worker/tasks) (Worker tasks), [`apps/api/app/api/v1`](https://github.com/eshaanpra/grantops/tree/main/apps/api/app/api/v1) (API routes), [`apps/api/app/core`](https://github.com/eshaanpra/grantops/tree/main/apps/api/app/core) (Core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_apps["Runtime apps"]
end

subgraph group_api["API backend"]
  node_api_router["API routes<br/>FastAPI v1"]
  node_api_services["Services<br/>Domain logic"]
  node_api_models["Models<br/>ORM domain"]
  node_api_schema["Schemas<br/>Pydantic contracts"]
  node_api_core["Core<br/>Config & security"]
  node_api_db[("Database<br/>Postgres")]
  node_ingestion["Ingestion<br/>Source adapters"]
  node_matching{{"Matching<br/>Scoring engine<br/>[matching.py]"}}
  node_parsing["Parsing<br/>Document parsers"]
  node_org_analysis["Org analysis<br/>LLM workflow"]
  node_granting["Grant logic<br/>Normalization<br/>[grant_summaries.py]"]
  node_task_queue["Task queue<br/>Celery bridge<br/>[task_queue.py]"]
end

subgraph group_web["Web frontend"]
  node_web_app["Web app<br/>Next.js UI"]
  node_web_client["API client<br/>HTTP client<br/>[api.ts]"]
  node_web_components["UI flows<br/>Interactive components"]
end

subgraph group_worker["Async jobs"]
  node_worker_app["Worker app<br/>Celery runtime<br/>[worker_app.py]"]
  node_worker_tasks["Worker tasks<br/>Async jobs"]
end

subgraph group_infra["Infrastructure"]
  node_docker["Docker stack<br/>Local runtime<br/>[docker-compose.yml]"]
  node_terraform["Terraform<br/>AWS deploy"]
end

subgraph group_shared["Shared code"]
  node_shared_types["Shared types<br/>TS/Python contracts"]
  node_shared_ui["UI primitives<br/>Design system"]
end

node_web_app -->|"calls"| node_web_client
node_web_components -->|"fetches"| node_web_client
node_web_app -->|"uses"| node_api_router
node_api_router -->|"delegates"| node_api_services
node_api_services -->|"reads/writes"| node_api_models
node_api_services -->|"shapes"| node_api_schema
node_api_core -->|"wires"| node_api_router
node_api_core -->|"connects"| node_api_db
node_ingestion -->|"loads"| node_api_models
node_matching -->|"scores"| node_api_models
node_parsing -->|"feeds"| node_api_services
node_org_analysis -->|"consumes"| node_parsing
node_granting -->|"supports"| node_api_services
node_api_services -->|"enqueues"| node_task_queue
node_worker_app -->|"runs"| node_worker_tasks
node_worker_tasks -->|"consumes"| node_task_queue
node_worker_tasks -->|"executes"| node_ingestion
node_worker_tasks -->|"executes"| node_matching
node_worker_tasks -->|"invokes"| node_api_services
node_web_components -->|"composes"| node_shared_ui
node_api_router -->|"aligns"| node_shared_types
node_web_client -->|"types"| node_shared_types
node_docker -->|"packages"| node_web_app
node_docker -->|"packages"| node_api_core
node_docker -->|"packages"| node_worker_app
node_terraform -->|"deploys"| node_api_core
node_terraform -->|"deploys"| node_web_app

click node_web_app "https://github.com/eshaanpra/grantops/tree/main/apps/web/app"
click node_web_client "https://github.com/eshaanpra/grantops/blob/main/apps/web/lib/api.ts"
click node_web_components "https://github.com/eshaanpra/grantops/tree/main/apps/web/components"
click node_api_router "https://github.com/eshaanpra/grantops/tree/main/apps/api/app/api/v1"
click node_api_services "https://github.com/eshaanpra/grantops/tree/main/apps/api/app/services"
click node_api_models "https://github.com/eshaanpra/grantops/tree/main/apps/api/app/models"
click node_api_schema "https://github.com/eshaanpra/grantops/tree/main/apps/api/app/schemas"
click node_api_core "https://github.com/eshaanpra/grantops/tree/main/apps/api/app/core"
click node_api_db "https://github.com/eshaanpra/grantops/tree/main/apps/api/alembic"
click node_ingestion "https://github.com/eshaanpra/grantops/tree/main/apps/api/app/services/ingestion"
click node_matching "https://github.com/eshaanpra/grantops/blob/main/apps/api/app/services/matching.py"
click node_parsing "https://github.com/eshaanpra/grantops/tree/main/apps/api/app/services/parsing"
click node_org_analysis "https://github.com/eshaanpra/grantops/blob/main/apps/api/app/services/organization_model_analysis.py"
click node_granting "https://github.com/eshaanpra/grantops/blob/main/apps/api/app/services/grant_summaries.py"
click node_task_queue "https://github.com/eshaanpra/grantops/blob/main/apps/api/app/services/task_queue.py"
click node_worker_app "https://github.com/eshaanpra/grantops/blob/main/apps/worker/worker_app.py"
click node_worker_tasks "https://github.com/eshaanpra/grantops/tree/main/apps/worker/tasks"
click node_shared_types "https://github.com/eshaanpra/grantops/tree/main/packages/shared/src"
click node_shared_ui "https://github.com/eshaanpra/grantops/tree/main/packages/ui/src"
click node_docker "https://github.com/eshaanpra/grantops/blob/main/infra/docker/docker-compose.yml"
click node_terraform "https://github.com/eshaanpra/grantops/tree/main/infra/aws/terraform"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_router,node_api_services,node_api_models,node_api_schema,node_api_core,node_api_db,node_ingestion,node_matching,node_parsing,node_org_analysis,node_granting,node_task_queue toneAmber
class node_web_app,node_web_client,node_web_components toneMint
class node_worker_app,node_worker_tasks toneRose
class node_docker,node_terraform toneIndigo
class node_shared_types,node_shared_ui toneTeal
```

## Components

### API backend

FastAPI app, domain services, and persistence

- [API routes](https://github.com/eshaanpra/grantops/tree/main/apps/api/app/api/v1): FastAPI v1 · Versioned domain endpoints for auth, grants, matches, pipeline, review, workspaces, and related resources · `apps/api/app/api/v1`
- [Services](https://github.com/eshaanpra/grantops/tree/main/apps/api/app/services): Domain logic · Business logic for ingestion, matching, extraction, summaries, analysis, and audit · `apps/api/app/services`
- [Models](https://github.com/eshaanpra/grantops/tree/main/apps/api/app/models): ORM domain · Database models for grants, applicants, IRS 990, matching, pipeline, sources, tenancy, and workspaces · `apps/api/app/models`
- [Schemas](https://github.com/eshaanpra/grantops/tree/main/apps/api/app/schemas): Pydantic contracts · Request and response shapes shared across API domains · `apps/api/app/schemas`
- [Core](https://github.com/eshaanpra/grantops/tree/main/apps/api/app/core): Config & security · Application config, logging, security, dependencies, and DB session wiring · `apps/api/app/core`
- [Database](https://github.com/eshaanpra/grantops/tree/main/apps/api/alembic): Postgres · Relational persistence and Alembic-managed schema evolution · `apps/api/alembic`
- [Ingestion](https://github.com/eshaanpra/grantops/tree/main/apps/api/app/services/ingestion): Source adapters · Grant-source discovery and adapters for public and non-government data · `apps/api/app/services/ingestion`
- [Matching](https://github.com/eshaanpra/grantops/blob/main/apps/api/app/services/matching.py): Scoring engine · Grant-to-organization fit and match evaluation · `apps/api/app/services/matching.py`
- [Parsing](https://github.com/eshaanpra/grantops/tree/main/apps/api/app/services/parsing): Document parsers · PDF and HTML parsing plus normalization and extraction rules · `apps/api/app/services/parsing`
- [Org analysis](https://github.com/eshaanpra/grantops/blob/main/apps/api/app/services/organization_model_analysis.py): LLM workflow · Organization document analysis and evidence bullet generation · `apps/api/app/services/organization_model_analysis.py`
- [Grant logic](https://github.com/eshaanpra/grantops/blob/main/apps/api/app/services/grant_summaries.py): Normalization · Grant summaries, grantor verification, and enrichment helpers · `apps/api/app/services/grant_summaries.py`
- [Task queue](https://github.com/eshaanpra/grantops/blob/main/apps/api/app/services/task_queue.py): Celery bridge · Dispatch boundary for background and scheduled jobs · `apps/api/app/services/task_queue.py`

### Web frontend

Next.js user workflows and client state

- [Web app](https://github.com/eshaanpra/grantops/tree/main/apps/web/app): Next.js UI · User-facing grant, workspace, review, and dashboard screens · `apps/web/app`
- [API client](https://github.com/eshaanpra/grantops/blob/main/apps/web/lib/api.ts): HTTP client · Small client layer used by frontend pages and components · `apps/web/lib/api.ts`
- [UI flows](https://github.com/eshaanpra/grantops/tree/main/apps/web/components): Interactive components · Dashboard, matches, pipeline, review, and workspace components · `apps/web/components`

### Async jobs

Celery tasks and scheduled processing

- [Worker app](https://github.com/eshaanpra/grantops/blob/main/apps/worker/worker_app.py): Celery runtime · Background worker and beat scheduler entrypoint · `apps/worker/worker_app.py`
- [Worker tasks](https://github.com/eshaanpra/grantops/tree/main/apps/worker/tasks): Async jobs · Ingestion, matching, applicant, and alert tasks · `apps/worker/tasks`

### Infrastructure

Docker, Terraform, and local bootstrap

- [Docker stack](https://github.com/eshaanpra/grantops/blob/main/infra/docker/docker-compose.yml): Local runtime · Compose setup and service containers for API, web, worker, Postgres, Redis, and MinIO · `infra/docker/docker-compose.yml`
- [Terraform](https://github.com/eshaanpra/grantops/tree/main/infra/aws/terraform): AWS deploy · Production infrastructure and bootstrap state for cloud deployment · `infra/aws/terraform`

### Shared code

Cross-package shared types and UI

- [Shared types](https://github.com/eshaanpra/grantops/tree/main/packages/shared/src): TS/Python contracts · Generated and shared type definitions used across packages · `packages/shared/src`
- [UI primitives](https://github.com/eshaanpra/grantops/tree/main/packages/ui/src): Design system · Reusable shared UI components · `packages/ui/src`

## Connections

- Web app → API client: calls · Pages use the frontend API client for backend requests
- UI flows → API client: fetches · Interactive views load and mutate data through the client layer
- Web app → API routes: uses · User workflows are backed by versioned API endpoints
- API routes → Services: delegates · Endpoints hand off business logic to services
- Services → Models: reads/writes · Services coordinate domain state via ORM models
- Services → Schemas: shapes · Services and routes exchange typed contracts
- Core → API routes: wires · Core config and dependencies assemble the API surface
- Core → Database: connects · Database sessions and migrations support persistence
- Ingestion → Models: loads · Ingestion populates grant and source tables
- Matching → Models: scores · Match scoring uses grant, applicant, and workspace data
- Parsing → Services: feeds · Parsed text and normalized evidence flow into service logic
- Org analysis → Parsing: consumes · Org analysis builds on extracted document content
- Grant logic → Services: supports · Grant normalization and verification support API workflows
- Services → Task queue: enqueues · Long-running work is handed to background jobs
- Worker app → Worker tasks: runs · Celery runtime executes task modules
- Worker tasks → Task queue: consumes · Tasks are scheduled and dispatched through the queue boundary
- Worker tasks → Ingestion: executes · Background jobs perform source ingestion and refreshes
- Worker tasks → Matching: executes · Worker processes run matching and scoring jobs
- Worker tasks → Services: invokes · Tasks reuse backend services for applicant and alert workflows
- UI flows → UI primitives: composes · Frontend screens are built from shared UI primitives
- API routes → Shared types: aligns · Backend contracts are mirrored in shared types
- API client → Shared types: types · The frontend client consumes shared API shapes
- Docker stack → Web app: packages · Compose brings up the web runtime
- Docker stack → Core: packages · Compose brings up the API runtime
- Docker stack → Worker app: packages · Compose brings up worker and scheduler services
- Terraform → Core: deploys · Cloud infrastructure targets the API stack
- Terraform → Web app: deploys · Cloud infrastructure targets the frontend stack
