# ahmed-hedhili-se/teramind architecture

> Architecture diagram of the GitHub repository ahmed-hedhili-se/teramind, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ahmed-hedhili-se/teramind
- Repository: https://github.com/ahmed-hedhili-se/teramind

## Overview

TeraMind is a GPU-rental site with customer accounts, an admin console, and an AI GPU advisor. Users browse and filter GPUs, then authenticate to manage rentals; advisor users submit a GitHub repository or workload description and receive GPU recommendations. The Angular client calls an Express API backed by PostgreSQL, with Redis used for login rate limiting. The graph retains the documented catalog, rental, admin, contact, and advisor capabilities. Some frontend-to-API and unsampled route wiring is documented but not shown in excerpts, so those links are dashed.

Main entry points: [`backend/src/services/agent.service.ts`](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/agent.service.ts) (Advisor orchestration), [`backend/src/lib/prisma.ts`](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/lib/prisma.ts) (PostgreSQL), [`backend/src/services/admin.service.ts`](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/admin.service.ts) (Admin operations), [`frontend/src/app/app.routes.ts`](https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/app.routes.ts) (Page routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Angular web app"]
  node_routes["Page routing<br/>[app.routes.ts]"]
  node_authclient["Auth client<br/>[auth-service.ts]"]
  node_gpuclient["GPU client<br/>[gpu-service.ts]"]
  node_rentalclient["Rental client<br/>[rental-service.ts]"]
  node_recommendclient["Advisor client<br/>[agent-service.ts]"]
  node_adminclient["Admin client<br/>[admin-service.ts]"]
  node_authguard["Access guards<br/>[auth-guard.ts]"]
end

subgraph group_api["Express API"]
  node_apiapp["API application<br/>[app.ts]"]
  node_adminroutes["Admin routes<br/>[admin.routes.ts]"]
  node_authroutes["Auth routes<br/>[auth.routes.ts]"]
  node_gpuroutes["GPU routes<br/>[gpu.routes.ts]"]
  node_rentalroutes["Rental routes<br/>[rental.routes.ts]"]
  node_agentroutes["Advisor routes<br/>[agent.routes.ts]"]
  node_admincontroller["Admin controller"]
end

subgraph group_domain["Product services"]
  node_adminservice["Admin operations<br/>[admin.service.ts]"]
  node_authservice["Authentication<br/>[auth.service.ts]"]
  node_rentalservice["Rental operations<br/>[rental.service.ts]"]
  node_availability["Availability"]
  node_contactservice["Contact inbox<br/>[contact.service.ts]"]
  node_gpuservice["GPU catalog<br/>[gpu.service.ts]"]
  node_recommendservice["Recommendation service"]
  node_agentservice["Advisor orchestration<br/>[agent.service.ts]"]
end

subgraph group_runtime["Data and AI runtime"]
  node_repoanalyzer["Repository analysis<br/>[repoAnalyzer.ts]"]
  node_agentloop["Advisor agent loop<br/>[loop.ts]"]
  node_rankconfigs["Configuration ranking<br/>[rankConfigs.ts]"]
  node_llm["Language model<br/>[llm.ts]"]
  node_postgres[("PostgreSQL<br/>[prisma.ts]")]
  node_redis[("Login rate limit<br/>[redis.ts]")]
end

node_visitor(("Site user"))
node_github["GitHub"]

node_visitor -->|"uses"| node_routes
node_routes -->|"guards"| node_authguard
node_routes -.->|"loads sign-in"| node_authclient
node_visitor -.->|"browses catalog"| node_gpuclient
node_visitor -.->|"manages rentals"| node_rentalclient
node_visitor -.->|"requests advice"| node_recommendclient
node_visitor -.->|"administers site"| node_adminclient
node_authclient -.->|"calls API"| node_authroutes
node_gpuclient -.->|"calls API"| node_gpuroutes
node_rentalclient -.->|"calls API"| node_rentalroutes
node_recommendclient -.->|"calls API"| node_agentroutes
node_adminclient -.->|"calls API"| node_adminroutes
node_apiapp -.->|"mounts routes"| node_adminroutes
node_adminroutes -->|"dispatches"| node_admincontroller
node_admincontroller -->|"calls"| node_adminservice
node_admincontroller -->|"calls inbox"| node_contactservice
node_adminservice -->|"queries"| node_postgres
node_adminservice -->|"checks units"| node_availability
node_adminservice -->|"uses status filter"| node_rentalservice
node_authservice -->|"reads and writes"| node_postgres
node_authservice -->|"rate limits login"| node_redis
node_rentalservice -.->|"reads and writes"| node_postgres
node_gpuservice -.->|"reads catalog"| node_postgres
node_recommendservice -.->|"reads catalog"| node_postgres
node_agentroutes -.->|"dispatches"| node_agentservice
node_agentservice -->|"analyzes repository"| node_repoanalyzer
node_agentservice -->|"runs agent"| node_agentloop
node_agentservice -->|"ranks options"| node_rankconfigs
node_agentservice -->|"requests generation"| node_llm
node_repoanalyzer -.->|"reads repository"| node_github
node_agentloop -.->|"uses model"| node_llm
node_agentloop -.->|"evaluates configurations"| node_rankconfigs

click node_routes "https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/app.routes.ts"
click node_authclient "https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/services/auth-service.ts"
click node_gpuclient "https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/services/gpu-service.ts"
click node_rentalclient "https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/services/rental-service.ts"
click node_recommendclient "https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/services/agent-service.ts"
click node_adminclient "https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/services/admin-service.ts"
click node_authguard "https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/guards/auth-guard.ts"
click node_apiapp "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/app.ts"
click node_adminroutes "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/routes/admin.routes.ts"
click node_authroutes "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/routes/auth.routes.ts"
click node_gpuroutes "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/routes/gpu.routes.ts"
click node_rentalroutes "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/routes/rental.routes.ts"
click node_agentroutes "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/routes/agent.routes.ts"
click node_admincontroller "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/controllers/admin.controller.ts"
click node_adminservice "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/admin.service.ts"
click node_authservice "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/auth.service.ts"
click node_rentalservice "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/rental.service.ts"
click node_availability "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/availability.service.ts"
click node_contactservice "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/contact.service.ts"
click node_gpuservice "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/gpu.service.ts"
click node_recommendservice "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/recommendation.service.ts"
click node_agentservice "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/agent.service.ts"
click node_repoanalyzer "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/agent/repoAnalyzer.ts"
click node_agentloop "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/agent/loop.ts"
click node_rankconfigs "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/agent/rankConfigs.ts"
click node_llm "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/agent/llm.ts"
click node_postgres "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/lib/prisma.ts"
click node_redis "https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/lib/redis.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_authclient,node_gpuclient,node_rentalclient,node_recommendclient,node_adminclient,node_authguard,node_visitor toneBlue
class node_apiapp,node_adminroutes,node_authroutes,node_gpuroutes,node_rentalroutes,node_agentroutes,node_admincontroller toneAmber
class node_adminservice,node_authservice,node_rentalservice,node_availability,node_contactservice,node_gpuservice,node_recommendservice,node_agentservice toneMint
class node_repoanalyzer,node_agentloop,node_rankconfigs,node_llm,node_postgres,node_redis toneRose
class node_github toneIndigo
```

## Components

### Angular web app

- [Page routing](https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/app.routes.ts): `frontend/src/app/app.routes.ts`
- [Auth client](https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/services/auth-service.ts): `frontend/src/app/core/services/auth-service.ts`
- [GPU client](https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/services/gpu-service.ts): `frontend/src/app/core/services/gpu-service.ts`
- [Rental client](https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/services/rental-service.ts): `frontend/src/app/core/services/rental-service.ts`
- [Advisor client](https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/services/agent-service.ts): `frontend/src/app/core/services/agent-service.ts`
- [Admin client](https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/services/admin-service.ts): `frontend/src/app/core/services/admin-service.ts`
- [Access guards](https://github.com/ahmed-hedhili-se/teramind/blob/main/frontend/src/app/core/guards/auth-guard.ts): `frontend/src/app/core/guards/auth-guard.ts`

### Express API

- [API application](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/app.ts): `backend/src/app.ts`
- [Admin routes](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/routes/admin.routes.ts): `backend/src/routes/admin.routes.ts`
- [Auth routes](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/routes/auth.routes.ts): `backend/src/routes/auth.routes.ts`
- [GPU routes](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/routes/gpu.routes.ts): `backend/src/routes/gpu.routes.ts`
- [Rental routes](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/routes/rental.routes.ts): `backend/src/routes/rental.routes.ts`
- [Advisor routes](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/routes/agent.routes.ts): `backend/src/routes/agent.routes.ts`
- [Admin controller](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/controllers/admin.controller.ts): `backend/src/controllers/admin.controller.ts`

### Product services

- [Admin operations](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/admin.service.ts): `backend/src/services/admin.service.ts`
- [Authentication](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/auth.service.ts): `backend/src/services/auth.service.ts`
- [Rental operations](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/rental.service.ts): `backend/src/services/rental.service.ts`
- [Availability](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/availability.service.ts): `backend/src/services/availability.service.ts`
- [Contact inbox](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/contact.service.ts): `backend/src/services/contact.service.ts`
- [GPU catalog](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/gpu.service.ts): `backend/src/services/gpu.service.ts`
- [Recommendation service](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/recommendation.service.ts): `backend/src/services/recommendation.service.ts`
- [Advisor orchestration](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/services/agent.service.ts): `backend/src/services/agent.service.ts`

### Data and AI runtime

- [Repository analysis](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/agent/repoAnalyzer.ts): `backend/src/agent/repoAnalyzer.ts`
- [Advisor agent loop](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/agent/loop.ts): `backend/src/agent/loop.ts`
- [Configuration ranking](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/agent/rankConfigs.ts): `backend/src/agent/rankConfigs.ts`
- [Language model](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/agent/llm.ts): `backend/src/agent/llm.ts`
- [PostgreSQL](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/lib/prisma.ts): `backend/src/lib/prisma.ts`
- [Login rate limit](https://github.com/ahmed-hedhili-se/teramind/blob/main/backend/src/lib/redis.ts): `backend/src/lib/redis.ts`

### Other components

- **Site user**
- **GitHub**

## Connections

- Site user → Page routing: uses
- Page routing → Access guards: guards (evidence: `frontend/src/app/app.routes.ts`)
- Page routing → Auth client: loads sign-in
- Site user → GPU client: browses catalog
- Site user → Rental client: manages rentals
- Site user → Advisor client: requests advice
- Site user → Admin client: administers site
- Auth client → Auth routes: calls API
- GPU client → GPU routes: calls API
- Rental client → Rental routes: calls API
- Advisor client → Advisor routes: calls API
- Admin client → Admin routes: calls API
- API application → Admin routes: mounts routes
- Admin routes → Admin controller: dispatches (evidence: `backend/src/routes/admin.routes.ts`)
- Admin controller → Admin operations: calls (evidence: `backend/src/controllers/admin.controller.ts`)
- Admin controller → Contact inbox: calls inbox (evidence: `backend/src/controllers/admin.controller.ts`)
- Admin operations → PostgreSQL: queries (evidence: `backend/src/services/admin.service.ts`)
- Admin operations → Availability: checks units (evidence: `backend/src/services/admin.service.ts`)
- Admin operations → Rental operations: uses status filter (evidence: `backend/src/services/admin.service.ts`)
- Authentication → PostgreSQL: reads and writes (evidence: `backend/src/services/auth.service.ts`)
- Authentication → Login rate limit: rate limits login (evidence: `backend/src/services/auth.service.ts`)
- Rental operations → PostgreSQL: reads and writes
- GPU catalog → PostgreSQL: reads catalog
- Recommendation service → PostgreSQL: reads catalog
- Advisor routes → Advisor orchestration: dispatches
- Advisor orchestration → Repository analysis: analyzes repository (evidence: `backend/src/services/agent.service.ts`)
- Advisor orchestration → Advisor agent loop: runs agent (evidence: `backend/src/services/agent.service.ts`)
- Advisor orchestration → Configuration ranking: ranks options (evidence: `backend/src/services/agent.service.ts`)
- Advisor orchestration → Language model: requests generation (evidence: `backend/src/services/agent.service.ts`)
- Repository analysis → GitHub: reads repository
- Advisor agent loop → Language model: uses model
- Advisor agent loop → Configuration ranking: evaluates configurations
