# ran1-987/cpp-restapi architecture

> Architecture diagram of the GitHub repository ran1-987/cpp-restapi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ran1-987/cpp-restapi
- Repository: https://github.com/ran1-987/cpp-restapi

## Overview

This is a C++ REST API backend for authentication and administrative user/role management. The main request path is client → Drogon controller → service → repository → PostgreSQL, with authentication and authorization applied to protected operations. Authentication additionally manages access/refresh tokens, password verification, and optional Redis-backed login throttling. Startup loads configuration, initializes shared application services and the database, and applies migrations before serving. The tree and excerpts support the principal boundaries; several service and wiring details are inferred only where the sampled code explicitly calls them.

Main entry points: [`src/services/AuthService.cpp`](https://github.com/ran1-987/cpp-restapi/blob/main/src/services/AuthService.cpp) (Auth service), [`src/database/DatabaseManager.cpp`](https://github.com/ran1-987/cpp-restapi/blob/main/src/database/DatabaseManager.cpp) (Database manager), [`src/services/UserService.cpp`](https://github.com/ran1-987/cpp-restapi/blob/main/src/services/UserService.cpp) (User service), [`src/repositories/UserRepository.cpp`](https://github.com/ran1-987/cpp-restapi/blob/main/src/repositories/UserRepository.cpp) (User repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime setup"]
  node_main["Server startup<br/>[main.cpp]"]
  node_config["Configuration<br/>[Config.cpp]"]
  node_context["Application context<br/>[AppContext.cpp]"]
end

subgraph group_auth["Authentication"]
  node_authctl["Auth endpoints<br/>[AuthController.cpp]"]
  node_authfilter["Auth filter<br/>[AuthFilter.cpp]"]
  node_authsvc["Auth service<br/>[AuthService.cpp]"]
  node_jwt["JWT utilities<br/>[JwtUtils.cpp]"]
  node_tokens["Refresh tokens"]
  node_redisclient["Redis client<br/>[RedisClient.cpp]"]
end

subgraph group_admin["User and roles"]
  node_userctl["User endpoints<br/>[UserController.cpp]"]
  node_usersvc["User service<br/>[UserService.cpp]"]
  node_rolectl["Role endpoints<br/>[RoleController.cpp]"]
  node_rolesvc["Role service<br/>[RoleService.cpp]"]
end

subgraph group_data["Persistence and infrastructure"]
  node_userrepo["User repository<br/>[UserRepository.cpp]"]
  node_rolerepo["Role repository<br/>[RoleRepository.cpp]"]
  node_dbmanager["Database manager"]
  node_transactions["Transactions"]
end

node_client(("API client"))
node_redis[("Redis")]
node_postgres[("PostgreSQL")]

node_client -->|"HTTP requests"| node_main
node_main -->|"loads config"| node_config
node_main -->|"initializes"| node_context
node_context -->|"starts database"| node_dbmanager
node_dbmanager -->|"connects and migrates"| node_postgres
node_client -->|"auth requests"| node_authctl
node_client -->|"user requests"| node_userctl
node_client -->|"role requests"| node_rolectl
node_authctl -->|"calls"| node_authsvc
node_authctl -->|"loads profile"| node_usersvc
node_authfilter -->|"verifies token"| node_jwt
node_userctl -->|"checks principal"| node_authfilter
node_rolectl -->|"checks principal"| node_authfilter
node_userctl -->|"calls"| node_usersvc
node_rolectl -->|"calls"| node_rolesvc
node_authsvc -->|"reads users"| node_userrepo
node_authsvc -->|"manages sessions"| node_tokens
node_authsvc -->|"issues tokens"| node_jwt
node_authsvc -.->|"checks login throttle"| node_redisclient
node_redisclient -.->|"reads and updates counters"| node_redis
node_usersvc -->|"manages users"| node_userrepo
node_usersvc -->|"resolves roles"| node_rolerepo
node_rolesvc -->|"manages roles"| node_rolerepo
node_userrepo -->|"executes queries"| node_dbmanager
node_rolerepo -->|"executes queries"| node_dbmanager
node_tokens -->|"executes queries"| node_dbmanager
node_userrepo -->|"uses transactions"| node_transactions
node_rolerepo -->|"uses transactions"| node_transactions
node_transactions -->|"commits queries"| node_postgres

click node_main "https://github.com/ran1-987/cpp-restapi/blob/main/src/main.cpp"
click node_config "https://github.com/ran1-987/cpp-restapi/blob/main/src/config/Config.cpp"
click node_context "https://github.com/ran1-987/cpp-restapi/blob/main/src/app/AppContext.cpp"
click node_authctl "https://github.com/ran1-987/cpp-restapi/blob/main/src/controllers/AuthController.cpp"
click node_authfilter "https://github.com/ran1-987/cpp-restapi/blob/main/src/http/AuthFilter.cpp"
click node_authsvc "https://github.com/ran1-987/cpp-restapi/blob/main/src/services/AuthService.cpp"
click node_jwt "https://github.com/ran1-987/cpp-restapi/blob/main/src/utils/JwtUtils.cpp"
click node_tokens "https://github.com/ran1-987/cpp-restapi/blob/main/src/repositories/RefreshTokenRepository.cpp"
click node_redisclient "https://github.com/ran1-987/cpp-restapi/blob/main/src/infrastructure/RedisClient.cpp"
click node_userctl "https://github.com/ran1-987/cpp-restapi/blob/main/src/controllers/UserController.cpp"
click node_usersvc "https://github.com/ran1-987/cpp-restapi/blob/main/src/services/UserService.cpp"
click node_rolectl "https://github.com/ran1-987/cpp-restapi/blob/main/src/controllers/RoleController.cpp"
click node_rolesvc "https://github.com/ran1-987/cpp-restapi/blob/main/src/services/RoleService.cpp"
click node_userrepo "https://github.com/ran1-987/cpp-restapi/blob/main/src/repositories/UserRepository.cpp"
click node_rolerepo "https://github.com/ran1-987/cpp-restapi/blob/main/src/repositories/RoleRepository.cpp"
click node_dbmanager "https://github.com/ran1-987/cpp-restapi/blob/main/src/database/DatabaseManager.cpp"
click node_transactions "https://github.com/ran1-987/cpp-restapi/blob/main/src/database/TransactionContext.cpp"

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,node_config,node_context,node_client toneBlue
class node_authctl,node_authfilter,node_authsvc,node_jwt,node_tokens,node_redisclient,node_redis,node_postgres toneAmber
class node_userctl,node_usersvc,node_rolectl,node_rolesvc toneMint
class node_userrepo,node_rolerepo,node_dbmanager,node_transactions toneRose
```

## Components

### Runtime setup

- [Server startup](https://github.com/ran1-987/cpp-restapi/blob/main/src/main.cpp): `src/main.cpp`
- [Configuration](https://github.com/ran1-987/cpp-restapi/blob/main/src/config/Config.cpp): `src/config/Config.cpp`
- [Application context](https://github.com/ran1-987/cpp-restapi/blob/main/src/app/AppContext.cpp): `src/app/AppContext.cpp`

### Authentication

- [Auth endpoints](https://github.com/ran1-987/cpp-restapi/blob/main/src/controllers/AuthController.cpp): `src/controllers/AuthController.cpp`
- [Auth filter](https://github.com/ran1-987/cpp-restapi/blob/main/src/http/AuthFilter.cpp): `src/http/AuthFilter.cpp`
- [Auth service](https://github.com/ran1-987/cpp-restapi/blob/main/src/services/AuthService.cpp): `src/services/AuthService.cpp`
- [JWT utilities](https://github.com/ran1-987/cpp-restapi/blob/main/src/utils/JwtUtils.cpp): `src/utils/JwtUtils.cpp`
- [Refresh tokens](https://github.com/ran1-987/cpp-restapi/blob/main/src/repositories/RefreshTokenRepository.cpp): `src/repositories/RefreshTokenRepository.cpp`
- [Redis client](https://github.com/ran1-987/cpp-restapi/blob/main/src/infrastructure/RedisClient.cpp): `src/infrastructure/RedisClient.cpp`

### User and roles

- [User endpoints](https://github.com/ran1-987/cpp-restapi/blob/main/src/controllers/UserController.cpp): `src/controllers/UserController.cpp`
- [User service](https://github.com/ran1-987/cpp-restapi/blob/main/src/services/UserService.cpp): `src/services/UserService.cpp`
- [Role endpoints](https://github.com/ran1-987/cpp-restapi/blob/main/src/controllers/RoleController.cpp): `src/controllers/RoleController.cpp`
- [Role service](https://github.com/ran1-987/cpp-restapi/blob/main/src/services/RoleService.cpp): `src/services/RoleService.cpp`

### Persistence and infrastructure

- [User repository](https://github.com/ran1-987/cpp-restapi/blob/main/src/repositories/UserRepository.cpp): `src/repositories/UserRepository.cpp`
- [Role repository](https://github.com/ran1-987/cpp-restapi/blob/main/src/repositories/RoleRepository.cpp): `src/repositories/RoleRepository.cpp`
- [Database manager](https://github.com/ran1-987/cpp-restapi/blob/main/src/database/DatabaseManager.cpp): `src/database/DatabaseManager.cpp`
- [Transactions](https://github.com/ran1-987/cpp-restapi/blob/main/src/database/TransactionContext.cpp): `src/database/TransactionContext.cpp`

### Other components

- **API client**
- **Redis**
- **PostgreSQL**

## Connections

- API client → Server startup: HTTP requests
- Server startup → Configuration: loads config
- Server startup → Application context: initializes
- Application context → Database manager: starts database
- Database manager → PostgreSQL: connects and migrates
- API client → Auth endpoints: auth requests
- API client → User endpoints: user requests
- API client → Role endpoints: role requests
- Auth endpoints → Auth service: calls
- Auth endpoints → User service: loads profile
- Auth filter → JWT utilities: verifies token
- User endpoints → Auth filter: checks principal
- Role endpoints → Auth filter: checks principal
- User endpoints → User service: calls
- Role endpoints → Role service: calls
- Auth service → User repository: reads users
- Auth service → Refresh tokens: manages sessions
- Auth service → JWT utilities: issues tokens
- Auth service → Redis client: checks login throttle
- Redis client → Redis: reads and updates counters
- User service → User repository: manages users
- User service → Role repository: resolves roles
- Role service → Role repository: manages roles
- User repository → Database manager: executes queries
- Role repository → Database manager: executes queries
- Refresh tokens → Database manager: executes queries
- User repository → Transactions: uses transactions
- Role repository → Transactions: uses transactions
- Transactions → PostgreSQL: commits queries
