# academic-innovation/django-lti architecture

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

- Interactive diagram: https://gitdiagram.com/academic-innovation/django-lti
- Repository: https://github.com/academic-innovation/django-lti

## Overview

##### Main Components

a) External Systems Layer:
- LTI Platform (e.g., Learning Management System)
- Client Browser

b) Application Layer (Core):
- OIDC Authentication Flow Component
- JWKS (JSON Web Key Set) Management
- LTI Launch Handler

c) Django Framework Layer:
- Middleware Component (LtiLaunchMiddleware)
- Views Layer
- Models Layer
- Services Layer

d) Database Layer:
- PostgreSQL/MySQL (based on Django's ORM)

##### Component Relationships

- LTI Platform → OIDC Login Initiation
- OIDC Flow → LTI Launch Handler
- LTI Launch Handler → Middleware
- Middleware → Views
- Views → Models
- Models → Database

##### Key Architectural Elements

a) Authentication Flow:
- JWKS endpoint (.well-known/jwks.json)
- OIDC initialization endpoint
- Key rotation mechanism

b) Core LTI Components:
- Resource Launch Handler
- Deep Linking Launch Handler
- Submission Review Handler
- Data Privacy Handler

##### Important Details

Annotations for:
- Security mechanisms (JWT handling)
- Session management
- Database models (LtiContext, LtiMembership, LtiLineItem)
- Service integrations (NRPS service)

##### Specific Implementation Notes

Callouts for:
- Middleware position (after SessionMiddleware)
- Key rotation mechanism
- Launch message handling flow
- Session state management

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Systems Layer
    subgraph External
        LMS[LTI Platform/LMS]
        Browser[Client Browser]
    end

    %% Authentication Layer
    subgraph Auth
        OIDC[OIDC Authentication Flow]
        JWKS[JWKS Management]:::security
        click JWKS "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/management/commands/rotate_keys.py"
    end

    %% Core Application Layer
    subgraph Core
        Launch[LTI Launch Handler]:::core
        click Launch "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/views.py"
        
        subgraph Services
            NRPS[NRPS Service]:::service
            click NRPS "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/services/nrps.py"
            ServicesLayer[Services Layer]:::service
            click ServicesLayer "https://github.com/academic-innovation/django-lti/tree/main/lti_tool/services/"
        end
    end

    %% Django Framework Layer
    subgraph Django
        Middleware[LtiLaunchMiddleware]:::middleware
        click Middleware "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/middleware.py"
        
        Views[Views Layer]:::views
        
        Models[Models Layer]:::models
        click Models "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/models.py"
        
        Decorators[Custom Decorators]:::util
        click Decorators "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/decorators.py"
        
        Utils[Utility Functions]:::util
        click Utils "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/utils.py"
        
        Constants[Core Constants]:::util
        click Constants "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/constants.py"
    end

    %% Database Layer
    subgraph Database
        DB[(PostgreSQL/MySQL)]
        
        subgraph Models
            LTIContext[LTI Context]:::model
            click LTIContext "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/migrations/0003_lticontext_memberships_url_ltimembership_is_active.py"
            
            LTIMembership[LTI Membership]:::model
            click LTIMembership "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/migrations/0003_lticontext_memberships_url_ltimembership_is_active.py"
            
            LTILineItem[LTI LineItem]:::model
            click LTILineItem "https://github.com/academic-innovation/django-lti/blob/main/lti_tool/migrations/0005_ltilineitem.py"
        end
    end

    %% Relationships
    LMS --> OIDC
    Browser --> LMS
    OIDC --> JWKS
    JWKS --> Launch
    Launch --> Middleware
    Middleware --> Views
    Views --> Models
    Models --> DB
    Views --> Services
    Services --> Models
    NRPS --> Models

    %% Styling
    classDef security fill:#ff9999
    classDef core fill:#99ccff
    classDef service fill:#ffcc99
    classDef middleware fill:#cc99ff
    classDef views fill:#99ff99
    classDef models fill:#ffff99
    classDef util fill:#cccccc
    classDef model fill:#99ffcc

    %% Legend
    subgraph Legend
        Security[Security Component]:::security
        CoreComp[Core Component]:::core
        ServiceComp[Service Component]:::service
        MiddlewareComp[Middleware Component]:::middleware
        ViewComp[View Component]:::views
        ModelComp[Model Component]:::models
        UtilComp[Utility Component]:::util
        DBModel[Database Model]:::model
    end
```
