# mayankkamriya/unihoxtask-authentication-api-ddd-architecture architecture

> Architecture diagram of the GitHub repository mayankkamriya/unihoxtask-authentication-api-ddd-architecture, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture
- Repository: https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture

## Overview

##### Project type and purpose
- This is a full-stack authentication system:
- Frontend: React (Vite) SPA for signup/sign-in, OTP flows, dashboard
- Backend: Node.js + Express API implementing DDD (Domain, Infrastructure, Presentation layers)
- Database: MongoDB via Mongoose
- External services: SMTP (Nodemailer) for email OTP, Twilio for SMS OTP
- Purpose: Provide secure password- and OTP-based user authentication with JWT authorization.

##### File structure
- Top level:
- backend/ — Express API, follows Domain-Driven Design
– src/domain/services: business logic (AuthService, TwilioService)
– src/infrastructure: persistence (Mongoose models), email sender, DB connection
– src/presentation: HTTP routes & middleware
- frontend/ — React SPA (components for signup, sign-in, OTP, dashboard)
- Config & deployment: vercel.json for backend, Vite config for frontend.

##### README for architectural insights
- Emphasizes DDD & SOLID: separation into domain, infrastructure, presentation
- Lists technology stack and API endpoints.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer" 
        direction TB
        ReactSPA["React SPA"]:::frontend
        ViteConfig["Vite Config"]:::frontend
        MainEntry["main.jsx"]:::frontend
        AppComponent["App.jsx"]:::frontend
        SignupComp["Signup.jsx"]:::frontend
        SigninPassComp["SigninPassword.jsx"]:::frontend
        SigninOTPComp["SigninOTP.jsx"]:::frontend
        DashboardComp["Dashboard.jsx 🔒"]:::frontend
        LayoutComp["MainP.jsx"]:::frontend
        EnvConfig["index.html (VITE_API_URL)"]:::frontend
    end

    %% Presentation Layer
    subgraph "Presentation Layer (API)" 
        direction TB
        APIEntry["index.js"]:::presentation
        SignupRoute["signup.js"]:::presentation
        SigninRoute["signin.js"]:::presentation
        OTProute["otp.js"]:::presentation
        AuthMiddleware["auth.js"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer" 
        direction TB
        AuthService["AuthService"]:::domain
        TwilioService["TwilioService"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer" 
        direction TB
        DBConn["db.js"]:::infra
        EmailSender["EmailSender.js"]:::infra
        UserModel["user.js"]:::infra
        OTPModel["otp.js"]:::infra
        MobileOTPModel["mobileotp.js"]:::infra
        MongoDB["MongoDB"]:::infraDb
    end

    %% External Services
    subgraph "External Services" 
        direction TB
        SMTP["SMTP (Nodemailer)"]:::external
        Twilio["Twilio SMS API"]:::external
    end

    %% Connections
    ReactSPA -->|HTTP JSON| APIEntry
    APIEntry -->|register| SignupRoute
    APIEntry -->|login/password| SigninRoute
    APIEntry -->|login/otp| OTProute
    SignupRoute -->|calls| AuthService
    SigninRoute -->|calls| AuthService
    OTProute -->|calls| AuthService
    AuthMiddleware -->|validates JWT| APIEntry
    AuthService -->|uses| UserModel
    AuthService -->|uses| OTPModel
    AuthService -->|uses| MobileOTPModel
    AuthService -->|creates JWT| AuthMiddleware
    AuthService -->|sends email| EmailSender
    AuthService -->|sends sms| TwilioService
    EmailSender -->|SMTP| SMTP
    TwilioService -->|SMS API| Twilio
    UserModel -->|CRUD| MongoDB
    OTPModel -->|CRUD| MongoDB
    MobileOTPModel -->|CRUD| MongoDB

    DashboardComp -->|fetch protected| APIEntry

    %% Click Events
    click ReactSPA "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/tree/main/frontend/"
    click ViteConfig "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/frontend/vite.config.js"
    click MainEntry "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/frontend/src/main.jsx"
    click AppComponent "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/frontend/src/App.jsx"
    click SignupComp "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/frontend/src/components/Signup.jsx"
    click SigninPassComp "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/frontend/src/components/SigninPassword.jsx"
    click SigninOTPComp "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/frontend/src/components/SigninOTP.jsx"
    click DashboardComp "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/frontend/src/components/Dashboard.jsx"
    click LayoutComp "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/frontend/src/components/MainP.jsx"
    click EnvConfig "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/frontend/index.html"
    click APIEntry "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/index.js"
    click SignupRoute "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/presentation/routes/signup.js"
    click SigninRoute "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/presentation/routes/signin.js"
    click OTProute "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/presentation/routes/otp.js"
    click AuthMiddleware "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/presentation/middleware/auth.js"
    click AuthService "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/domain/services/AuthService.js"
    click TwilioService "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/domain/services/twilioservices.js"
    click DBConn "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/infrastructure/db.js"
    click EmailSender "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/infrastructure/email/EmailSender.js"
    click UserModel "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/infrastructure/models/user.js"
    click OTPModel "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/infrastructure/models/otp.js"
    click MobileOTPModel "https://github.com/mayankkamriya/unihoxtask-authentication-api-ddd-architecture/blob/main/backend/src/infrastructure/models/mobileotp.js"

    %% Styles
    classDef frontend fill:#D0E7FF,stroke:#0366d6,color:#0366d6;
    classDef presentation fill:#E8F0FE,stroke:#1967d2,color:#1967d2;
    classDef domain fill:#E6F4EA,stroke:#137333,color:#137333;
    classDef infra fill:#FEF3C7,stroke:#D97706,color:#D97706;
    classDef infraDb fill:#FEF3C7,stroke:#A16207,color:#A16207;
    classDef external fill:#FEE2E2,stroke:#B91C1C,color:#B91C1C;
```
