# meeio-app/backend architecture

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

- Interactive diagram: https://gitdiagram.com/meeio-app/backend
- Repository: https://github.com/meeio-app/backend

## Overview

##### Main Components

a) Client Layer:
- External clients (mobile/web applications)
- REST API endpoints grouping

b) Application Layer:
- Controllers (organized by domain: Flashcard, Review, Session, Topic, Unit, User, Admin)
- Security components (Authentication, Authorization)
- Message handling system

c) Domain Layer:
- Entities
- Repositories
- Services
- Spaced Repetition Algorithm

d) Infrastructure Layer:
- Database
- Message Queue
- Cache
- External Services

##### REST API Architecture
- Main resource endpoints (/flashcards, /topics, /units, /reviews, /sessions)
- Authentication/authorization flow
- Rate limiting component

##### Domain-Driven Design Elements
- Clear separation of domain entities (Flashcard, Topic, Unit, Review, Session)
- Repository pattern implementation
- Service layer organization

##### Core Features
- Spaced Repetition System (FSRS4Algorithm, Fsrs4_5Algorithm)
- Analytics capabilities
- User management and security

**[Client Applications]**
- ↓ HTTP/REST
**[API Gateway Layer]**
- Rate Limiting
- CORS
- Authentication
- ↓
**[Controller Layer]**
- Resource Controllers (Flashcard, Topic, etc.)
- Admin Controllers
- Security Controllers
- ↓
**[Service Layer]**
- SpacedRepetitionScheduler
- Resource Services
- Security Services
- ↓
**[Domain Layer]**
- Entities
- Repositories
- Value Objects
- ↓
**[Infrastructure Layer]**
- Database (Doctrine)
- Message Queue (Symfony Messenger)
- Cache

##### Important Relationships to Highlight

- Authentication flow through TokenAuthenticator
- Message handling system for email notifications
- Entity relationships (User -> Topics -> Units -> Flashcards)
- Spaced repetition algorithm integration with review system

##### Technical Stack Callouts

- Symfony Framework
- Doctrine ORM
- Symfony Messenger
- Docker/DevContainer
- Apache Server
- Supervisor Process Manager

This architecture emphasizes the RESTful nature of the application while showing how the spaced repetition system is integrated into the core business logic.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        MobileApp["Mobile App"]
        WebApp["Web App"]
    end

    subgraph Gateway["API Gateway Layer"]
        RateLimiter["Rate Limiter"]:::security
        click RateLimiter "https://github.com/meeio-app/backend/blob/master/src/EventSubscriber/RateLimiterSubscriber.php"
        Auth["Authentication"]:::security
        click Auth "https://github.com/meeio-app/backend/blob/master/src/Security/TokenAuthenticator.php"
        CORS["CORS Handler"]
    end

    subgraph Controllers["Controller Layer"]
        direction TB
        FlashCardCtrl["Flashcard Controller"]:::controller
        click FlashCardCtrl "https://github.com/meeio-app/backend/tree/master/src/Controller/Flashcard/"
        ReviewCtrl["Review Controller"]:::controller
        click ReviewCtrl "https://github.com/meeio-app/backend/tree/master/src/Controller/Review/"
        SessionCtrl["Session Controller"]:::controller
        click SessionCtrl "https://github.com/meeio-app/backend/tree/master/src/Controller/Session/"
        TopicCtrl["Topic Controller"]:::controller
        click TopicCtrl "https://github.com/meeio-app/backend/tree/master/src/Controller/Topic/"
        UnitCtrl["Unit Controller"]:::controller
        click UnitCtrl "https://github.com/meeio-app/backend/tree/master/src/Controller/Unit/"
        UserCtrl["User Controller"]:::controller
        click UserCtrl "https://github.com/meeio-app/backend/tree/master/src/Controller/User/"
        AuthCtrl["Authentication Controller"]:::security
        click AuthCtrl "https://github.com/meeio-app/backend/blob/master/src/Controller/Security/AuthenticationController.php"
    end

    subgraph Services["Service Layer"]
        direction TB
        SRScheduler["Spaced Repetition Scheduler"]:::service
        click SRScheduler "https://github.com/meeio-app/backend/blob/master/src/SpacedRepetition/SpacedRepetitionScheduler.php"
        AttributeParser["Attribute Parser"]:::service
        click AttributeParser "https://github.com/meeio-app/backend/blob/master/src/Service/AttributeParser.php"
        FilterConverter["Filter Converter"]:::service
        click FilterConverter "https://github.com/meeio-app/backend/blob/master/src/Service/FilterConverter.php"
        RequestDecoder["Request Decoder"]:::service
        click RequestDecoder "https://github.com/meeio-app/backend/blob/master/src/Service/RequestDecoder.php"
        ResourceFinder["Resource Finder"]:::service
        click ResourceFinder "https://github.com/meeio-app/backend/blob/master/src/Service/ResourceFinder.php"
    end

    subgraph Domain["Domain Layer"]
        direction TB
        subgraph Entities["Entities"]
            direction TB
            Flashcard["Flashcard"]:::entity
            click Flashcard "https://github.com/meeio-app/backend/blob/master/src/Entity/Flashcard.php"
            Review["Review"]:::entity
            click Review "https://github.com/meeio-app/backend/blob/master/src/Entity/Review.php"
            Session["Session"]:::entity
            click Session "https://github.com/meeio-app/backend/blob/master/src/Entity/Session.php"
            Topic["Topic"]:::entity
            click Topic "https://github.com/meeio-app/backend/blob/master/src/Entity/Topic.php"
            Unit["Unit"]:::entity
            click Unit "https://github.com/meeio-app/backend/blob/master/src/Entity/Unit.php"
            User["User"]:::entity
            click User "https://github.com/meeio-app/backend/blob/master/src/Entity/User.php"
        end

        subgraph Repositories["Repositories"]
            direction TB
            FlashcardRepo["Flashcard Repository"]:::repo
            click FlashcardRepo "https://github.com/meeio-app/backend/blob/master/src/Repository/FlashcardRepository.php"
            ReviewRepo["Review Repository"]:::repo
            click ReviewRepo "https://github.com/meeio-app/backend/blob/master/src/Repository/ReviewRepository.php"
            SessionRepo["Session Repository"]:::repo
            click SessionRepo "https://github.com/meeio-app/backend/blob/master/src/Repository/SessionRepository.php"
            TopicRepo["Topic Repository"]:::repo
            click TopicRepo "https://github.com/meeio-app/backend/blob/master/src/Repository/TopicRepository.php"
            UnitRepo["Unit Repository"]:::repo
            click UnitRepo "https://github.com/meeio-app/backend/blob/master/src/Repository/UnitRepository.php"
            UserRepo["User Repository"]:::repo
            click UserRepo "https://github.com/meeio-app/backend/blob/master/src/Repository/UserRepository.php"
        end

        subgraph SRS["Spaced Repetition System"]
            direction TB
            FSRS4["FSRS4 Algorithm"]:::algorithm
            click FSRS4 "https://github.com/meeio-app/backend/blob/master/src/SpacedRepetition/Fsrs4Algorithm.php"
            FSRS45["FSRS4.5 Algorithm"]:::algorithm
            click FSRS45 "https://github.com/meeio-app/backend/blob/master/src/SpacedRepetition/Fsrs4_5Algorithm.php"
        end

        subgraph Security["Security"]
            direction TB
            Voters["Resource Voters"]:::security
            click Voters "https://github.com/meeio-app/backend/tree/master/src/Voter"
            AuthFailure["Auth Failure Handler"]:::security
            click AuthFailure "https://github.com/meeio-app/backend/blob/master/src/Security/AuthenticationFailureHandler.php"
        end
    end

    subgraph Infrastructure["Infrastructure Layer"]
        direction TB
        Database[(Database)]:::infra
        click Database "https://github.com/meeio-app/backend/blob/master/config/packages/doctrine.yaml"
        Cache[(Cache)]:::infra
        click Cache "https://github.com/meeio-app/backend/blob/master/config/packages/cache.yaml"
        MessageQueue["Message Queue"]:::infra
        click MessageQueue "https://github.com/meeio-app/backend/blob/master/config/packages/messenger.yaml"
        EmailHandler["Email Handler"]:::messaging
        click EmailHandler "https://github.com/meeio-app/backend/blob/master/src/MessageHandler/SendTextEmailMessageHandler.php"
        Supervisor["Supervisor Daemon"]:::infra
        click Supervisor "https://github.com/meeio-app/backend/blob/master/.docker/supervisord.conf"
    end

    %% Relationships
    Client --> Gateway
    Gateway --> Controllers
    Controllers --> Services
    Services --> Domain
    Domain --> Infrastructure

    %% Styling
    classDef controller fill:#2196F3,stroke:#1565C0,color:white
    classDef service fill:#4CAF50,stroke:#2E7D32,color:white
    classDef entity fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef repo fill:#FF9800,stroke:#EF6C00,color:white
    classDef algorithm fill:#00BCD4,stroke:#00838F,color:white
    classDef security fill:#F44336,stroke:#C62828,color:white
    classDef infra fill:#795548,stroke:#4E342E,color:white
    classDef messaging fill:#607D8B,stroke:#37474F,color:white

    %% Legend
    subgraph Legend
        direction TB
        L1["Controllers"]:::controller
        L2["Services"]:::service
        L3["Entities"]:::entity
        L4["Repositories"]:::repo
        L5["Algorithms"]:::algorithm
        L6["Security"]:::security
        L7["Infrastructure"]:::infra
        L8["Messaging"]:::messaging
    end
```
