# kennethsaita-sudo/afyaplus-week7-cost-optimised architecture

> Architecture diagram of the GitHub repository kennethsaita-sudo/afyaplus-week7-cost-optimised, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kennethsaita-sudo/afyaplus-week7-cost-optimised
- Repository: https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised

## Overview

AfyaPlus Week 7 provides a basic FastAPI service, an optimized triage route with caching and duplicate-request coalescing, and a separate MCP clinic-directory service. The principal triage workflow accepts a patient message and returns routing guidance; clinic search and details are a distinct capability. The sampled `main.py` does not mount the optimized router, so the graph shows it as a separate route module rather than claiming it is reachable through the main app. The clinic data is read from JSON; other wiring is limited to the sampled source.

Main entry points: [`app/week7_routes.py`](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/app/week7_routes.py) (Optimized triage), [`mcp_server/server.py`](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/mcp_server/server.py) (MCP tools and resource), [`mcp_server/catalogue.py`](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/mcp_server/catalogue.py) (Catalogue operations), [`app/cost_optimisation.py`](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/app/cost_optimisation.py) (Cache and batching)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_main_app["Basic API<br/>[main.py]"]
  node_triage_route["Optimized triage<br/>[week7_routes.py]"]
  node_metrics_route["Optimization metrics<br/>[week7_routes.py]"]
end

subgraph group_optimisation["Triage Optimisation"]
  node_cost_controls["Cache and batching"]
  node_fallback["Triage fallback<br/>[week7_routes.py]"]
end

subgraph group_directory["Clinic Directory"]
  node_mcp_server["MCP tools and resource<br/>[server.py]"]
  node_catalogue_logic["Catalogue operations<br/>[catalogue.py]"]
  node_clinic_data["Clinic catalogue<br/>[clinics.json]"]
end

node_http_user(("HTTP caller"))
node_mcp_client(("MCP client"))

node_http_user -->|"requests basic endpoints"| node_main_app
node_http_user -->|"submits triage"| node_triage_route
node_http_user -->|"requests metrics"| node_metrics_route
node_triage_route -->|"checks cache and batches"| node_cost_controls
node_triage_route -->|"runs on cache miss"| node_fallback
node_metrics_route -->|"reads statistics"| node_cost_controls
node_mcp_client -->|"calls tools or resource"| node_mcp_server
node_mcp_server -->|"dispatches directory calls"| node_catalogue_logic
node_catalogue_logic -->|"loads catalogue"| node_clinic_data

click node_main_app "https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/main.py"
click node_triage_route "https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/app/week7_routes.py"
click node_metrics_route "https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/app/week7_routes.py"
click node_cost_controls "https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/app/cost_optimisation.py"
click node_fallback "https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/app/week7_routes.py"
click node_mcp_server "https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/mcp_server/server.py"
click node_catalogue_logic "https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/mcp_server/catalogue.py"
click node_clinic_data "https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/mcp_server/data/clinics.json"

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_app,node_triage_route,node_metrics_route,node_mcp_client toneBlue
class node_cost_controls,node_fallback toneAmber
class node_mcp_server,node_catalogue_logic,node_clinic_data toneMint
class node_http_user toneIndigo
```

## Components

### HTTP API

- [Basic API](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/main.py): `main.py`
- [Optimized triage](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/app/week7_routes.py): `app/week7_routes.py`
- [Optimization metrics](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/app/week7_routes.py): `app/week7_routes.py`

### Triage Optimisation

- [Cache and batching](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/app/cost_optimisation.py): `app/cost_optimisation.py`
- [Triage fallback](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/app/week7_routes.py): `app/week7_routes.py`

### Clinic Directory

- [MCP tools and resource](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/mcp_server/server.py): `mcp_server/server.py`
- [Catalogue operations](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/mcp_server/catalogue.py): `mcp_server/catalogue.py`
- [Clinic catalogue](https://github.com/kennethsaita-sudo/afyaplus-week7-cost-optimised/blob/main/mcp_server/data/clinics.json): `mcp_server/data/clinics.json`

### Other components

- **HTTP caller**
- **MCP client**

## Connections

- HTTP caller → Basic API: requests basic endpoints
- HTTP caller → Optimized triage: submits triage
- HTTP caller → Optimization metrics: requests metrics
- Optimized triage → Cache and batching: checks cache and batches
- Optimized triage → Triage fallback: runs on cache miss
- Optimization metrics → Cache and batching: reads statistics
- MCP client → MCP tools and resource: calls tools or resource
- MCP tools and resource → Catalogue operations: dispatches directory calls
- Catalogue operations → Clinic catalogue: loads catalogue
