# l4s3r/authn-z architecture

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

- Interactive diagram: https://gitdiagram.com/l4s3r/authn-z
- Repository: https://github.com/l4s3r/authn-z

## Overview

Auth N&Z is a FastAPI identity and multi-tenant authorization engine. A user reaches authentication and domain operations through the API gateway; authentication can use passwords, MFA, passkeys, or OAuth, then issues tokens and sessions. Workspace, policy, task, and notification capabilities extend that flow. The graph preserves documented product branches, while unsampled implementation links are omitted or marked unverified; relationships between API dependencies and services are based on the source index.

Main entry points: [`api/dependencies.py`](https://github.com/l4s3r/authn-z/blob/master/api/dependencies.py) (API Dependencies), [`authenticator.py`](https://github.com/l4s3r/authn-z/blob/master/authenticator.py) (Authentication), [`server.py`](https://github.com/l4s3r/authn-z/blob/master/server.py) (FastAPI Gateway), [`api/v1/auth_router.py`](https://github.com/l4s3r/authn-z/blob/master/api/v1/auth_router.py) (Auth Endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API Surface"]
  node_gateway["FastAPI Gateway<br/>[server.py]"]
  node_router["Router Factory<br/>[router.py]"]
  node_deps["API Dependencies<br/>[dependencies.py]"]
  node_schemas["Request Schemas<br/>[schemas.py]"]
  node_authroutes["Auth Endpoints<br/>[auth_router.py]"]
  node_mfaroutes["MFA Endpoints<br/>[mfa_router.py]"]
end

subgraph group_identity["Identity &amp; Sessions"]
  node_authenticator["Authentication<br/>[authenticator.py]"]
  node_oauth["OAuth / OIDC<br/>[oauth_provider.py]"]
  node_webauthn["Passkeys"]
  node_device["Device Trust"]
  node_tokens["Token Service<br/>[token_service.py]"]
  node_sessions["Session Store<br/>[session_store.py]"]
  node_users["User Repository<br/>[user_repository.py]"]
end

subgraph group_authorization["Authorization &amp; Tenancy"]
  node_guards["Authorization Guards<br/>[guards.py]"]
  node_policy["Policy Engine<br/>[policy_engine.py]"]
  node_opa["OPA Client<br/>[opa_client.py]"]
end

subgraph group_domain["Product Domains"]
  node_workspaces["Workspace API"]
  node_workspace_store["Workspace Repository"]
  node_tasks["Task API<br/>[task_router.py]"]
  node_task_store["Task Repository<br/>[task_repository.py]"]
  node_websocket["Realtime Events"]
end

subgraph group_platform["Persistence &amp; Operations"]
  node_audit["Audit Logging<br/>[audit_logger.py]"]
  node_metrics["Metrics<br/>[metrics.py]"]
  node_database[("PostgreSQL Sessions<br/>[database.py]")]
end

node_user(("Client / User"))
node_redis[("Redis")]
node_email["SMTP Email"]
node_identity_provider["OAuth Providers"]

node_user -->|"sends requests"| node_gateway
node_gateway -->|"mounts routes"| node_router
node_router -->|"registers routes"| node_authroutes
node_authroutes -->|"uses dependencies"| node_deps
node_mfaroutes -->|"uses dependencies"| node_deps
node_authroutes -->|"validates payloads"| node_schemas
node_mfaroutes -->|"validates payloads"| node_schemas
node_deps -->|"provides service"| node_authenticator
node_deps -->|"provides service"| node_tokens
node_deps -->|"provides service"| node_sessions
node_deps -->|"provides repository"| node_users
node_deps -->|"provides service"| node_device
node_deps -->|"provides service"| node_oauth
node_deps -->|"provides service"| node_webauthn
node_authenticator -->|"queries accounts"| node_users
node_authenticator -->|"issues tokens"| node_tokens
node_authenticator -->|"manages sessions"| node_sessions
node_authenticator -->|"checks trusted devices"| node_device
node_user -->|"signs in socially"| node_oauth
node_oauth -->|"exchanges credentials"| node_identity_provider
node_user -->|"uses passkey"| node_webauthn
node_user -->|"submits MFA"| node_mfaroutes
node_guards -->|"uses request dependencies"| node_deps
node_deps -->|"provides policy service"| node_policy
node_policy -->|"evaluates externally"| node_opa
node_policy -->|"caches decisions"| node_redis
node_user -->|"manages tenants"| node_workspaces
node_workspaces -.->|"persists membership"| node_workspace_store
node_user -->|"manages tasks"| node_tasks
node_tasks -->|"persists tasks"| node_task_store
node_tasks -->|"publishes events"| node_websocket
node_websocket -->|"synchronizes broadcasts"| node_redis
node_workspaces -->|"dispatches invitations"| node_email
node_user -->|"generates security events"| node_audit
node_gateway -->|"exposes telemetry"| node_metrics
node_users -->|"reads and writes"| node_database
node_workspace_store -->|"reads and writes"| node_database
node_task_store -->|"reads and writes"| node_database
node_sessions -->|"stores sessions"| node_redis

click node_gateway "https://github.com/l4s3r/authn-z/blob/master/server.py"
click node_router "https://github.com/l4s3r/authn-z/blob/master/api/router.py"
click node_deps "https://github.com/l4s3r/authn-z/blob/master/api/dependencies.py"
click node_schemas "https://github.com/l4s3r/authn-z/blob/master/api/schemas.py"
click node_authroutes "https://github.com/l4s3r/authn-z/blob/master/api/v1/auth_router.py"
click node_mfaroutes "https://github.com/l4s3r/authn-z/blob/master/api/v1/mfa_router.py"
click node_authenticator "https://github.com/l4s3r/authn-z/blob/master/authenticator.py"
click node_oauth "https://github.com/l4s3r/authn-z/blob/master/oauth_provider.py"
click node_webauthn "https://github.com/l4s3r/authn-z/blob/master/webauthn_service.py"
click node_device "https://github.com/l4s3r/authn-z/blob/master/device_trust_service.py"
click node_tokens "https://github.com/l4s3r/authn-z/blob/master/token_service.py"
click node_sessions "https://github.com/l4s3r/authn-z/blob/master/session_store.py"
click node_users "https://github.com/l4s3r/authn-z/blob/master/user_repository.py"
click node_guards "https://github.com/l4s3r/authn-z/blob/master/guards.py"
click node_policy "https://github.com/l4s3r/authn-z/blob/master/policy_engine.py"
click node_opa "https://github.com/l4s3r/authn-z/blob/master/opa_client.py"
click node_workspaces "https://github.com/l4s3r/authn-z/blob/master/api/v1/workspace_router.py"
click node_workspace_store "https://github.com/l4s3r/authn-z/blob/master/workspace_repository.py"
click node_tasks "https://github.com/l4s3r/authn-z/blob/master/api/v1/task_router.py"
click node_task_store "https://github.com/l4s3r/authn-z/blob/master/task_repository.py"
click node_websocket "https://github.com/l4s3r/authn-z/blob/master/api/v1/websocket_router.py"
click node_audit "https://github.com/l4s3r/authn-z/blob/master/audit_logger.py"
click node_metrics "https://github.com/l4s3r/authn-z/blob/master/metrics.py"
click node_database "https://github.com/l4s3r/authn-z/blob/master/database.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_gateway,node_router,node_deps,node_schemas,node_authroutes,node_mfaroutes,node_user toneBlue
class node_authenticator,node_oauth,node_webauthn,node_device,node_tokens,node_sessions,node_users,node_redis toneAmber
class node_guards,node_policy,node_opa toneMint
class node_workspaces,node_workspace_store,node_tasks,node_task_store,node_websocket toneRose
class node_audit,node_metrics,node_database,node_email,node_identity_provider toneIndigo
```

## Components

### API Surface

- [FastAPI Gateway](https://github.com/l4s3r/authn-z/blob/master/server.py): `server.py`
- [Router Factory](https://github.com/l4s3r/authn-z/blob/master/api/router.py): `api/router.py`
- [API Dependencies](https://github.com/l4s3r/authn-z/blob/master/api/dependencies.py): `api/dependencies.py`
- [Request Schemas](https://github.com/l4s3r/authn-z/blob/master/api/schemas.py): `api/schemas.py`
- [Auth Endpoints](https://github.com/l4s3r/authn-z/blob/master/api/v1/auth_router.py): `api/v1/auth_router.py`
- [MFA Endpoints](https://github.com/l4s3r/authn-z/blob/master/api/v1/mfa_router.py): `api/v1/mfa_router.py`

### Identity & Sessions

- [Authentication](https://github.com/l4s3r/authn-z/blob/master/authenticator.py): `authenticator.py`
- [OAuth / OIDC](https://github.com/l4s3r/authn-z/blob/master/oauth_provider.py): `oauth_provider.py`
- [Passkeys](https://github.com/l4s3r/authn-z/blob/master/webauthn_service.py): `webauthn_service.py`
- [Device Trust](https://github.com/l4s3r/authn-z/blob/master/device_trust_service.py): `device_trust_service.py`
- [Token Service](https://github.com/l4s3r/authn-z/blob/master/token_service.py): `token_service.py`
- [Session Store](https://github.com/l4s3r/authn-z/blob/master/session_store.py): `session_store.py`
- [User Repository](https://github.com/l4s3r/authn-z/blob/master/user_repository.py): `user_repository.py`

### Authorization & Tenancy

- [Authorization Guards](https://github.com/l4s3r/authn-z/blob/master/guards.py): `guards.py`
- [Policy Engine](https://github.com/l4s3r/authn-z/blob/master/policy_engine.py): `policy_engine.py`
- [OPA Client](https://github.com/l4s3r/authn-z/blob/master/opa_client.py): `opa_client.py`

### Product Domains

- [Workspace API](https://github.com/l4s3r/authn-z/blob/master/api/v1/workspace_router.py): `api/v1/workspace_router.py`
- [Workspace Repository](https://github.com/l4s3r/authn-z/blob/master/workspace_repository.py): `workspace_repository.py`
- [Task API](https://github.com/l4s3r/authn-z/blob/master/api/v1/task_router.py): `api/v1/task_router.py`
- [Task Repository](https://github.com/l4s3r/authn-z/blob/master/task_repository.py): `task_repository.py`
- [Realtime Events](https://github.com/l4s3r/authn-z/blob/master/api/v1/websocket_router.py): `api/v1/websocket_router.py`

### Persistence & Operations

- [Audit Logging](https://github.com/l4s3r/authn-z/blob/master/audit_logger.py): `audit_logger.py`
- [Metrics](https://github.com/l4s3r/authn-z/blob/master/metrics.py): `metrics.py`
- [PostgreSQL Sessions](https://github.com/l4s3r/authn-z/blob/master/database.py): `database.py`

### Other components

- **Client / User**
- **Redis**
- **SMTP Email**
- **OAuth Providers**

## Connections

- Client / User → FastAPI Gateway: sends requests
- FastAPI Gateway → Router Factory: mounts routes (evidence: `server.py`)
- Router Factory → Auth Endpoints: registers routes (evidence: `api/router.py`)
- Auth Endpoints → API Dependencies: uses dependencies (evidence: `api/v1/auth_router.py`)
- MFA Endpoints → API Dependencies: uses dependencies (evidence: `api/v1/mfa_router.py`)
- Auth Endpoints → Request Schemas: validates payloads (evidence: `api/v1/auth_router.py`)
- MFA Endpoints → Request Schemas: validates payloads (evidence: `api/v1/mfa_router.py`)
- API Dependencies → Authentication: provides service (evidence: `api/dependencies.py`)
- API Dependencies → Token Service: provides service (evidence: `api/dependencies.py`)
- API Dependencies → Session Store: provides service (evidence: `api/dependencies.py`)
- API Dependencies → User Repository: provides repository (evidence: `api/dependencies.py`)
- API Dependencies → Device Trust: provides service (evidence: `api/dependencies.py`)
- API Dependencies → OAuth / OIDC: provides service (evidence: `api/dependencies.py`)
- API Dependencies → Passkeys: provides service (evidence: `api/dependencies.py`)
- Authentication → User Repository: queries accounts (evidence: `authenticator.py`)
- Authentication → Token Service: issues tokens (evidence: `authenticator.py`)
- Authentication → Session Store: manages sessions (evidence: `authenticator.py`)
- Authentication → Device Trust: checks trusted devices (evidence: `authenticator.py`)
- Client / User → OAuth / OIDC: signs in socially
- OAuth / OIDC → OAuth Providers: exchanges credentials
- Client / User → Passkeys: uses passkey
- Client / User → MFA Endpoints: submits MFA
- Authorization Guards → API Dependencies: uses request dependencies (evidence: `guards.py`)
- API Dependencies → Policy Engine: provides policy service (evidence: `api/dependencies.py`)
- Policy Engine → OPA Client: evaluates externally (evidence: `policy_engine.py`)
- Policy Engine → Redis: caches decisions
- Client / User → Workspace API: manages tenants
- Workspace API → Workspace Repository: persists membership
- Client / User → Task API: manages tasks
- Task API → Task Repository: persists tasks (evidence: `api/v1/task_router.py`)
- Task API → Realtime Events: publishes events (evidence: `api/v1/task_router.py`)
- Realtime Events → Redis: synchronizes broadcasts (evidence: `api/v1/websocket_router.py`)
- Workspace API → SMTP Email: dispatches invitations
- Client / User → Audit Logging: generates security events
- FastAPI Gateway → Metrics: exposes telemetry (evidence: `server.py`)
- User Repository → PostgreSQL Sessions: reads and writes (evidence: `user_repository.py`)
- Workspace Repository → PostgreSQL Sessions: reads and writes (evidence: `workspace_repository.py`)
- Task Repository → PostgreSQL Sessions: reads and writes (evidence: `task_repository.py`)
- Session Store → Redis: stores sessions
