# premjithx86/umamicircle architecture

> Architecture diagram of the GitHub repository premjithx86/umamicircle, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/premjithx86/umamicircle
- Repository: https://github.com/premjithx86/umamicircle

## Overview

1. **Repository shape**
   - This is a three-part monorepo:
     - a **Node/Express backend** at the root,
     - a **public React user app** in `umami-frontend`,
     - a **React admin dashboard** in `umami-admin`.
   - The three apps share one backend API and one MongoDB data layer, but the two frontends are deployed/run independently.

2. **Backend entry and request pipeline**
   - `server.js` is the runtime entry point and boots the Express app from `src/app.js`.
   - The backend is organized in the usual boundary layers:
     - `src/config` for environment, MongoDB, and Firebase setup,
     - `src/middleware` for auth, admin auth, moderation, and upload handling,
     - `src/routes` for feature-specific HTTP endpoints,
     - `src/services` for non-trivial business logic,
     - `src/models` for Mongoose schemas.

3. **Primary backend domains**
   - The API is split by business area rather than by UI:
     - `postRoutes`, `recipeRoutes`, `commentRoutes`, `socialRoutes`
     - `messagingRoutes`, `notificationRoutes`
     - `aiRoutes`, `uploadRoutes`
     - `userRoutes`, `adminRoutes`
   - This suggests the backend is the central orchestration layer for content creation, social interactions, messaging, moderation, and AI features.

4. **Data model boundary**
   - MongoDB/Mongoose is the main persistence layer.
   - The model set shows the core domain objects:
     - social/content: `User`, `Post`, `Recipe`, `Comment`, `Report`
     - communication: `Conversation`, `Message`, `Notification`
     - admin/safety: `Admin`, `AuditLog`, `BlockedSession`, `ModerationCache`
     - AI usage tracking: `AIChatHistory`, `AIChatUsage`
   - The presence of these models indicates the backend keeps both product data and operational/security state.

5. **Authentication and authorization**
   - The project uses **Firebase Authentication** on the client side, with backend middleware (`auth.js`, `adminAuth.js`) enforcing access control.
   - User-facing routes are protected separately from admin-only routes.
   - This creates a clear split between:
     - authenticated community actions in the public app,
     - privileged moderation/management actions in the admin app.

6. **Content safety and moderation flow**
   - Moderation is a first-class subsystem, not an afterthought.
   - `textModerationMiddleware` and `services/moderationService.js` handle text safety, while the README also references external moderation providers for image/text screening.
   - `ModerationCache`, `Report`, `BlockedSession`, and `AuditLog` show that moderation is persisted, reviewable, and auditable.
   - Likely flow: user-generated content enters via content routes, is checked/screened, then stored and/or queued for admin review if needed.

7. **AI subsystem**
   - `aiRoutes` and `services/aiService.js` implement “UmamiBot,” the cooking assistant.
   - The README says it is powered by a Groq-hosted Llama model, with additional food-detection support from Hugging Face.
   - `AIChatHistory` and `AIChatUsage` imply the backend tracks conversation state and usage limits/analytics.
   - This is a distinct backend capability with its own persistence and quota/telemetry concerns.

8. **Real-time messaging and notifications**
   - Messaging is handled by `messagingRoutes` plus `services/messagingService.js`, with Socket.io listed in the stack and a frontend `socket.js` client.
   - The data model (`Conversation`, `Message`) indicates a conversation-based chat system rather than simple one-off messages.
   - Notifications are a separate subsystem (`notificationRoutes`, `notificationService`, `Notification` model), likely fed by social actions, messaging, and moderation events.

9. **Media upload path**
   - `uploadMiddleware.js` and `uploadRoutes` define a dedicated media ingestion boundary.
   - The README references Cloudinary, so the architecture likely routes image uploads through the backend and stores/transforms media externally rather than in the app server.
   - This is important for food photography, which is a core product concern.

10. **Public frontend structure**
   - `umami-frontend` is a Vite/React app built around feature pages:
     - feed/explore/profile/search/settings
     - post and recipe creation/detail views
     - chat, notifications, AI chat, auth flows
   - It uses contexts for auth and theme, a route protection layer (`ProtectedRoute`), and a dedicated API client in `src/services/api.js`.
   - The frontend is the primary consumer of the public API and real-time socket connection.

11. **Admin dashboard structure**
   - `umami-admin` is a separate React/Vite app for operations and moderation.
   - Its pages focus on admin workflows: dashboard, user management, reports, moderation queue, activity logs, login.
   - `AdminContext` and `adminService.js` suggest the dashboard authenticates independently and calls admin endpoints only.
   - This separation keeps high-privilege workflows isolated from the consumer UI.

12. **Cross-cutting services and operational boundaries**
   - `auditService.js`, `notificationService.js`, `messagingService.js`, and `moderationService.js` show the backend favors service-layer encapsulation for side effects and multi-step workflows.
   - The architecture is centered on:
     - React clients → Express routes → service layer → Mongoose models/external services
     - plus real-time Socket.io events for chat/notifications.
   - For an architecture diagram, the key boundaries are: **public app**, **admin app**, **API server**, **MongoDB**, **Firebase auth**, **Cloudinary storage**, **AI/moderation providers**, and **Socket.io real-time channel**.

Main entry points: [`umami-frontend`](https://github.com/premjithx86/umamicircle/tree/main/umami-frontend) (User app), [`src/app.js`](https://github.com/premjithx86/umamicircle/blob/main/src/app.js) (Express app), [`src/services`](https://github.com/premjithx86/umamicircle/tree/main/src/services) (Services), [`src/routes`](https://github.com/premjithx86/umamicircle/tree/main/src/routes) (Routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_server["server.js<br/>entrypoint<br/>[server.js]"]
  node_app["Express app<br/>[app.js]"]
  node_config["Config"]
  node_middleware["Middleware<br/>request guards"]
  node_routes["Routes<br/>http api"]
  node_services["Services<br/>business logic"]
  node_models[("Models")]
end

subgraph group_public["Public app"]
  node_publicapp["User app<br/>react client"]
  node_publicpages["Pages<br/>views"]
  node_publicapi["API client<br/>client api<br/>[api.js]"]
  node_publicsocket(("Socket client<br/>realtime client<br/>[socket.js]"))
  node_publicauth(("Auth context<br/>state/auth<br/>[AuthContext.jsx]"))
end

subgraph group_admin["Admin app"]
  node_adminapp["Admin app<br/>react client"]
  node_adminpages["Admin pages<br/>views"]
  node_adminservice["Admin API<br/>client api<br/>[adminService.js]"]
  node_adminctx(("Admin context<br/>state/auth<br/>[AdminContext.jsx]"))
end

subgraph group_external["External systems"]
  node_mongodb[("MongoDB<br/>datastore")]
  node_firebase(("Firebase Auth<br/>identity provider"))
  node_cloudinary[("Cloudinary<br/>media storage")]
  node_aiproviders(("AI providers<br/>llm/vision"))
  node_socketio(("Socket.io<br/>realtime bus"))
end

node_server -->|"starts"| node_app
node_app -->|"loads"| node_config
node_app -->|"applies"| node_middleware
node_app -->|"mounts"| node_routes
node_routes -->|"delegates"| node_services
node_services -->|"reads/writes"| node_models
node_config -->|"connects"| node_mongodb
node_config -->|"configures"| node_firebase
node_middleware -->|"verifies"| node_firebase
node_middleware -->|"uploads"| node_cloudinary
node_services -->|"calls"| node_aiproviders
node_services -->|"emits"| node_socketio
node_publicapp -->|"contains"| node_publicpages
node_publicapp -->|"uses"| node_publicapi
node_publicapp -->|"subscribes"| node_publicsocket
node_publicapp -->|"wraps"| node_publicauth
node_publicauth -->|"authenticates"| node_firebase
node_publicapi -->|"calls"| node_routes
node_adminapp -->|"contains"| node_adminpages
node_adminapp -->|"uses"| node_adminservice
node_adminapp -->|"wraps"| node_adminctx
node_adminservice -->|"calls"| node_routes
node_adminctx -->|"authenticates"| node_firebase

click node_server "https://github.com/premjithx86/umamicircle/blob/main/server.js"
click node_app "https://github.com/premjithx86/umamicircle/blob/main/src/app.js"
click node_config "https://github.com/premjithx86/umamicircle/tree/main/src/config"
click node_middleware "https://github.com/premjithx86/umamicircle/tree/main/src/middleware"
click node_routes "https://github.com/premjithx86/umamicircle/tree/main/src/routes"
click node_services "https://github.com/premjithx86/umamicircle/tree/main/src/services"
click node_models "https://github.com/premjithx86/umamicircle/tree/main/src/models"
click node_publicapp "https://github.com/premjithx86/umamicircle/tree/main/umami-frontend"
click node_publicpages "https://github.com/premjithx86/umamicircle/tree/main/umami-frontend/src/pages"
click node_publicapi "https://github.com/premjithx86/umamicircle/blob/main/umami-frontend/src/services/api.js"
click node_publicsocket "https://github.com/premjithx86/umamicircle/blob/main/umami-frontend/src/services/socket.js"
click node_publicauth "https://github.com/premjithx86/umamicircle/blob/main/umami-frontend/src/context/AuthContext.jsx"
click node_adminapp "https://github.com/premjithx86/umamicircle/tree/main/umami-admin"
click node_adminpages "https://github.com/premjithx86/umamicircle/tree/main/umami-admin/src/pages"
click node_adminservice "https://github.com/premjithx86/umamicircle/blob/main/umami-admin/src/services/adminService.js"
click node_adminctx "https://github.com/premjithx86/umamicircle/blob/main/umami-admin/src/context/AdminContext.jsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_app,node_config,node_middleware,node_routes,node_services,node_models toneBlue
class node_publicapp,node_publicpages,node_publicapi,node_publicsocket,node_publicauth toneAmber
class node_adminapp,node_adminpages,node_adminservice,node_adminctx toneMint
class node_mongodb,node_firebase,node_cloudinary,node_aiproviders,node_socketio toneRose
```

## Components

### Backend

Express API, services, and data models

- [server.js](https://github.com/premjithx86/umamicircle/blob/main/server.js): entrypoint · Boots the backend runtime · `server.js`
- [Express app](https://github.com/premjithx86/umamicircle/blob/main/src/app.js): express app · Wires middleware and routes · `src/app.js`
- [Config](https://github.com/premjithx86/umamicircle/tree/main/src/config): backend config · MongoDB, Firebase, and environment setup · `src/config`
- [Middleware](https://github.com/premjithx86/umamicircle/tree/main/src/middleware): request guards · Auth, admin auth, moderation, and uploads · `src/middleware`
- [Routes](https://github.com/premjithx86/umamicircle/tree/main/src/routes): http api · Feature endpoints for content, chat, AI, and admin · `src/routes`
- [Services](https://github.com/premjithx86/umamicircle/tree/main/src/services): business logic · Side effects and multi-step workflows · `src/services`
- [Models](https://github.com/premjithx86/umamicircle/tree/main/src/models): mongoose models · Core domain and operational schemas · `src/models`

### Public app

React user-facing client

- [User app](https://github.com/premjithx86/umamicircle/tree/main/umami-frontend): react client · Public feed, content, chat, and AI experience · `umami-frontend`
- [Pages](https://github.com/premjithx86/umamicircle/tree/main/umami-frontend/src/pages): views · Home, explore, profiles, content, chat, and settings · `umami-frontend/src/pages`
- [API client](https://github.com/premjithx86/umamicircle/blob/main/umami-frontend/src/services/api.js): client api · Calls the shared backend API · `umami-frontend/src/services/api.js`
- [Socket client](https://github.com/premjithx86/umamicircle/blob/main/umami-frontend/src/services/socket.js): realtime client · Receives chat and notification events · `umami-frontend/src/services/socket.js`
- [Auth context](https://github.com/premjithx86/umamicircle/blob/main/umami-frontend/src/context/AuthContext.jsx): state/auth · User session and protected routes · `umami-frontend/src/context/AuthContext.jsx`

### Admin app

React moderation and operations client

- [Admin app](https://github.com/premjithx86/umamicircle/tree/main/umami-admin): react client · Moderation and operations dashboard · `umami-admin`
- [Admin pages](https://github.com/premjithx86/umamicircle/tree/main/umami-admin/src/pages): views · Dashboard, users, reports, queue, and logs · `umami-admin/src/pages`
- [Admin API](https://github.com/premjithx86/umamicircle/blob/main/umami-admin/src/services/adminService.js): client api · Calls privileged admin endpoints · `umami-admin/src/services/adminService.js`
- [Admin context](https://github.com/premjithx86/umamicircle/blob/main/umami-admin/src/context/AdminContext.jsx): state/auth · Admin session and access state · `umami-admin/src/context/AdminContext.jsx`

### External systems

Datastores, auth, media, AI, and realtime services

- **MongoDB**: datastore · Primary persistence for users, content, chat, and moderation
- **Firebase Auth**: identity provider · Client-side authentication foundation
- **Cloudinary**: media storage · Image upload and transformation backend
- **AI providers**: llm/vision · Groq Llama and Hugging Face support
- **Socket.io**: realtime bus · Pushes chat and notification events

## Connections

- server.js → Express app: starts · Runtime entry launches the Express application
- Express app → Config: loads · Initializes environment, database, and auth config
- Express app → Middleware: applies · Installs request guards and upload handling
- Express app → Routes: mounts · Registers feature-specific HTTP endpoints
- Routes → Services: delegates · Routes hand off complex workflows to services
- Services → Models: reads/writes · Services persist and query domain state
- Config → MongoDB: connects · MongoDB is the primary data store
- Config → Firebase Auth: configures · Firebase supports client authentication
- Middleware → Firebase Auth: verifies · Auth middleware validates identity tokens
- Middleware → Cloudinary: uploads · Media ingestion is routed to external storage
- Services → AI providers: calls · AI and moderation services use external models/providers
- Services → Socket.io: emits · Messaging and notifications push realtime events
- User app → Pages: contains · User-facing features are organized as pages
- User app → API client: uses · Frontend reads and writes through the shared API
- User app → Socket client: subscribes · Frontend listens for realtime updates
- User app → Auth context: wraps · Public app manages authenticated user state
- Auth context → Firebase Auth: authenticates · Client session is based on Firebase auth
- API client → Routes: calls · User app talks to public backend endpoints
- Admin app → Admin pages: contains · Admin workflows are page-based
- Admin app → Admin API: uses · Dashboard talks to admin endpoints through a service layer
- Admin app → Admin context: wraps · Admin session and permissions are centralized in context
- Admin API → Routes: calls · Admin dashboard reaches privileged backend routes
- Admin context → Firebase Auth: authenticates · Admin access depends on the shared auth foundation
