# ridetrip-tour/profiles-service architecture

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

- Interactive diagram: https://gitdiagram.com/ridetrip-tour/profiles-service
- Repository: https://github.com/ridetrip-tour/profiles-service

## Overview

Profile Service is a FastAPI service for user profile data, visibility/settings, favorite locations, and device tracking. Users access profile and settings operations; auth-service provisions, permanently deletes, and restores profiles through internal routes. Routes delegate profile work to ProfileManager, which coordinates persistence, cache, and gateway checks. Device registration is handled separately through request middleware. The graph follows the README and SOURCE INDEX relationships; unsampled implementations are represented only where the index or README supports them.

Main entry points: [`app/services/profiles_manager.py`](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/services/profiles_manager.py) (Profile manager), [`app/routes/profiles_routes.py`](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/routes/profiles_routes.py) (Profile API), [`app/dependencies/profiles.py`](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/dependencies/profiles.py) (Manager dependencies), [`app/services/cache_manager.py`](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/services/cache_manager.py) (Cache manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_profile_routes["Profile API<br/>[profiles_routes.py]"]
  node_internal_routes["Internal API<br/>[internal_routes.py]"]
  node_admin_routes["Admin API<br/>[admin_routes.py]"]
  node_auth_deps["Auth checks<br/>[auth.py]"]
  node_schemas["Profile schemas"]
  node_admin_schemas["Admin schemas<br/>[admin_schemas.py]"]
end

subgraph group_domain["Profile domain"]
  node_profile_manager["Profile manager"]
  node_profile_crud["Profile persistence<br/>[profiles_crud.py]"]
  node_settings_crud["Settings persistence"]
  node_favorites_crud["Favorite locations"]
  node_device_manager["Device manager<br/>[devices_manager.py]"]
  node_device_crud["Device persistence<br/>[devices_crud.py]"]
end

subgraph group_infra["Storage and integrations"]
  node_models["Data models<br/>[models.py]"]
  node_database[("PostgreSQL<br/>[database.py]")]
  node_cache["Cache manager<br/>[cache_manager.py]"]
  node_redis[("Redis")]
  node_gateway_client["Gateway client<br/>[gateway_client.py]"]
end

subgraph group_request["Request processing"]
  node_request_middleware["Request middleware<br/>[request_context.py]"]
  node_dependencies["Manager dependencies<br/>[profiles.py]"]
end

node_user(("User client"))
node_auth(("Auth service"))
node_gateway{{"Gateway services"}}

node_user -->|"calls profile API"| node_profile_routes
node_auth -->|"provisions profiles"| node_internal_routes
node_profile_routes -->|"checks identity"| node_auth_deps
node_profile_routes -->|"injects manager"| node_dependencies
node_profile_routes -->|"validates payloads"| node_schemas
node_profile_routes -->|"delegates operations"| node_profile_manager
node_internal_routes -->|"restricts callers"| node_auth_deps
node_internal_routes -->|"delegates lifecycle"| node_profile_manager
node_internal_routes -->|"accepts profile data"| node_schemas
node_admin_routes -->|"injects manager"| node_dependencies
node_admin_routes -->|"uses admin payloads"| node_admin_schemas
node_dependencies -->|"constructs manager"| node_profile_manager
node_dependencies -->|"gets session"| node_database
node_dependencies -->|"constructs cache"| node_cache
node_profile_manager -->|"reads and writes profiles"| node_profile_crud
node_profile_manager -->|"manages settings"| node_settings_crud
node_profile_manager -->|"manages favorites"| node_favorites_crud
node_profile_manager -->|"checks references"| node_gateway_client
node_profile_manager -->|"caches profile data"| node_cache
node_profile_crud -->|"uses profile models"| node_models
node_settings_crud -->|"uses settings models"| node_models
node_favorites_crud -->|"uses favorite models"| node_models
node_request_middleware -->|"registers devices"| node_device_manager
node_request_middleware -->|"loads profile context"| node_profile_manager
node_request_middleware -->|"uses cache"| node_cache
node_device_manager -->|"registers and reads"| node_device_crud
node_device_manager -->|"throttles writes"| node_cache
node_device_crud -->|"uses device model"| node_models
node_gateway_client -->|"requests references"| node_gateway
node_cache -->|"gets and sets keys"| node_redis
node_database -->|"creates database sessions"| node_models

click node_profile_routes "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/routes/profiles_routes.py"
click node_internal_routes "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/routes/internal_routes.py"
click node_admin_routes "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/routes/admin_routes.py"
click node_auth_deps "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/dependencies/auth.py"
click node_schemas "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/schemas/profiles_schemas.py"
click node_admin_schemas "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/schemas/admin_schemas.py"
click node_profile_manager "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/services/profiles_manager.py"
click node_profile_crud "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/crud/profiles_crud.py"
click node_settings_crud "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/crud/profile_settings_crud.py"
click node_favorites_crud "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/crud/favorite_locations_crud.py"
click node_device_manager "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/services/devices_manager.py"
click node_device_crud "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/crud/devices_crud.py"
click node_models "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/db/models.py"
click node_database "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/db/database.py"
click node_cache "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/services/cache_manager.py"
click node_gateway_client "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/clients/gateway_client.py"
click node_request_middleware "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/middlerware/request_context.py"
click node_dependencies "https://github.com/ridetrip-tour/profiles-service/blob/develop/app/dependencies/profiles.py"

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_profile_routes,node_internal_routes,node_admin_routes,node_auth_deps,node_schemas,node_admin_schemas,node_user toneBlue
class node_profile_manager,node_profile_crud,node_settings_crud,node_favorites_crud,node_device_manager,node_device_crud toneAmber
class node_models,node_database,node_cache,node_redis,node_gateway_client toneMint
class node_request_middleware,node_dependencies toneRose
class node_auth,node_gateway toneIndigo
```

## Components

### API and access

- [Profile API](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/routes/profiles_routes.py): `app/routes/profiles_routes.py`
- [Internal API](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/routes/internal_routes.py): `app/routes/internal_routes.py`
- [Admin API](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/routes/admin_routes.py): `app/routes/admin_routes.py`
- [Auth checks](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/dependencies/auth.py): `app/dependencies/auth.py`
- [Profile schemas](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/schemas/profiles_schemas.py): `app/schemas/profiles_schemas.py`
- [Admin schemas](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/schemas/admin_schemas.py): `app/schemas/admin_schemas.py`

### Profile domain

- [Profile manager](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/services/profiles_manager.py): `app/services/profiles_manager.py`
- [Profile persistence](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/crud/profiles_crud.py): `app/crud/profiles_crud.py`
- [Settings persistence](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/crud/profile_settings_crud.py): `app/crud/profile_settings_crud.py`
- [Favorite locations](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/crud/favorite_locations_crud.py): `app/crud/favorite_locations_crud.py`
- [Device manager](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/services/devices_manager.py): `app/services/devices_manager.py`
- [Device persistence](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/crud/devices_crud.py): `app/crud/devices_crud.py`

### Storage and integrations

- [Data models](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/db/models.py): `app/db/models.py`
- [PostgreSQL](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/db/database.py): `app/db/database.py`
- [Cache manager](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/services/cache_manager.py): `app/services/cache_manager.py`
- **Redis**
- [Gateway client](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/clients/gateway_client.py): `app/clients/gateway_client.py`

### Request processing

- [Request middleware](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/middlerware/request_context.py): `app/middlerware/request_context.py`
- [Manager dependencies](https://github.com/ridetrip-tour/profiles-service/blob/develop/app/dependencies/profiles.py): `app/dependencies/profiles.py`

### Other components

- **User client**
- **Auth service**
- **Gateway services**

## Connections

- User client → Profile API: calls profile API
- Auth service → Internal API: provisions profiles
- Profile API → Auth checks: checks identity (evidence: `app/routes/profiles_routes.py`)
- Profile API → Manager dependencies: injects manager (evidence: `app/dependencies/profiles.py`)
- Profile API → Profile schemas: validates payloads (evidence: `app/routes/profiles_routes.py`)
- Profile API → Profile manager: delegates operations (evidence: `app/routes/profiles_routes.py`)
- Internal API → Auth checks: restricts callers (evidence: `app/routes/internal_routes.py`)
- Internal API → Profile manager: delegates lifecycle (evidence: `app/routes/internal_routes.py`)
- Internal API → Profile schemas: accepts profile data (evidence: `app/routes/internal_routes.py`)
- Admin API → Manager dependencies: injects manager (evidence: `app/routes/admin_routes.py`)
- Admin API → Admin schemas: uses admin payloads (evidence: `app/routes/admin_routes.py`)
- Manager dependencies → Profile manager: constructs manager (evidence: `app/dependencies/profiles.py`)
- Manager dependencies → PostgreSQL: gets session (evidence: `app/dependencies/profiles.py`)
- Manager dependencies → Cache manager: constructs cache (evidence: `app/dependencies/profiles.py`)
- Profile manager → Profile persistence: reads and writes profiles (evidence: `app/services/profiles_manager.py`)
- Profile manager → Settings persistence: manages settings (evidence: `app/services/profiles_manager.py`)
- Profile manager → Favorite locations: manages favorites (evidence: `app/services/profiles_manager.py`)
- Profile manager → Gateway client: checks references (evidence: `app/services/profiles_manager.py`)
- Profile manager → Cache manager: caches profile data (evidence: `app/services/profiles_manager.py`)
- Profile persistence → Data models: uses profile models (evidence: `app/crud/profiles_crud.py`)
- Settings persistence → Data models: uses settings models (evidence: `app/crud/profile_settings_crud.py`)
- Favorite locations → Data models: uses favorite models (evidence: `app/crud/favorite_locations_crud.py`)
- Request middleware → Device manager: registers devices (evidence: `app/middlerware/request_context.py`)
- Request middleware → Profile manager: loads profile context (evidence: `app/middlerware/request_context.py`)
- Request middleware → Cache manager: uses cache (evidence: `app/middlerware/request_context.py`)
- Device manager → Device persistence: registers and reads (evidence: `app/services/devices_manager.py`)
- Device manager → Cache manager: throttles writes (evidence: `app/services/devices_manager.py`)
- Device persistence → Data models: uses device model (evidence: `app/crud/devices_crud.py`)
- Gateway client → Gateway services: requests references (evidence: `app/clients/gateway_client.py`)
- Cache manager → Redis: gets and sets keys (evidence: `app/services/cache_manager.py`)
- PostgreSQL → Data models: creates database sessions (evidence: `app/db/database.py`)
