# haidepzai269/mindex-backend architecture

> Architecture diagram of the GitHub repository haidepzai269/mindex-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/haidepzai269/mindex-backend
- Repository: https://github.com/haidepzai269/mindex-backend

## Overview

Mindex Backend is a Go API for document-centered AI study and collaboration. The principal workflow is that a user uploads a document, background workers extract and chunk it, then chat and retrieval features can answer questions using document content. The tree also exposes authentication, billing, collections, study tools, community features, and WebSocket rooms. The upload worker, RAG tool, startup wiring, and selected utilities were sampled; other feature links reflect the module structure and are shown conservatively.

Main entry points: [`routes`](https://github.com/haidepzai269/mindex-backend/tree/main/routes) (API routes), [`config/database.go`](https://github.com/haidepzai269/mindex-backend/blob/main/config/database.go) (PostgreSQL), [`main.go`](https://github.com/haidepzai269/mindex-backend/blob/main/main.go) (Application startup), [`controllers/chat.go`](https://github.com/haidepzai269/mindex-backend/blob/main/controllers/chat.go) (Chat and sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and identity"]
  node_server["Application startup<br/>[main.go]"]
  node_routes["API routes"]
  node_auth["Authentication<br/>[auth.go]"]
  node_middleware["Access middleware<br/>[auth.go]"]
end

subgraph group_documents["Documents and retrieval"]
  node_documents_api["Document management<br/>[document.go]"]
  node_upload_workers["Upload workers<br/>[worker.go]"]
  node_pipeline["Extraction and indexing<br/>[pipeline.go]"]
  node_search["Hybrid retrieval<br/>[hybrid_search.go]"]
  node_collections["Collections<br/>[collections.go]"]
end

subgraph group_ai["AI and study"]
  node_chat["Chat and sessions<br/>[chat.go]"]
  node_study["Study features<br/>[studytools.go]"]
  node_ai_orchestrator["AI provider routing<br/>[ai_orchestrator.go]"]
  node_tool_framework["AI tools"]
  node_rag_tool["Document search tool<br/>[rag_search_tool.go]"]
  node_rewriter["Query rewriting<br/>[query_rewriter.go]"]
end

subgraph group_platform["Platform services"]
  node_postgres[("PostgreSQL<br/>[database.go]")]
  node_redis[("Redis<br/>[redis.go]")]
  node_processing_client["Processing service client"]
  node_rooms["Realtime rooms<br/>[room_hub.go]"]
  node_billing["Billing<br/>[billing.go]"]
end

node_user(("User"))
node_external_ai{{"AI providers"}}
node_frontend(("Frontend client"))

node_server -->|"registers"| node_routes
node_server -->|"connects"| node_postgres
node_server -->|"connects"| node_redis
node_server -->|"starts"| node_upload_workers
node_server -->|"starts"| node_rooms
node_frontend -->|"calls API"| node_routes
node_routes -->|"protects routes"| node_middleware
node_routes -->|"registers auth"| node_auth
node_routes -->|"registers documents"| node_documents_api
node_routes -->|"registers chat"| node_chat
node_routes -->|"registers collections"| node_collections
node_routes -->|"registers study"| node_study
node_routes -->|"registers billing"| node_billing
node_upload_workers -->|"claims jobs"| node_postgres
node_upload_workers -->|"processes jobs"| node_pipeline
node_pipeline -->|"stores chunks"| node_postgres
node_pipeline -.->|"requests embeddings"| node_external_ai
node_chat -->|"rewrites queries"| node_rewriter
node_chat -->|"requests AI"| node_ai_orchestrator
node_chat -->|"invokes tool"| node_rag_tool
node_rag_tool -->|"searches documents"| node_search
node_rag_tool -.->|"generates embedding"| node_external_ai
node_ai_orchestrator -.->|"calls providers"| node_external_ai
node_documents_api -->|"reads and writes"| node_postgres
node_collections -->|"reads and writes"| node_postgres
node_auth -->|"reads and writes"| node_postgres
node_auth -->|"checks auth state"| node_redis
node_processing_client -->|"queues tasks"| node_redis
node_chat -.->|"uses realtime"| node_rooms
node_billing -->|"updates account"| node_postgres

click node_server "https://github.com/haidepzai269/mindex-backend/blob/main/main.go"
click node_routes "https://github.com/haidepzai269/mindex-backend/tree/main/routes"
click node_auth "https://github.com/haidepzai269/mindex-backend/blob/main/controllers/auth.go"
click node_middleware "https://github.com/haidepzai269/mindex-backend/blob/main/middleware/auth.go"
click node_chat "https://github.com/haidepzai269/mindex-backend/blob/main/controllers/chat.go"
click node_study "https://github.com/haidepzai269/mindex-backend/blob/main/controllers/studytools.go"
click node_ai_orchestrator "https://github.com/haidepzai269/mindex-backend/blob/main/utils/ai_orchestrator.go"
click node_tool_framework "https://github.com/haidepzai269/mindex-backend/tree/main/internal/tools"
click node_rag_tool "https://github.com/haidepzai269/mindex-backend/blob/main/internal/tools/rag_search_tool.go"
click node_rewriter "https://github.com/haidepzai269/mindex-backend/blob/main/utils/query_rewriter.go"
click node_documents_api "https://github.com/haidepzai269/mindex-backend/blob/main/controllers/document.go"
click node_upload_workers "https://github.com/haidepzai269/mindex-backend/blob/main/workers/worker.go"
click node_pipeline "https://github.com/haidepzai269/mindex-backend/blob/main/workers/pipeline.go"
click node_search "https://github.com/haidepzai269/mindex-backend/blob/main/utils/hybrid_search.go"
click node_collections "https://github.com/haidepzai269/mindex-backend/blob/main/controllers/collections.go"
click node_postgres "https://github.com/haidepzai269/mindex-backend/blob/main/config/database.go"
click node_redis "https://github.com/haidepzai269/mindex-backend/blob/main/config/redis.go"
click node_processing_client "https://github.com/haidepzai269/mindex-backend/blob/main/utils/processing_client.go"
click node_rooms "https://github.com/haidepzai269/mindex-backend/blob/main/internal/ws/room_hub.go"
click node_billing "https://github.com/haidepzai269/mindex-backend/blob/main/controllers/billing.go"

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_server,node_routes,node_auth,node_middleware,node_user,node_frontend toneBlue
class node_documents_api,node_upload_workers,node_pipeline,node_search,node_collections toneAmber
class node_chat,node_study,node_ai_orchestrator,node_tool_framework,node_rag_tool,node_rewriter toneMint
class node_postgres,node_redis,node_processing_client,node_rooms,node_billing toneRose
class node_external_ai toneIndigo
```

## Components

### API and identity

- [Application startup](https://github.com/haidepzai269/mindex-backend/blob/main/main.go): `main.go`
- [API routes](https://github.com/haidepzai269/mindex-backend/tree/main/routes): `routes`
- [Authentication](https://github.com/haidepzai269/mindex-backend/blob/main/controllers/auth.go): `controllers/auth.go`
- [Access middleware](https://github.com/haidepzai269/mindex-backend/blob/main/middleware/auth.go): `middleware/auth.go`

### Documents and retrieval

- [Document management](https://github.com/haidepzai269/mindex-backend/blob/main/controllers/document.go): `controllers/document.go`
- [Upload workers](https://github.com/haidepzai269/mindex-backend/blob/main/workers/worker.go): `workers/worker.go`
- [Extraction and indexing](https://github.com/haidepzai269/mindex-backend/blob/main/workers/pipeline.go): `workers/pipeline.go`
- [Hybrid retrieval](https://github.com/haidepzai269/mindex-backend/blob/main/utils/hybrid_search.go): `utils/hybrid_search.go`
- [Collections](https://github.com/haidepzai269/mindex-backend/blob/main/controllers/collections.go): `controllers/collections.go`

### AI and study

- [Chat and sessions](https://github.com/haidepzai269/mindex-backend/blob/main/controllers/chat.go): `controllers/chat.go`
- [Study features](https://github.com/haidepzai269/mindex-backend/blob/main/controllers/studytools.go): `controllers/studytools.go`
- [AI provider routing](https://github.com/haidepzai269/mindex-backend/blob/main/utils/ai_orchestrator.go): `utils/ai_orchestrator.go`
- [AI tools](https://github.com/haidepzai269/mindex-backend/tree/main/internal/tools): `internal/tools`
- [Document search tool](https://github.com/haidepzai269/mindex-backend/blob/main/internal/tools/rag_search_tool.go): `internal/tools/rag_search_tool.go`
- [Query rewriting](https://github.com/haidepzai269/mindex-backend/blob/main/utils/query_rewriter.go): `utils/query_rewriter.go`

### Platform services

- [PostgreSQL](https://github.com/haidepzai269/mindex-backend/blob/main/config/database.go): `config/database.go`
- [Redis](https://github.com/haidepzai269/mindex-backend/blob/main/config/redis.go): `config/redis.go`
- [Processing service client](https://github.com/haidepzai269/mindex-backend/blob/main/utils/processing_client.go): `utils/processing_client.go`
- [Realtime rooms](https://github.com/haidepzai269/mindex-backend/blob/main/internal/ws/room_hub.go): `internal/ws/room_hub.go`
- [Billing](https://github.com/haidepzai269/mindex-backend/blob/main/controllers/billing.go): `controllers/billing.go`

### Other components

- **User**
- **AI providers**
- **Frontend client**

## Connections

- Application startup → API routes: registers
- Application startup → PostgreSQL: connects
- Application startup → Redis: connects
- Application startup → Upload workers: starts
- Application startup → Realtime rooms: starts
- Frontend client → API routes: calls API
- API routes → Access middleware: protects routes
- API routes → Authentication: registers auth
- API routes → Document management: registers documents
- API routes → Chat and sessions: registers chat
- API routes → Collections: registers collections
- API routes → Study features: registers study
- API routes → Billing: registers billing
- Upload workers → PostgreSQL: claims jobs
- Upload workers → Extraction and indexing: processes jobs
- Extraction and indexing → PostgreSQL: stores chunks
- Extraction and indexing → AI providers: requests embeddings
- Chat and sessions → Query rewriting: rewrites queries
- Chat and sessions → AI provider routing: requests AI
- Chat and sessions → Document search tool: invokes tool
- Document search tool → Hybrid retrieval: searches documents
- Document search tool → AI providers: generates embedding
- AI provider routing → AI providers: calls providers
- Document management → PostgreSQL: reads and writes
- Collections → PostgreSQL: reads and writes
- Authentication → PostgreSQL: reads and writes
- Authentication → Redis: checks auth state
- Processing service client → Redis: queues tasks
- Chat and sessions → Realtime rooms: uses realtime
- Billing → PostgreSQL: updates account
