# skill-exchange-2025/skill-exchange-back architecture

> Architecture diagram of the GitHub repository skill-exchange-2025/skill-exchange-back, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/skill-exchange-2025/skill-exchange-back
- Repository: https://github.com/skill-exchange-2025/skill-exchange-back

## Overview

##### Project type and purpose
- This is a backend service written in TypeScript using the NestJS framework. Its purpose is to power a “Skill Exchange” marketplace: handling user authentication/authorization, user/profile management, course/lesson listings and payments, real‑time messaging, and file uploads.

##### High‑level architectural overview
- Monolithic NestJS application, structured into feature modules.
- Exposes HTTP/REST endpoints for all resource operations.
- Exposes WebSocket gateway for real‑time messaging.
- Persists data in MongoDB via Mongoose schemas.
- Integrates with external services: Stripe (payments), Google Meet (video lessons), OTP service, local file storage.

##### Main components
A. Clients
- Web/Mobile frontends (HTTP REST & WebSocket)
B. NestJS App (Docker container)
1. AuthModule
- Controllers: /auth, /permission‑groups
- Services: AuthService, PermissionGroupsService
- Guards & Decorators: JWT auth, role & permission checks
- Schemas: OTP, PermissionGroup
2. UsersModule
- Controllers: /users
- Services: UsersService
- Schemas: User, UserSkill, DesiredSkill
3. ProfileModule
- Controllers: /profile
- Services: ProfileService
- Schemas: Profile
4. MarketplaceModule
- Controllers: /marketplace, /lessons, /payment, /stripe-webhook, /webhook
- Services: MarketplaceService, LessonsService, PaymentService, NotificationService, GoogleMeetService
- Schemas: Listing, Lesson, Review, Transaction, Payment, Wallet
5. MessagingModule
- Controller/Gateway: MessagingController, MessagingGateway
- Service: MessagingService
- Schemas: Channel, Message
6. FileUploadModule
- Handles file uploads (multipart) and persists files under /uploads
7. Core
- app.controller, app.service, app.module, main.ts
- Global middleware or interceptors (if any)
C. Infrastructure
- MongoDB (Docker‑compose service)
- Local filesystem (uploads volume)
- External APIs:
– Stripe (payment processing, webhooks)
– Google Meet (lesson video conferencing)
– OTP provider (SMS/email)
D. CI/CD & Deployment
- GitHub Actions (.github/workflows/deploy.yml)
- Dockerfile & docker‑compose.yml (build & orchestrate NestJS + MongoDB)
- Test harness: Jest (unit & e2e), custom test-scripts for API smoke tests

##### Key relationships & data flows
- Client → HTTP REST → NestJS Controllers → Services → MongoDB
- Client → WebSocket → MessagingGateway → MessagingService → MongoDB
- AuthController issues JWT tokens, other modules use JWT guard for auth
- MarketplaceService calls Stripe API for payments and webhooks
- LessonsService calls GoogleMeetService for meeting links
- FileUploadModule writes to local /uploads folder (mounted volume)
- CI/CD runs on push: builds Docker image, runs tests, deploys

##### Architectural patterns & principles
- Modularization: feature modules encapsulate domain logic
- Controller‑Service‑Repository (via Mongoose) pattern
- Dependency Injection (Nest core)
- Guard‐Decorator pattern for auth, roles, permissions
- Single container monolith, easily split into microservices later if needed

## Diagram (Mermaid)

```mermaid
graph TB
    %% Clients
    WebClient["Web/Mobile Clients"]:::client

    %% Docker Container for NestJS App
    subgraph "Docker Container: SkillExchange App"
        direction TB
        Core["Core\n(src/main.ts\napp.module.ts)"]:::core
        AuthModule["AuthModule"]:::module
        UsersModule["UsersModule"]:::module
        ProfileModule["ProfileModule"]:::module
        MarketplaceModule["MarketplaceModule"]:::module
        MessagingModule["MessagingModule"]:::module
        FileUploadModule["FileUploadModule"]:::module
        Uploads["Uploads Volume"]:::filestore
    end

    %% MongoDB Container
    subgraph "Docker Container: MongoDB"
        direction TB
        MongoDB["MongoDB"]:::database
    end

    %% External Services
    Stripe["Stripe API"]:::external
    GoogleMeet["Google Meet API"]:::external
    OTPService["OTP Provider"]:::external

    %% Connections
    WebClient -->|HTTP/REST| AuthModule
    WebClient -->|HTTP/REST| UsersModule
    WebClient -->|HTTP/REST| ProfileModule
    WebClient -->|HTTP/REST| MarketplaceModule
    WebClient -->|WS| MessagingModule

    AuthModule -->|Mongoose| MongoDB
    UsersModule -->|Mongoose| MongoDB
    ProfileModule -->|Mongoose| MongoDB
    MarketplaceModule -->|Mongoose| MongoDB
    MessagingModule -->|Mongoose| MongoDB

    AuthModule -->|SMS/Email OTP| OTPService
    MarketplaceModule -->|Payment API| Stripe
    Stripe -->|Webhook POST| MarketplaceModule
    MarketplaceModule -->|Video Links| GoogleMeet
    FileUploadModule -->|writes to| Uploads

    %% Click Events
    click AuthModule "https://github.com/skill-exchange-2025/skill-exchange-back/tree/main/src/auth"
    click UsersModule "https://github.com/skill-exchange-2025/skill-exchange-back/tree/main/src/users"
    click ProfileModule "https://github.com/skill-exchange-2025/skill-exchange-back/tree/main/src/profile"
    click MarketplaceModule "https://github.com/skill-exchange-2025/skill-exchange-back/tree/main/src/marketplace"
    click MessagingModule "https://github.com/skill-exchange-2025/skill-exchange-back/tree/main/src/messaging"
    click FileUploadModule "https://github.com/skill-exchange-2025/skill-exchange-back/blob/main/src/file-upload/file-upload.module.ts"
    click Uploads "https://github.com/skill-exchange-2025/skill-exchange-back/tree/main/uploads/"
    click Core "https://github.com/skill-exchange-2025/skill-exchange-back/blob/main/src/main.ts"

    %% Styles
    classDef client fill:#d0b3ff,stroke:#7f3fbf,color:#000
    classDef module fill:#b3d1ff,stroke:#1f5f9f,color:#000
    classDef database fill:#c2f0c2,stroke:#2f7f2f,color:#000
    classDef external fill:#ffd9b3,stroke:#bf6600,color:#000
    classDef filestore fill:#d9d9d9,stroke:#666666,color:#000
    classDef core fill:#ffcccc,stroke:#bf4040,color:#000
```
