# nahyan0077/eduverse-backend architecture

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

- Interactive diagram: https://gitdiagram.com/nahyan0077/eduverse-backend
- Repository: https://github.com/nahyan0077/eduverse-backend

## Overview

Eduverse is a microservices backend organized around a shared architectural pattern: each service has `presentation` controllers/routes, `application` use cases, `domain` entities/interfaces, and `infrastructure` adapters for MongoDB, Kafka, sockets, and external APIs. That structure is consistent across the repo and is the main diagram boundary to capture.

The request entrypoint is the `api-gateway`. It exposes the public HTTP surface, applies rate limiting, and proxies requests to the downstream services. It also contains boot-time config/environment wiring, so the diagram should show it as the single front door rather than a business-capability service.

`auth-service` is responsible for authentication and account lifecycle. It contains login, signup, Google auth, logout, OTP verification, password reset, and user lookup flows. It uses MongoDB for user and OTP persistence, bcrypt/JWT utilities for credential handling, and Kafka producers/consumers to fan out account-related events such as verification mail, forgot-password flow, user creation, and instructor moderation events.

`user-service` is the administrative/user-management domain. Its use cases focus on creating users, listing students and instructors, updating profiles, blocking/unblocking users, and approving/rejecting instructor applications. It persists users in MongoDB and publishes/consumes Kafka events for moderation and profile synchronization, so it acts as the platform’s central user-state coordinator outside of authentication.

`course-service` is the largest domain slice and covers course catalog and learning operations. It owns categories, courses, assessments, enrollments, reviews, results, and certificate generation. It uses MongoDB for all course-domain aggregates and listens to Kafka events such as course purchase success, user creation, and instructor verification/rejection to keep course access and teaching status in sync. The certificate assets/fonts in the repo indicate server-side certificate generation is part of this service.

`payment-service` handles monetization and payment-session orchestration. It supports one-time course payments and subscription payments, stores payment/session records in MongoDB, and integrates with Stripe via its webhook controller and session/payment use cases. It emits Kafka events like course purchase success and chat subscription success, which are the key downstream triggers for entitlement updates in other services.

`chat-service` manages messaging and real-time communication. It includes chat threads, messages, unread counts, user presence/last-seen style updates, and a socket bootstrap, which makes it the only service with a WebSocket-style runtime boundary. MongoDB stores chat/message state, while Kafka consumers keep chat subscriptions and user-created state synchronized with other services.

`notification-service` is the asynchronous outbound messaging layer. It consumes Kafka events for forgot-password, instructor verification/rejection, and user updates, then sends mail through SendGrid helpers. This service is intentionally narrow: it does not own core business state, only notification delivery and email-template orchestration.

Kafka is the main integration bus across the platform. Synchronous HTTP is used for user-facing API calls through the gateway, while cross-service side effects are propagated by Kafka producers/consumers. The important event flows to capture are account verification/reset, instructor approval workflow, purchase success leading to enrollment/access updates, and chat subscription propagation.

MongoDB is the primary persistence technology in each business service, but each service owns its own data model and repository layer. There is no shared database module across services; instead, the repo is structured for service-level data ownership and isolation, which is a key architectural boundary.

The deployment story is containerized and cloud-native. Every service has its own Dockerfile, there are GitHub Actions build workflows per service, and Kubernetes manifests under `manifests/k8s` define deployments plus an ingress controller. Local Kafka development is supported via `kafka-dev/docker-compose.yaml`, reinforcing that Kafka is a required platform dependency in both local and production setups.

A useful architecture diagram should therefore show: client traffic entering the API gateway; the gateway routing to the six backend services; MongoDB per service; Kafka as the shared async backbone between auth, user, course, payment, chat, and notification; and external providers for Stripe and SendGrid. The only real-time path to highlight separately is chat service socket handling, since it bypasses the ordinary request/response flow.

Main entry points: [`kafka-dev/docker-compose.yaml`](https://github.com/nahyan0077/eduverse-backend/blob/main/kafka-dev/docker-compose.yaml) (Kafka bus), [`api-gateway/src/presentation/server.ts`](https://github.com/nahyan0077/eduverse-backend/blob/main/api-gateway/src/presentation/server.ts) (API Gateway), [`payment-service/src/infrastructure/database/mongo/repositories/createPayment.ts`](https://github.com/nahyan0077/eduverse-backend/blob/main/payment-service/src/infrastructure/database/mongo/repositories/createPayment.ts) (Payment store), [`auth-service/src/infrastructure/database/mongodb/repositories/createUser.ts`](https://github.com/nahyan0077/eduverse-backend/blob/main/auth-service/src/infrastructure/database/mongodb/repositories/createUser.ts) (Auth store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_platform["Platform"]
  node_client(("Clients"))
  node_kafka_bus["Kafka bus<br/>event backbone"]
  node_mongodb[("MongoDB<br/>data stores")]
  node_stripe["Stripe<br/>payment provider"]
  node_sendgrid["SendGrid<br/>email provider"]
end

subgraph group_gateway["API Gateway"]
  node_api_gateway["API Gateway<br/>front door<br/>[server.ts]"]
end

subgraph group_auth["Auth Service"]
  node_auth_api["Auth API<br/>auth endpoints<br/>[server.ts]"]
  node_auth_core["Auth core<br/>use cases"]
  node_auth_store[("Auth store<br/>mongo+kafka<br/>[createUser.ts]")]
end

subgraph group_user["User Service"]
  node_user_api["User API<br/>admin endpoints<br/>[server.ts]"]
  node_user_core["User core<br/>use cases"]
  node_user_store[("User store<br/>mongo+kafka<br/>[createUser.ts]")]
end

subgraph group_course["Course Service"]
  node_course_api["Course API<br/>course endpoints<br/>[server.ts]"]
  node_course_core["Course core<br/>use cases"]
  node_course_store[("Course store<br/>mongo+kafka<br/>[createCourse.ts]")]
end

subgraph group_payment["Payment Service"]
  node_payment_api["Payment API<br/>billing endpoints<br/>[server.ts]"]
  node_payment_core["Payment core<br/>billing use cases"]
  node_payment_store[("Payment store<br/>mongo+kafka<br/>[createPayment.ts]")]
end

subgraph group_chat["Chat Service"]
  node_chat_api["Chat API<br/>chat endpoints<br/>[server.ts]"]
  node_chat_realtime{{"Socket layer<br/>realtime runtime<br/>[socket.ts]"}}
  node_chat_core["Chat core<br/>use cases"]
  node_chat_store[("Chat store<br/>mongo+kafka<br/>[createChat.ts]")]
end

subgraph group_notification["Notification Service"]
  node_notification_api["Notification API<br/>mail endpoints<br/>[server.ts]"]
  node_notification_worker["Mail worker<br/>email delivery"]
end

node_client -->|"HTTP"| node_api_gateway
node_api_gateway -->|"route"| node_auth_api
node_api_gateway -->|"route"| node_user_api
node_api_gateway -->|"route"| node_course_api
node_api_gateway -->|"route"| node_payment_api
node_api_gateway -->|"route"| node_chat_api
node_api_gateway -->|"route"| node_notification_api
node_auth_api -->|"uses"| node_auth_core
node_auth_core -->|"persist/event"| node_auth_store
node_auth_store -->|"mongo"| node_mongodb
node_auth_store -->|"publish/consume"| node_kafka_bus
node_user_api -->|"uses"| node_user_core
node_user_core -->|"persist/event"| node_user_store
node_user_store -->|"mongo"| node_mongodb
node_user_store -->|"publish/consume"| node_kafka_bus
node_course_api -->|"uses"| node_course_core
node_course_core -->|"persist/event"| node_course_store
node_course_store -->|"mongo"| node_mongodb
node_course_store -->|"consume"| node_kafka_bus
node_payment_api -->|"uses"| node_payment_core
node_payment_core -->|"persist/event"| node_payment_store
node_payment_store -->|"mongo"| node_mongodb
node_payment_store -->|"webhook/api"| node_stripe
node_payment_store -->|"publish"| node_kafka_bus
node_chat_api -->|"uses"| node_chat_core
node_chat_api -->|"bootstrap"| node_chat_realtime
node_chat_realtime -->|"events"| node_chat_core
node_chat_core -->|"persist/event"| node_chat_store
node_chat_store -->|"mongo"| node_mongodb
node_chat_store -->|"consume"| node_kafka_bus
node_notification_api -->|"trigger"| node_notification_worker
node_notification_worker -->|"email"| node_sendgrid
node_notification_worker -->|"consume"| node_kafka_bus
node_kafka_bus -.->|"events"| node_auth_store
node_kafka_bus -.->|"events"| node_user_store
node_kafka_bus -.->|"events"| node_course_store
node_kafka_bus -.->|"events"| node_payment_store
node_kafka_bus -.->|"events"| node_chat_store
node_kafka_bus -.->|"events"| node_notification_worker

click node_api_gateway "https://github.com/nahyan0077/eduverse-backend/blob/main/api-gateway/src/presentation/server.ts"
click node_auth_api "https://github.com/nahyan0077/eduverse-backend/blob/main/auth-service/src/presentation/server.ts"
click node_auth_core "https://github.com/nahyan0077/eduverse-backend/blob/main/auth-service/src/application/useCases/loginUserUseCase.ts"
click node_auth_store "https://github.com/nahyan0077/eduverse-backend/blob/main/auth-service/src/infrastructure/database/mongodb/repositories/createUser.ts"
click node_user_api "https://github.com/nahyan0077/eduverse-backend/blob/main/user-service/src/presentation/server.ts"
click node_user_core "https://github.com/nahyan0077/eduverse-backend/blob/main/user-service/src/application/useCases/createUserUseCase.ts"
click node_user_store "https://github.com/nahyan0077/eduverse-backend/blob/main/user-service/src/infrastructure/database/mongo/respositories/createUser.ts"
click node_course_api "https://github.com/nahyan0077/eduverse-backend/blob/main/course-service/src/presentation/server.ts"
click node_course_core "https://github.com/nahyan0077/eduverse-backend/blob/main/course-service/src/application/useCases/course/createCourseUseCase.ts"
click node_course_store "https://github.com/nahyan0077/eduverse-backend/blob/main/course-service/src/infrastructure/database/mongodb/repositories/course/createCourse.ts"
click node_payment_api "https://github.com/nahyan0077/eduverse-backend/blob/main/payment-service/src/presentation/server.ts"
click node_payment_core "https://github.com/nahyan0077/eduverse-backend/blob/main/payment-service/src/application/useCases/createSessionUseCase.ts"
click node_payment_store "https://github.com/nahyan0077/eduverse-backend/blob/main/payment-service/src/infrastructure/database/mongo/repositories/createPayment.ts"
click node_chat_api "https://github.com/nahyan0077/eduverse-backend/blob/main/chat-service/src/presentation/server.ts"
click node_chat_realtime "https://github.com/nahyan0077/eduverse-backend/blob/main/chat-service/src/_boot/socket.ts"
click node_chat_core "https://github.com/nahyan0077/eduverse-backend/blob/main/chat-service/src/application/useCases/createChatUseCase.ts"
click node_chat_store "https://github.com/nahyan0077/eduverse-backend/blob/main/chat-service/src/infrastructure/database/mongodb/repositories/createChat.ts"
click node_notification_api "https://github.com/nahyan0077/eduverse-backend/blob/main/notification-service/src/presentation/server.ts"
click node_notification_worker "https://github.com/nahyan0077/eduverse-backend/blob/main/notification-service/src/infrastructure/services/mail/sendVerificationMail.ts"
click node_kafka_bus "https://github.com/nahyan0077/eduverse-backend/blob/main/kafka-dev/docker-compose.yaml"

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_client,node_kafka_bus,node_mongodb,node_stripe,node_sendgrid,node_chat_api,node_chat_realtime,node_chat_core,node_chat_store toneBlue
class node_api_gateway,node_notification_api,node_notification_worker toneAmber
class node_auth_api,node_auth_core,node_auth_store toneMint
class node_user_api,node_user_core,node_user_store toneRose
class node_course_api,node_course_core,node_course_store toneIndigo
class node_payment_api,node_payment_core,node_payment_store toneTeal
```

## Components

### Platform

Shared infrastructure and deployment layer

- **Clients**: http clients · Browsers or API consumers calling the public backend
- [Kafka bus](https://github.com/nahyan0077/eduverse-backend/blob/main/kafka-dev/docker-compose.yaml): event backbone · Shared async backbone for cross-service side effects · `kafka-dev/docker-compose.yaml`
- **MongoDB**: data stores · Service-owned MongoDB persistence across the platform
- **Stripe**: payment provider · External billing and webhook provider
- **SendGrid**: email provider · External email delivery provider

### API Gateway

Public HTTP entrypoint and request proxy

- [API Gateway](https://github.com/nahyan0077/eduverse-backend/blob/main/api-gateway/src/presentation/server.ts): front door · Public HTTP surface, rate limiting, config wiring, and downstream proxying · `api-gateway/src/presentation/server.ts`

### Auth Service

Authentication and account lifecycle

- [Auth API](https://github.com/nahyan0077/eduverse-backend/blob/main/auth-service/src/presentation/server.ts): auth endpoints · Login, signup, OTP, password reset, Google auth, logout, and user lookup flows · `auth-service/src/presentation/server.ts`
- [Auth core](https://github.com/nahyan0077/eduverse-backend/blob/main/auth-service/src/application/useCases/loginUserUseCase.ts): use cases · Credential handling, verification, and account lifecycle orchestration · `auth-service/src/application/useCases/loginUserUseCase.ts`
- [Auth store](https://github.com/nahyan0077/eduverse-backend/blob/main/auth-service/src/infrastructure/database/mongodb/repositories/createUser.ts): mongo+kafka · User and OTP persistence plus account-related Kafka producers/consumers · `auth-service/src/infrastructure/database/mongodb/repositories/createUser.ts`

### User Service

Administrative user-state management

- [User API](https://github.com/nahyan0077/eduverse-backend/blob/main/user-service/src/presentation/server.ts): admin endpoints · User listing, profile updates, blocking, and instructor moderation · `user-service/src/presentation/server.ts`
- [User core](https://github.com/nahyan0077/eduverse-backend/blob/main/user-service/src/application/useCases/createUserUseCase.ts): use cases · Administrative user management and moderation workflows · `user-service/src/application/useCases/createUserUseCase.ts`
- [User store](https://github.com/nahyan0077/eduverse-backend/blob/main/user-service/src/infrastructure/database/mongo/respositories/createUser.ts): mongo+kafka · User persistence and moderation/profile synchronization events · `user-service/src/infrastructure/database/mongo/respositories/createUser.ts`

### Course Service

Catalog, enrollment, assessment, and certificates

- [Course API](https://github.com/nahyan0077/eduverse-backend/blob/main/course-service/src/presentation/server.ts): course endpoints · Catalog, assessment, enrollment, review, result, and certificate routes · `course-service/src/presentation/server.ts`
- [Course core](https://github.com/nahyan0077/eduverse-backend/blob/main/course-service/src/application/useCases/course/createCourseUseCase.ts): use cases · Catalog, learning, assessment, and certificate generation logic · `course-service/src/application/useCases/course/createCourseUseCase.ts`
- [Course store](https://github.com/nahyan0077/eduverse-backend/blob/main/course-service/src/infrastructure/database/mongodb/repositories/course/createCourse.ts): mongo+kafka · Course-domain persistence plus event-driven access synchronization · `course-service/src/infrastructure/database/mongodb/repositories/course/createCourse.ts`

### Payment Service

Payment-session and monetization orchestration

- [Payment API](https://github.com/nahyan0077/eduverse-backend/blob/main/payment-service/src/presentation/server.ts): billing endpoints · Payment, session, subscription, and Stripe webhook controllers · `payment-service/src/presentation/server.ts`
- [Payment core](https://github.com/nahyan0077/eduverse-backend/blob/main/payment-service/src/application/useCases/createSessionUseCase.ts): billing use cases · Session creation, payment updates, and subscription orchestration · `payment-service/src/application/useCases/createSessionUseCase.ts`
- [Payment store](https://github.com/nahyan0077/eduverse-backend/blob/main/payment-service/src/infrastructure/database/mongo/repositories/createPayment.ts): mongo+kafka · Payment/session persistence and purchase-success event publishing · `payment-service/src/infrastructure/database/mongo/repositories/createPayment.ts`

### Chat Service

Messaging and realtime communication

- [Chat API](https://github.com/nahyan0077/eduverse-backend/blob/main/chat-service/src/presentation/server.ts): chat endpoints · Chat thread, message, unread-count, and presence-related routes · `chat-service/src/presentation/server.ts`
- [Socket layer](https://github.com/nahyan0077/eduverse-backend/blob/main/chat-service/src/_boot/socket.ts): realtime runtime · WebSocket-style bootstrap for realtime chat communication · `chat-service/src/_boot/socket.ts`
- [Chat core](https://github.com/nahyan0077/eduverse-backend/blob/main/chat-service/src/application/useCases/createChatUseCase.ts): use cases · Thread, message, unread-count, and last-seen coordination · `chat-service/src/application/useCases/createChatUseCase.ts`
- [Chat store](https://github.com/nahyan0077/eduverse-backend/blob/main/chat-service/src/infrastructure/database/mongodb/repositories/createChat.ts): mongo+kafka · Chat/message persistence and synchronization consumers · `chat-service/src/infrastructure/database/mongodb/repositories/createChat.ts`

### Notification Service

Outbound email delivery

- [Notification API](https://github.com/nahyan0077/eduverse-backend/blob/main/notification-service/src/presentation/server.ts): mail endpoints · Minimal HTTP surface for notification-related actions · `notification-service/src/presentation/server.ts`
- [Mail worker](https://github.com/nahyan0077/eduverse-backend/blob/main/notification-service/src/infrastructure/services/mail/sendVerificationMail.ts): email delivery · Kafka-driven email templates and SendGrid delivery · `notification-service/src/infrastructure/services/mail/sendVerificationMail.ts`

## Connections

- Clients → API Gateway: HTTP · Client traffic enters through the gateway
- API Gateway → Auth API: route · Gateway proxies auth requests
- API Gateway → User API: route · Gateway proxies user-management requests
- API Gateway → Course API: route · Gateway proxies course requests
- API Gateway → Payment API: route · Gateway proxies billing requests
- API Gateway → Chat API: route · Gateway proxies chat HTTP requests
- API Gateway → Notification API: route · Gateway proxies notification-related requests
- Auth API → Auth core: uses · Controllers invoke authentication use cases
- Auth core → Auth store: persist/event · Auth logic writes users/OTP data and emits account events
- Auth store → MongoDB: mongo · Auth service owns its MongoDB collections
- Auth store → Kafka bus: publish/consume · Auth service exchanges account and moderation events
- User API → User core: uses · Controllers invoke user-management use cases
- User core → User store: persist/event · User logic updates state and emits moderation/profile events
- User store → MongoDB: mongo · User service owns its MongoDB collections
- User store → Kafka bus: publish/consume · User service synchronizes state through Kafka
- Course API → Course core: uses · Controllers invoke course-domain use cases
- Course core → Course store: persist/event · Course logic stores aggregates and reacts to platform events
- Course store → MongoDB: mongo · Course service owns its MongoDB collections
- Course store → Kafka bus: consume · Course service listens for purchases and user/instructor updates
- Payment API → Payment core: uses · Controllers invoke payment and subscription use cases
- Payment core → Payment store: persist/event · Payment logic records sessions and emits purchase events
- Payment store → MongoDB: mongo · Payment service owns its MongoDB collections
- Payment store → Stripe: webhook/api · Payment service integrates with Stripe
- Payment store → Kafka bus: publish · Payment success events fan out to other services
- Chat API → Chat core: uses · Chat HTTP controllers invoke message/thread use cases
- Chat API → Socket layer: bootstrap · Chat service boots a realtime socket runtime
- Socket layer → Chat core: events · Realtime messages flow through chat use cases
- Chat core → Chat store: persist/event · Chat logic stores messages and unread counts
- Chat store → MongoDB: mongo · Chat service owns its MongoDB collections
- Chat store → Kafka bus: consume · Chat service consumes subscription and user lifecycle events
- Notification API → Mail worker: trigger · Notification surface delegates to mail delivery workflows
- Mail worker → SendGrid: email · Notification service sends mail through SendGrid
- Mail worker → Kafka bus: consume · Notification service reacts to forgot-password and instructor events
- Kafka bus → Auth store: events · Account and verification flows propagate through Kafka
- Kafka bus → User store: events · Moderation and user sync propagate through Kafka
- Kafka bus → Course store: events · Course access and instructor state stay synchronized via Kafka
- Kafka bus → Payment store: events · Purchase-success events originate from payment flows
- Kafka bus → Chat store: events · Chat subscription and user-created events propagate via Kafka
- Kafka bus → Mail worker: events · Notification service consumes asynchronous messaging events
