# moyangzhan/langchain4j-aideepin architecture

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

- Interactive diagram: https://gitdiagram.com/moyangzhan/langchain4j-aideepin
- Repository: https://github.com/moyangzhan/langchain4j-aideepin

## Overview

##### Project type and purpose
- This is the backend service of “LangChain4j-AIDeepin,” an AI-powered productivity tool.
- It exposes REST APIs for both an end-user web client (chat, image generation, knowledge base, workflow) and an admin web client (system configuration, statistics, user/model/KB management).
- It’s implemented as a multi-module Maven project using Spring Boot.

##### File structure
- Top-level modules:
- adi-bootstrap – Bootstraps and configures the Spring Boot application (profiles,  logging).
- adi-chat – Main REST API for user-side features (chat, drawing, KB, workflow, files).
- adi-admin – Admin REST API for management functions.
- adi-common – Shared domain, DTOs, entities, mappers, repositories, services, AOP, configuration, and plugin interfaces for models/embedding/graph/search.
- Deployment descriptors: Dockerfile under adi-bootstrap, docker-compose.yml + .env files.
- Resources: SQL DDL (docs/create.sql), MyBatis XML mappers, Spring YAML configs, logback.

##### README insights
- Technical stack: JDK17, Spring Boot 3.x, LangChain4j, LangGraph4j
- Databases: PostgreSQL + pgvector + Apache AGE (or Neo4j), Redis (for caching, rate-limit, SSE).
- External dependencies: AI platforms (OpenAI, DeepSeek, DashScope, QianFan, Ollama, ...), search engines (Google Custom Search), file storage (Aliyun OSS).
- Features: multi-session chat, image gen/edit, RAG via vector/graph search, custom workflows, usage/statistics tracking.

a. Main components:
- Frontends:
- User Web UI (Vue3/Vite/TypeScript)
- Admin Web UI (Vue3/Vite/TypeScript)
- API Services (Spring Boot):
- Bootstrap Module (entry point)
- Chat Module (controllers: ConversationController, DrawController, etc.)
- Admin Module (controllers: AdminUserController, StatisticController, SystemConfigController, etc.)
- Shared Common Module (layered: controllers → services → mappers → database)
- Databases:
- PostgreSQL (primary data, pgvector extension)
- Graph DB (Apache AGE on Postgres or Neo4j)
- Redis (caching, rate-limit, SSE streams)
- External Systems:
- AI Model Providers (OpenAI, DeepSeek, DashScope, QianFan, Ollama, …)
- Search Engines (Google Custom Search, future Bing/Baidu)
- File Storage (Aliyun OSS)

b. Relationships and data flow:
- UIs → REST endpoints (Chat & Admin modules)
- Modules → Common services → MyBatis mappers → DB
- Services → Redis (cache, pub/sub for SSE)
- Services → External AI platforms & search engines via HTTP clients
- Services → File operator context → Aliyun OSS or local FS

c. Architectural patterns & principles:
- Modular Maven multi-module structure
- Layered architecture: Controller → Service → Repository (MyBatis)
- Plugin / Strategy pattern for AI providers, embedding stores, graph stores, search engines
- AOP for logging, request validation, distributed locking
- Dependency injection via Spring Boot
- Docker-compose for environment orchestration

d. Key technologies:
- Spring Boot, Spring MVC, Spring Data Redis
- MyBatis (mapper XML under resources/mapper)
- pgvector & Apache AGE or Neo4j
- LangChain4j / LangGraph4j
- Maven multi-module build
- Docker, Docker Compose

##### Detail
- Essential modules (bootstrap, chat, admin, common).
- Plugin/strategy sub-components only if space permits (e.g., AIModelService implementations).
- Avoid over-simplification—represent the core flow: UI → Controller → Service → Mapper → DB → External.
- Persistence store and external dependency is visible.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "User Interface" 
        direction TB
        UserWebUI["User Web UI"]:::ui
        AdminWebUI["Admin Web UI"]:::ui
    end

    %% API Modules
    subgraph "API Services" 
        direction TB
        BootstrapModule["Bootstrap Module"]:::service
        ChatModule["Chat Module"]:::service
        AdminModule["Admin Module"]:::service
    end

    %% Common Module
    subgraph "Common Module" 
        direction TB
        CommonService["Common Services"]:::common
        ConversationMapper["MyBatis Mappers"]:::common
        AOP["AOP & Config"]:::common
    end

    %% Data Stores
    subgraph "Datastores" 
        direction TB
        Postgres["PostgreSQL\n(pgvector)"]:::db
        GraphDB["Graph DB\n(Apache AGE/Neo4j)"]:::db
        Redis["Redis\n(Cache & SSE)"]:::db
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        AIProviders["AI Model Providers"]:::ext
        SearchEngines["Search Engines"]:::ext
        FileStorage["File Storage\n(Aliyun OSS)"]:::ext
    end

    %% Connections
    UserWebUI -->|"HTTP REST"| ChatModule
    AdminWebUI -->|"HTTP REST"| AdminModule

    ChatModule -->|"uses"| CommonService
    AdminModule -->|"uses"| CommonService

    BootstrapModule -->|"wires modules"| ChatModule
    BootstrapModule -->|"wires modules"| AdminModule

    CommonService -->|"calls mappers"| ConversationMapper
    ConversationMapper -->|"JDBC"| Postgres

    CommonService -->|"Redis Pub/Sub"| Redis
    CommonService -->|"Graph queries"| GraphDB

    CommonService -->|"HTTP API"| AIProviders
    CommonService -->|"HTTP API"| SearchEngines

    CommonService -->|"File ops"| FileStorage

    %% Click Events
    click BootstrapModule "https://github.com/moyangzhan/langchain4j-aideepin/tree/main/adi-bootstrap/"
    click ChatModule "https://github.com/moyangzhan/langchain4j-aideepin/tree/main/adi-chat/"
    click AdminModule "https://github.com/moyangzhan/langchain4j-aideepin/tree/main/adi-admin/"
    click CommonService "https://github.com/moyangzhan/langchain4j-aideepin/tree/main/adi-common/"
    click ConversationMapper "https://github.com/moyangzhan/langchain4j-aideepin/blob/main/adi-common/src/main/resources/mapper/ConversationMapper.xml"
    click AIProviders "https://github.com/moyangzhan/langchain4j-aideepin/tree/main/docker-compose/"
    click SearchEngines "https://github.com/moyangzhan/langchain4j-aideepin/tree/main/docker-compose/"
    click FileStorage "https://github.com/moyangzhan/langchain4j-aideepin/tree/main/docker-compose/"

    %% Styles
    classDef ui fill:#b2f2bb,stroke:#2f6627,color:#000
    classDef service fill:#aed6f1,stroke:#1b4f72,color:#000
    classDef common fill:#d6eaf8,stroke:#1b4f72,color:#000
    classDef db fill:#fadbd8,stroke:#922b21,color:#000
    classDef ext fill:#e8daef,stroke:#6c3483,color:#000
```
