# tekdi/all-saas-user-microservice architecture

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

- Interactive diagram: https://gitdiagram.com/tekdi/all-saas-user-microservice
- Repository: https://github.com/tekdi/all-saas-user-microservice

## Overview

##### Project Type & Purpose
- The project is a backend API server built with the NestJS framework using TypeScript. It is structured as a modular, feature-based application supporting multiple domains (for example: attendance, auth, cohort, courses, RBAC, etc.) along with various adapters for external integrations (like Hasura, Postgres, and Diksha).
- The README “NestJS starter repository” shows that the project follows Nest’s best practices and is intended to be scalable and maintainable. It’s designed to handle a variety of business functionalities including authentication, role-based access control, user and cohort management, and interfacing with external services.

##### Analyzing the File Structure
- Top-Level Structure: Notice directories like “src” for application code, “adapters” which provide integration layers, “common” for shared utilities, decorators, and guards, as well as configurations and scaffolding files (Dockerfile, Jenkinsfile, docker-compose.yml, etc.) for deployment and CI/CD.
- Modular Domains: Within “src” you have separated modules such as “attendance”, “auth”, “cohort”, “course”, “fields”, “rbac”, “user”, “userTenantMapping”, etc. This modular breakdown is reflective of the typical NestJS approach where each module encapsulates controllers, services, DTOs, and entities related to specific functionality.
- Adapters: The “adapters” directory contains subdirectories for different external service integrations. For example, there are adapters for Hasura (e.g. for RBAC, attendance, cohort members) and Postgres. This separation indicates that external services are abstracted so that the business logic in your modules can remain independent of the underlying data sources or APIs.
- Configurations & CI/CD: Files and directories like “.github/workflows”, “Jenkinsfile”, “Dockerfile”, and “docker-compose.yml” suggest that the project is set up for containerized deployment and automated testing/deployment pipelines.

##### Main Components
a. API Gateway / Entry Point:
- NestJS application’s main entry (main.ts) which initializes the entire server.
b. Domain Modules / Functional Components:
- Each module should ideally encapsulate its controllers (handling HTTP requests), services (business logic), DTOs (data transfer objects), and Entities (database schema representations).
c. Adapters / Integration Layers:
- Hasura Adapter for GraphQL interactions, RBAC, and related services.
- Postgres Adapter managing data persistence.
- Diksha Adapter (and possibly others) for interfacing with external course or content services.
d. Common Shared Components:
- Elements like Common Utilities, Guards, Filters, Decorators, and a Database Module that are used across various modules.
e. Infrastructure & CI/CD:

##### Relationships & Interactions
- How modules interact with the adapters (for example, the Attendance module calling a specific Hasura or Postgres adapter) via service locators.
- Data flow between the modules and the database/integrations.
- Optionally, show how CI/CD components (from GitHub workflows, Docker, Kubernetes manifests) relate to the overall system deployment and ongoing operations.

##### Architectural Patterns & Design Principles
- Modular architecture pattern inherent to NestJS which provides separation of concerns: controllers, services, and adapters are decoupled.
- Use of adapter or façade patterns where external systems (database, third-party APIs) are abstracted behind local interfaces.
- That dependency inversion is used in orchestrating business logic through service locators.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% API Gateway
    API["API Gateway (main.ts)"]:::gateway

    %% Domain Modules Subgraph
    subgraph "Domain Modules"
        A["Attendance Module\n(controllers, services, DTOs, entities)"]:::module
        B["Auth Module\n(auth.controller.ts, auth.service.ts, DTOs)"]:::module
        C["Cohort Module\n(cohort.controller.ts, cohort.service.ts, DTOs, entities)"]:::module
        D["Course Module\n(course.controller.ts, course.module.ts)"]:::module
        E["Course Tracking Module\n(courseTracking.controller.ts, DTOs, module)"]:::module
        F["Fields Module\n(fields.controller.ts, fields.service.ts, DTOs, entities)"]:::module
        G["RBAC Module\n(assign-privilege, assign-role, privilege, role)"]:::module
        H["User Module\n(user.controller.ts, user.service.ts, DTOs, entities)"]:::module
        I["UserTenantMapping Module\n(user-tenant-mapping.controller.ts, adapter, DTOs, entities)"]:::module
    end

    %% Adapters Subgraph
    subgraph "Adapters"
        J["Hasura Adapter"]:::adapter
        K["Postgres Adapter"]:::adapter
        L["Diksha Adapter"]:::adapter
    end

    %% Common Shared Components
    Cmn["Common Shared Components\n(database module, decorators, guards, filters, responses, utils)"]:::common

    %% CI/CD & Deployment Artifacts Subgraph
    subgraph "CI/CD & Deployment"
        M["Jenkins Pipeline"]:::cicd
        N["GitHub Workflows"]:::cicd
        O["Container & Orchestration"]:::cicd
    end

    %% Relationships: API Gateway to Domain Modules
    API -->|"calls"| A
    API -->|"calls"| B
    API -->|"calls"| C
    API -->|"calls"| D
    API -->|"calls"| E
    API -->|"calls"| F
    API -->|"calls"| G
    API -->|"calls"| H
    API -->|"calls"| I

    %% Domain Modules using Adapters (representative integrations)
    A -->|"integrates"| J
    A -->|"integrates"| K
    C -->|"integrates"| J
    C -->|"integrates"| K
    D -->|"integrates"| L
    I -->|"integrates"| K

    %% Domain Modules using Common Shared Components (representative)
    A ---|"uses"| Cmn
    B ---|"uses"| Cmn
    C ---|"uses"| Cmn
    G ---|"uses"| Cmn
    H ---|"uses"| Cmn
    I ---|"uses"| Cmn

    %% CI/CD Deployment connecting to API Gateway
    M -->|"deploys"| API
    N -->|"triggers"| API
    O -->|"orchestrates"| API

    %% Styles
    classDef gateway fill:#ff9999,stroke:#660000,stroke-width:2px;
    classDef module fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef adapter fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef common fill:#fff2cc,stroke:#996600,stroke-width:2px;
    classDef cicd fill:#ffd9b3,stroke:#994d00,stroke-width:2px;

    %% Click Events
    click API "https://github.com/tekdi/all-saas-user-microservice/blob/main/src/main.ts"
    click A "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/attendance"
    click B "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/auth"
    click C "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/cohort"
    click D "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/course"
    click E "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/courseTracking"
    click F "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/fields"
    click G "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/rbac"
    click H "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/user"
    click I "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/userTenantMapping"
    click J "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/adapters/hasura"
    click K "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/adapters/postgres"
    click L "https://github.com/tekdi/all-saas-user-microservice/blob/main/src/adapters/diksha/dikshaCourse.adapter.ts"
    click Cmn "https://github.com/tekdi/all-saas-user-microservice/tree/main/src/common"
    click M "https://github.com/tekdi/all-saas-user-microservice/tree/main/Jenkinsfile"
    click N "https://github.com/tekdi/all-saas-user-microservice/tree/main/.github/workflows"
    click O "https://github.com/tekdi/all-saas-user-microservice/tree/main/Dockerfile"
```
