# lalithsha/post-wizards architecture

> Architecture diagram of the GitHub repository lalithsha/post-wizards, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lalithsha/post-wizards
- Repository: https://github.com/lalithsha/post-wizards

## Overview

##### Project Type and Purpose
- This is a full-stack Next.js 13 application, using the App Router for both server-rendered and client-rendered pages.
- It implements authentication flows (sign-in, sign-up), a landing page, user dashboards, and saved-items views.
- It exposes two serverless API routes—`/api/generator` and `/api/posts`—and uses MongoDB as its data store.

##### File Structure
- src/app: App-router folders for auth (`(auth)`), landing (`(landingPage)`), dashboard, and saved views.
- src/components & src/components/ui: React UI components (Navbar, Sidebar, buttons, forms, etc.).
- src/contexts: React Context (DashboardContext) for client-side state.
- src/lib: `mongodb.js` handles DB connections, `utils.js` holds shared helper functions.
- src/models: Mongoose/Post model for the `posts` collection.
- src/utils: encryption and keys utilities, likely for token handling.
- middleware.ts: Global middleware (authentication guard, routing logic).
- Configuration: next.config.js, Tailwind, ESLint, PostCSS, jsconfig.json.

##### Core Architectural Components
a. Frontend (Next.js React App)
- Page layouts & nested routing (landing page, auth, dashboard, saved).
- UI components folder.
- React Context for client state sharing.
b. Backend / Serverless API
- `/api/generator/route.js`: Handles text/image generation requests.
- `/api/posts/route.js`: CRUD operations for posts.
- `middleware.ts`: Pre-request logic (auth checks, redirects).
c. Data Layer
- MongoDB Atlas (or self-hosted) cluster.
- `lib/mongodb.js`: Connection pooling.
- `models/post.js`: Schema definitions.
d. Utilities & Security
- Encryption utilities (src/utils/encryption.js) for sensitive data.
- Key management (src/utils/keys.js).
e. Deployment
- Vercel (serverless functions for API routes, automatic builds).
- Tailwind & PostCSS for styling pipeline.

##### Architectural Patterns
- File-based routing → map folders to route handlers.
- SSR & SSG (Next.js rendering strategies).
- Serverless functions for API layer.
- React Context for cross-page state.
- Separation of concerns: UI vs. data-access vs. middleware.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Browser["Web Browser / Client"]:::external

    %% Next.js App Server
    subgraph "Next.js App Server"
        direction TB

        %% Middleware Layer
        Middleware["Global Middleware (Auth Guard)"]:::util

        %% App Router
        subgraph "App Router (Routes & Layouts)" 
            direction TB
            RootLayout["Root Layout & Globals"]:::frontend
            Landing["Landing Page"]:::frontend
            AuthSignIn["Sign-In Route"]:::frontend
            AuthSignUp["Sign-Up Route"]:::frontend
            Dashboard["Dashboard Pages"]:::frontend
            Saved["Saved Items Pages"]:::frontend
        end

        %% React Context
        ReactContext["DashboardContext (Client State)"]:::frontend

        %% UI Components
        subgraph "UI Components"
            direction TB
            Button["Button"]:::frontend
            Form["Form"]:::frontend
            Input["Input"]:::frontend
            Label["Label"]:::frontend
            Sheet["Sheet"]:::frontend
            Textarea["Textarea"]:::frontend
            Navbar["Navbar"]:::frontend
            Sidebar["Sidebar"]:::frontend
            NewSidebar["New Sidebar"]:::frontend
            MobileSidebar["Mobile Sidebar"]:::frontend
            LandingNavbar["Landing Navbar"]:::frontend
            LandingHero["Landing Hero"]:::frontend
        end

        %% Serverless API
        subgraph "Serverless Functions (API Routes)"
            direction TB
            GeneratorAPI["Generator API"]:::backend
            PostsAPI["Posts API"]:::backend
        end

        %% Data Layer Utilities & Models
        subgraph "Lib & Models"
            direction TB
            MongoConn["MongoDB Connection Utility"]:::util
            UtilsLib["Shared Utility Functions"]:::util
            PostModel["Mongoose Post Model"]:::util
        end

        %% Security Utilities
        subgraph "Utilities & Security"
            direction TB
            Encryption["Encryption Utilities"]:::util
            Keys["Key Management Utilities"]:::util
        end

        %% Configuration
        subgraph "Configuration Files"
            direction TB
            NextConfig["next.config.js"]:::util
            TailwindConfig["tailwind.config.js"]:::util
            PostcssConfig["postcss.config.js"]:::util
            JsConfig["jsconfig.json"]:::util
            ESLintConfig[".eslintrc.json"]:::util
        end
    end

    %% Database
    MongoDB["MongoDB Database"]:::database

    %% Connections
    Browser -->|"page request"| Middleware
    Middleware -->|"auth check"| RootLayout
    RootLayout --> Landing
    RootLayout --> AuthSignIn
    RootLayout --> AuthSignUp
    RootLayout --> Dashboard
    RootLayout --> Saved
    RootLayout -->|loads UI| Navbar
    RootLayout -->|loads UI| LandingNavbar
    Dashboard --> ReactContext
    Saved --> ReactContext

    Landing --> LandingHero
    Landing -->|uses UI| LandingNavbar

    AuthSignIn --> Button
    AuthSignIn --> Form
    AuthSignIn --> Input
    AuthSignIn --> Label

    AuthSignUp --> Button
    AuthSignUp --> Form
    AuthSignUp --> Input
    AuthSignUp --> Label

    Dashboard --> Sidebar
    Saved --> Sidebar
    Sidebar --> MobileSidebar
    NewSidebar -->|optional| Dashboard

    %% API Flow
    LandingHero -->|API call| GeneratorAPI
    Dashboard -->|API call| PostsAPI
    GeneratorAPI --> MongoConn
    PostsAPI --> MongoConn
    MongoConn --> MongoDB

    %% Middle ware on API
    GeneratorAPI -->|auth guard| Middleware
    PostsAPI -->|auth guard| Middleware

    %% Lib and utils usage
    GeneratorAPI --> UtilsLib
    PostsAPI --> UtilsLib
    PostsAPI --> PostModel

    Encryption --> GeneratorAPI
    Encryption --> PostsAPI
    Keys --> GeneratorAPI
    Keys --> PostsAPI

    %% Styles and config pipeline
    TailwindConfig --> RootLayout
    PostcssConfig --> RootLayout
    JsConfig --> RootLayout
    ESLintConfig --> RootLayout

    %% Click Events
    click RootLayout "https://github.com/lalithsha/post-wizards/blob/main/src/app/layout.js"
    click Landing "https://github.com/lalithsha/post-wizards/blob/main/src/app/(landingPage)/page.js"
    click AuthSignIn "https://github.com/lalithsha/post-wizards/blob/main/src/app/(auth)/(routes)/sign-in/[[...sign-in]]/page.jsx"
    click AuthSignUp "https://github.com/lalithsha/post-wizards/blob/main/src/app/(auth)/(routes)/sign-up/[[...sign-up]]/page.jsx"
    click Dashboard "https://github.com/lalithsha/post-wizards/blob/main/src/app/dashboard/[userid]/page.jsx"
    click Saved "https://github.com/lalithsha/post-wizards/blob/main/src/app/saved/[userid]/page.jsx"
    click GeneratorAPI "https://github.com/lalithsha/post-wizards/blob/main/src/app/api/generator/route.js"
    click PostsAPI "https://github.com/lalithsha/post-wizards/blob/main/src/app/api/posts/route.js"
    click Middleware "https://github.com/lalithsha/post-wizards/blob/main/middleware.ts"
    click MongoConn "https://github.com/lalithsha/post-wizards/blob/main/src/lib/mongodb.js"
    click UtilsLib "https://github.com/lalithsha/post-wizards/blob/main/src/lib/utils.js"
    click PostModel "https://github.com/lalithsha/post-wizards/blob/main/src/models/post.js"
    click Encryption "https://github.com/lalithsha/post-wizards/blob/main/src/utils/encryption.js"
    click Keys "https://github.com/lalithsha/post-wizards/blob/main/src/utils/keys.js"
    click ReactContext "https://github.com/lalithsha/post-wizards/blob/main/src/contexts/DashboardContext.jsx"
    click Button "https://github.com/lalithsha/post-wizards/blob/main/src/components/ui/button.jsx"
    click Form "https://github.com/lalithsha/post-wizards/blob/main/src/components/ui/form.jsx"
    click Input "https://github.com/lalithsha/post-wizards/blob/main/src/components/ui/input.jsx"
    click Label "https://github.com/lalithsha/post-wizards/blob/main/src/components/ui/label.jsx"
    click Sheet "https://github.com/lalithsha/post-wizards/blob/main/src/components/ui/sheet.jsx"
    click Textarea "https://github.com/lalithsha/post-wizards/blob/main/src/components/ui/textarea.jsx"
    click Navbar "https://github.com/lalithsha/post-wizards/blob/main/src/components/Navbar.jsx"
    click Sidebar "https://github.com/lalithsha/post-wizards/blob/main/src/components/sidebar.jsx"
    click NewSidebar "https://github.com/lalithsha/post-wizards/blob/main/src/components/newsidebar.jsx"
    click MobileSidebar "https://github.com/lalithsha/post-wizards/blob/main/src/components/Mobile-sidebar.jsx"
    click LandingNavbar "https://github.com/lalithsha/post-wizards/blob/main/src/components/landing-navbar.jsx"
    click LandingHero "https://github.com/lalithsha/post-wizards/blob/main/src/components/landing-hero.jsx"
    click NextConfig "https://github.com/lalithsha/post-wizards/blob/main/next.config.js"
    click TailwindConfig "https://github.com/lalithsha/post-wizards/blob/main/tailwind.config.js"
    click PostcssConfig "https://github.com/lalithsha/post-wizards/blob/main/postcss.config.js"
    click JsConfig "https://github.com/lalithsha/post-wizards/blob/main/jsconfig.json"
    click ESLintConfig "https://github.com/lalithsha/post-wizards/blob/main/.eslintrc.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef backend fill:#D0F0D8,stroke:#028a0f,color:#028a0f
    classDef database fill:#FFE5B4,stroke:#e07a00,color:#e07a00
    classDef util fill:#F0F0F0,stroke:#666666,color:#333333
    classDef external fill:#F5E8FF,stroke:#872dc6,color:#872dc6
```
