# wp113department-cell/multi-agent-company architecture

> Architecture diagram of the GitHub repository wp113department-cell/multi-agent-company, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/wp113department-cell/multi-agent-company
- Repository: https://github.com/wp113department-cell/multi-agent-company

## Overview

#### Purpose and Entry Points
Gridiron is an autonomous multi-agent software-engineering platform: it accepts repository-scoped goals, plans and decomposes work, dispatches specialist agents, enforces safety/approval gates, and returns verified artifacts. The service entry point is FastAPI at `backend/app/main.py`; the operator UI is a Next.js App Router app rooted at `apps/web/app/layout.tsx` and `apps/web/app/page.tsx`. HTTP APIs are organized under `backend/app/api/`.

#### Client and API Boundary
The TypeScript frontend provides task, fleet, approval, repository, chat, metrics, and review consoles. It calls the backend through the API client and protects browser routes via its auth/middleware layer.
- `apps/web/lib/api.ts`
- `apps/web/middleware.ts`
- `apps/web/app/tasks/[id]/page.tsx`

Backend routers expose the corresponding control-plane resources: tasks, goals/epics, agent fleet, approvals, streaming chat, artifacts, settings, and repository management.
- `backend/app/api/tasks.py`
- `backend/app/api/specialized_agents.py`
- `backend/app/api/chat.py`

#### Orchestration Pipeline
The central execution flow is a stateful graph: input task → bootstrap/context → planning stages (PM, architect, decomposer) → dependency-aware dispatch → manager-led implementation, QA, and review. Pipeline state, concurrency, conflict checks, cost control, and queue abstraction isolate orchestration policy from individual agents.
- `backend/app/pipeline/graph.py`
- `backend/app/pipeline/dispatcher.py`
- `backend/app/pipeline/state.py`

Agents share base/graph contracts; individual roles are implemented in Python and paired with role prompt documents. This supports both core pipeline agents and directly invokable specialists.
- `backend/app/agents/base.py`
- `backend/app/agents/base_graph.py`
- `backend/roles/manager.md`

#### Fleet Governance and Execution Controls
The fleet layer selects capable agents/models, tracks budgets, checkpoints, metrics, events, audit records, failures, and approval requirements. It is the control boundary around execution rather than merely an agent catalog.
- `backend/app/fleet/fleet_manager.py`
- `backend/app/fleet/agent_registry.py`
- `backend/app/fleet/approval_gate.py`

Model providers are routed through the fleet, with Anthropic expected by default and Groq compatibility present.
- `backend/app/fleet/model_router.py`
- `backend/app/agents/groq_adapter.py`

#### Repository Intelligence, Worktrees, and Safety
Agents inspect and modify target repositories through repository tools: scanning/AST and cross-file analysis build context; git worktrees isolate changes. Policy engines and sandboxing guard commands and file mutations; RBAC and encrypted credential storage enforce access boundaries.
- `backend/app/repo_tools/context_builder.py`
- `backend/app/repo_tools/worktree.py`
- `backend/app/policy/engine_v2.py`
- `backend/app/policy/sandbox.py`
- `backend/app/security/credential_vault.py`

Destructive operations and publish-like actions are routed through approval gates rather than trusted model decisions.

#### Persistence, Memory, and Eventing
PostgreSQL is the primary durable store, managed with SQLAlchemy-style models/repositories and Alembic migrations. Project-scoped engineering memory supports retrieval, lifecycle/analytics, and embeddings. Artifacts abstract database versus S3 storage. Runtime activity is emitted through an in-process/Redis Streams event bus; execution can use asyncio or RQ/Redis queues.
- `backend/app/db/models.py`
- `backend/app/memory/store.py`
- `backend/app/event_bus/bus.py`
- `backend/app/event_bus/redis_streams.py`
- `backend/app/artifacts/s3_store.py`

#### Runtime and Infrastructure
Backend requires Python 3.11+, FastAPI, PostgreSQL 16 with pgvector, and Docker for isolated high-risk command execution. Redis is optional for RQ and Redis Streams; S3 is optional for artifacts; Voyage AI may supply embeddings; Sentry and alert webhooks are optional observability integrations. The frontend runs on Node 20+ / pnpm and is deployable separately; Docker Compose coordinates local dependencies.
- `backend/Dockerfile`
- `apps/web/Dockerfile`
- `docker-compose.yml`
- `backend/migrations/versions/001_initial_schema.py`

Main entry points: [`backend/app/fleet/fleet_manager.py`](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/fleet/fleet_manager.py) (Fleet manager), [`backend/app/api/tasks.py`](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/api/tasks.py) (Control-plane routers), [`backend/app/pipeline/graph.py`](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/pipeline/graph.py) (Execution graph), [`backend/app/fleet/approval_gate.py`](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/fleet/approval_gate.py) (Approval gate)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Operator Client"]
  node_web_ui["Next.js operator UI<br/>web app<br/>[layout.tsx]"]
  node_web_auth["Route auth middleware<br/>[middleware.ts]"]
  node_api_client["Backend API client<br/>TypeScript client<br/>[api.ts]"]
end

subgraph group_control["Control Plane"]
  node_fastapi["FastAPI service<br/>API entrypoint<br/>[main.py]"]
  node_api_routers["Control-plane routers<br/>API routers<br/>[tasks.py]"]
end

subgraph group_execution["Agent Execution"]
  node_pipeline_graph{{"Execution graph<br/>stateful pipeline<br/>[graph.py]"}}
  node_dispatcher["Dependency dispatcher<br/>orchestration policy<br/>[dispatcher.py]"]
  node_agent_contracts["Agent contracts &amp; roles<br/>agent framework<br/>[base_graph.py]"]
  node_fleet["Fleet manager<br/>execution control<br/>[fleet_manager.py]"]
  node_model_router["Model router<br/>provider routing<br/>[model_router.py]"]
end

subgraph group_governance["Safety &amp; Repository Access"]
  node_approval_gate["Approval gate<br/>governance gate<br/>[approval_gate.py]"]
  node_repo_context["Repository context builder<br/>repository intelligence<br/>[context_builder.py]"]
  node_worktrees["Git worktrees<br/>change isolation<br/>[worktree.py]"]
  node_policy_sandbox["Policy sandbox<br/>safety enforcement<br/>[sandbox.py]"]
end

subgraph group_state["State &amp; Runtime Services"]
  node_postgres[("PostgreSQL + pgvector<br/>durable store<br/>[models.py]")]
  node_memory[("Engineering memory<br/>retrieval store<br/>[store.py]")]
  node_event_bus["Event bus<br/>runtime eventing<br/>[bus.py]"]
  node_artifacts[("Artifact storage<br/>artifact store<br/>[s3_store.py]")]
end

node_web_ui -->|"protects routes"| node_web_auth
node_web_ui -->|"uses"| node_api_client
node_api_client -->|"HTTP"| node_fastapi
node_fastapi -->|"mounts"| node_api_routers
node_api_routers -->|"submits tasks"| node_pipeline_graph
node_api_routers -->|"manages fleet"| node_fleet
node_api_routers -->|"approval actions"| node_approval_gate
node_pipeline_graph -->|"dispatches stages"| node_dispatcher
node_pipeline_graph -->|"builds context"| node_repo_context
node_dispatcher -->|"requests execution"| node_fleet
node_fleet -->|"runs roles"| node_agent_contracts
node_fleet -->|"selects provider"| node_model_router
node_fleet -->|"gates actions"| node_approval_gate
node_agent_contracts -->|"modifies in isolation"| node_worktrees
node_worktrees -->|"operations checked by"| node_policy_sandbox
node_approval_gate -->|"authorizes restricted actions"| node_policy_sandbox
node_pipeline_graph -->|"persists state"| node_postgres
node_fleet -->|"records control data"| node_postgres
node_repo_context -->|"retrieves project knowledge"| node_memory
node_fleet -->|"emits activity"| node_event_bus
node_pipeline_graph -->|"produces verified artifacts"| node_artifacts
node_api_routers -->|"streams chat/activity"| node_event_bus

click node_web_ui "https://github.com/wp113department-cell/multi-agent-company/blob/main/apps/web/app/layout.tsx"
click node_web_auth "https://github.com/wp113department-cell/multi-agent-company/blob/main/apps/web/middleware.ts"
click node_api_client "https://github.com/wp113department-cell/multi-agent-company/blob/main/apps/web/lib/api.ts"
click node_fastapi "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/main.py"
click node_api_routers "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/api/tasks.py"
click node_pipeline_graph "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/pipeline/graph.py"
click node_dispatcher "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/pipeline/dispatcher.py"
click node_agent_contracts "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/agents/base_graph.py"
click node_fleet "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/fleet/fleet_manager.py"
click node_approval_gate "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/fleet/approval_gate.py"
click node_repo_context "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/repo_tools/context_builder.py"
click node_worktrees "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/repo_tools/worktree.py"
click node_policy_sandbox "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/policy/sandbox.py"
click node_postgres "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/db/models.py"
click node_memory "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/memory/store.py"
click node_event_bus "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/event_bus/bus.py"
click node_artifacts "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/artifacts/s3_store.py"
click node_model_router "https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/fleet/model_router.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_web_ui,node_web_auth,node_api_client toneBlue
class node_fastapi,node_api_routers toneAmber
class node_pipeline_graph,node_dispatcher,node_agent_contracts,node_fleet,node_model_router toneMint
class node_approval_gate,node_repo_context,node_worktrees,node_policy_sandbox toneRose
class node_postgres,node_memory,node_event_bus,node_artifacts toneIndigo
```

## Components

### Operator Client

- [Next.js operator UI](https://github.com/wp113department-cell/multi-agent-company/blob/main/apps/web/app/layout.tsx): web app · Task, fleet, approval, repository, chat, metrics, and review consoles. · `apps/web/app/layout.tsx`
- [Route auth middleware](https://github.com/wp113department-cell/multi-agent-company/blob/main/apps/web/middleware.ts): middleware · `apps/web/middleware.ts`
- [Backend API client](https://github.com/wp113department-cell/multi-agent-company/blob/main/apps/web/lib/api.ts): TypeScript client · `apps/web/lib/api.ts`

### Control Plane

- [FastAPI service](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/main.py): API entrypoint · `backend/app/main.py`
- [Control-plane routers](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/api/tasks.py): API routers · Tasks, agents, approvals, chat, artifacts, settings, and repositories. · `backend/app/api/tasks.py`

### Agent Execution

- [Execution graph](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/pipeline/graph.py): stateful pipeline · Bootstraps context, plans work, dispatches dependencies, and coordinates implementation through review. · `backend/app/pipeline/graph.py`
- [Dependency dispatcher](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/pipeline/dispatcher.py): orchestration policy · Applies concurrency, conflict, cost, and queue controls. · `backend/app/pipeline/dispatcher.py`
- [Agent contracts & roles](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/agents/base_graph.py): agent framework · Shared base and graph contracts support core and directly invoked specialists. · `backend/app/agents/base_graph.py`
- [Fleet manager](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/fleet/fleet_manager.py): execution control · Selects agents and models while tracking budgets, checkpoints, events, failures, and audit records. · `backend/app/fleet/fleet_manager.py`
- [Model router](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/fleet/model_router.py): provider routing · Routes fleet inference to Anthropic by default with Groq compatibility. · `backend/app/fleet/model_router.py`

### Safety & Repository Access

- [Approval gate](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/fleet/approval_gate.py): governance gate · Requires operator approval for destructive or publish-like actions. · `backend/app/fleet/approval_gate.py`
- [Repository context builder](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/repo_tools/context_builder.py): repository intelligence · Builds scan, AST, and cross-file context for agents. · `backend/app/repo_tools/context_builder.py`
- [Git worktrees](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/repo_tools/worktree.py): change isolation · Isolates agent modifications in target repositories. · `backend/app/repo_tools/worktree.py`
- [Policy sandbox](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/policy/sandbox.py): safety enforcement · Guards commands and file mutations. · `backend/app/policy/sandbox.py`

### State & Runtime Services

- [PostgreSQL + pgvector](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/db/models.py): durable store · Stores SQLAlchemy-managed operational data and migrations. · `backend/app/db/models.py`
- [Engineering memory](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/memory/store.py): retrieval store · Project-scoped memory supports retrieval, lifecycle analytics, and embeddings. · `backend/app/memory/store.py`
- [Event bus](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/event_bus/bus.py): runtime eventing · In-process bus with Redis Streams runtime option. · `backend/app/event_bus/bus.py`
- [Artifact storage](https://github.com/wp113department-cell/multi-agent-company/blob/main/backend/app/artifacts/s3_store.py): artifact store · Abstracts durable database or S3-backed artifacts. · `backend/app/artifacts/s3_store.py`

## Connections

- Next.js operator UI → Route auth middleware: protects routes
- Next.js operator UI → Backend API client: uses
- Backend API client → FastAPI service: HTTP
- FastAPI service → Control-plane routers: mounts
- Control-plane routers → Execution graph: submits tasks
- Control-plane routers → Fleet manager: manages fleet
- Control-plane routers → Approval gate: approval actions
- Execution graph → Dependency dispatcher: dispatches stages
- Execution graph → Repository context builder: builds context
- Dependency dispatcher → Fleet manager: requests execution
- Fleet manager → Agent contracts & roles: runs roles
- Fleet manager → Model router: selects provider
- Fleet manager → Approval gate: gates actions
- Agent contracts & roles → Git worktrees: modifies in isolation
- Git worktrees → Policy sandbox: operations checked by
- Approval gate → Policy sandbox: authorizes restricted actions
- Execution graph → PostgreSQL + pgvector: persists state
- Fleet manager → PostgreSQL + pgvector: records control data
- Repository context builder → Engineering memory: retrieves project knowledge
- Fleet manager → Event bus: emits activity
- Execution graph → Artifact storage: produces verified artifacts
- Control-plane routers → Event bus: streams chat/activity
