# lychuss/open-med-backend architecture

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

- Interactive diagram: https://gitdiagram.com/lychuss/open-med-backend
- Repository: https://github.com/lychuss/open-med-backend

## Overview

This is a medical-services backend with authentication, a protected doctor-search route, and Socket.IO rooms that relay WebRTC signaling. The intended HTTP flow is client → Express route → authentication and controller; however, the sampled controller is empty and does not call the doctor-query service, so that connection is not inferred. The README provides no further capability detail, and the schema was not sampled; the graph shows only relationships evidenced by the provided excerpts.

Main entry points: [`src/app.ts`](https://github.com/lychuss/open-med-backend/blob/main/src/app.ts) (Express app), [`src/config/socket.ts`](https://github.com/lychuss/open-med-backend/blob/main/src/config/socket.ts) (Socket.IO handlers), [`src/routers/users.routes.ts`](https://github.com/lychuss/open-med-backend/blob/main/src/routers/users.routes.ts) (Doctor route), [`lib/better-auth.ts`](https://github.com/lychuss/open-med-backend/blob/main/lib/better-auth.ts) (Better Auth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_http["HTTP API"]
  node_app["Express app<br/>[app.ts]"]
  node_users_route["Doctor route<br/>[users.routes.ts]"]
  node_users_controller["Doctor controller"]
end

subgraph group_identity["Identity"]
  node_auth_middleware["Session guard"]
  node_auth["Better Auth<br/>[better-auth.ts]"]
end

subgraph group_realtime["Realtime"]
  node_socket_server["Socket.IO handlers<br/>[socket.ts]"]
  node_server_entry["HTTP server entry<br/>[server.ts]"]
end

subgraph group_data["Data access"]
  node_users_service["Doctor query<br/>[users.services.ts]"]
  node_auth_prisma["Auth Prisma client<br/>[seed.ts]"]
  node_db_prisma["Query Prisma client<br/>[prisma.ts]"]
end

node_client(("Frontend client"))
node_postgres[("PostgreSQL")]
node_socket_client(("Realtime client"))

node_client -->|"sends HTTP"| node_app
node_app -->|"routes auth"| node_auth
node_app -->|"mounts route"| node_users_route
node_users_route -->|"checks session"| node_auth_middleware
node_users_route -->|"dispatches request"| node_users_controller
node_auth_middleware -->|"gets session"| node_auth
node_auth -->|"configures adapter"| node_auth_prisma
node_auth_prisma -->|"reads and updates"| node_postgres
node_users_service -->|"queries doctors"| node_db_prisma
node_db_prisma -->|"connects"| node_postgres
node_server_entry -->|"listens on server"| node_socket_server
node_socket_server -->|"serves HTTP app"| node_app
node_socket_client -->|"joins and signals"| node_socket_server
node_socket_server -->|"relays room events"| node_socket_client

click node_app "https://github.com/lychuss/open-med-backend/blob/main/src/app.ts"
click node_users_route "https://github.com/lychuss/open-med-backend/blob/main/src/routers/users.routes.ts"
click node_users_controller "https://github.com/lychuss/open-med-backend/blob/main/src/controllers/users.controller.ts"
click node_users_service "https://github.com/lychuss/open-med-backend/blob/main/src/services/users.services.ts"
click node_auth_middleware "https://github.com/lychuss/open-med-backend/blob/main/src/middlewares/authentication.middlewares.ts"
click node_auth "https://github.com/lychuss/open-med-backend/blob/main/lib/better-auth.ts"
click node_auth_prisma "https://github.com/lychuss/open-med-backend/blob/main/prisma/seed.ts"
click node_db_prisma "https://github.com/lychuss/open-med-backend/blob/main/lib/prisma.ts"
click node_socket_server "https://github.com/lychuss/open-med-backend/blob/main/src/config/socket.ts"
click node_server_entry "https://github.com/lychuss/open-med-backend/blob/main/src/server.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_app,node_users_route,node_users_controller,node_client,node_socket_client toneBlue
class node_auth_middleware,node_auth,node_postgres toneAmber
class node_socket_server,node_server_entry toneMint
class node_users_service,node_auth_prisma,node_db_prisma toneRose
```

## Components

### HTTP API

- [Express app](https://github.com/lychuss/open-med-backend/blob/main/src/app.ts): `src/app.ts`
- [Doctor route](https://github.com/lychuss/open-med-backend/blob/main/src/routers/users.routes.ts): `src/routers/users.routes.ts`
- [Doctor controller](https://github.com/lychuss/open-med-backend/blob/main/src/controllers/users.controller.ts): `src/controllers/users.controller.ts`

### Identity

- [Session guard](https://github.com/lychuss/open-med-backend/blob/main/src/middlewares/authentication.middlewares.ts): `src/middlewares/authentication.middlewares.ts`
- [Better Auth](https://github.com/lychuss/open-med-backend/blob/main/lib/better-auth.ts): `lib/better-auth.ts`

### Realtime

- [Socket.IO handlers](https://github.com/lychuss/open-med-backend/blob/main/src/config/socket.ts): `src/config/socket.ts`
- [HTTP server entry](https://github.com/lychuss/open-med-backend/blob/main/src/server.ts): `src/server.ts`

### Data access

- [Doctor query](https://github.com/lychuss/open-med-backend/blob/main/src/services/users.services.ts): `src/services/users.services.ts`
- [Auth Prisma client](https://github.com/lychuss/open-med-backend/blob/main/prisma/seed.ts): `prisma/seed.ts`
- [Query Prisma client](https://github.com/lychuss/open-med-backend/blob/main/lib/prisma.ts): `lib/prisma.ts`

### Other components

- **Frontend client**
- **PostgreSQL**
- **Realtime client**

## Connections

- Frontend client → Express app: sends HTTP (evidence: `src/app.ts`)
- Express app → Better Auth: routes auth (evidence: `src/app.ts`)
- Express app → Doctor route: mounts route (evidence: `src/app.ts`)
- Doctor route → Session guard: checks session (evidence: `src/routers/users.routes.ts`)
- Doctor route → Doctor controller: dispatches request (evidence: `src/routers/users.routes.ts`)
- Session guard → Better Auth: gets session (evidence: `src/middlewares/authentication.middlewares.ts`)
- Better Auth → Auth Prisma client: configures adapter (evidence: `lib/better-auth.ts`)
- Auth Prisma client → PostgreSQL: reads and updates (evidence: `prisma/seed.ts`)
- Doctor query → Query Prisma client: queries doctors (evidence: `src/services/users.services.ts`)
- Query Prisma client → PostgreSQL: connects (evidence: `lib/prisma.ts`)
- HTTP server entry → Socket.IO handlers: listens on server (evidence: `src/server.ts`)
- Socket.IO handlers → Express app: serves HTTP app (evidence: `src/config/socket.ts`)
- Realtime client → Socket.IO handlers: joins and signals (evidence: `src/config/socket.ts`)
- Socket.IO handlers → Realtime client: relays room events (evidence: `src/config/socket.ts`)
