How sandeshchhetri985016/writegy works
1. System shape
- The active production architecture is a two-app full stack: a React 18 SPA in frontend/ and a single Spring Boot 3.5 backend in backend/.
- The backend is the central application boundary for business logic, persistence, auth verification, document processing, export, and grammar checking.
- archive/ contains earlier microservice experiments (gateway, user, document, NLP, notification, analytics) but they are historical and not the active runtime path.
2. Frontend subsystem
- The React app is organized by feature: auth, dashboard, editor, settings, and admin.
- frontend/src/lib/api/* wraps backend calls; frontend/src/lib/supabase.js integrates Supabase client-side auth.
- UI state is split across contexts such as AuthContext and EditorContext, with routing protection via ProtectedRoute.
- The editor layer includes rich text, markdown, and canvas editing, plus file upload, grammar suggestion panels, and auto-save behavior.
3. Backend subsystem
- The Spring Boot backend follows a standard layered design: controllers → services → repositories → JPA entities/DTOs.
- Main controllers are AuthController, DocumentController, GrammarController, ExportController, UserController, SettingsController, and AdminController.
- Services encapsulate domain logic such as document management, auth, storage, text extraction, export, and grammar checking.
4. Authentication and security boundary
- Authentication is Supabase-backed on the client, but the backend still enforces access using JWT validation.
- Backend security includes a JWT filter, authentication entry point, CORS config, and rate limiting.
- The common flow is: user signs in with Supabase in the browser, frontend sends the JWT to the backend, and the backend validates it before allowing document or profile operations.
- /auth/sync and /auth/me are the main bridge endpoints for aligning Supabase identity with backend user records.
5. Core data model and persistence
- The persistent domain lives in PostgreSQL via JPA/Hibernate and Flyway migrations.
- Key entities include User, UserProfile, UserPreferences, Document, DocumentVersion, UserEvent, and WritingMetrics.
- The schema history shows document hierarchy and canvas support, indicating the backend stores both classic documents and richer structured content.
- Repositories isolate database access for users, profiles, preferences, and documents.
6. Document lifecycle flow
- Document operations are handled by the backend API: list, create, fetch, update, delete, and hierarchical child-document handling.
- The frontend editor sends document content to the backend, which persists the document metadata/content and version/history data.
- Auto-save happens in the browser, but persistence is centralized in the backend so content survives refreshes and reconnects.
7. File upload and storage flow
- The project uses a hybrid upload pattern: the frontend can extract text from uploaded files first, then send both the file and extracted text to the backend as multipart form data.
- Backend storage is split between database content and object storage.
- StorageService and R2Config indicate an abstraction over external file storage; the README and environment setup point to Supabase Storage as the primary target.
8. Grammar/AI processing
- Grammar checking is exposed by the backend as a dedicated API and consumed by the editor UI for inline suggestions.
- The result is not just a corrected text blob; the UI is designed around suggestions, applying individual fixes, and highlighting affected spans.
- The repo also contains an archived standalone NLP service experiment, showing that AI/grammar processing was explored as a separate service before being folded into the current architecture.
9. Export and document output
- ExportController and ExportService generate downloadable document formats such as PDF, DOCX, and Markdown.
- Export is treated as a backend responsibility because it depends on the persisted document model, formatting rules, and server-side file generation.
10. Operational and deployment boundaries
- The active deployment target is Render for the backend, with Dockerfiles for both frontend and backend.
- docker-compose.yml, render.yaml, Makefile, and the Scripts/ folder support local orchestration, backups, cache clearing, and DB migration workflows.
- backend/src/main/resources/db/migration/ and infra/supabase/migrations/ show two migration tracks: backend-managed schema evolution and Supabase infrastructure setup.
- infra/monitoring/ contains Prometheus/Grafana provisioning, so observability is a first-class operational concern rather than an afterthought.
11. Historical architecture in archive/
- The archived backend experiments reveal a prior microservice decomposition: API gateway, user service, document service, NLP service, notification service, and analytics service.
- These modules are useful for understanding intended bounded contexts, but they are not the current mainline execution path.
- For an architecture diagram, they should be shown separately as legacy/experimental subsystems, not as live dependencies of the current SPA + monolith backend + Supabase stack.
Main entry points: App.jsx React SPA · WritegyApplication.java Spring Boot app · api-gateway API gateway · render.yaml Ops tooling
Components 25
Backend
Main Spring Boot application boundary for business logic and persistence.
- Spring Boot app · Main server-side application for auth verification, documents, grammar, export, and settings.
backend/src/main/java/com/writegy/WritegyApplication.java - Security · JWT filters, auth entry point, CORS, and request throttling.
backend/src/main/java/com/writegy/security - Auth API · Auth bridge endpoints including identity sync and current-user lookup.
backend/src/main/java/com/writegy/controller/AuthController.java - Document API · Document CRUD, hierarchy, persistence, and versioned content lifecycle.
backend/src/main/java/com/writegy/controller/DocumentController.java - Grammar API · Grammar checking and suggestion generation for editor assistance.
backend/src/main/java/com/writegy/controller/GrammarController.java - Export API · Server-side generation of PDF, DOCX, and Markdown outputs.
backend/src/main/java/com/writegy/controller/ExportController.java - Domain model · Users, profiles, preferences, documents, versions, events, and metrics persisted via JPA.
backend/src/main/java/com/writegy/model/entity - Storage layer · Object storage abstraction and text extraction support for uploaded files.
backend/src/main/java/com/writegy/service/StorageService.java - PostgreSQL + Flyway · Database schema and migrations for the active backend data model.
backend/src/main/resources/db/migration
Frontend
React SPA organized by product features and client-side state.
- React SPA · Primary browser application for auth, dashboard, editing, settings, and admin flows.
frontend/src/App.jsx - Auth UI · Login/register/forgot-password screens and session entry flow.
frontend/src/features/auth - Dashboard UI · Document list, tree view, and recent activity surfaces.
frontend/src/features/dashboard - Editor UI · Rich text, markdown, canvas editing, uploads, suggestions, and export actions.
frontend/src/features/editor - Settings UI · Profile, preferences, and subscription screens.
frontend/src/features/settings - Admin UI · Administrative dashboard for privileged user workflows.
frontend/src/features/admin - Client state · Auth and editor context plus auto-save and local storage hooks.
frontend/src/contexts - API layer · Axios-backed API wrappers for auth, documents, export, and grammar calls.
frontend/src/lib/api - Supabase client · Client-side identity and session management used before backend validation.
frontend/src/lib/supabase.js
Infra
Deployment, migrations, monitoring, and local orchestration support.
- Ops tooling · Render deployment, Docker, compose, backup/migration scripts, and monitoring config.
render.yaml
Legacy experiments
Archived microservice and earlier-service experiments retained for reference.
- API gateway · Archived gateway experiment with routing, auth, and rate-limit filters.
archive/experiments/backend-services/api-gateway - User service · Archived auth/profile service experiment backed by Supabase integration.
archive/experiments/backend-services/user-service - Document service · Archived document-processing and storage service experiment.
archive/experiments/backend-services/document-service - NLP service · Archived standalone grammar/NLP service experiment.
archive/experiments/backend-services/nlp-service - Notification service · Archived WebSocket notification service experiment.
archive/experiments/backend-services/notification-service - Analytics service · Archived event analytics service experiment.
archive/experiments/backend-services/analytics-service
Connections 29
- React SPA → Auth UI: routes to · Auth screens are part of the SPA route tree.
- React SPA → Dashboard UI: routes to · Dashboard is the main post-login surface.
- React SPA → Editor UI: routes to · Editor hosts document creation and editing workflows.
- React SPA → Settings UI: routes to · Settings screens manage profile and preferences.
- React SPA → Admin UI: routes to · Admin surface is exposed within the SPA.
- React SPA → Client state: uses · Shared contexts and hooks manage session and editor state.
- React SPA → API layer: calls · UI actions are translated into backend API requests.
- React SPA → Supabase client: auths with · Client-side sign-in uses Supabase before backend verification.
- API layer → Spring Boot app: requests · Frontend API wrappers send document, export, grammar, and auth traffic to the backend.
- Supabase client → Auth API: bridges via JWT · Supabase identity is synchronized and validated through backend auth endpoints.
- Spring Boot app → Security: protected by · Requests are filtered through JWT, CORS, and rate limiting.
- Spring Boot app → Auth API: exposes · Auth endpoints align external identity with backend user records.
- Spring Boot app → Document API: exposes · Document lifecycle endpoints manage content and hierarchy.
- Spring Boot app → Grammar API: exposes · Grammar checking is served from the backend.
- Spring Boot app → Export API: exposes · Export endpoints generate downloadable artifacts.
- Spring Boot app → Domain model: persists via · Services operate over JPA entities and repositories.
- Spring Boot app → Storage layer: uses · Uploads and extraction flow through object storage and parsing services.
- Domain model → PostgreSQL + Flyway: stored in · Entities are mapped to the PostgreSQL schema managed by Flyway.
- Storage layer → PostgreSQL + Flyway: tracks metadata in · Stored files are associated with persisted document records.
- Ops tooling → Spring Boot app: deploys · Render and Docker-based operations target the backend service.
- Ops tooling → React SPA: builds · Frontend has its own Dockerized build and local runtime support.
- Ops tooling → PostgreSQL + Flyway: migrates · Database migrations and scripts manage schema evolution.
- API gateway → User service: routes to · Gateway experiment forwarded auth and profile traffic.
- API gateway → Document service: routes to · Gateway experiment forwarded document traffic.
- API gateway → NLP service: routes to · Gateway experiment forwarded NLP traffic.
- API gateway → Notification service: routes to · Gateway experiment forwarded notifications.
- API gateway → Analytics service: routes to · Gateway experiment forwarded analytics traffic.
- User service → Document service: shared context · Historical services reflect earlier bounded-context splitting.
- Document service → NLP service: paired with · Document and NLP were separate experiments before consolidation.