# mvp-rockets/backend-core architecture

> Architecture diagram of the GitHub repository mvp-rockets/backend-core, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mvp-rockets/backend-core
- Repository: https://github.com/mvp-rockets/backend-core

## Overview

##### Main Components

A. Core Application Layer:
- Express.js Server (main application entry point - index.js)
- API Routes Layer (api-routes.js, aws-api-routes.js, gcp-api-routes.js)
- Resource Modules (resources/ directory)
- Authentication System (passport/ directory)

B. Database Layer:
- Sequelize ORM (models/ directory)
- Migrations System
- Database Health Checks

C. External Services Integration:
- AWS Services (S3, Cognito)
- Google Cloud Platform Services
- Pub/Sub System
- SQS Queue System
- Redis Cache

D. Notification System:
- Multiple Providers (SMS, Email, WhatsApp)
- Message Formatting
- Multiple Language Support

##### Relationships and Data Flow

**[External Clients] → [API Layer]**
- ↓
**[Authentication] ← [Core Application] → [Resource Modules]**
- ↓
- [Services Layer]
- ↓
- ┌───────────────┴─────────────────┐
- ↓               ↓                 ↓
**[Database] [External Services]  [Notification System]**

##### Specific Implementation Details

A. API Layer:
- REST endpoints
- Health check endpoints
- WebSocket support (socket.js)
- Route handlers

B. Authentication:
- Passport strategies
- Token verification (multiple providers)
- OTP services
- Magic link authentication

C. Database:
- User model
- Migrations
- Health checks
- Query handlers

D. Notification System:
- Multiple providers (FCM, SMS, Email, WhatsApp)
- Message formatting
- Multi-language support
- Provider-specific implementations

E. External Services:
- AWS S3 for file storage
- Cognito for authentication
- GCP services
- Queue systems (SQS, Pub/Sub)

##### Additional Elements

Supporting components:
- Cron jobs system
- Health monitoring
- Environment configurations
- Test infrastructure
- Docker containerization

##### Implementation Notes

- Version/environment indicators
- Scaling points
- Health check paths

Remember to include configuration management and environment-specific setups, as the project supports multiple environments (dev, test, ci) and uses Docker for containerization.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "External Clients"
        Client1[Web Client]
        Client2[Mobile Client]
    end

    subgraph "API Layer"
        APIRoutes["API Routes"]:::core
        AWSRoutes["AWS Routes"]:::aws
        GCPRoutes["GCP Routes"]:::gcp
        WebSocket["WebSocket Handler"]:::core
    end

    subgraph "Core Application"
        Server["Express Server"]:::core
        ResourceModules["Resource Modules"]:::core
        HealthMonitor["Health Monitoring"]:::core
    end

    subgraph "Authentication"
        PassportAuth["Passport Strategies"]:::auth
        MagicLink["Magic Link Auth"]:::auth
        OTPService["OTP Service"]:::auth
        TokenVerifier["Token Verifier"]:::auth
    end

    subgraph "Database Layer"
        Models["Sequelize Models"]:::db
        Migrations["Database Migrations"]:::db
        DBHealth["Health Checks"]:::db
        UserModel["User Model"]:::db
    end

    subgraph "External Services"
        AWS["AWS Services"]:::aws
        GCP["GCP Services"]:::gcp
        PubSub["Pub/Sub System"]:::messaging
        SQS["SQS Queue"]:::messaging
        Redis["Redis Cache"]:::cache
        Cognito["AWS Cognito"]:::aws
    end

    subgraph "Notification System"
        NotifHandler["Notification Handler"]:::notification
        Providers["Multiple Providers"]:::notification
        MessageFormat["Message Formatter"]:::notification
        LangSupport["Multi-language Support"]:::notification
    end

    Client1 & Client2 --> APIRoutes & AWSRoutes & GCPRoutes
    APIRoutes & AWSRoutes & GCPRoutes --> Server
    Server --> ResourceModules
    Server --> PassportAuth
    ResourceModules --> Models
    ResourceModules --> NotifHandler
    ResourceModules --> AWS & GCP
    NotifHandler --> Providers
    NotifHandler --> MessageFormat
    MessageFormat --> LangSupport
    Server --> PubSub & SQS
    Server --> Redis
    PassportAuth --> Cognito
    PassportAuth --> TokenVerifier
    PassportAuth --> OTPService
    PassportAuth --> MagicLink
    HealthMonitor --> DBHealth

    %% Click Events
    click Server "https://github.com/mvp-rockets/backend-core/blob/master/index.js"
    click APIRoutes "https://github.com/mvp-rockets/backend-core/blob/master/api-routes.js"
    click AWSRoutes "https://github.com/mvp-rockets/backend-core/blob/master/aws-api-routes.js"
    click GCPRoutes "https://github.com/mvp-rockets/backend-core/blob/master/gcp-api-routes.js"
    click WebSocket "https://github.com/mvp-rockets/backend-core/blob/master/socket.js"
    click ResourceModules "https://github.com/mvp-rockets/backend-core/tree/master/resources"
    click PassportAuth "https://github.com/mvp-rockets/backend-core/tree/master/passport"
    click Models "https://github.com/mvp-rockets/backend-core/tree/master/models"
    click Migrations "https://github.com/mvp-rockets/backend-core/tree/master/migrations"
    click DBHealth "https://github.com/mvp-rockets/backend-core/blob/master/resources/healthz/services/check-db-health-service.js"
    click AWS "https://github.com/mvp-rockets/backend-core/tree/master/resources/aws"
    click GCP "https://github.com/mvp-rockets/backend-core/tree/master/resources/gcp"
    click PubSub "https://github.com/mvp-rockets/backend-core/tree/master/PUBSUB"
    click SQS "https://github.com/mvp-rockets/backend-core/tree/master/sqs"
    click Redis "https://github.com/mvp-rockets/backend-core/blob/master/utils/redis.js"
    click Cognito "https://github.com/mvp-rockets/backend-core/tree/master/resources/cognito"
    click NotifHandler "https://github.com/mvp-rockets/backend-core/blob/master/notifications/notification-handler.js"
    click Providers "https://github.com/mvp-rockets/backend-core/tree/master/notifications/modes"
    click MessageFormat "https://github.com/mvp-rockets/backend-core/tree/master/notifications/sms-formatter"
    click LangSupport "https://github.com/mvp-rockets/backend-core/tree/master/locales/notifications"
    click MagicLink "https://github.com/mvp-rockets/backend-core/blob/master/resources/auth/apis/login-with-magic-link-api.js"
    click OTPService "https://github.com/mvp-rockets/backend-core/blob/master/lib/otp-service.js"
    click TokenVerifier "https://github.com/mvp-rockets/backend-core/blob/master/lib/token-verifier.js"
    click UserModel "https://github.com/mvp-rockets/backend-core/blob/master/models/user.js"
    click HealthMonitor "https://github.com/mvp-rockets/backend-core/tree/master/resources/healthz/services"

    %% Styling
    classDef core fill:#2374ab
    classDef auth fill:#ff4d4d
    classDef db fill:#ffa500
    classDef aws fill:#ff9900
    classDef gcp fill:#4285f4
    classDef notification fill:#9c27b0
    classDef messaging fill:#00c853
    classDef cache fill:#78909c

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Authentication]:::auth
        L3[Database]:::db
        L4[AWS Services]:::aws
        L5[GCP Services]:::gcp
        L6[Notification]:::notification
        L7[Messaging]:::messaging
        L8[Cache]:::cache
    end
```
