Skip to content

monsterxwx/synap

Repository files navigation

๐Ÿง  AI Synap SaaS

English | ็ฎ€ไฝ“ไธญๆ–‡

Project Banner

๐Ÿง  AI Synap SaaS - Next-Gen Thinking Tool

Next.js TypeScript Tailwind CSS

DeepSeek Lemon Squeezy

Supabase

License Deploy

A production-ready, AI-powered mind mapping platform built with Next.js 15, DeepSeek, and ReactFlow.

Benchmarking industry leaders like Mapify, featuring real-time streaming generation, infinite node expansion, and a complete commercialization loop.

Project Banner

Project Banner

โœจ Project Overview

This project is a full-stack AI SaaS application that transforms unstructured text, PDFs, and Word documents into structured, interactive mind maps instantly.

Unlike simple wrappers, this project implements a highly customized streaming graph engine that renders nodes in real-time as the AI "thinks", solving complex layout stability issues. It includes a robust credit-based monetization system integrated with Lemon Squeezy and Supabase, supporting tiered subscriptions (Free/Pro/Unlimited).

๐Ÿ’ณ ็‚นๅ‡ปๆŸฅ็œ‹ๆต‹่ฏ•ไฟก็”จๅกไฟกๆฏ (Test Cards for Lemon Squeezy)

๐Ÿ’ณ Payment Testing Instructions:

  • This project is currently in Lemon Squeezy Test Mode (Sandbox).
  • Please DO NOT use a real credit card.
  • Test Card Number: 4242 4242 4242 4242
  • Expiration Date: Any future date (e.g., 12/30)
  • CVC: Any 3 digits (e.g., 123)

๐Ÿš€ Key Features

๐ŸŽจ Core Experience

  • Stream-to-Graph Rendering: Utilizes Vercel AI SDK + useObject to render nodes incrementally without canvas flickering.
  • Infinite AI Expansion: Users can click any node to recursively generate child nodes, enabling limitless brainstorming sessions.
  • Smart Layout Engine: Custom DAGRE-based algorithm with dynamic width/height calculation based on text content.
  • Multi-Modal Input: Supports direct text input and file parsing (PDF/DOCX/TXT up to 10MB) via pdf2json and mammoth.

๐Ÿ’ฐ Commercialization & SaaS Features

  • Tiered Subscription System:
    • Basic: Free trial, limited credits, watermarked exports.
    • Pro: High limits, HD export, infinite expansion.
    • Unlimited: Uncapped usage for power users.
  • Dynamic Credit System: "Pay-as-you-go" logic based on input character count (fair usage policy), securing API costs.
  • Secure Payments: Full Lemon Squeezy integration (Checkout & Webhooks) with automated credit top-ups and monthly resets.
  • Real-time UI Sync: UI updates instantly upon payment or usage via Supabase Realtime subscriptions and custom Event dispatchers.

๐Ÿ› ๏ธ User Interface

  • High-Performance Canvas: Built on @xyflow/react (ReactFlow v12), capable of handling hundreds of nodes.
  • Export Options: HD PNG download with dynamic watermarking logic for free users.
  • Responsive Design: Mobile-friendly sidebar, pricing modals, and interactive controls using Shadcn/UI.

๐Ÿ—๏ธ Tech Stack

Category Technologies
Framework Next.js 15 (App Router), TypeScript, React 19
Styling Tailwind CSS, Shadcn/UI, Lucide React, Framer Motion
AI & LLM DeepSeek V3 API, Vercel AI SDK (@ai-sdk/react)
Visualization ReactFlow v12, Dagre (Graph Layout), html-to-image
Backend & Auth Supabase (PostgreSQL, Auth, Realtime), Edge Functions
Payments Lemon Squeezy API, Lemon Squeezy Webhooks
File Processing pdf2json, mammoth.js

๐Ÿ’ก Technical Highlights & Challenges Solved

1. DeepSeek JSON Mode Compatibility

Challenge: The upstream API had strict mode incompatibilities with standard SDKs, leading to JSON parsing errors during streaming. Solution: Implemented a custom fetch interceptor layer that forcibly injects JSON schemas and system prompts, ensuring 100% valid JSON output for the graph parser.

// Code Snippet: Custom Interceptor
const deepseek = createOpenAI({
  // ...
  fetch: async (url, options) => {
    // Inject JSON instructions to system prompt dynamically
    // Force response_format to json_object
    // ...
  }
});

2. State Management for Infinite Expansion

Challenge: Accessing the latest user subscription tier inside the ReactFlow closure (hooks) was causing "stale state" issues (e.g., users upgraded to Pro but still got blocked). Solution: Utilized useRef + useEffect synchronization pattern within custom hooks to ensure the expansion logic always accesses the real-time userTier status without unnecessary re-renders.

3. Dynamic & Fair Billing Logic

Challenge: Charging a fixed rate for variable input sizes (e.g., 1 sentence vs. 10MB PDF) is unfair and risky. Solution: Designed a pre-generation calculation algorithm: Cost = Base Fee + (CharCount / 500). The frontend estimates cost for UX, while the backend strictly enforces the deduction before API calls to prevent abuse.

4. Real-time Credit Synchronization

Challenge: Updating the UI immediately after a background webhook event (payment success) or an AI generation. Solution: Implemented a "Double Insurance" strategy:

  1. Supabase Realtime: Subscribes to database changes for cross-device sync.
  2. Custom Events: window.dispatchEvent('user:refresh-credits') for instant client-side feedback after actions.

๐Ÿ—„๏ธ Database Schema (Supabase)

The project uses a robust PostgreSQL schema handling users and subscriptions:

  • profiles: Stores credits, tier ('basic'/'pro'/'unlimited'), Lemon Squeezy IDs, billing cycles, and last reset dates.
  • mind_maps: Stores the JSON structure of graphs, linked to users for history retrieval.
  • Auth Triggers: Automatically initializes user profiles with default credits upon registration.

๐Ÿš€ Getting Started

  1. Clone the repository

    git clone https://github.com/monsterxwx/synap.git
  2. Install dependencies

    npm install
    # or
    pnpm install
  3. Environment Setup Create a .env.local file with the following keys:

    DEEPSEEK_API_KEY=
    NEXT_PUBLIC_SUPABASE_URL=
    NEXT_PUBLIC_SUPABASE_ANON_KEY=
    NEXT_PUBLIC_APP_URL=http://localhost:3000
    SUPABASE_SERVICE_ROLE_KEY=
    LEMONSQUEEZY_API_KEY=
    LEMONSQUEEZY_STORE_ID=263875
    LEMONSQUEEZY_WEBHOOK_SECRET=secret-synap-888
    NEXT_PUBLIC_VARIANT_PRO_MONTHLY=
    NEXT_PUBLIC_VARIANT_UNLIMITED_MONTHLY=
    NEXT_PUBLIC_VARIANT_PRO_YEARLY=
    NEXT_PUBLIC_VARIANT_UNLIMITED_YEARLY=
    
  4. Run the development server

    npm run dev

๐Ÿค Contact & Hire Me

I am a Full-Stack Developer specializing in building complex, AI-driven web applications. I have extensive experience in:

  • Next.js / React Ecosystem
  • LLM Integration (DeepSeek, OpenAI, Claude)
  • SaaS Architecture & Payment Integration

If you are looking for a developer to build your next MVP or scale your product, feel free to reach out.


About

A production-ready, AI-powered mind mapping platform built with Next.js 15, DeepSeek, and ReactFlow.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published