# openedx/enterprise-access architecture

> Architecture diagram of the GitHub repository openedx/enterprise-access, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openedx/enterprise-access
- Repository: https://github.com/openedx/enterprise-access

## Overview

##### Project type and purpose
- This is a Python/Django-based, modular monolith service (“enterprise-access”) that exposes REST-style APIs and BFF endpoints, processes background work via Celery, and produces/consumes Kafka events.
- Its core goal is to manage enterprise user access to content (assignments, subsidies, provisioning, billing) and integrate with upstream systems (LMS, catalog, e-commerce, license manager) plus analytics (Segment) and payment (Stripe).

##### File structure
- Top-level: manage.py, WSGI, Celery entrypoint, Docker and Devstack config.
- “enterprise_access/apps/…” contains a suite of Django apps (core, api, bffs, content_assignments, subsidy_access_policy, subsidy_request, provisioning, customer_billing, enterprise_groups, events, track, workflow).
- Each app defines models, serializers, views/endpoints, admin, tasks, management commands, migrations, and tests.
- There are OpenAPI specs (api.yaml, api-compact.yaml) driving API definitions.
- Celery is configured in celery.py; Kafka/event consumption in management commands and event bus packages.
- External clients under apps/api_client for talking to LMS, catalog, e-commerce, etc.
- Settings split by environment (base, devstack, production, test).

##### README for additional insights
- Service runs on Django + Gunicorn in Docker; leverages Devstack for local dependencies (Kafka, Postgres, Redis).
- It consumes and produces “openedx-events” topics via edx_event_bus_kafka.
- Analytics events dispatched via track_event (Segment).
- Management commands exist to test and bootstrap event flows.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Clients["Client Browsers / edX MFEs"]:::external

    %% HTTP Layer
    subgraph "HTTP/API Layer"
        direction TB
        Manage["manage.py"]:::frontend
        WSGI["wsgi.py"]:::frontend
        Router["Django Router"]:::frontend
        API["REST API: apps/api, apps/api/v1"]:::frontend
        BFF["BFF Layer: apps/bffs"]:::frontend
        Spec1["api.yaml"]:::frontend
        Spec2["api-compact.yaml"]:::frontend
        APIClients["API Clients\napps/api_client"]:::frontend
    end

    %% Persistence Layer
    subgraph "Persistence"
        DB["PostgreSQL"]:::infra
    end

    %% Async Layer
    subgraph "Async Layer"
        direction TB
        Broker["Redis/RabbitMQ Broker"]:::async
        CeleryConfig["Celery Config\ncelery.py"]:::async
        TasksCore["Core Tasks\ntasks.py"]:::async
        TasksApp["App-specific Tasks\napps/.../tasks.py"]:::async
    end

    %% Event Bus
    subgraph "Event Bus"
        direction TB
        Kafka["Kafka Cluster\n(openedx-events)"]:::event
        ManagementConsumer["Consumer Command\nconsume_enterprise_ping_events.py"]:::event
        EventUtils["Event Utils\napps/events/utils.py"]:::event
    end

    %% External Services
    subgraph "External Services"
        direction TB
        LMS["LMS Client"]:::external
        Catalog["Enterprise Catalog Client"]:::external
        Discovery["Discovery Service Client"]:::external
        Ecom["E-commerce Client"]:::external
        LicenseMgr["License Manager Client"]:::external
        Stripe["Stripe Integration"]:::external
        Segment["Segment Tracking"]:::external
    end

    %% Configuration
    subgraph "Configuration"
        direction TB
        Base["base.py"]:::infra
        DevstackSet["devstack.py"]:::infra
        Prod["production.py"]:::infra
        TestSet["test.py"]:::infra
    end

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

    %% Connections
    Clients -->|"HTTP/REST"| Manage
    Manage --> WSGI
    WSGI --> Router
    Spec1 --> Router
    Spec2 --> Router
    Router --> API
    Router --> BFF
    API --> Router
    BFF --> Router
    Router --> ORM[(ORM)]
    ORM --> DB

    Router -->|"AMQP"| Broker
    API -->|"AMQP"| Broker
    BFF -->|"AMQP"| Broker
    Broker --> TasksCore
    Broker --> TasksApp
    CeleryConfig --> Broker
    CeleryConfig --> TasksCore
    CeleryConfig --> TasksApp

    TasksCore --> DB
    TasksApp --> DB
    TasksCore -->|"Kafka"| Kafka
    TasksApp -->|"Kafka"| Kafka

    Kafka --> ManagementConsumer
    ManagementConsumer --> Router
    ManagementConsumer --> TasksApp
    ManagementConsumer --> DB
    Kafka --> EventUtils

    Router -->|"HTTP/REST"| LMS
    Router -->|"HTTP/REST"| Catalog
    Router -->|"HTTP/REST"| Discovery
    Router -->|"HTTP/REST"| Ecom
    Router -->|"HTTP/REST"| LicenseMgr
    Router -->|"Webhook/HTTP"| Stripe
    Router -->|"Analytics"| Segment
    TasksCore -->|"Analytics"| Segment
    TasksApp -->|"Analytics"| Segment

    Base --> Router
    DevstackSet --> Router
    Prod --> Router
    TestSet --> Router
    Base --> CeleryConfig
    DevstackSet --> CeleryConfig
    Prod --> CeleryConfig
    TestSet --> CeleryConfig

    Docker --> DB
    Docker --> Broker
    Docker --> Kafka

    %% Click Events
    click API "https://github.com/openedx/enterprise-access/tree/main/enterprise_access/apps/api"
    click BFF "https://github.com/openedx/enterprise-access/tree/main/enterprise_access/apps/bffs"
    click CeleryConfig "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/celery.py"
    click TasksCore "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/tasks.py"
    click TasksApp "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/apps/content_assignments/tasks.py"
    click ManagementConsumer "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/apps/core/management/commands/consume_enterprise_ping_events.py"
    click EventUtils "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/apps/events/utils.py"
    click Spec1 "https://github.com/openedx/enterprise-access/blob/main/api.yaml"
    click Spec2 "https://github.com/openedx/enterprise-access/blob/main/api-compact.yaml"
    click Base "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/settings/base.py"
    click DevstackSet "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/settings/devstack.py"
    click Prod "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/settings/production.py"
    click TestSet "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/settings/test.py"
    click LMS "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/apps/api_client/lms_client.py"
    click Catalog "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/apps/api_client/enterprise_catalog_client.py"
    click Discovery "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/apps/api_client/discovery_client.py"
    click Ecom "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/apps/api_client/ecommerce_client.py"
    click LicenseMgr "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/apps/api_client/license_manager_client.py"
    click Stripe "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/apps/customer_billing/stripe_api.py"
    click Segment "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/apps/track/segment.py"
    click Manage "https://github.com/openedx/enterprise-access/blob/main/manage.py"
    click WSGI "https://github.com/openedx/enterprise-access/blob/main/enterprise_access/wsgi.py"
    click Docker "https://github.com/openedx/enterprise-access/blob/main/docker-compose.yml"

    %% Styles
    classDef frontend fill:#E0F2FF,stroke:#333,stroke-width:1px
    classDef async fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef event fill:#E0FFE0,stroke:#333,stroke-width:1px
    classDef external fill:#EEEEEE,stroke:#333,stroke-width:1px
    classDef infra fill:#F5F5F5,stroke:#333,stroke-width:1px
```
