# faridun90/dream-int architecture

> Architecture diagram of the GitHub repository faridun90/dream-int, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/faridun90/dream-int
- Repository: https://github.com/faridun90/dream-int

## Overview

##### Main Components
a. Next.js Frontend:
- Client-side views and pages: Include the “app” folder routes such as the homepage (app/page.tsx), authentication pages (app/(auth)/sign-in, app/(auth)/sign-up), and dashboard pages (app/(dashboard)/admin).
- Layouts: Show components like “app/layout.tsx” and specialized route layouts (app/(auth)/layout.tsx).
b. API Layer:
- API Routes: Represent endpoints under app/api (e.g., authentication with nextauth, dream, user, and onboarding routes). Indicate that these routes serve as the entry points for backend logic.
c. Components & UI Library:
- Present the reusable UI components (components/ folder, including form components and UI elements) that encapsulate the presentation logic.
d. Database & ORM:
- Prisma Component: Include the prisma folder, schema (prisma/schema.prisma), migration history (prisma/migrations), and seed file (prisma/seed.ts). This part is key to showing how data is modeled and persisted.
e. Authentication & Middleware:
- Libraries and utilities for authentication (lib/auth.ts and types/next-auth.d.ts) and middleware (middleware.ts) which control access and request handling.
f. External services and background processing:
- BullMQ Service: Indicate external message queue processing with services/bullmqService.ts.
- Worker process: Show the “workers/worker.js” as handling background tasks.
- Redis: Represent usage via utils/redis.js (likely part of caching or session management).

##### Relationships and Interactions
- Client-side Views (pages/components) communicate with API endpoints (via HTTP requests or Next.js server-side functions).
- API Routes interact with the database through Prisma.
- Authentication modules (both UI forms and API endpoints) integrate using NextAuth (and related configurations in the app/api/auth folder).
- Middleware sits between client requests and rendering/API responses, enforcing logic like access control.
- The BullMQ service and associated worker are designed to process background jobs (e.g., asynchronous tasks) and likely interact with a message queue (and probably Redis).
- Directional data flow: user actions → frontend pages → API endpoints → Database/External Services, while acknowledging background processing flows.

##### Architectural Patterns and Design Principles
- Emphasis on separation of concerns: Different directories host distinct layers/features (routing in app, API endpoints in app/api, view components in components, and business logic in lib and services).
- Next.js routing and layout system based on file-system routing.
- Use of middleware for tasks such as authentication and request handling.
- Modular design with components promoting reuse and separation between presentation and logic.

##### Relevant Technologies and Frameworks
- Next.js for the full-stack application infrastructure.
- Prisma ORM for database management.
- NextAuth (implied within app/api/auth) for authentication workflows.
- BullMQ and likely Redis (via utils/redis.js) for background job processing and caching.
- Tailwind CSS (indicated by tailwind.config.ts) for styling.
- TypeScript (evidenced by tsconfig.json, .ts/js files) ensuring static typing throughout the project.

##### Specific Elements
- Use clear labels for every component (e.g., “Next.js Pages”, “API Routes”, “Prisma Database”, “Authentication Middleware”, “BullMQ Service & Worker”).

##### Final Assembly
- API layer to the “Database Layer” (Prisma ORM and associated migrations).
- Additionally, insert the “Middleware/Authentication” component between the Frontend and API if applicable to show security gating.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level user
    User["User Browser"]:::external

    %% Frontend Layer
    subgraph "Frontend Layer"
        nodeHome["Homepage (app/page.tsx)"]:::frontend
        nodeLayout["Layout (app/layout.tsx)"]:::frontend
        nodeAuthLayout["Auth Layout (app/(auth)/layout.tsx)"]:::frontend
        nodeSignIn["Sign-In Page (app/(auth)/sign-in/page.tsx)"]:::frontend
        nodeSignUp["Sign-Up Page (app/(auth)/sign-up/page.tsx)"]:::frontend
        nodeDashboard["Dashboard (app/(dashboard)/admin/page.tsx)"]:::frontend
        nodeOnboarding["Onboarding (app/onboarding/page.tsx)"]:::frontend
        nodeComponents["UI Components (components)"]:::ui
    end

    %% Authentication & Middleware
    middleware["Auth & Middleware (lib/auth.ts,types/next-auth.d.ts,middleware.ts)"]:::auth

    %% API Layer
    subgraph "API Layer"
        apiBase["API Base (app/api/route.ts)"]:::api
        apiAuth["API Auth (app/api/auth/[...nextauth]/route.ts)"]:::api
        apiDream["Dream API (app/api/dream/route.ts)"]:::api
        apiUser["User API (app/api/user/route.ts)"]:::api
        apiUserOnboard["User Onboard API (app/api/user/onboard/route.ts)"]:::api
    end

    %% Database Layer
    subgraph "Database Layer"
        prismaDB["Prisma Database (prisma/schema.prisma,migrations,seed.ts)"]:::db
    end

    %% Background Processing
    subgraph "Background Processing"
        bullmq["BullMQ Service (services/bullmqService.ts)"]:::background
        worker["Worker Process (workers/worker.js)"]:::background
        redis["Redis (utils/redis.js)"]:::background
    end

    %% Connections
    User -->|"navigates"| nodeHome
    nodeHome -->|"triggers"| middleware
    nodeSignIn -->|"login action"| middleware
    middleware -->|"routes to"| apiBase

    apiBase -->|"calls"| apiAuth
    apiBase -->|"calls"| apiDream
    apiBase -->|"calls"| apiUser
    apiBase -->|"calls"| apiUserOnboard
    apiBase -->|"queries"| prismaDB
    apiBase -->|"triggers"| bullmq
    bullmq -->|"processes"| worker
    bullmq -->|"checks"| redis

    %% UI Components linked to pages (non-critical dependency)
    nodeComponents -.-> nodeHome
    nodeComponents -.-> nodeSignIn
    nodeComponents -.-> nodeSignUp
    nodeComponents -.-> nodeDashboard

    %% Click Events for Next.js Frontend components
    click nodeHome "https://github.com/faridun90/dream-int/blob/main/app/page.tsx"
    click nodeLayout "https://github.com/faridun90/dream-int/blob/main/app/layout.tsx"
    click nodeAuthLayout "https://github.com/faridun90/dream-int/blob/main/app/(auth)/layout.tsx"
    click nodeSignIn "https://github.com/faridun90/dream-int/blob/main/app/(auth)/sign-in/page.tsx"
    click nodeSignUp "https://github.com/faridun90/dream-int/blob/main/app/(auth)/sign-up/page.tsx"
    click nodeDashboard "https://github.com/faridun90/dream-int/blob/main/app/(dashboard)/admin/page.tsx"
    click nodeOnboarding "https://github.com/faridun90/dream-int/blob/main/app/onboarding/page.tsx"
    click nodeComponents "https://github.com/faridun90/dream-int/tree/main/components"

    %% Click Events for API Layer components
    click apiBase "https://github.com/faridun90/dream-int/blob/main/app/api/route.ts"
    click apiAuth "https://github.com/faridun90/dream-int/blob/main/app/api/auth/[...nextauth]/route.ts"
    click apiDream "https://github.com/faridun90/dream-int/blob/main/app/api/dream/route.ts"
    click apiUser "https://github.com/faridun90/dream-int/blob/main/app/api/user/route.ts"
    click apiUserOnboard "https://github.com/faridun90/dream-int/blob/main/app/api/user/onboard/route.ts"

    %% Click Events for Database & ORM
    click prismaDB "https://github.com/faridun90/dream-int/blob/main/prisma/schema.prisma"

    %% Click Events for Authentication & Middleware
    click middleware "https://github.com/faridun90/dream-int/blob/main/lib/auth.ts"

    %% Click Events for Background Processing components
    click bullmq "https://github.com/faridun90/dream-int/blob/main/services/bullmqService.ts"
    click worker "https://github.com/faridun90/dream-int/blob/main/workers/worker.js"
    click redis "https://github.com/faridun90/dream-int/blob/main/utils/redis.js"

    %% Styles
    classDef frontend fill:#d4f5d4,stroke:#333,stroke-width:2px;
    classDef api fill:#ffecb3,stroke:#333,stroke-width:2px;
    classDef auth fill:#f5d4d4,stroke:#333,stroke-width:2px;
    classDef db fill:#d4d4f5,stroke:#333,stroke-width:2px;
    classDef background fill:#e0f7fa,stroke:#333,stroke-width:2px;
    classDef ui fill:#ffe0f0,stroke:#333,stroke-width:2px;
    classDef external fill:#fff0b3,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
```
