# shaukinkhan477/newsletter-creator-app architecture

> Architecture diagram of the GitHub repository shaukinkhan477/newsletter-creator-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shaukinkhan477/newsletter-creator-app
- Repository: https://github.com/shaukinkhan477/newsletter-creator-app

## Overview

##### Project Type & Purpose
- This is a full-stack newsletter management platform.
- Frontend: Angular 17 SPA with NgRx, internationalization, accessibility, Cypress e2e and Jest unit tests.
- Backend: Node.js + Express REST API and Apollo GraphQL server, MongoDB (Mongoose), Passport.js for Google OAuth, JWT auth, node-cron for scheduling, Nodemailer for email dispatch.

##### Main Components
a. Frontend Application
- Angular client served by `ng serve` or Docker + Nginx.
- Feature modules: Auth, Posts (Newsletters), Subscribers, Templates, Analytics.
- State management via NgRx (store slices: auth, posts, subscribers).
- HTTP interceptor for JWT.
b. Backend Services
- Express + Apollo Server listening on `server.js`.
- REST endpoints under `/api/*` (auth, posts, subscribers).
- GraphQL endpoint at `/graphql`.
- OpenAPI docs served at `/api-docs`.
- Middlewares: JWT guard, Passport Google OAuth strategy.
- Cron job (`cron.js`) for scheduled dispatch.
c. Database
- MongoDB via Mongoose models (User, Post, Subscriber).
d. External Services
- Google OAuth (Passport.js).
- SMTP provider (Mailtrap or other) via Nodemailer.
- Optional third-party tracking (Google Analytics, Meta Pixel).
e. DevOps & CI/CD
- Dockerfiles for frontend & backend.
- docker-compose.yaml orchestrating backend, frontend, MongoDB.
- GitHub workflows: ESLint, SonarQube, CI/CD pipeline.

##### Relationships & Data Flows
- User ↔ Angular SPA: login/signup, dashboard interactions.
- SPA → Backend:
- REST calls for CRUD and scheduler operations.
- GraphQL queries/mutations for per-user data.
- JWT token in Authorization header (via interceptor).
- Backend → MongoDB: data persistence.
- Cron → Backend logic → MongoDB to fetch scheduled posts → Nodemailer → SMTP.
- Backend → External OAuth provider → user profile → JWT issuance.
- Frontend analytics dashboard reads metrics from REST/GraphQL.

##### Architectural Patterns & Design Principles
- Frontend: Feature modules + shared components, unidirectional NgRx state, HTTP interceptor pattern.
- Backend: MVC/Router-Controller-Service pattern, middleware pipeline, dual API layer (REST + GraphQL).
- Separation of concerns: scheduler isolated in `cron.js`, auth logic in `passport.js` & middleware, docs in `openapi.yaml`.
- Containerization for consistency across environments.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph "Client Layer" 
        direction TB
        Angular["Angular SPA\n(Angular17 + NgRx)"]:::frontend
        subgraph "Feature Modules"
            direction TB
            AuthModule["Auth Module"]:::frontend
            PostsModule["Posts Module"]:::frontend
            SubscribersModule["Subscribers Module"]:::frontend
            TemplatesModule["Templates Module"]:::frontend
            AnalyticsModule["Analytics Module"]:::frontend
        end
        Store["NgRx Store"]:::frontend
        Interceptor["Auth HTTP Interceptor\n(JWT)"]:::frontend
        Cypress["Cypress E2E Tests"]:::devops
        Jest["Jest Unit Tests"]:::devops
    end

    %% API Gateway Layer
    subgraph "API Gateway Layer"
        direction TB
        API["Express + Apollo Server\n(server.js)"]:::backend
        subgraph "REST Endpoints"
            direction TB
            AuthRoutes["Auth Routes"]:::backend
            PostRoutes["Post Routes"]:::backend
            SubscriberRoutes["Subscriber Routes"]:::backend
        end
        subgraph "Controllers"
            direction TB
            AuthController["Auth Controller"]:::backend
            PostController["Post Controller"]:::backend
            SubscriberController["Subscriber Controller"]:::backend
        end
        GraphQL["GraphQL Schema & Resolvers"]:::backend
        JWTMiddleware["JWT Guard Middleware"]:::backend
        OAuthStrategy["Passport Google OAuth"]:::backend
        OpenAPI["OpenAPI Docs"]:::backend
    end

    %% Scheduler Worker Layer
    subgraph "Scheduler Worker"
        direction TB
        CronJob["Cron Scheduler\n(node-cron + Nodemailer)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        direction TB
        MongoDB["MongoDB\n(Mongoose)"]:::db
        subgraph "Models"
            direction TB
            UserModel["User Model"]:::db
            PostModel["Post Model"]:::db
            SubscriberModel["Subscriber Model"]:::db
        end
    end

    %% External Services Layer
    subgraph "External Services"
        direction TB
        OAuthProvider["Google OAuth"]:::external
        SMTP["SMTP Provider\n(Nodemailer)"]:::external
        AnalyticsExt["Third-Party Analytics"]:::external
    end

    %% DevOps Layer
    subgraph "DevOps & CI/CD"
        direction TB
        FE_Docker["Frontend Dockerfile"]:::devops
        BE_Docker["Backend Dockerfile"]:::devops
        Compose["Docker Compose"]:::devops
        CI_CD["CI/CD & Workflows"]:::devops
    end

    %% Connections
    Angular -->|"uses modules"| AuthModule
    Angular --> PostsModule
    Angular --> SubscribersModule
    Angular --> TemplatesModule
    Angular --> AnalyticsModule
    Angular --> Store
    Angular --> Interceptor

    Angular -->|REST/GraphQL| API
    AuthModule -->|dispatch actions| Store
    PostsModule -->|dispatch actions| Store

    API -->|uses routes| AuthRoutes
    API --> PostRoutes
    API --> SubscriberRoutes
    AuthRoutes --> AuthController
    PostRoutes --> PostController
    SubscriberRoutes --> SubscriberController

    API -->|serves| GraphQL
    API -->|serves| OpenAPI
    API --> JWTMiddleware
    API --> OAuthStrategy

    API -->|reads/writes| MongoDB
    AuthController --> MongoDB
    PostController --> MongoDB
    SubscriberController --> MongoDB
    GraphQL --> MongoDB

    CronJob -->|invokes| API
    CronJob --> MongoDB
    CronJob --> SMTP

    API --> OAuthProvider
    Angular --> AnalyticsExt

    FE_Docker --> Angular
    BE_Docker --> API
    Compose --> FE_Docker
    Compose --> BE_Docker
    Compose --> MongoDB
    Compose --> CronJob

    CI_CD --> FE_Docker
    CI_CD --> BE_Docker

    %% Click Events
    click Angular "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetterCreatorApp/src"
    click AuthModule "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetterCreatorApp/src/app/auth"
    click PostsModule "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetterCreatorApp/src/app/components/posts"
    click SubscribersModule "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetterCreatorApp/src/app/components/subscribers"
    click TemplatesModule "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetterCreatorApp/src/app/components/templates"
    click AnalyticsModule "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetterCreatorApp/src/app/components/analytics"
    click Store "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetterCreatorApp/src/app/store"
    click Interceptor "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetterCreatorApp/src/app/interceptors/auth.interceptor.ts"
    click Cypress "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetterCreatorApp/cypress"
    click Jest "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetterCreatorApp/jest.config.ts"
    click Jest "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetterCreatorApp/src/test"
    click API "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/server.js"
    click AuthRoutes "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/routes/auth.routes.js"
    click PostRoutes "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/routes/post.routes.js"
    click SubscriberRoutes "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/routes/subscriber.routes.js"
    click AuthController "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/controllers/auth.controller.js"
    click PostController "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/controllers/post.controller.js"
    click SubscriberController "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/controllers/subscriber.controller.js"
    click GraphQL "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/graphql/schema.graphql"
    click GraphQL "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/graphql/resolvers.js"
    click GraphQL "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/graphql/index.js"
    click JWTMiddleware "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/middlewares/auth.middleware.js"
    click OAuthStrategy "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/config/passport.js"
    click CronJob "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/cron.js"
    click UserModel "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/models/user.model.js"
    click PostModel "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/models/post.model.js"
    click SubscriberModel "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/models/subscriber.model.js"
    click MongoDB "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/config/db.js"
    click OpenAPI "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/newsLetter-backend/docs/openapi.yaml"
    click BE_Docker "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetter-backend/Dockerfile"
    click FE_Docker "https://github.com/shaukinkhan477/newsletter-creator-app/tree/main/newsLetterCreatorApp/Dockerfile"
    click Compose "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/docker-compose.yml"
    click CI_CD "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/.github/workflows/ci-cd.yml"
    click CI_CD "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/.github/workflows/eslint.yml"
    click CI_CD "https://github.com/shaukinkhan477/newsletter-creator-app/blob/main/.github/workflows/sonarqube.yml"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#DFFFE0,stroke:#28a745,color:#28a745;
    classDef db fill:#FFF4E5,stroke:#FF8C00,color:#FF8C00;
    classDef external fill:#F0E0FF,stroke:#6f42c1,color:#6f42c1;
    classDef devops fill:#E8E8E8,stroke:#444,color:#444;
```
