# tough-dev-school/education-backend architecture

> Architecture diagram of the GitHub repository tough-dev-school/education-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tough-dev-school/education-backend
- Repository: https://github.com/tough-dev-school/education-backend

## Overview

##### Main Components
- Web/API Server: Represent the Django application acting as a WSGI server (or ASGI if applicable). It handles HTTP requests from clients (the frontend, which is a vue.js application in a separate repo).
- Core/Configuration Layer: Include the “core” component that holds global settings, configurations, integrations (e.g., payment integrations, third-party APIs), middleware, and shared utility functions.
- Database: Indicate Postgres as the central relational database (configured via docker-compose).
- Redis/Cache and Celery Tasks: Show the caching layer and message broker (Redis) that support background workers (Celery) – as indicated by the celery.py file and tasks directories in “src/core/tasks.”
- External Integrations: Create external components for payment gateways (Tinkoff, Stripebank, banking), email/messaging services (Dashamail, Postmark), file storage (S3), and notifications (Telegram). These should be depicted outside of the main application boundaries and connected via integration service modules.

##### Architectural Patterns and Design Principles
- Modular and Domain-Driven Organization: Emphasize that the design splits the application into many self-contained Django apps (each with its own models, migrations, tests, services, and API endpoints). This encapsulation supports clear separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    subgraph "Frontend"
        FE["Client (Frontend)"]:::external
    end

    %% API Layer
    subgraph "API Layer"
        DjangoAPI["Django Web/API Server"]:::internal
        Admin["Django Admin"]:::internal
    end

    %% Domain-specific Django Apps
    subgraph "Domain Apps"
        Users["Users App"]:::internal
        Orders["Orders App"]:::internal
        Products["Products App"]:::internal
        Homework["Homework App"]:::internal
        Tinkoff["Tinkoff App"]:::internal
        Stripebank["Stripebank App"]:::internal
        Amocrm["amocrm App"]:::internal
        Banking["Banking App"]:::internal
        Dashamail["Dashamail App"]:::internal
        Mailing["Mailing App"]:::internal
        Notion["Notion App"]:::internal
        Studying["Studying App"]:::internal
    end

    %% Core/Configuration and Background Tasks
    subgraph "Core/Configuration & Background"
        CoreConfig["Core Configuration"]:::internal
        CoreConf["Core Configurations Directory"]:::internal
        CeleryWorker["Celery Worker"]:::internal
        CeleryTasks["Celery Tasks"]:::internal
    end

    %% Data Layer
    subgraph "Data Layer"
        PostgresDB["Postgres DB"]:::internal
        RedisBroker["Redis/Cache"]:::internal
    end

    %% External Integrations
    subgraph "External Integrations"
        TinkoffGateway["Tinkoff Payment Gateway"]:::external
        StripebankGateway["Stripebank Payment Gateway"]:::external
        BankingGateway["Banking Payment Gateway"]:::external
        DashamailService["Dashamail Email Service"]:::external
        PostmarkService["Postmark Email Service"]:::external
        TelegramService["Telegram Notification"]:::external
        S3Storage["S3 Storage"]:::external
    end

    %% Infrastructure
    subgraph "Infrastructure"
        DockerCompose["Docker Compose"]:::infrastructure
        DockerfileNode["Dockerfile"]:::infrastructure
    end

    %% Connections from Frontend to API
    FE -->|"HTTP_Request"| DjangoAPI

    %% API Layer connections
    DjangoAPI -->|"Delegates_to"| Users
    DjangoAPI -->|"Delegates_to"| Orders
    DjangoAPI -->|"Delegates_to"| Products
    DjangoAPI -->|"Delegates_to"| Homework
    DjangoAPI -->|"Delegates_to"| Tinkoff
    DjangoAPI -->|"Delegates_to"| Stripebank
    DjangoAPI -->|"Delegates_to"| Amocrm
    DjangoAPI -->|"Delegates_to"| Banking
    DjangoAPI -->|"Delegates_to"| Dashamail
    DjangoAPI -->|"Delegates_to"| Mailing
    DjangoAPI -->|"Delegates_to"| Notion
    DjangoAPI -->|"Delegates_to"| Studying
    DjangoAPI -->|"Accessible_Admin"| Admin
    DjangoAPI -->|"Offload_Tasks"| CeleryWorker

    %% Domain Apps interacting with Database
    Users <-->|"DB_Query"| PostgresDB
    Orders <-->|"DB_Query"| PostgresDB
    Products <-->|"DB_Query"| PostgresDB
    Homework <-->|"DB_Query"| PostgresDB
    Tinkoff <-->|"DB_Query"| PostgresDB
    Stripebank <-->|"DB_Query"| PostgresDB
    Amocrm <-->|"DB_Query"| PostgresDB
    Banking <-->|"DB_Query"| PostgresDB
    Dashamail <-->|"DB_Query"| PostgresDB
    Mailing <-->|"DB_Query"| PostgresDB
    Notion <-->|"DB_Query"| PostgresDB
    Studying <-->|"DB_Query"| PostgresDB

    %% Background Tasks flow
    CeleryWorker -->|"Queue_Tasks"| CeleryTasks
    CeleryTasks -->|"Notify"| TelegramService
    CeleryWorker -->|"Uses"| RedisBroker

    %% External Payment Integrations from Domain Apps
    Tinkoff -->|"Process_Payment"| TinkoffGateway
    Stripebank -->|"Process_Payment"| StripebankGateway
    Banking -->|"Process_Payment"| BankingGateway

    %% External Email/Notification Integrations
    Dashamail -->|"Send_Email"| DashamailService
    Mailing -->|"Send_Email"| PostmarkService

    %% Core configurations for integrations
    CoreConfig -->|"Configures"| S3Storage
    CoreConfig -->|"Configures"| TelegramService
    CoreConfig -->|"Imports_Integrations"| CoreConf

    %% Infrastructure hosts
    DockerCompose -->|"Hosts"| DjangoAPI
    DockerCompose -->|"Hosts"| PostgresDB
    DockerCompose -->|"Hosts"| RedisBroker
    DockerfileNode -->|"Defines_Image"| DjangoAPI

    %% Styles
    classDef internal fill:#AED6F1,stroke:#1F618D,color:#1F618D;
    classDef external fill:#F9E79F,stroke:#B9770E,color:#B9770E;
    classDef infrastructure fill:#D5F5E3,stroke:#28B463,color:#28B463;

    %% Click Events
    click DjangoAPI "https://github.com/tough-dev-school/education-backend/blob/master/src/manage.py"
    click DjangoAPI "https://github.com/tough-dev-school/education-backend/blob/master/src/core/wsgi.py"
    click Users "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/users"
    click Orders "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/orders"
    click Products "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/products"
    click Homework "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/homework"
    click Tinkoff "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/tinkoff"
    click Stripebank "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/stripebank"
    click Amocrm "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/amocrm"
    click Banking "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/banking"
    click Dashamail "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/dashamail"
    click Mailing "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/mailing"
    click Notion "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/notion"
    click Studying "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/studying"
    click CoreConfig "https://github.com/tough-dev-school/education-backend/blob/master/src/core/settings.py"
    click CoreConf "https://github.com/tough-dev-school/education-backend/tree/master/src/core/conf"
    click CeleryWorker "https://github.com/tough-dev-school/education-backend/blob/master/src/core/celery.py"
    click CeleryTasks "https://github.com/tough-dev-school/education-backend/tree/master/src/core/tasks"
    click PostgresDB "https://github.com/tough-dev-school/education-backend/blob/master/docker-compose.yml"
    click RedisBroker "https://github.com/tough-dev-school/education-backend/blob/master/docker-compose.yml"
    click Banking "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/banking"
    click BankingGateway "https://github.com/tough-dev-school/education-backend/tree/master/src/core/conf/integrations/banking/"
    click Dashamail "https://github.com/tough-dev-school/education-backend/tree/master/src/apps/dashamail"
    click dashamail_conf "https://github.com/tough-dev-school/education-backend/blob/master/src/core/conf/integrations/dashamail.py"
    click S3Storage "https://github.com/tough-dev-school/education-backend/blob/master/src/core/integrations/s3.py"
    click TelegramService "https://github.com/tough-dev-school/education-backend/blob/master/src/core/integrations/tg.py"
    click TelegramService "https://github.com/tough-dev-school/education-backend/blob/master/src/core/tasks/tg.py"
    click DockerCompose "https://github.com/tough-dev-school/education-backend/blob/master/docker-compose.yml"
    click DockerfileNode "https://github.com/tough-dev-school/education-backend/tree/master/Dockerfile"
```
