How ronakmaheshwari/second-brain works
Project Type & Purpose
• This is a full-stack web application called “Second Brain,” providing personal knowledge management via a React-based SPA frontend and a Node.js/Express backend.
• The backend uses Prisma to interact with a PostgreSQL database (hosted on NeonDB via Supabase), handles authentication with JWT/Zod, and connects to Supabase Storage for file attachments.
High-Level Components
a. Client Layer
• Browser / Device (Web & Mobile Friendly)
• React SPA (Vite build) using Tailwind CSS and React components under frontend/src/ui and pages under frontend/src/ui/pages.
b. API Layer (Backend)
• Express.js server entry point (backend/src/index.ts)
• Middleware (authentication, request validation in backend/src/middleware.ts)
• Route handlers for:
• /brain (note management)
• /content (CRUD operations + Markdown processing)
• /check (search/tag suggestions)
• /user (signup/signin, JWT issuance)
• Utility modules (backend/src/utils.ts) for shared logic (e.g., full-text search helpers).
c. Data Layer
• Prisma ORM (backend/prisma/schema.prisma)
• Migrations folder with SQL scripts
• PostgreSQL database on NeonDB (via Supabase)
d. Storage & External Services
• Supabase (Authentication, Database, Storage buckets for sync & backups)
• Vercel (frontend hosting)
• Render.com (backend hosting)
Interactions & Data Flow
1. End user interacts with the React SPA in the browser.
2. SPA sends HTTP requests (REST) to Express API endpoints over HTTPS.
3. Express middleware validates JWT/Zod schemas, then routes to the appropriate controller.
4. Controllers invoke Prisma client to read/write in the PostgreSQL database.
5. For file attachments or backups, the backend or frontend directly interfaces with Supabase Storage API.
6. Responses flow back through middleware to the SPA, which renders updated state.
7. Deployment pipelines: frontend pushed to Vercel, backend to Render, with environment variables configured (e.g., SUPABASE_URL, JWT_SECRET).
Architectural Patterns & Principles
• Layered architecture (Presentation → API → Business Logic → Data Access).
• Separation of concerns: UI components vs. API routes vs. data models.
• RESTful services with JWT-based auth and schema validation via Zod.
• Infrastructure as code for database schema via Prisma migrations.
• Third-party integration for BaaS (Supabase for DB, Auth, Storage).