# line/line-fido2-server architecture

> Architecture diagram of the GitHub repository line/line-fido2-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/line/line-fido2-server
- Repository: https://github.com/line/line-fido2-server

## Overview

##### Project Type & Purpose
- This is a modular, multi-module Java/Spring Boot project providing:
- A FIDO2 (WebAuthn) Server implementation (certified by FIDO Alliance)
- A “relying party” demo server (RP Server) that fronts the WebAuthn flows
- Underlying common message models and core domain logic provided as libraries
- Key use case: Registration and Authentication of users via FIDO2 authenticators.

##### File Structure
- Top-level modules:
- **common**: Shared message/domain classes (DTOs) used by both servers
- **fido2-core**: Core FIDO2 logic (challenge generation, attestation verification, COSE processing); no persistence
- **fido2-demo/base**: Spring Data JPA layer (entities, repos, services) wired on top of fido2-core
- **fido2-demo/demo**: Spring Boot application exposing FIDO2 REST endpoints, using base module
- **rpserver**: Spring Boot “relying party” demo with static front-end, controllers, adapters to call the FIDO2 server
- Cross-cutting:
- **docker-compose.yml** to spin up rpserver + demo
- **Data stores**: MySQL/H2 for user credentials & metadata, Redis for session/challenge storage
- **External**: FIDO Alliance Metadata Service (MDSv3) for metadata certificate fetch

##### README Insights
- Modules and dependencies are explicitly listed
- Technologies: Spring Boot 2.7, Java 11, Spring Data JPA, H2/MySQL, Redis, Spring REST Docs, Swagger
- Features: multiple attestation types, MDS integration, optional Android/iOS origin checks

##### Main Components & Interactions
a. Components:
1. **Web Client** (Browser or Mobile using WebAuthn API)
2. **RP Server** (rpserver module) – serves static UI, handles initial user requests, proxies to FIDO2 Server
3. **FIDO2 Server** (fido2-demo/demo module):
- Controllers → Services → Repositories
- Depends on **fido2-demo/base** for JPA and **fido2-core** for domain logic
4. **Relational DB** (H2/MySQL) – stores UserKeyEntity, Metadata, RP info
5. **Redis** – stores session state / challenge data
6. **External MDSv3 Service** – FIDO Alliance metadata endpoint
7. **Common Library** (common module) – message definitions shared by both servers
8. **Core Library** (fido2-core module) – challenge/attestation logic

b. Relationships:
- Web Client ↔ RP Server (HTTPS, REST)
- RP Server ↔ FIDO2 Server (HTTPS, REST, using common DTOs)
- FIDO2 Server → Redis (for challenges)
- FIDO2 Server → RDB (for credentials, metadata)
- FIDO2 Server → External MDSv3 (HTTP fetch of metadata TOC & certificates)
- All server modules depend on **common**; demo depends on **base**, which depends on **core**

c. Architectural Patterns & Principles:
- **Layered** (Controller → Service → Repository) within each Spring Boot app
- **Modularization**: clear separation of domain logic (core), persistence (base), shared messages (common), and runtime apps (demo & rpserver)
- **Hexagonal/Library** style for fido2-core (no direct I/O)
- **API Gateway-style proxy**: RP Server fronts the flow

d. Technologies/Frameworks:
- Java 11, Spring Boot (2.7.x)
- Spring MVC, Spring Data JPA, Spring Cache/Redis
- Docker + docker-compose
- Swagger UI, Spring REST Docs

##### Detailed Yet Focused
- Module’s role: common vs core vs base vs demo vs rpserver
- Runtime vs compile-time dependencies distinctly
- Do **not** enumerate every class; group by package or module
- Challenge‐response flow (registration & authentication) is obvious

- Two Spring Boot microservices (RP Server & FIDO2 Server)
- The shared libraries feeding into them
- Backing stores (RDB, Redis) and external metadata service
- Web client interaction
- Data flows and dependency directions

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    WebClient["Web Client (Browser/Mobile)"]:::client

    %% RP Server
    subgraph "RP Server (Spring Boot)" 
        RpApp["RpserverApplication\n(port:8080)"]:::service
    end

    %% FIDO2 Server
    subgraph "FIDO2 Server (Spring Boot)"
        FidoApp["Fido2StarterDemoApplication\n(port:8081)"]:::service
    end

    %% Libraries (Compile-time Dependencies)
    subgraph Libraries
        Common["Common Library\n(shared DTOs & models)"]:::library
        Core["Core Library\n(FIDO2 domain logic)"]:::library
        Base["Base Persistence Module\n(Spring Data JPA)"]:::library
    end

    %% Datastores
    subgraph Datastores
        RDB["Relational DB\n(MySQL/H2)"]:::rdb
        Redis["Redis\n(Session Store)"]:::redis
    end

    %% External Service
    ExternalMDS["External MDSv3 Service\n(FIDO Alliance)"]:::external

    %% Orchestration
    Docker["docker-compose.yml"]:::config

    %% Runtime Interactions
    WebClient -->|"HTTPS"| RpApp
    RpApp -->|"REST/HTTPS"| FidoApp
    FidoApp -->|"JDBC"| RDB
    FidoApp -->|"Redis TCP"| Redis
    FidoApp -->|"HTTP"| ExternalMDS

    %% Compile-time Dependencies
    RpApp -.->|uses| Common
    RpApp -.->|uses| Core
    FidoApp -.->|uses| Common
    FidoApp -.->|uses| Base
    Base -.->|depends on| Core
    Base -.->|uses| Common

    %% Orchestration Connections
    Docker --> RpApp
    Docker --> FidoApp

    %% Click Events
    click Common "https://github.com/line/line-fido2-server/tree/main/common/"
    click Core "https://github.com/line/line-fido2-server/tree/main/fido2-core/"
    click Base "https://github.com/line/line-fido2-server/tree/main/fido2-demo/base/"
    click FidoApp "https://github.com/line/line-fido2-server/blob/main/fido2-demo/demo/src/main/java/com/linecorp/line/auth/fido/fido2/demo/Fido2StarterDemoApplication.java"
    click RpApp "https://github.com/line/line-fido2-server/blob/main/rpserver/src/main/java/com/linecorp/line/auth/fido/fido2/rpserver/RpserverApplication.java"
    click Docker "https://github.com/line/line-fido2-server/blob/main/docker-compose.yml"

    %% Styles
    classDef client fill:#E0FFFF,stroke:#333,stroke-width:1px
    classDef service fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef library fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef rdb fill:#90EE90,stroke:#333,stroke-width:1px
    classDef redis fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#FFFFFF,stroke-dasharray: 5 5,stroke:#333,stroke-width:1px
    classDef config fill:#FFFACD,stroke:#333,stroke-width:1px
```
