# artemelyashevich/mmf-ask architecture

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

- Interactive diagram: https://gitdiagram.com/artemelyashevich/mmf-ask
- Repository: https://github.com/artemelyashevich/mmf-ask

## Overview

##### Project Type and Purpose
- This is a standalone, monolithic web-API built with Spring Boot that simulates a StackOverflow-style Q&A system.
- It exposes REST endpoints for posts, comments, categories, programming languages, users, favorites and handles authentication/authorization (JWT + email activation), plus a WebSocket chat.

##### Architectural Overview
- Layered, MVC-style design:
- API Layer (Controllers + DTOs + Mappers)
- Service Layer (business logic + converters)
- Data Access Layer (Spring Data MongoDB Repositories + Entities)
- Cross-cutting Concerns (Security, Configuration, Utilities)
- External Integrations (MongoDB, SMTP/email sender, Prometheus metrics)

##### Main Components
a. Client → API Gateway
- Clients (e.g., web UI, Postman) issue HTTP(S) requests to REST controllers.
- WebSocket clients connect to the /ws/chat endpoint for real-time messaging.
b. Spring Boot Application
- API Layer
- Controllers (e.g., PostController, AuthController, ChatController)
- DTOs and Mappers for request/response translation
- Service Layer
- Business services (PostService, AuthService, ChatService, etc.)
- Converters for domain transformations
- Data Access Layer
- MongoDB repositories for each aggregate (PostRepository, UserRepository, CommentRepository…)
- Domain entities representing collections
- Security
- JWT filter chain, AuthenticationEntryPoint, AccessDeniedHandler
- CORS config, WebSocket STOMP security interceptor
- Configuration
- SwaggerConfig (OpenAPI docs)
- WebSocketConfig, CommandLineRunner for startup data
c. External Systems
- MongoDB (persistent storage)
- SMTP/Email server (activation/reset code delivery via Thymeleaf templates)
- Prometheus (scrapes /actuator/prometheus for metrics)
- Docker & docker-compose orchestration

##### Relationships and Data Flows
- WebSocket handshake from clients to ChatController → ChatService → ChatMessageRepository.
- JWT issuance by AuthService → User through EmailSender → external SMTP.

##### Architectural Patterns & Principles
- Layered Architecture (separation of concerns)
- DTO/Mapper pattern for API boundary
- Repository pattern (Spring Data) for persistence
- Dependency Injection (Spring) in controllers, services, repositories
- Eventual consistency / stateless services
- Real-time messaging via STOMP over WebSocket

##### Essential Elements to Capture
- Controllers → Services → Repositories → MongoDB
- Auth flow (registration → email activation → JWT issuance → secured endpoints)
- WebSocket chat flow
- Docker-compose relationships (app ←→ mongo)
- Monitoring (Prometheus ←→ /actuator)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    Clients["Clients (Web UI, Postman)"]:::external
    WSClients["WebSocket Clients"]:::external

    %% Docker Compose orchestration
    subgraph "Docker Compose"
        direction TB
        AppContainer["MMFASK App"]:::external
        MongoContainer["MongoDB"]:::dao
        AppContainer --- MongoContainer
    end

    %% Spring Boot Application Entry
    Application["Application (Entry Point)"]:::external
    click Application "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/Application.java"

    %% API Layer
    subgraph "API Layer" 
        direction TB
        Controllers["Controllers<br/>(PostController, AuthController, ChatController)"]:::api
        click Controllers "https://github.com/artemelyashevich/mmf-ask/tree/main/src/main/java/com/elyashevich/mmfask/api/controller"
        ChatControllerNode["ChatController"]:::api
        click ChatControllerNode "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/api/ws/ChatController.java"
        DTOs["DTOs"]:::api
        click DTOs "https://github.com/artemelyashevich/mmf-ask/tree/main/src/main/java/com/elyashevich/mmfask/api/dto"
        subgraph "Mappers" 
            direction TB
            MapperInterfaces["Mapper Interfaces"]:::api
            click MapperInterfaces "https://github.com/artemelyashevich/mmf-ask/tree/main/src/main/java/com/elyashevich/mmfask/api/mapper"
            MapperImpl["Mapper Implementations"]:::api
            click MapperImpl "https://github.com/artemelyashevich/mmf-ask/tree/main/src/main/java/com/elyashevich/mmfask/api/mapper/impl"
        end
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        BusinessServices["Business Services"]:::service
        click BusinessServices "https://github.com/artemelyashevich/mmf-ask/tree/main/src/main/java/com/elyashevich/mmfask/service"
        subgraph "Converters"
            direction TB
            ConverterInterface["Converter Interface"]:::service
            click ConverterInterface "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/service/converter/Converter.java"
            ConverterImpl["Converter Implementations"]:::service
            click ConverterImpl "https://github.com/artemelyashevich/mmf-ask/tree/main/src/main/java/com/elyashevich/mmfask/service/converter/impl"
        end
        MailServiceNode["MailService"]:::service
        click MailServiceNode "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/service/MailService.java"
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        Repositories["Repositories"]:::dao
        click Repositories "https://github.com/artemelyashevich/mmf-ask/tree/main/src/main/java/com/elyashevich/mmfask/repository"
        Entities["Entities"]:::dao
        click Entities "https://github.com/artemelyashevich/mmf-ask/tree/main/src/main/java/com/elyashevich/mmfask/entity"
    end

    %% Security & Configurations
    subgraph "Cross-cutting Concerns"
        direction TB
        SecurityConfig["SecurityConfig"]:::config
        click SecurityConfig "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/config/SecurityConfig.java"
        SecurityFilter["SecurityFilter"]:::config
        click SecurityFilter "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/security/SecurityFilter.java"
        AuthEntryPoint["JwtAuthenticationEntryPoint"]:::config
        click AuthEntryPoint "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/security/JwtAuthenticationEntryPoint.java"
        AccessDeniedHandler["JwtAccessDeniedHandler"]:::config
        click AccessDeniedHandler "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/security/JwtAccessDeniedHandler.java"
        StompInterceptor["AuthChannelInterceptorAdapter"]:::config
        click StompInterceptor "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/security/AuthChannelInterceptorAdapter.java"
        CORSConfig["CustomCorsConfiguration"]:::config
        click CORSConfig "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/config/CustomCorsConfiguration.java"
        WebSocketConfig["WebSocketConfig"]:::config
        click WebSocketConfig "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/config/WebSocketConfig.java"
        SwaggerConfig["SwaggerConfig"]:::config
        click SwaggerConfig "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/config/SwaggerConfig.java"
        StartupLoader["CommandLineRunnerConfig"]:::config
        click StartupLoader "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/java/com/elyashevich/mmfask/config/CommandLineRunnerConfig.java"
    end

    %% External Integrations
    subgraph "External Systems"
        direction TB
        SMTP["SMTP / Email Server"]:::external
        Templates["Thymeleaf Templates"]:::external
        click Templates "https://github.com/artemelyashevich/mmf-ask/tree/main/src/main/resources/templates"
        Prometheus["Prometheus"]:::external
        click Prometheus "https://github.com/artemelyashevich/mmf-ask/blob/main/prometheus.yml"
        ActuatorCfg["Actuator (/actuator/prometheus)"]:::external
        click ActuatorCfg "https://github.com/artemelyashevich/mmf-ask/blob/main/src/main/resources/application.yml"
    end

    %% Flows
    Clients -->|"HTTP(S) requests"| Controllers
    WSClients -->|"STOMP WebSocket (/ws/chat)"| ChatControllerNode
    Controllers -->|"invoke"| BusinessServices
    ChatControllerNode -->|"use"| MailServiceNode
    BusinessServices -->|"save()/find()"| Repositories
    Repositories -->|"persist"/retrieve| MongoContainer
    BusinessServices -->|"sendEmail()"| SMTP
    Prometheus -->|"METRICS scrape"| ActuatorCfg
    AppContainer -->|"runs"| Application
    Application --> Controllers
    Application --> BusinessServices
    Application --> Repositories
    Application --> SecurityConfig

    %% Styles
    classDef api fill:#cce5ff,stroke:#004085,color:#004085;
    classDef service fill:#d4edda,stroke:#155724,color:#155724;
    classDef dao fill:#fff3cd,stroke:#856404,color:#856404;
    classDef config fill:#e2e3e5,stroke:#383d41,color:#383d41;
    classDef external fill:#f5c6cb,stroke:#721c24,color:#721c24;
```
