# sagargwal/agenthire architecture

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

- Interactive diagram: https://gitdiagram.com/sagargwal/agenthire
- Repository: https://github.com/sagargwal/agenthire

## Overview

AgentHire is a FastAPI backend for company-aware job-description drafting and publishing. A recruiter authenticates, opens a chat session, and sends requests through the JD-builder API; a LangGraph agent gathers company and historical-JD context, presents it for confirmation, drafts and sanitizes a JD, then pauses for approval before publishing. Supporting branches provide authentication and public career-page reads. The README documents integrations and workflow stages not fully visible in the sampled source; the frontend and employee knowledge-entry workflow are not present in this tree.

Main entry points: [`backend/app/agents/jd_builder/tools.py`](https://github.com/sagargwal/agenthire/blob/master/backend/app/agents/jd_builder/tools.py) (Context and drafting tools), [`backend/app/routers/auth.py`](https://github.com/sagargwal/agenthire/blob/master/backend/app/routers/auth.py) (Auth endpoints), [`backend/app/routers/jd_builder.py`](https://github.com/sagargwal/agenthire/blob/master/backend/app/routers/jd_builder.py) (JD chat API), [`backend/app/agents/jd_builder/graph.py`](https://github.com/sagargwal/agenthire/blob/master/backend/app/agents/jd_builder/graph.py) (Conversation graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_main["FastAPI app<br/>[main.py]"]
  node_auth_routes["Auth endpoints<br/>[auth.py]"]
  node_security["Token security<br/>[security.py]"]
  node_auth_guard["Auth dependency<br/>[auth_dependency.py]"]
  node_jd_api["JD chat API<br/>[jd_builder.py]"]
  node_careers_api["Careers endpoints<br/>[careers.py]"]
end

subgraph group_agent["JD agent workflow"]
  node_agent_graph["Conversation graph<br/>[graph.py]"]
  node_agent_state["Conversation state<br/>[state.py]"]
  node_agent_tools["Context and drafting tools<br/>[tools.py]"]
end

subgraph group_data["Company and JD data"]
  node_mysql_session["MySQL sessions<br/>[database.py]"]
  node_user_model["User accounts<br/>[user.py]"]
  node_refresh_model["Refresh tokens<br/>[refresh_token.py]"]
  node_pg_session["PostgreSQL sessions<br/>[postgres_db.py]"]
  node_company_model["Company knowledge model<br/>[nexus_company.py]"]
  node_posted_jds[("Published JD records<br/>[nexus_company.py]")]
end

subgraph group_integrations["External services"]
  node_redis[("Redis memory")]
  node_elasticsearch[("Historical JD search")]
  node_openai["GPT-4o"]
end

node_recruiter(("Recruiter"))
node_hr_approval(("HR approval"))
node_careers_page(("Careers page"))

node_main -->|"registers routes"| node_auth_routes
node_main -->|"registers routes"| node_jd_api
node_main -->|"registers routes"| node_careers_api
node_auth_routes -->|"queries accounts"| node_mysql_session
node_auth_routes -->|"reads and writes"| node_user_model
node_auth_routes -->|"stores tokens"| node_refresh_model
node_auth_routes -->|"creates tokens"| node_security
node_auth_guard -->|"decodes token"| node_security
node_jd_api -->|"requires identity"| node_auth_guard
node_jd_api -->|"checks usage"| node_mysql_session
node_jd_api -->|"checks account"| node_user_model
node_jd_api -->|"invokes conversation"| node_agent_graph
node_agent_graph -->|"uses state"| node_agent_state
node_agent_graph -->|"dispatches tools"| node_agent_tools
node_agent_graph -->|"persists sessions"| node_redis
node_agent_tools -->|"queries company data"| node_pg_session
node_agent_tools -->|"uses company schema"| node_company_model
node_agent_tools -->|"searches precedent"| node_elasticsearch
node_agent_tools -->|"generates JD text"| node_openai
node_agent_tools -->|"saves publication"| node_posted_jds
node_agent_tools -->|"pauses for approval"| node_hr_approval
node_careers_api -->|"reads career data"| node_pg_session
node_careers_api -->|"uses company schema"| node_company_model
node_careers_api -->|"serves listings"| node_careers_page
node_hr_approval -.->|"resumes chat"| node_agent_graph

click node_main "https://github.com/sagargwal/agenthire/blob/master/backend/main.py"
click node_auth_routes "https://github.com/sagargwal/agenthire/blob/master/backend/app/routers/auth.py"
click node_security "https://github.com/sagargwal/agenthire/blob/master/backend/app/core/security.py"
click node_auth_guard "https://github.com/sagargwal/agenthire/blob/master/backend/app/core/auth_dependency.py"
click node_mysql_session "https://github.com/sagargwal/agenthire/blob/master/backend/app/core/database.py"
click node_user_model "https://github.com/sagargwal/agenthire/blob/master/backend/app/models/user.py"
click node_refresh_model "https://github.com/sagargwal/agenthire/blob/master/backend/app/models/refresh_token.py"
click node_jd_api "https://github.com/sagargwal/agenthire/blob/master/backend/app/routers/jd_builder.py"
click node_agent_graph "https://github.com/sagargwal/agenthire/blob/master/backend/app/agents/jd_builder/graph.py"
click node_agent_state "https://github.com/sagargwal/agenthire/blob/master/backend/app/agents/jd_builder/state.py"
click node_agent_tools "https://github.com/sagargwal/agenthire/blob/master/backend/app/agents/jd_builder/tools.py"
click node_pg_session "https://github.com/sagargwal/agenthire/blob/master/backend/app/core/postgres_db.py"
click node_company_model "https://github.com/sagargwal/agenthire/blob/master/backend/app/models/nexus_company.py"
click node_posted_jds "https://github.com/sagargwal/agenthire/blob/master/backend/app/models/nexus_company.py"
click node_careers_api "https://github.com/sagargwal/agenthire/blob/master/backend/app/routers/careers.py"

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_main,node_auth_routes,node_security,node_auth_guard,node_jd_api,node_careers_api toneBlue
class node_agent_graph,node_agent_state,node_agent_tools toneAmber
class node_mysql_session,node_user_model,node_refresh_model,node_pg_session,node_company_model,node_posted_jds toneMint
class node_redis,node_elasticsearch,node_openai toneRose
class node_recruiter,node_hr_approval,node_careers_page toneIndigo
```

## Components

### API and identity

- [FastAPI app](https://github.com/sagargwal/agenthire/blob/master/backend/main.py): `backend/main.py`
- [Auth endpoints](https://github.com/sagargwal/agenthire/blob/master/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Token security](https://github.com/sagargwal/agenthire/blob/master/backend/app/core/security.py): `backend/app/core/security.py`
- [Auth dependency](https://github.com/sagargwal/agenthire/blob/master/backend/app/core/auth_dependency.py): `backend/app/core/auth_dependency.py`
- [JD chat API](https://github.com/sagargwal/agenthire/blob/master/backend/app/routers/jd_builder.py): `backend/app/routers/jd_builder.py`
- [Careers endpoints](https://github.com/sagargwal/agenthire/blob/master/backend/app/routers/careers.py): `backend/app/routers/careers.py`

### JD agent workflow

- [Conversation graph](https://github.com/sagargwal/agenthire/blob/master/backend/app/agents/jd_builder/graph.py): `backend/app/agents/jd_builder/graph.py`
- [Conversation state](https://github.com/sagargwal/agenthire/blob/master/backend/app/agents/jd_builder/state.py): `backend/app/agents/jd_builder/state.py`
- [Context and drafting tools](https://github.com/sagargwal/agenthire/blob/master/backend/app/agents/jd_builder/tools.py): `backend/app/agents/jd_builder/tools.py`

### Company and JD data

- [MySQL sessions](https://github.com/sagargwal/agenthire/blob/master/backend/app/core/database.py): `backend/app/core/database.py`
- [User accounts](https://github.com/sagargwal/agenthire/blob/master/backend/app/models/user.py): `backend/app/models/user.py`
- [Refresh tokens](https://github.com/sagargwal/agenthire/blob/master/backend/app/models/refresh_token.py): `backend/app/models/refresh_token.py`
- [PostgreSQL sessions](https://github.com/sagargwal/agenthire/blob/master/backend/app/core/postgres_db.py): `backend/app/core/postgres_db.py`
- [Company knowledge model](https://github.com/sagargwal/agenthire/blob/master/backend/app/models/nexus_company.py): `backend/app/models/nexus_company.py`
- [Published JD records](https://github.com/sagargwal/agenthire/blob/master/backend/app/models/nexus_company.py): `backend/app/models/nexus_company.py`

### External services

- **Redis memory**
- **Historical JD search**
- **GPT-4o**

### Other components

- **Recruiter**
- **HR approval**
- **Careers page**

## Connections

- FastAPI app → Auth endpoints: registers routes (evidence: `backend/main.py`)
- FastAPI app → JD chat API: registers routes (evidence: `backend/main.py`)
- FastAPI app → Careers endpoints: registers routes (evidence: `backend/main.py`)
- Auth endpoints → MySQL sessions: queries accounts (evidence: `backend/app/routers/auth.py`)
- Auth endpoints → User accounts: reads and writes (evidence: `backend/app/routers/auth.py`)
- Auth endpoints → Refresh tokens: stores tokens (evidence: `backend/app/routers/auth.py`)
- Auth endpoints → Token security: creates tokens (evidence: `backend/app/routers/auth.py`)
- Auth dependency → Token security: decodes token (evidence: `backend/app/core/auth_dependency.py`)
- JD chat API → Auth dependency: requires identity (evidence: `backend/app/routers/jd_builder.py`)
- JD chat API → MySQL sessions: checks usage (evidence: `backend/app/routers/jd_builder.py`)
- JD chat API → User accounts: checks account (evidence: `backend/app/routers/jd_builder.py`)
- JD chat API → Conversation graph: invokes conversation (evidence: `backend/app/routers/jd_builder.py`)
- Conversation graph → Conversation state: uses state (evidence: `backend/app/agents/jd_builder/graph.py`)
- Conversation graph → Context and drafting tools: dispatches tools (evidence: `backend/app/agents/jd_builder/graph.py`)
- Conversation graph → Redis memory: persists sessions (evidence: `README.md`)
- Context and drafting tools → PostgreSQL sessions: queries company data (evidence: `backend/app/agents/jd_builder/tools.py`)
- Context and drafting tools → Company knowledge model: uses company schema (evidence: `backend/app/agents/jd_builder/tools.py`)
- Context and drafting tools → Historical JD search: searches precedent (evidence: `README.md`)
- Context and drafting tools → GPT-4o: generates JD text (evidence: `backend/app/agents/jd_builder/tools.py`)
- Context and drafting tools → Published JD records: saves publication (evidence: `backend/app/agents/jd_builder/tools.py`)
- Context and drafting tools → HR approval: pauses for approval (evidence: `README.md`)
- Careers endpoints → PostgreSQL sessions: reads career data (evidence: `backend/app/routers/careers.py`)
- Careers endpoints → Company knowledge model: uses company schema (evidence: `backend/app/routers/careers.py`)
- Careers endpoints → Careers page: serves listings (evidence: `README.md`)
- HR approval → Conversation graph: resumes chat
