# tiny-factories/tiny-garden-discord architecture

> Architecture diagram of the GitHub repository tiny-factories/tiny-garden-discord, 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/tiny-factories/tiny-garden-discord
- Repository: https://github.com/tiny-factories/tiny-garden-discord

## Overview

##### Project type and purpose
- This is a full-stack web application built with Next.js on the frontend and Node.js API routes on the backend, persisting data in MongoDB.
- Purpose: user-driven blogging/CMS platform (“Tiny Garden”) with user registration, authentication (email verification, password reset), post creation, narrative sections, and import capabilities.

##### File structure
- Top-level “pages” directory implements:
- UI routes: pages/*.jsx (e.g., index.jsx, edit.jsx, login.jsx)
- API routes: pages/api/* (auth.js, posts/index.js, user/password/reset.js, etc.)
- “components” directory houses reusable React components (footer, layout, post editors, narrative editors)
- “db” directory encapsulates MongoDB connection and data-access objects (db/index.js, post.js, user.js, token.js)
- “lib” holds helper utilities (API helpers, fetch wrapper, mail sender, default config)
- “middlewares” layer for session management, Passport authentication, database connection, general request handling
- “hooks” for client-side React hooks (user context, etc.)
- Config files: next.config.js, jsconfig.json, .eslintrc, .gitignore, schema JSON files

##### README for additional insights
- Confirms Next.js + MongoDB foundation
- Mentions planned extensions (rich-text editor, wildcard domains) but current core is Next.js SSR/SSG pages + REST-style API + MongoDB

## Diagram (Mermaid)

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

    %% Next.js Server
    subgraph "Next.js Server"
        direction TB
        Pages["UI Routes (pages/*.jsx)"]:::ui
        Hooks["React Hooks (hooks/*.js)"]:::util
        API["API Routes (pages/api/*)"]:::api
        Middleware["Middleware Layer (middlewares/*)"]:::middleware
        Lib["Utilities/Lib (lib/*)"]:::util
    end

    %% Database and External Service
    MongoDB(("MongoDB")):::db
    EmailService["Email Service (SMTP/SendGrid)"]:::external

    %% Data Flows
    Browser -->|"1. Page Requests (HTTP/HTTPS)"| Pages
    Pages -->|"uses hooks for data"| Hooks
    Hooks -->|"fetch via HTTP/HTTPS"| API
    Browser -->|"2. AJAX / Fetch Calls"| API

    API -->|"3. Pass through"| Middleware
    Middleware -->|"4. CRUD Operations"| MongoDB

    API -->|"5. sendEmail() via lib/mail"| Lib
    Lib -->|"SMTP/Webhooks"| EmailService

    %% Click Events
    click Pages "https://github.com/tiny-factories/tiny-garden-discord/tree/main/pages/"
    click API "https://github.com/tiny-factories/tiny-garden-discord/tree/main/pages/api/"
    click Middleware "https://github.com/tiny-factories/tiny-garden-discord/tree/main/middlewares/"
    click Lib "https://github.com/tiny-factories/tiny-garden-discord/tree/main/lib/"
    click MongoDB "https://github.com/tiny-factories/tiny-garden-discord/tree/main/db/"
    click Hooks "https://github.com/tiny-factories/tiny-garden-discord/tree/main/hooks/"

    %% Styles
    classDef ui fill:#D0E6FF,stroke:#0366d6,stroke-width:2px
    classDef api fill:#DFFFE0,stroke:#228B22,stroke-width:2px
    classDef middleware fill:#FFEFD5,stroke:#FF8C00,stroke-width:2px
    classDef db fill:#FFF5BA,stroke:#DAA520,stroke-width:2px
    classDef external fill:#E0F7FF,stroke:#00A3CC,stroke-width:2px
    classDef util fill:#F0F0F0,stroke:#888,stroke-width:2px
```
