How aditya-sinha1/social-marketing-saas works
Purpose and runtime
SocialGen is a multi-tenant social-marketing SaaS: users generate AI content, apply brand voice, manage campaign schedules, view engagement analytics, and connect publishing accounts. It runs as a React/Vite SPA plus a Node.js/Express API, with native SQLite as the primary local relational store. Node 22+ is material for node:sqlite.
Key entry points: frontend/src/main.jsx, frontend/src/App.jsx, backend/src/server.js, and backend/src/app.js.
Client application and navigation
The SPA owns presentation, client-side routing, authenticated navigation, and API invocation. App.jsx composes application routes/pages; Layout.jsx provides the shared shell; ProtectedRoute.jsx prevents access to product pages without an authenticated session.
State is split between session identity and broader application state in frontend/src/context/AuthContext.jsx and frontend/src/context/GlobalStateContext.jsx. HTTP requests are centralized through frontend/src/services/api.js, forming the client/server boundary.
Primary user-facing workflows are represented by pages including frontend/src/pages/BlogGenerator.jsx, frontend/src/pages/Calendar.jsx, and frontend/src/pages/SocialAccounts.jsx.
API composition and security boundary
Express application setup and route registration are centralized in backend/src/app.js; process startup/listening is in backend/src/server.js. API domains are divided into auth, AI, calendar, dashboard, and social integrations: backend/src/routes/auth.js, backend/src/routes/ai.js, backend/src/routes/calendar.js, backend/src/routes/dashboard.js, and backend/src/routes/social.js.
JWT authentication middleware protects tenant-scoped operations and establishes the authenticated user context before routes access records or external integrations: backend/src/middleware/auth.js. Auth routes register/login users with bcrypt-hashed credentials and expose profile/settings updates.
Persistence and tenant data
SQLite connection/schema lifecycle is owned by backend/src/db/connection.js; reusable persistence operations reside in backend/src/db/queries.js. The main data boundary is authenticated-user ownership: campaigns, AI jobs/history, settings/brand voice, and social connections should be accessed through the route plus auth-context path rather than directly from the frontend.
backend/src/seed_db.js supports initializing representative local data. Firebase has optional admin/document-cloud integration hooks in backend/src/db/firebase.js; repository-level Firebase rules and indexes are defined in firestore.rules and firestore.indexes.json.
AI content-generation pipeline
Authenticated clients submit and manage generation jobs through backend/src/routes/ai.js. The route layer persists job state/history and delegates model interaction to backend/src/services/gemini.js. Gemini 2.5 Flash is the external generation service, authenticated by GEMINI_API_KEY.
Brand personalization flows from per-user settings/profile into generation prompts: the product supports formality, humor, energy, technicality, warmth, and word inclusion/exclusion controls. Results can be retrieved, edited, deleted, retried, and consumed by blog/remix/hashtag UI workflows.
Campaign lifecycle, analytics, and publication
Calendar CRUD is exposed by backend/src/routes/calendar.js and displayed through frontend/src/pages/Calendar.jsx. Scheduling behavior is encapsulated in backend/src/services/scheduler.js, separating campaign persistence from publish-time orchestration.
Dashboard aggregation is served by backend/src/routes/dashboard.js and rendered by frontend/src/pages/Dashboard.jsx; engagement seeding/simulation support is in backend/src/services/engagementSeeder.js.
Social OAuth and publishing are isolated behind backend/src/routes/social.js, backend/src/services/socialAuth.js, and backend/src/services/socialPublishers.js. LinkedIn, Twitter/X, and Meta credentials are optional external dependencies configured through environment variables; OAuth tokens and posting behavior should remain server-side.
Infrastructure and configuration
Backend environment loading/configuration is centralized in backend/src/load_env.js and backend/src/config/index.js; the template is backend/.env.example. Required operational secrets are JWT and Gemini keys; OAuth client secrets are also backend-only. Frontend Firebase client initialization exists at frontend/src/firebase.js, while Firebase deployment configuration is in firebase.json.
Components 24
React SPA
- SPA entry
frontend/src/main.jsx - App routes
frontend/src/App.jsx - Shared layout
- Protected route · Blocks product pages without a session.
- Session & app state
frontend/src/context/AuthContext.jsx - API client
frontend/src/services/api.js - Generator, calendar & accounts
frontend/src/pages/BlogGenerator.jsx - Dashboard
frontend/src/pages/Dashboard.jsx
Node API
- Server startup
backend/src/server.js - Express app · Registers API middleware and domain routes.
backend/src/app.js - Auth routes
backend/src/routes/auth.js - JWT auth context · Establishes authenticated tenant identity.
backend/src/middleware/auth.js - AI jobs API
backend/src/routes/ai.js - Calendar API
backend/src/routes/calendar.js - Dashboard API
backend/src/routes/dashboard.js - Social API
backend/src/routes/social.js
Data & external services
- SQLite database · Owns local schema and connection lifecycle.
backend/src/db/connection.js - Persistence queries
backend/src/db/queries.js - Gemini generation · Builds personalized prompts and calls Gemini 2.5 Flash.
backend/src/services/gemini.js - Publish scheduler
backend/src/services/scheduler.js - Social OAuth
backend/src/services/socialAuth.js - Social publishers
backend/src/services/socialPublishers.js - LinkedIn, X & Meta
- Gemini 2.5 Flash
Connections 33
- SPA entry → App routes: mounts
- App routes → Shared layout: composes
- App routes → Protected route: guards
- Protected route → Session & app state: checks session
- App routes → Generator, calendar & accounts: routes to
- App routes → Dashboard: routes to
- Generator, calendar & accounts → API client: invokes
- Dashboard → API client: fetches analytics
- API client → Express app: HTTPS API
- Server startup → Express app: starts
- Express app → Auth routes: registers
- Express app → JWT auth context: applies
- Express app → AI jobs API: registers
- Express app → Calendar API: registers
- Express app → Dashboard API: registers
- Express app → Social API: registers
- JWT auth context → AI jobs API: protects
- JWT auth context → Calendar API: protects
- JWT auth context → Dashboard API: protects
- JWT auth context → Social API: protects
- Auth routes → Persistence queries: users and settings
- AI jobs API → Persistence queries: job history and brand settings
- AI jobs API → Gemini generation: generates
- Calendar API → Persistence queries: campaign CRUD
- Calendar API → Publish scheduler: schedules
- Dashboard API → Persistence queries: aggregates engagement
- Social API → Social OAuth: OAuth flows
- Social API → Social publishers: publishes
- Persistence queries → SQLite database: reads and writes
- Publish scheduler → Social publishers: dispatches due posts
- Social OAuth → LinkedIn, X & Meta: authorizes
- Social publishers → LinkedIn, X & Meta: posts to
- Gemini generation → Gemini 2.5 Flash: generation requests