# willlkhang/chatbot-platform architecture

> Architecture diagram of the GitHub repository willlkhang/chatbot-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/willlkhang/chatbot-platform
- Repository: https://github.com/willlkhang/chatbot-platform

## Overview

1. **Overall shape**
   - This is a **polyglot monorepo** with multiple independently deployable apps:
     - a **Next.js frontend**
     - a **Spring Boot microservices backend**
     - several **Python AI/support services**
   - The backend is organized around a **single external entrypoint** (the API gateway), while internal services are split by responsibility.

2. **Frontend boundary**
   - `frontend/my-fe` is the user-facing UI built with **Next.js/React** and SCSS styling.
   - It contains app routes for **login, signup, and chat-like UI components**.
   - Architecturally, it should be drawn as the client that talks outward to backend APIs and, for AI features, may call service endpoints exposed through the backend or directly to supporting services depending on deployment.

3. **API edge and routing**
   - `springboot_be/gateway-service` is the **single backend entrypoint**.
   - It sits in front of the internal services and handles request routing, so the frontend does not need to know individual service locations.
   - `springboot_be/discovery-service` provides **service discovery**, and `springboot_be/config-service` centralizes service configuration for the microservices.

4. **Authentication and identity**
   - `springboot_be/authorization-service` is the **OAuth2/authentication issuer**.
   - It contains custom password authentication classes and an auth controller, indicating token issuance and login handling are centralized here.
   - `springboot_be/base-service` holds shared auth/domain DTOs such as `User`, `LoginRequest`, and `UserResponse`, suggesting it is a **shared contract module** rather than a runtime service.
   - `springboot_be/user-service` is the resource-side user profile/registration service; its `ResourceServerConfig` suggests it validates tokens rather than issuing them.

5. **Business services**
   - `springboot_be/chat-service` owns **chat persistence and chat-message handling**.
   - `springboot_be/personalization-service` owns **user-specific personalization state**.
   - These services have the standard Spring layers: controller, service, repository, and domain/model classes, so they should be drawn as separate bounded contexts behind the gateway.

6. **Data storage**
   - The backend is designed to persist business data in **Postgres**; the repo includes a Docker init script under `docker/postgres/init/01-schemas.sql`.
   - Some Python components use their own embedded stores:
     - `classifier_app/databases/data/resources.db` for SQLite-based classifier data
     - `ragbot/data/*.sqlite` for course/content corpora
   - This implies a mixed-storage architecture: **Postgres for core backend services**, **SQLite/files for AI tooling and local corpora**.

7. **AI / retrieval subsystem**
   - `ragbot` is a standalone **RAG-style assistant pipeline**.
   - Its structure includes ingestion, repository, graph/node orchestration, reranking, cosine similarity utilities, prompt templates, and knowledge files.
   - The important boundary is that this subsystem is **content-driven**: it ingests course/knowledge assets from `ragbot/knowledge` and `ragbot/data`, then serves retrieval/generation logic to the rest of the system.

8. **Classification subsystem**
   - `classifier_app` is a separate Python service for **text classification**.
   - It includes controller and database layers, a persisted **LinearSVC joblib model**, and SQLite-backed resources.
   - This should be shown as an AI inference service that can be called over HTTP by the frontend or by other backend components when classification is needed.

9. **Document extraction and data preparation**
   - `unit_extractor` is a utility service for **extracting text from documents**.
   - It supports multiple source formats: PDF, DOC/DOCX, PPT/PPTX, TXT, and ZIP, then serializes extracted content to JSON or text.
   - `synthetic_data_generator` is a separate offline pipeline that creates training data, likely feeding the classifier or related AI workflows.
   - These two are best drawn as **preprocessing/ETL tools**, not user-facing runtime services.

10. **Deployment model**
   - The repo includes Dockerfiles for the frontend, Python services, and each Spring Boot service, plus a top-level `docker-compose.yml`.
   - That points to a **containerized local/dev deployment** where the gateway, discovery/config, auth, user, chat, and personalization services are run together with supporting Postgres and AI containers.
   - The core architecture diagram should emphasize: **UI → gateway → microservices → Postgres**, with **auth/token issuance** as a separate path and **AI services** as auxiliary backends.

11. **Suggested diagram boundaries**
   - Group the system into four boxes:
     - **Presentation**: Next.js frontend
     - **Core backend platform**: gateway, config, discovery, auth, user, chat, personalization, shared base-service
     - **Data layer**: Postgres plus service-local SQLite/model files
     - **AI/support services**: ragbot, classifier_app, unit_extractor, synthetic_data_generator
   - The most important flows are **login/token issuance**, **gateway-routed business requests**, and **AI-assisted content/query processing**.

Main entry points: [`springboot_be/gateway-service`](https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/gateway-service) (API Gateway), [`springboot_be/authorization-service`](https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/authorization-service) (Auth Service), [`docker/postgres/init/01-schemas.sql`](https://github.com/willlkhang/chatbot-platform/blob/main/docker/postgres/init/01-schemas.sql) (Postgres), [`ragbot/data/ICT159_all.sqlite`](https://github.com/willlkhang/chatbot-platform/blob/main/ragbot/data/ICT159_all.sqlite) (Local AI Stores)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_frontend["Next.js UI<br/>frontend"]
end

subgraph group_backend["Core Backend"]
  node_gateway["API Gateway<br/>edge-router"]
  node_config["Config Service<br/>config-server"]
  node_discovery["Discovery<br/>service-registry"]
  node_auth["Auth Service<br/>oauth2-issuer"]
  node_user["User Service<br/>profile-service"]
  node_chat["Chat Service<br/>conversation-service"]
  node_personalization["Personalization<br/>preference-service"]
  node_base["Base Contracts<br/>shared-dto-module"]
end

subgraph group_data["Data Layer"]
  node_postgres[("Postgres<br/>relational-db<br/>[01-schemas.sql]")]
  node_ai_store[("Local AI Stores<br/>sqlite-and-assets<br/>[ICT159_all.sqlite]")]
end

subgraph group_ai["AI Support"]
  node_ragbot["RAG Bot<br/>retrieval-assistant"]
  node_classifier["Classifier App<br/>inference-service"]
  node_extractor["Unit Extractor<br/>document-etl"]
  node_synthetic["Synthetic Data<br/>offline-generator"]
end

node_frontend -->|"API calls"| node_gateway
node_frontend -->|"login"| node_auth
node_gateway -->|"register/lookup"| node_discovery
node_gateway -->|"load config"| node_config
node_gateway -->|"auth route"| node_auth
node_gateway -->|"user route"| node_user
node_gateway -->|"chat route"| node_chat
node_gateway -->|"prefs route"| node_personalization
node_auth -->|"shared DTOs"| node_base
node_user -->|"shared DTOs"| node_base
node_auth -->|"auth data"| node_postgres
node_user -->|"user data"| node_postgres
node_chat -->|"chat data"| node_postgres
node_personalization -->|"prefs data"| node_postgres
node_ragbot -->|"knowledge"| node_ai_store
node_classifier -->|"model/db"| node_ai_store
node_extractor -->|"serialized text"| node_ai_store
node_synthetic -->|"training data"| node_ai_store
node_extractor -.->|"ingest"| node_ragbot
node_synthetic -.->|"train"| node_classifier
node_ragbot -.->|"ai endpoint"| node_gateway
node_classifier -.->|"ai endpoint"| node_gateway

click node_frontend "https://github.com/willlkhang/chatbot-platform/tree/main/frontend/my-fe"
click node_gateway "https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/gateway-service"
click node_config "https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/config-service"
click node_discovery "https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/discovery-service"
click node_auth "https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/authorization-service"
click node_user "https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/user-service"
click node_chat "https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/chat-service"
click node_personalization "https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/personalization-service"
click node_base "https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/base-service"
click node_postgres "https://github.com/willlkhang/chatbot-platform/blob/main/docker/postgres/init/01-schemas.sql"
click node_ai_store "https://github.com/willlkhang/chatbot-platform/blob/main/ragbot/data/ICT159_all.sqlite"
click node_ragbot "https://github.com/willlkhang/chatbot-platform/tree/main/ragbot"
click node_classifier "https://github.com/willlkhang/chatbot-platform/tree/main/classifier_app"
click node_extractor "https://github.com/willlkhang/chatbot-platform/tree/main/unit_extractor"
click node_synthetic "https://github.com/willlkhang/chatbot-platform/tree/main/synthetic_data_generator"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend toneBlue
class node_gateway,node_config,node_discovery,node_auth,node_user,node_chat,node_personalization,node_base toneAmber
class node_postgres,node_ai_store toneMint
class node_ragbot,node_classifier,node_extractor,node_synthetic toneRose
```

## Components

### Presentation

User-facing frontend

- [Next.js UI](https://github.com/willlkhang/chatbot-platform/tree/main/frontend/my-fe): frontend · User-facing web client with login, signup, and chat screens · `frontend/my-fe`

### Core Backend

Spring Boot edge, identity, and business services

- [API Gateway](https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/gateway-service): edge-router · Single backend entrypoint and request router · `springboot_be/gateway-service`
- [Config Service](https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/config-service): config-server · Centralized Spring configuration source · `springboot_be/config-service`
- [Discovery](https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/discovery-service): service-registry · Service registry used by backend services · `springboot_be/discovery-service`
- [Auth Service](https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/authorization-service): oauth2-issuer · Authentication and token issuance boundary · `springboot_be/authorization-service`
- [User Service](https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/user-service): profile-service · User registration and resource-side account service · `springboot_be/user-service`
- [Chat Service](https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/chat-service): conversation-service · Chat persistence and message handling · `springboot_be/chat-service`
- [Personalization](https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/personalization-service): preference-service · User-specific personalization state and APIs · `springboot_be/personalization-service`
- [Base Contracts](https://github.com/willlkhang/chatbot-platform/tree/main/springboot_be/base-service): shared-dto-module · Shared domain and DTO definitions for auth and users · `springboot_be/base-service`

### Data Layer

Primary and service-local storage

- [Postgres](https://github.com/willlkhang/chatbot-platform/blob/main/docker/postgres/init/01-schemas.sql): relational-db · Primary database for core backend services · `docker/postgres/init/01-schemas.sql`
- [Local AI Stores](https://github.com/willlkhang/chatbot-platform/blob/main/ragbot/data/ICT159_all.sqlite): sqlite-and-assets · SQLite corpora, model files, and knowledge assets · `ragbot/data/ICT159_all.sqlite`

### AI Support

Retrieval, classification, and preprocessing services

- [RAG Bot](https://github.com/willlkhang/chatbot-platform/tree/main/ragbot): retrieval-assistant · Standalone retrieval and generation pipeline · `ragbot`
- [Classifier App](https://github.com/willlkhang/chatbot-platform/tree/main/classifier_app): inference-service · Text classification service with persisted LinearSVC model · `classifier_app`
- [Unit Extractor](https://github.com/willlkhang/chatbot-platform/tree/main/unit_extractor): document-etl · Document text extraction and serialization pipeline · `unit_extractor`
- [Synthetic Data](https://github.com/willlkhang/chatbot-platform/tree/main/synthetic_data_generator): offline-generator · Offline training data generation pipeline · `synthetic_data_generator`

## Connections

- Next.js UI → API Gateway: API calls · Frontend sends application requests through the backend edge
- Next.js UI → Auth Service: login · Authentication flow for issuing tokens
- API Gateway → Discovery: register/lookup · Gateway relies on service discovery for routing
- API Gateway → Config Service: load config · Gateway and peers consume centralized configuration
- API Gateway → Auth Service: auth route · Gateway forwards authentication requests to the issuer
- API Gateway → User Service: user route · Gateway routes user/profile requests
- API Gateway → Chat Service: chat route · Gateway routes chat requests
- API Gateway → Personalization: prefs route · Gateway routes personalization requests
- Auth Service → Base Contracts: shared DTOs · Auth service uses shared login and user contracts
- User Service → Base Contracts: shared DTOs · User service uses shared login and user contracts
- Auth Service → Postgres: auth data · Identity and credential persistence
- User Service → Postgres: user data · Profiles and registration records
- Chat Service → Postgres: chat data · Conversation and message persistence
- Personalization → Postgres: prefs data · Stored personalization state
- RAG Bot → Local AI Stores: knowledge · Retrieval pipeline reads corpora and SQLite assets
- Classifier App → Local AI Stores: model/db · Classifier loads its joblib model and SQLite resources
- Unit Extractor → Local AI Stores: serialized text · Extraction output can feed local corpora and datasets
- Synthetic Data → Local AI Stores: training data · Offline generator produces dataset artifacts
- Unit Extractor → RAG Bot: ingest · Document extraction prepares content for retrieval
- Synthetic Data → Classifier App: train · Generated data can be used to train classification models
- RAG Bot → API Gateway: ai endpoint · AI assistant functionality may be exposed through the backend edge
- Classifier App → API Gateway: ai endpoint · Classification can be invoked through backend-facing APIs
