# cartobucket/auth architecture

> Architecture diagram of the GitHub repository cartobucket/auth, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cartobucket/auth
- Repository: https://github.com/cartobucket/auth

## Overview

##### Main Components Identification

The system consists of several key microservices and components that should be represented:

a) Core Services:
- Auth API Service (auth-api)
- Authorization Server API (auth-authorization-server-api)
- Data Service (auth-data)
- Single Server (auth-single-server)

b) Data Layer:
- PostgreSQL Database Client (auth-data-postgres-client)
- gRPC Data Services (auth-data-grpc-server, auth-data-grpc-client)

##### Architectural Patterns to Highlight

- Microservices architecture
- gRPC communication between services
- Domain-Driven Design (DDD) patterns
- OAuth 2.1 & OIDC flows

##### Component Relationships

**[External Clients] → [Auth API Service]**
- ↘ [Authorization Server API]

**[Auth Services] ↔ [gRPC Layer] ↔ [Data Services] ↔ [PostgreSQL]**

##### Detailed Component Breakdown

For each major component, include:

a) Auth API Service:
- Applications management
- Clients management
- Users management
- Templates management
- Scopes management

b) Authorization Server:
- OAuth 2.1 flows
- OIDC implementation
- JWT handling
- JWKS endpoints

c) Data Layer:
- Domain models
- Repository implementations
- Service interfaces

##### Elements

- Service boundaries
- API endpoints
- Data flow directions
- Security zones
- Authentication flows
- Database connections

##### Implementation Details

Show:
- gRPC service connections
- REST API endpoints
- Database interactions
- Template rendering flows
- JWT handling

##### Security Boundaries

Clearly mark:
- Public endpoints
- Protected resources
- Internal service communication
- Authentication boundaries

**[Client Layer]**
- ↓
**[API Gateway Layer]**
- ↓
**[Service Layer]**
- ↓
**[Data Access Layer]**
- ↓
**[Storage Layer]**

Remember to:
- Keep components aligned with the domain model
- Clear boundaries between services
- Authentication and authorization flows
- Public vs. private interfaces
- Major data flows

This will provide a clear visualization of the system's architecture while maintaining the necessary level of detail for implementation understanding.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef external fill:#2374AB,color:white
    classDef api fill:#48A9A6,color:white
    classDef service fill:#4DAA57,color:white
    classDef data fill:#E4C44C,color:black
    classDef storage fill:#D4D4D4,color:black
    classDef security fill:#E76D83,color:white

    %% External Layer
    Client["External Clients"]:::external

    %% API Gateway Layer
    subgraph API_Layer["API Layer"]
        AuthAPI["Auth API Service"]:::api
        AuthServer["Authorization Server API"]:::api
        SingleServer["Single Server"]:::api
    end

    %% Service Layer
    subgraph Service_Layer["Service Layer"]
        AppService["Application Service"]:::service
        AuthService["Authorization Service"]:::service
        ClientService["Client Service"]:::service
        UserService["User Service"]:::service
    end

    %% Data Access Layer
    subgraph Data_Layer["Data Access Layer"]
        GRPCServer["gRPC Server"]:::data
        GRPCClient["gRPC Client"]:::data
        PostgresClient["PostgreSQL Client"]:::data
    end

    %% Storage Layer
    Database[(PostgreSQL Database)]:::storage

    %% Relationships
    Client --> AuthAPI
    Client --> AuthServer
    Client --> SingleServer

    AuthAPI --> AppService
    AuthAPI --> ClientService
    AuthAPI --> UserService

    AuthServer --> AuthService
    AuthServer --> ClientService
    AuthServer --> UserService

    SingleServer --> AppService
    SingleServer --> AuthService
    SingleServer --> ClientService
    SingleServer --> UserService

    AppService & AuthService & ClientService & UserService --> GRPCClient
    GRPCClient --> GRPCServer
    GRPCServer --> PostgresClient
    PostgresClient --> Database

    %% Click Events
    click AuthAPI "https://github.com/cartobucket/auth/tree/main/auth-api/"
    click AuthServer "https://github.com/cartobucket/auth/tree/main/auth-authorization-server-api/"
    click SingleServer "https://github.com/cartobucket/auth/tree/main/auth-single-server/src/main/java/com/cartobucket/auth/single/server/"
    click AppService "https://github.com/cartobucket/auth/blob/main/auth-data/src/main/java/com/cartobucket/auth/data/services/ApplicationService.java"
    click AuthService "https://github.com/cartobucket/auth/blob/main/auth-data/src/main/java/com/cartobucket/auth/data/services/AuthorizationServerService.java"
    click ClientService "https://github.com/cartobucket/auth/blob/main/auth-data/src/main/java/com/cartobucket/auth/data/services/ClientService.java"
    click UserService "https://github.com/cartobucket/auth/blob/main/auth-data/src/main/java/com/cartobucket/auth/data/services/UserService.java"
    click GRPCServer "https://github.com/cartobucket/auth/tree/main/auth-data-grpc-server/"
    click GRPCClient "https://github.com/cartobucket/auth/tree/main/auth-data-grpc-client/"
    click PostgresClient "https://github.com/cartobucket/auth/tree/main/auth-data-postgres-client/src/main/java/com/cartobucket/auth/postgres/client/"

    %% Legend
    subgraph Legend
        ExtL["External"]:::external
        APIL["API Services"]:::api
        ServL["Domain Services"]:::service
        DataL["Data Services"]:::data
        StorL["Storage"]:::storage
    end
```
