How rsayyed591/ai-dev-assistant works
1. This repository is a two-part monorepo: a Next.js frontend in ai-dev-assistant-frontend and an Express/MongoDB backend in ai-dev-assistant-backend. The frontend is the user-facing shell; the backend owns authentication, AI calls, persistence, and request policy.
2. The frontend uses the Next.js App Router structure (app/page.tsx, app/commit/page.tsx, app/rephrase/page.tsx, app/history/page.tsx, app/profile/page.tsx). That suggests five main screens: landing, commit generation, text rephrasing, history, and profile. components/AuthModal.tsx is the key shared UI boundary for sign-in/sign-up.
3. The backend is organized in a standard layered Express shape: routes define HTTP endpoints, controllers handle request/response logic, middleware enforces auth and rate limits, services isolate the Groq LLM integration, models define MongoDB data structures, and utils/prompts.js centralizes prompt templates. This clean separation is the main architectural boundary in the API.
4. Authentication is JWT-based. auth.controller.js and auth.route.js handle register/login, auth.middleware.js protects AI and user routes, and the frontend likely stores and forwards the token for protected requests. The API design assumes all AI features are unavailable until the user is authenticated.
5. The primary business flows are two AI generation paths: rephrasing and commit message generation. /api/rephrase and /api/commit likely accept user text plus tone/context, pass that input through prompt builders in utils/prompts.js, call the Groq service in services/groq.service.js, and return a cleaned-up natural-language result.
6. History tracking is a separate user-centric subsystem exposed via /api/history. Because the backend tree only includes user.model.js and no dedicated history model, the last-10-request history is likely stored on the user document itself rather than in a standalone collection. That makes history a bounded per-user record, not an application-wide audit log.
7. The profile subsystem (/api/profile) is the read side of user state. It probably returns account metadata plus usage-related data that the frontend profile page can display. This sits alongside history as the “account data” boundary, distinct from the AI generation endpoints.
8. Rate limiting is enforced in backend middleware (rateLimit.middleware.js) and is described as per user/IP. Architecturally, that means request throttling sits in front of the AI endpoints to protect the Groq integration and control abuse, while remaining independent from business logic.
9. Persistence is MongoDB via Mongoose, configured in src/config/db.js. The only visible model is user.model.js, so user identity, auth-related fields, and any stored history are probably the core persisted state. No separate cache, job queue, or analytics store is present in the tree.
10. The backend also has a vercel.json and a top-level api/index.js, indicating it is deployable as a serverless-compatible Express API on Vercel. That deployment boundary matters because the backend is not just a local Node server; it is packaged to run behind a serverless platform while still exposing the same route structure.
11. The external dependency with the biggest architectural impact is Groq’s LLM API. The backend is effectively a thin orchestration layer between authenticated user input, prompt templates, and the model response. This keeps prompt logic centralized and prevents the frontend from ever talking directly to the LLM provider.
12. Overall data flow is: user interacts with the Next.js pages → frontend sends authenticated requests to Express endpoints → middleware checks JWT and rate limits → controllers validate/shape input → prompt utilities and Groq service generate output → MongoDB stores user/history state → response returns to the UI. The main boundaries are UI, API/auth policy, LLM orchestration, and persistence.
Main entry points: app.js App bootstrap · commit.controller.js Commit controller · rephrase.controller.js Rephrase controller · layout.tsx App shell
Components 24
Frontend
Next.js App Router UI for the assistant
- App shell · Global layout and landing entry for the client app
ai-dev-assistant-frontend/app/layout.tsx - Landing · Main entry screen for the assistant
ai-dev-assistant-frontend/app/page.tsx - Commit UI · Commit message generation screen
ai-dev-assistant-frontend/app/commit/page.tsx - Rephrase UI · Text rephrasing screen
ai-dev-assistant-frontend/app/rephrase/page.tsx - History UI · User history screen
ai-dev-assistant-frontend/app/history/page.tsx - Profile UI · User profile screen
ai-dev-assistant-frontend/app/profile/page.tsx - Auth modal · Shared sign-in and sign-up boundary
ai-dev-assistant-frontend/components/AuthModal.tsx
Backend
Express API, policy, and persistence
- API entry · Vercel-compatible backend bootstrap
ai-dev-assistant-backend/api/index.js - App bootstrap · Express application wiring and route registration
ai-dev-assistant-backend/src/app.js - Mongo config · MongoDB connection setup
ai-dev-assistant-backend/src/config/db.js - Auth routes · Register and login endpoints
ai-dev-assistant-backend/src/routes/auth.route.js - AI routes · Commit and rephrase HTTP endpoints
ai-dev-assistant-backend/src/routes/commit.route.js - History route · User history endpoint
ai-dev-assistant-backend/src/routes/history.route.js - Profile route · User profile endpoint
ai-dev-assistant-backend/src/routes/profile.route.js - Auth guard · JWT protection for private endpoints
ai-dev-assistant-backend/src/middleware/auth.middleware.js - Rate limit · Per-user and per-IP request throttling
ai-dev-assistant-backend/src/middleware/rateLimit.middleware.js - User model · Core persisted user state and stored history
ai-dev-assistant-backend/src/models/user.model.js - Auth controller · Login and registration request logic
ai-dev-assistant-backend/src/controllers/auth.controller.js - Commit controller · Commit generation request logic
ai-dev-assistant-backend/src/controllers/commit.controller.js - Rephrase controller · Rephrase generation request logic
ai-dev-assistant-backend/src/controllers/rephrase.controller.js - History controller · Reads per-user request history
ai-dev-assistant-backend/src/controllers/history.controller.js - Profile controller · Reads account and usage data
ai-dev-assistant-backend/src/controllers/profile.controller.js
AI Orchestration
Prompting and model integration inside the API
- Prompt utils · Centralized prompt templates and shaping
ai-dev-assistant-backend/src/utils/prompts.js - Groq service · Model API integration and response handling
ai-dev-assistant-backend/src/services/groq.service.js
Connections 36
- App shell → Landing: hosts · The app shell contains the primary landing route
- App shell → Commit UI: routes to · Shell provides navigation to commit generation
- App shell → Rephrase UI: routes to · Shell provides navigation to rephrase generation
- App shell → History UI: routes to · Shell provides navigation to history
- App shell → Profile UI: routes to · Shell provides navigation to profile
- Auth modal → Landing: auths · Landing UI uses the shared auth modal
- Auth modal → Commit UI: auths · Protected generation flows rely on the shared auth modal
- Auth modal → Rephrase UI: auths · Protected generation flows rely on the shared auth modal
- API entry → App bootstrap: boots · Serverless entry initializes the Express app
- App bootstrap → Auth routes: mounts · Registers authentication endpoints
- App bootstrap → AI routes: mounts · Registers commit and rephrase endpoints
- App bootstrap → History route: mounts · Registers history endpoints
- App bootstrap → Profile route: mounts · Registers profile endpoints
- App bootstrap → Mongo config: connects · App startup connects to MongoDB
- Auth routes → Auth controller: handles · Auth routes delegate to controller logic
- AI routes → Commit controller: handles · Commit route delegates to commit controller
- AI routes → Rephrase controller: handles · Rephrase route delegates to rephrase controller
- History route → History controller: handles · History route delegates to history controller
- Profile route → Profile controller: handles · Profile route delegates to profile controller
- Auth controller → Auth guard: uses · Auth logic is coupled to JWT policy
- Commit controller → Auth guard: protected by · Commit generation requires authenticated access
- Rephrase controller → Auth guard: protected by · Rephrase generation requires authenticated access
- History controller → Auth guard: protected by · History access requires authenticated access
- Profile controller → Auth guard: protected by · Profile access requires authenticated access
- Commit controller → Rate limit: throttled by · AI generation is rate limited before execution
- Rephrase controller → Rate limit: throttled by · AI generation is rate limited before execution
- Commit controller → Prompt utils: builds prompt · Commit generation uses shared prompt templates
- Rephrase controller → Prompt utils: builds prompt · Rephrase generation uses shared prompt templates
- Prompt utils → Groq service: drives · Prompt output is sent to the LLM client
- Commit controller → Groq service: calls · Commit generation executes through the Groq client
- Rephrase controller → Groq service: calls · Rephrase generation executes through the Groq client
- History controller → User model: reads · History is stored on the user document
- Profile controller → User model: reads · Profile data comes from persisted user state
- Auth controller → User model: writes · Registration and login depend on user persistence
- Commit controller → User model: updates · Generation flow can append user history
- Rephrase controller → User model: updates · Generation flow can append user history