How moonixt/kot-space works
Project Type and Purpose
• This is a full-stack Progressive Web App (PWA) built with Next.js and TypeScript.
• It’s a responsive, note-taking application (“Кot-space”) featuring markdown support, tag organization, encrypted storage, user authentication via Supabase, and Stripe integration for payments.
File Structure Analysis
• app/: Next.js 13+ App Router directory holding all page routes, API endpoints, layouts, and global styles.
• app/api/: Serverless functions (chat, Stripe customer portal, Stripe webhook).
• app/[feature]/: Pages for chat, dashboard, notes, editor, authentication (login, signup, reset/update password), settings, pricing, etc.
• components/ under app: UI elements specific to pages (AuthenticatedRoute, CalendarView, ChatAssistant, etc.).
• globals.css, layout.tsx: Global styling and root layout.
• components/: Global UI component library (button, checkbox, dialog, etc.) and i18n providers.
• context/: React Context providers (AuthContext, ThemeContext, MusicPlayerContext).
• lib/: Utility modules (Supabase client, event emitter, subscription checker, encryption helper).
• i18n/: Internationalization setup and locale files.
• forge.config.js, next.config.ts, build configs, ESLint, Tailwind, TypeScript config.
Main System Components
a. Client (Browser/PWA)
• Next.js React components (app pages + UI library)
• Service Worker (public/sw.js) for offline support
• Context Providers (Auth, Theme, MusicPlayer)
• i18n TranslationProvider
• Responsive/adaptive layout (TailwindCSS + custom CSS in globals.css)
b. Next.js Server (Serverless Functions)
• API Routes under app/api:
• /chat → AI-driven chat assistant
• /stripe/customer-portal → Stripe customer portal integration
• /webhook/stripe → Stripe event webhook handler
• Supabase client usage for authentication and database queries
c. Backend Services
• Supabase:
• Auth (sign up, login, password reset)
• Database (notes, tags, metadata)
• Storage (if attachments)
• Stripe (payment processing, subscription management)
• External AI service (if used by chat route)
d. Utilities & Helpers
• lib/utils.ts, lib/encryption.ts: data encryption/decryption before storing notes
• lib/eventEmitter: in-app event handling (e.g., for real-time UI updates)
Component Relationships & Data Flow
• User interacts with the Next.js PWA client →
• Client routes requests to Next.js serverless API endpoints (via fetch/axios) →
• API routes use Supabase SDK to authenticate, read/write note data →
• Stripe API is called from serverless functions for payment operations →
• Stripe sends webhook events → Next.js /api/webhook/stripe updates subscription status in Supabase →
• Client listens for changes (via polling or real-time subscriptions) and updates UI.
Architectural Patterns & Design Principles
• Serverless Functions: All backend logic lives in Next.js API routes.
• Context-Driven State Management: Auth, theme, and music contexts wrap the app for global state.
• i18n: Dynamic locale loading with React context and TranslationProvider.
• PWA: Service worker for offline caching and installability.
• Encryption at Rest: Note content encrypted on the client via Encryption component before sending to Supabase.
• Responsive/Adaptive Layout: TailwindCSS + CSS media queries and utility classes used throughout components.
Final Delivery
• Capturing all serverless routes, contexts, i18n, PWA service worker, and external integrations.