# adrianhajdin/subscription-tracker-api architecture

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

- Interactive diagram: https://gitdiagram.com/adrianhajdin/subscription-tracker-api
- Repository: https://github.com/adrianhajdin/subscription-tracker-api

## Overview

##### Main Components
- API Entry Point: Represent the main server file (app.js), which initializes the Express server.
- Configuration Layer: Include the config directory that contains files for environment setup and integration with external services (Arcjet for security/rate limiting, nodemailer for email handling, Upstash for workflow automation).
- Controllers: Outline controllers (auth.controller.js, user.controller.js, subscription.controller.js, workflow.controller.js) that handle incoming business logic.
- Routes: Map out the routes directory where route files demonstrate how endpoints (for authentication, subscription, user, workflow) direct requests to their corresponding controllers.
- Middlewares: Highlight custom middleware (e.g., auth, error handling, Arcjet middleware) which process requests before reaching controllers.
- Models and Database: Illustrate the models (subscription.model.js, user.model.js) along with the database connection file (mongodb.js), emphasizing the interaction with MongoDB via Mongoose.
- Utilities: Mark out the utils directory (email-template.js, send-email.js) which encapsulate shared helper functions, such as building email content or sending emails.

##### Relationships and Interactions
- Incoming HTTP requests first hit the Express server (API Entry Point) and follow the chain via routes that direct them to the appropriate controllers.
- Controllers process the request with business logic and often interact with models to query or update the database.
- Middleware components are interwoven in this chain (e.g., authentication and error handling), ensuring proper security, validation, and centralized error responses.
- External integration points with Arcjet (for rate limiting/bot protection), Upstash (for workflow/email reminders), and Nodemailer (for sending emails) should be depicted as auxiliary services connected to the main API flow.

##### Architectural Patterns and Technologies
- The separation into controllers, routes, and middlewares reflects a common MVC-like structure for an API.
- The project enforces security and scalability by isolating configuration for third-party integrations and error handling.
- Technologies like Node.js, Express.js, and MongoDB are central to the API’s functionality.
- Integration with tools like Arcjet and Upstash is important in terms of extended capabilities (advanced rate limiting, email automation).

## Diagram (Mermaid)

```mermaid
graph TD
    Client("Client"):::core
    API("API Entry (app.js)"):::core
    Client --> API

    subgraph "Middlewares"
        mw_arcjet("Arcjet Middleware (arcjet.middleware.js)"):::middleware
        mw_auth("Auth Middleware (auth.middleware.js)"):::middleware
        mw_error("Error Middleware (error.middleware.js)"):::middleware
        mw_arcjet --> mw_auth
        mw_auth --> mw_error
    end
    API --> mw_arcjet

    subgraph "Routes"
        route_auth("Auth Routes (auth.routes.js)"):::route
        route_subscription("Subscription Routes (subscription.routes.js)"):::route
        route_user("User Routes (user.routes.js)"):::route
        route_workflow("Workflow Routes (workflow.routes.js)"):::route
        route_auth --> route_subscription
        route_subscription --> route_user
        route_user --> route_workflow
    end
    mw_error --> route_auth

    subgraph "Controllers"
        ctrl_auth("Auth Controller (auth.controller.js)"):::controller
        ctrl_subscription("Subscription Controller (subscription.controller.js)"):::controller
        ctrl_user("User Controller (user.controller.js)"):::controller
        ctrl_workflow("Workflow Controller (workflow.controller.js)"):::controller
        ctrl_auth --> ctrl_subscription
        ctrl_subscription --> ctrl_user
        ctrl_user --> ctrl_workflow
    end
    route_workflow --> ctrl_auth

    subgraph "Models & Database"
        model_subscription("Subscription Model (subscription.model.js)"):::model
        model_user("User Model (user.model.js)"):::model
        db_mongodb("MongoDB Connection (mongodb.js)"):::model
        model_subscription --> model_user
        model_user --> db_mongodb
    end
    ctrl_workflow --> model_subscription

    subgraph "Configuration"
        config_arcjet("Arcjet Config (arcjet.js)"):::config
        config_env("Env Config (env.js)"):::config
        config_nodemailer("Nodemailer Config (nodemailer.js)"):::config
        config_upstash("Upstash Config (upstash.js)"):::config
        config_arcjet --> config_env
        config_env --> config_nodemailer
        config_nodemailer --> config_upstash
    end
    ctrl_auth --> config_arcjet
    ctrl_subscription --> config_nodemailer
    ctrl_workflow --> config_upstash

    subgraph "Utilities"
        util_email_template("Email Template Utility (email-template.js)"):::utility
        util_send_email("Send Email Utility (send-email.js)"):::utility
        util_email_template --> util_send_email
    end
    ctrl_auth --> util_email_template

    %% Click Events
    click API "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/app.js"
    click config_arcjet "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/config/arcjet.js"
    click config_env "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/config/env.js"
    click config_nodemailer "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/config/nodemailer.js"
    click config_upstash "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/config/upstash.js"
    click ctrl_auth "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/controllers/auth.controller.js"
    click ctrl_subscription "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/controllers/subscription.controller.js"
    click ctrl_user "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/controllers/user.controller.js"
    click ctrl_workflow "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/controllers/workflow.controller.js"
    click route_auth "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/routes/auth.routes.js"
    click route_subscription "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/routes/subscription.routes.js"
    click route_user "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/routes/user.routes.js"
    click route_workflow "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/routes/workflow.routes.js"
    click mw_arcjet "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/middlewares/arcjet.middleware.js"
    click mw_auth "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/middlewares/auth.middleware.js"
    click mw_error "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/middlewares/error.middleware.js"
    click model_subscription "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/models/subscription.model.js"
    click model_user "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/models/user.model.js"
    click db_mongodb "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/database/mongodb.js"
    click util_email_template "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/utils/email-template.js"
    click util_send_email "https://github.com/adrianhajdin/subscription-tracker-api/blob/main/utils/send-email.js"

    %% Styles
    classDef core fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef config fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef middleware fill:#ffb6c1,stroke:#000,stroke-width:2px;
    classDef route fill:#fdfd96,stroke:#000,stroke-width:2px;
    classDef controller fill:#ffdead,stroke:#000,stroke-width:2px;
    classDef model fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef utility fill:#ffa500,stroke:#000,stroke-width:2px;

    class Client,API core;
    class config_arcjet,config_env,config_nodemailer,config_upstash config;
    class mw_arcjet,mw_auth,mw_error middleware;
    class route_auth,route_subscription,route_user,route_workflow route;
    class ctrl_auth,ctrl_subscription,ctrl_user,ctrl_workflow controller;
    class model_subscription,model_user,db_mongodb model;
    class util_email_template,util_send_email utility;
```
