# rami-shalhoub/thesis-backend architecture

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

- Interactive diagram: https://gitdiagram.com/rami-shalhoub/thesis-backend
- Repository: https://github.com/rami-shalhoub/thesis-backend

## Overview

##### Project Type and Purpose
- This is a backend-only ASP.NET Core 8 application serving as the API layer for a thesis application.
- It exposes user authentication and AI‐driven chat endpoints, persists data in PostgreSQL (with pgvector extension), and integrates with external AI services (Deepseek, OpenAI).
- Future components (not yet implemented) include IPFS and a Hyperledger Fabric gateway for blockchain storage.

##### High-Level Layered Architecture
- Presentation/API Layer
- Controllers (AuthController, ChatController)
- HTTP endpoints defined in Backend.http for testing
- Business Logic Layer
- Services (AuthService, JwtService, ChatService, DeepseekService, SourceService)
- IAuthService, IJwtService, IChatService, IDeepseekService, ISourceService interfaces
- Automapper profiles for mapping between Models and DTOs (ChatProfile, UserProfile)
- Data Access Layer
- Repositories (AuthRepository, SessionRepository, MessageRepository, ContextSummaryRepository)
- EF Core DbContext (ThesisDappDBContext) and Migrations
- Domain models (User, Session, Message, ContextSummary, Document, RevokedToken, AccessLog)
- External Services
- Deepseek API (DeepseekService)
- OpenAI embeddings (via DeepseekService’s OpenAIApiKey)
- Future: IPFS node, Hyperledger Fabric gateway
- Database
- PostgreSQL instance with pgvector extension
- Tables generated via EF Core migrations

##### Interactions and Data Flow
- Client → AuthController: register/login → AuthService → JwtService → returns JWT tokens
- Client (with JWT) → ChatController: create session, send messages → ChatService
- ChatService calls DeepseekService (calls Deepseek API → possibly OpenAI)
- ChatService records inputs/responses via SessionRepository, MessageRepository, ContextSummaryRepository
- All repositories interact with ThesisDappDBContext to CRUD PostgreSQL

##### Architectural Patterns and Principles
- Layered Architecture (Presentation, Service, Repository, Database)
- Dependency Injection of interfaces for loose coupling and testability
- Repository Pattern for data persistence abstraction
- DTOs for transport models, AutoMapper for mapping
- Configuration via appsettings.json (ConnectionStrings, JWT settings, Deepseek settings)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% API Layer
    subgraph "API Layer"
        AuthController["AuthController"]:::presentation
        ChatController["ChatController"]:::presentation
    end

    %% Service Layer
    subgraph "Service Layer"
        AuthService["AuthService"]:::service
        JwtService["JwtService"]:::service
        ChatService["ChatService"]:::service
        DeepseekService["DeepseekService"]:::service
        SourceService["SourceService"]:::service
        AutoMapper["AutoMapper"]:::utility
    end

    %% Repository Layer
    subgraph "Repository Layer"
        AuthRepository["AuthRepository"]:::dataaccess
        SessionRepository["SessionRepository"]:::dataaccess
        MessageRepository["MessageRepository"]:::dataaccess
        ContextSummaryRepository["ContextSummaryRepository"]:::dataaccess
    end

    %% Domain Models
    subgraph "Domain Models"
        User["User"]:::model
        SessionModel["Session"]:::model
        MessageModel["Message"]:::model
        ContextSummaryModel["ContextSummary"]:::model
        Document["Document"]:::model
        RevokedToken["RevokedToken"]:::model
        AccessLog["AccessLog"]:::model
    end

    %% EF Core Context & Migrations
    subgraph "Data & Migrations"
        ThesisDappDBContext["ThesisDappDBContext"]:::dataaccess
        Migrations["Migrations"]:::dataaccess
    end

    %% Database
    PostgreSQL["PostgreSQL\n(pgvector)"]:::db

    %% External Services
    subgraph "External Services"
        DeepseekAPI["Deepseek API"]:::external
        OpenAI["OpenAI Embedding API"]:::external
    end

    %% Future Components
    subgraph "Future Components"
        IPFS["IPFS Service"]:::future
        Fabric["Hyperledger Fabric Gateway"]:::future
    end

    %% Connections
    AuthController -->|"Invoke business logic"| AuthService
    AuthService -->|"Generate JWT"| JwtService
    JwtService -->|"JWT token"| AuthController

    ChatController -->|"Invoke business logic"| ChatService
    ChatService -->|"calls"| DeepseekService
    DeepseekService -.->|"HTTP calls to Deepseek/OpenAI"| DeepseekAPI
    DeepseekService -.->|"HTTP calls to Deepseek/OpenAI"| OpenAI

    AuthService -->|"CRUD operations via EF Core"| AuthRepository
    ChatService -->|"CRUD operations via EF Core"| SessionRepository
    ChatService -->|"CRUD operations via EF Core"| MessageRepository
    ChatService -->|"CRUD operations via EF Core"| ContextSummaryRepository

    AuthRepository --> ThesisDappDBContext
    SessionRepository --> ThesisDappDBContext
    MessageRepository --> ThesisDappDBContext
    ContextSummaryRepository --> ThesisDappDBContext

    ThesisDappDBContext -->|"SQL via EF Core"| PostgreSQL

    ChatService -.->|"Upcoming"| IPFS
    ChatService -.->|"Upcoming"| Fabric

    AuthService --- AutoMapper
    ChatService --- AutoMapper

    %% Click Events
    click AuthController "https://github.com/rami-shalhoub/thesis-backend/blob/main/controllers/AuthController.cs"
    click ChatController "https://github.com/rami-shalhoub/thesis-backend/blob/main/controllers/ChatController.cs"
    click AuthService "https://github.com/rami-shalhoub/thesis-backend/blob/main/services/Auth/AuthService.cs"
    click JwtService "https://github.com/rami-shalhoub/thesis-backend/blob/main/services/Auth/JwtService.cs"
    click ChatService "https://github.com/rami-shalhoub/thesis-backend/blob/main/services/AI/ChatService.cs"
    click DeepseekService "https://github.com/rami-shalhoub/thesis-backend/blob/main/services/AI/DeepseekService.cs"
    click SourceService "https://github.com/rami-shalhoub/thesis-backend/blob/main/services/AI/SourceService.cs"
    click AuthRepository "https://github.com/rami-shalhoub/thesis-backend/blob/main/repositories/auth/AuthRepository.cs"
    click SessionRepository "https://github.com/rami-shalhoub/thesis-backend/blob/main/repositories/AI/SessionRepository.cs"
    click MessageRepository "https://github.com/rami-shalhoub/thesis-backend/blob/main/repositories/AI/MessageRepository.cs"
    click ContextSummaryRepository "https://github.com/rami-shalhoub/thesis-backend/blob/main/repositories/AI/ContextSummaryRepository.cs"
    click ThesisDappDBContext "https://github.com/rami-shalhoub/thesis-backend/blob/main/data/ThesisDappDBContext.cs"
    click Migrations "https://github.com/rami-shalhoub/thesis-backend/tree/main/Migrations/"
    click User "https://github.com/rami-shalhoub/thesis-backend/blob/main/models/User.cs"
    click SessionModel "https://github.com/rami-shalhoub/thesis-backend/blob/main/models/Session.cs"
    click MessageModel "https://github.com/rami-shalhoub/thesis-backend/blob/main/models/Message.cs"
    click ContextSummaryModel "https://github.com/rami-shalhoub/thesis-backend/blob/main/models/ContextSummary.cs"
    click Document "https://github.com/rami-shalhoub/thesis-backend/blob/main/models/Document.cs"
    click RevokedToken "https://github.com/rami-shalhoub/thesis-backend/blob/main/models/RevokedToken.cs"
    click AccessLog "https://github.com/rami-shalhoub/thesis-backend/blob/main/models/AccessLog.cs"
    click AutoMapper "https://github.com/rami-shalhoub/thesis-backend/blob/main/mappings/ChatProfile.cs"
    click AutoMapper "https://github.com/rami-shalhoub/thesis-backend/blob/main/mappings/UserProfile.cs"

    %% Styles
    classDef presentation fill:#D0E7FF,stroke:#003366,color:#003366
    classDef service fill:#DFFFD0,stroke:#336600,color:#336600
    classDef dataaccess fill:#FFE7C0,stroke:#994C00,color:#994C00
    classDef db fill:#E0E0E0,stroke:#666666,color:#333333
    classDef external fill:#E7D0FF,stroke:#660099,color:#660099
    classDef future fill:#FFD0D0,stroke:#990000,color:#990000,stroke-dasharray: 5 5
    classDef model fill:#FFFFE0,stroke:#999900,color:#666600
    classDef utility fill:#F0F0F0,stroke:#888888,color:#555555,stroke-dasharray: 2 2
```
