# marcoskrul/development-challenge-nine architecture

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

- Interactive diagram: https://gitdiagram.com/marcoskrul/development-challenge-nine
- Repository: https://github.com/marcoskrul/development-challenge-nine

## Overview

This repository implements a patient-register CRUD web application: users browse/search a paginated patient list, create or edit a patient and address, and retrieve or delete records. The React client provides patient routes, shared patient state, and API requests; the Node/Express server is organized around HTTP handling, application services, and database repositories. Patient creation validates and normalizes inputs, checks email uniqueness, then saves patient and address records transactionally. The graph emphasizes relationships shown in excerpts and documented capabilities; unsampled routes and service wiring are left unasserted.

Main entry points: [`server/src/infra/http/controllers/PatientController.ts`](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/http/controllers/PatientController.ts) (Patient controller), [`client/src/routes/patients.routes.tsx`](https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/routes/patients.routes.tsx) (Patient routes), [`server/src/application/services/patient/SavePatientService.ts`](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/SavePatientService.ts) (Create patient), [`client/src/routes/index.routes.tsx`](https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/routes/index.routes.tsx) (App routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Patient web client"]
  node_routes["App routes<br/>[index.routes.tsx]"]
  node_patient_routes["Patient routes"]
  node_patient_list["Patient control<br/>[index.tsx]"]
  node_patient_table["Patient table<br/>[PatientsTable.tsx]"]
  node_patient_form["Patient form<br/>[index.tsx]"]
  node_patient_context["Patient state and API<br/>[index.tsx]"]
  node_api_client["HTTP client<br/>[api.ts]"]
end

subgraph group_server["HTTP application"]
  node_http_routes["HTTP routes<br/>[patient.routes.ts]"]
  node_controller["Patient controller"]
end

subgraph group_domain["Patient operations"]
  node_save_service["Create patient"]
  node_update_service["Update patient"]
  node_list_service["List patients"]
  node_get_service["Get patient"]
  node_delete_service["Delete patient"]
end

subgraph group_storage["Persistence"]
  node_patient_repo["Patient repository"]
  node_address_repo["Address repository"]
  node_database[("PostgreSQL database<br/>[index.ts]")]
end

node_user(("Clinic user"))
node_browser(("Browser"))
node_api_server(("Patient API"))

node_user -->|"uses"| node_browser
node_browser -->|"opens"| node_routes
node_routes -->|"routes to"| node_patient_routes
node_patient_routes -->|"renders"| node_patient_list
node_patient_routes -->|"renders"| node_patient_form
node_patient_list -->|"uses"| node_patient_table
node_patient_routes -->|"provides"| node_patient_context
node_patient_context -->|"sends requests"| node_api_client
node_api_client -.->|"calls"| node_api_server
node_api_server -.->|"handles CRUD"| node_http_routes
node_http_routes -.->|"dispatches"| node_controller
node_controller -.->|"invokes"| node_save_service
node_controller -.->|"invokes"| node_update_service
node_controller -.->|"invokes"| node_list_service
node_controller -.->|"invokes"| node_get_service
node_controller -.->|"invokes"| node_delete_service
node_update_service -->|"delegates"| node_save_service
node_save_service -->|"checks and saves"| node_patient_repo
node_save_service -->|"saves address"| node_address_repo
node_patient_repo -.->|"reads and writes"| node_database
node_address_repo -.->|"reads and writes"| node_database

click node_routes "https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/routes/index.routes.tsx"
click node_patient_routes "https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/routes/patients.routes.tsx"
click node_patient_list "https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/pages/PatientControl/index.tsx"
click node_patient_table "https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/pages/PatientControl/PatientsTable.tsx"
click node_patient_form "https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/pages/PatientPersistence/index.tsx"
click node_patient_context "https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/context/Patients/index.tsx"
click node_api_client "https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/services/api.ts"
click node_http_routes "https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/http/routes/patient.routes.ts"
click node_controller "https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/http/controllers/PatientController.ts"
click node_save_service "https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/SavePatientService.ts"
click node_update_service "https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/UpdatePatientService.ts"
click node_list_service "https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/ListPatientsService.ts"
click node_get_service "https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/GetPatientByIdService.ts"
click node_delete_service "https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/DeletePatientService.ts"
click node_patient_repo "https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/database/repositories/patient/implementations/PostgreSQL/Prisma/PatientRepository.ts"
click node_address_repo "https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/database/repositories/address/implementations/PostgreSQL/Prisma/AddressRepository.ts"
click node_database "https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/database/client/index.ts"

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_routes,node_patient_routes,node_patient_list,node_patient_table,node_patient_form,node_patient_context,node_api_client,node_user,node_browser toneBlue
class node_http_routes,node_controller toneAmber
class node_save_service,node_update_service,node_list_service,node_get_service,node_delete_service,node_api_server toneMint
class node_patient_repo,node_address_repo,node_database toneRose
```

## Components

### Patient web client

- [App routes](https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/routes/index.routes.tsx): `client/src/routes/index.routes.tsx`
- [Patient routes](https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/routes/patients.routes.tsx): `client/src/routes/patients.routes.tsx`
- [Patient control](https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/pages/PatientControl/index.tsx): `client/src/pages/PatientControl/index.tsx`
- [Patient table](https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/pages/PatientControl/PatientsTable.tsx): `client/src/pages/PatientControl/PatientsTable.tsx`
- [Patient form](https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/pages/PatientPersistence/index.tsx): `client/src/pages/PatientPersistence/index.tsx`
- [Patient state and API](https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/context/Patients/index.tsx): `client/src/context/Patients/index.tsx`
- [HTTP client](https://github.com/marcoskrul/development-challenge-nine/blob/main/client/src/services/api.ts): `client/src/services/api.ts`

### HTTP application

- [HTTP routes](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/http/routes/patient.routes.ts): `server/src/infra/http/routes/patient.routes.ts`
- [Patient controller](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/http/controllers/PatientController.ts): `server/src/infra/http/controllers/PatientController.ts`

### Patient operations

- [Create patient](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/SavePatientService.ts): `server/src/application/services/patient/SavePatientService.ts`
- [Update patient](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/UpdatePatientService.ts): `server/src/application/services/patient/UpdatePatientService.ts`
- [List patients](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/ListPatientsService.ts): `server/src/application/services/patient/ListPatientsService.ts`
- [Get patient](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/GetPatientByIdService.ts): `server/src/application/services/patient/GetPatientByIdService.ts`
- [Delete patient](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/application/services/patient/DeletePatientService.ts): `server/src/application/services/patient/DeletePatientService.ts`

### Persistence

- [Patient repository](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/database/repositories/patient/implementations/PostgreSQL/Prisma/PatientRepository.ts): `server/src/infra/database/repositories/patient/implementations/PostgreSQL/Prisma/PatientRepository.ts`
- [Address repository](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/database/repositories/address/implementations/PostgreSQL/Prisma/AddressRepository.ts): `server/src/infra/database/repositories/address/implementations/PostgreSQL/Prisma/AddressRepository.ts`
- [PostgreSQL database](https://github.com/marcoskrul/development-challenge-nine/blob/main/server/src/infra/database/client/index.ts): `server/src/infra/database/client/index.ts`

### Other components

- **Clinic user**
- **Browser**
- **Patient API**

## Connections

- Clinic user → Browser: uses
- Browser → App routes: opens (evidence: `client/src/routes/index.routes.tsx`)
- App routes → Patient routes: routes to (evidence: `client/src/routes/index.routes.tsx`)
- Patient routes → Patient control: renders (evidence: `client/src/routes/patients.routes.tsx`)
- Patient routes → Patient form: renders (evidence: `client/src/routes/patients.routes.tsx`)
- Patient control → Patient table: uses (evidence: `client/src/pages/PatientControl/index.tsx`)
- Patient routes → Patient state and API: provides (evidence: `client/src/routes/patients.routes.tsx`)
- Patient state and API → HTTP client: sends requests (evidence: `client/src/context/Patients/index.tsx`)
- HTTP client → Patient API: calls
- Patient API → HTTP routes: handles CRUD
- HTTP routes → Patient controller: dispatches
- Patient controller → Create patient: invokes
- Patient controller → Update patient: invokes
- Patient controller → List patients: invokes
- Patient controller → Get patient: invokes
- Patient controller → Delete patient: invokes
- Update patient → Create patient: delegates (evidence: `server/src/application/services/patient/UpdatePatientService.ts`)
- Create patient → Patient repository: checks and saves (evidence: `server/src/application/services/patient/SavePatientService.ts`)
- Create patient → Address repository: saves address (evidence: `server/src/application/services/patient/SavePatientService.ts`)
- Patient repository → PostgreSQL database: reads and writes
- Address repository → PostgreSQL database: reads and writes
