# kunal-rathore-111/neptune architecture

> Architecture diagram of the GitHub repository kunal-rathore-111/neptune, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kunal-rathore-111/neptune
- Repository: https://github.com/kunal-rathore-111/neptune

## Overview

1. **Overall shape**
   Neptune is a three-runtime monorepo: a React/Vite frontend, an Express backend API, and a separate Hono-based AI microservice. Shared code lives in `packages/*` so the client and server can reuse UI primitives, validation schemas, icons, and utility functions.

2. **User-facing client**
   `apps/web/client` is the browser app. It is a routed SPA with pages for landing, docs, auth, dashboard, profiles, shared content, and legal content. The UI is built from reusable components and custom hooks, with TanStack Query-style data hooks wrapping the service layer.

3. **Client state and data access**
   The client does not talk to the database directly. It uses an `api/axiosInstance.ts` plus dedicated service modules for each feature area: sign-in/out, content CRUD, profile fetch, sharing, password reset, OTP, chat, and Magic Fill. A small Redux slice in `store/uiSlice.ts` appears to manage local UI state such as drawers or layout toggles.

4. **Backend API as the application orchestrator**
   `apps/web/server` is the main business-logic layer. It exposes routes for authentication, user account management, bookmark/content CRUD, sharing, OTP flows, and AI-related actions. Controllers delegate to service modules, which in turn handle persistence, hashing, session/auth logic, and external service calls.

5. **Auth and account boundary**
   The server contains dedicated middlewares for sign-up/sign-in validation, auth protection, account operations, password reset, and OTP verification. Supporting libs include session handling, hashing, request IDs, and rate limiting. This indicates that identity, password updates, and account deletion are enforced on the server side rather than in the client.

6. **Bookmark/content subsystem**
   The core domain is saved content management. Server-side `contentController`, `contentService`, and `embeddingService` handle bookmark creation, editing, deletion, and retrieval. Validation is centralized through shared Zod schemas in `packages/validator`, so both input shape and domain rules are consistent across layers.

7. **Sharing subsystem**
   Public access is separated from authenticated management. There are distinct controllers/services for content sharing and user profile sharing, likely backed by share hashes or links. The client has pages for shared content and shared profiles, which consume these public endpoints without needing full authentication.

8. **AI and “Magic Fill” flow**
   AI functionality is split out of the main backend into `apps/aiServer`. The main server calls this service for AI-assisted features such as chat, embeddings, and Magic Fill. The AI service itself has controllers/routes for chat, embedding generation, and URL-based metadata filling.

9. **AI service responsibilities**
   The AI server is a thin stateless microservice that likely does two things: fetches or scrapes source content from URLs and invokes external models for generation. Its code references Cheerio for HTML scraping and external model integration through Google GenAI and Groq. This keeps LLM/network-heavy logic out of the main application server.

10. **Persistence layer**
   Database access is centralized in `packages/database`, which contains Drizzle ORM configuration, schema definitions, and migration history. The application server is the only layer that should touch PostgreSQL directly. That creates a clear boundary: client → API → database, with AI calls routed separately through the AI service.

11. **Shared packages**
   The monorepo packages are important architectural building blocks:
   - `packages/ui`: reusable design-system-style React components
   - `packages/icons`: shared icon set
   - `packages/libs`: common utilities and category helpers
   - `packages/validator`: shared Zod schemas
   - `packages/typescript-config` and `packages/eslint-config`: standardization across workspaces  
   These reduce duplication and keep feature code thin.

12. **Deployment and environment split**
   Each runtime has its own deployment config and environment file: client, server, and AI server are separated for independent hosting. The repo also includes GitHub Actions workflows and Dockerfiles, which suggests each service can be built and deployed independently rather than as a single monolith.

13. **Primary request flows**
   The main flow is: browser app submits auth/content actions to the Express server; the server validates, stores, and serves data from PostgreSQL; AI-assisted actions are forwarded to the AI microservice; the AI microservice calls external model providers and scraping utilities; results flow back through the server to the UI. Public sharing bypasses most authentication but still reads from the same backend domain model.

14. **Architecture takeaway**
   This is not a simple frontend/backend split; it is a modular monorepo with a clear separation between product UI, core application API, and AI-specific processing. The strongest diagram boundaries are: browser client, main API server, AI microservice, PostgreSQL, and external LLM providers.

Main entry points: [`apps/web/server/src/routes/indexRoute.ts`](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/routes/indexRoute.ts) (Routes), [`apps/web/server/src/services/content/contentService.ts`](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/services/content/contentService.ts) (Services), [`apps/web/server/src/controllers/ai/aiController.ts`](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/controllers/ai/aiController.ts) (AI Ctrl), [`apps/web/client/src/components/dashboard/MainContentArea.tsx`](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/components/dashboard/MainContentArea.tsx) (UI Components)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web Client"]
  node_client_app["App Shell<br/>spa entry<br/>[App.tsx]"]
  node_client_pages["Pages<br/>route views<br/>[Dashboard.tsx]"]
  node_client_services["API Services<br/>data access"]
  node_client_hooks["Query Hooks<br/>state/data hooks"]
  node_client_store["UI Store<br/>redux slice<br/>[uiSlice.ts]"]
  node_client_components["UI Components<br/>feature components"]
end

subgraph group_server["Main API"]
  node_server_routes["Routes<br/>[indexRoute.ts]"]
  node_server_middlewares["Middlewares<br/>request pipeline<br/>[authMiddleware.ts]"]
  node_server_user_ctrl["User Ctrl<br/>account controllers<br/>[signController.ts]"]
  node_server_content_ctrl["Content Ctrl<br/>domain controller"]
  node_server_share_ctrl["Share Ctrl<br/>public access"]
  node_server_ai_ctrl["AI Ctrl<br/>integration controller<br/>[aiController.ts]"]
  node_server_services["Services<br/>business logic<br/>[contentService.ts]"]
  node_server_libs["Server Libs<br/>support libs<br/>[sessions.ts]"]
end

subgraph group_ai["AI Service"]
  node_ai_routes["AI Routes<br/>hono routes<br/>[chat.ts]"]
  node_ai_controllers["AI Controllers<br/>request handlers<br/>[chatController.ts]"]
  node_ai_models["AI Models<br/>model/scrape logic<br/>[groqModels.ts]"]
end

subgraph group_shared["Shared Packages"]
  node_pkg_validator["Validator<br/>zod schemas<br/>[index.ts]"]
  node_pkg_ui["UI Kit<br/>react library<br/>[index.tsx]"]
  node_pkg_icons["Icons<br/>icon library<br/>[index.tsx]"]
  node_pkg_libs["Shared Utils<br/>helpers<br/>[index.ts]"]
end

subgraph group_infra["Data & Infra"]
  node_db_schema[("Schema<br/>[schema.ts]")]
  node_db_client[("DB Client<br/>drizzle client<br/>[dbDrizzle.ts]")]
end

node_client_app -->|"renders"| node_client_pages
node_client_pages -->|"composes"| node_client_components
node_client_pages -->|"reads data via"| node_client_hooks
node_client_hooks -->|"calls"| node_client_services
node_client_services -->|"requests"| node_server_routes
node_client_store -->|"drives"| node_client_components
node_client_components -->|"uses"| node_pkg_ui
node_client_components -->|"uses"| node_pkg_icons
node_client_services -->|"adheres to"| node_pkg_validator
node_server_routes -->|"passes through"| node_server_middlewares
node_server_routes -->|"dispatches to"| node_server_user_ctrl
node_server_routes -->|"dispatches to"| node_server_content_ctrl
node_server_routes -->|"dispatches to"| node_server_share_ctrl
node_server_routes -->|"dispatches to"| node_server_ai_ctrl
node_server_user_ctrl -->|"delegates"| node_server_services
node_server_content_ctrl -->|"delegates"| node_server_services
node_server_share_ctrl -->|"delegates"| node_server_services
node_server_ai_ctrl -->|"orchestrates"| node_server_services
node_server_services -->|"persists via"| node_db_client
node_db_client -->|"uses"| node_db_schema
node_server_services -->|"validates with"| node_pkg_validator
node_server_middlewares -->|"depends on"| node_server_libs
node_server_ai_ctrl -->|"calls service"| node_ai_routes
node_ai_routes -->|"invokes"| node_ai_controllers
node_ai_controllers -->|"uses"| node_ai_models
node_ai_models -->|"shares schemas"| node_pkg_validator
node_server_ai_ctrl -.->|"forwards to"| node_ai_routes
node_ai_models -.->|"responds to"| node_server_routes

click node_client_app "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/App.tsx"
click node_client_pages "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/Pages/Dashboard.tsx"
click node_client_services "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/services/fetchDataService.ts"
click node_client_hooks "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/hooks/react-query-hooks/useDashboardFetch.ts"
click node_client_store "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/store/uiSlice.ts"
click node_client_components "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/components/dashboard/MainContentArea.tsx"
click node_server_routes "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/routes/indexRoute.ts"
click node_server_middlewares "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/middlewares/authMiddleware.ts"
click node_server_user_ctrl "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/controllers/user/signController.ts"
click node_server_content_ctrl "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/controllers/content/contentController.ts"
click node_server_share_ctrl "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/controllers/share/contentShareController.ts"
click node_server_ai_ctrl "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/controllers/ai/aiController.ts"
click node_server_services "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/services/content/contentService.ts"
click node_server_libs "https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/libs/sessions.ts"
click node_ai_routes "https://github.com/kunal-rathore-111/neptune/blob/main/apps/aiServer/src/routes/chat.ts"
click node_ai_controllers "https://github.com/kunal-rathore-111/neptune/blob/main/apps/aiServer/src/controller/chatController.ts"
click node_ai_models "https://github.com/kunal-rathore-111/neptune/blob/main/apps/aiServer/src/models/groqModels.ts"
click node_db_schema "https://github.com/kunal-rathore-111/neptune/blob/main/packages/database/src/drizzle/schema.ts"
click node_db_client "https://github.com/kunal-rathore-111/neptune/blob/main/packages/database/src/drizzle/dbDrizzle.ts"
click node_pkg_validator "https://github.com/kunal-rathore-111/neptune/blob/main/packages/validator/src/index.ts"
click node_pkg_ui "https://github.com/kunal-rathore-111/neptune/blob/main/packages/ui/src/index.tsx"
click node_pkg_icons "https://github.com/kunal-rathore-111/neptune/blob/main/packages/icons/src/index.tsx"
click node_pkg_libs "https://github.com/kunal-rathore-111/neptune/blob/main/packages/libs/src/index.ts"

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_client_app,node_client_pages,node_client_services,node_client_hooks,node_client_store,node_client_components toneBlue
class node_server_routes,node_server_middlewares,node_server_user_ctrl,node_server_content_ctrl,node_server_share_ctrl,node_server_ai_ctrl,node_server_services,node_server_libs toneAmber
class node_ai_routes,node_ai_controllers,node_ai_models toneMint
class node_pkg_validator,node_pkg_ui,node_pkg_icons,node_pkg_libs toneRose
class node_db_schema,node_db_client toneIndigo
```

## Components

### Web Client

React/Vite SPA for product UI

- [App Shell](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/App.tsx): spa entry · Client routing and top-level app composition · `apps/web/client/src/App.tsx`
- [Pages](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/Pages/Dashboard.tsx): route views · Landing, docs, auth, dashboard, profile, shared, and legal screens · `apps/web/client/src/Pages/Dashboard.tsx`
- [API Services](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/services/fetchDataService.ts): data access · Axios-backed feature services for auth, content, sharing, chat, and Magic Fill · `apps/web/client/src/services/fetchDataService.ts`
- [Query Hooks](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/hooks/react-query-hooks/useDashboardFetch.ts): state/data hooks · React Query-style hooks wrapping service calls and mutations · `apps/web/client/src/hooks/react-query-hooks/useDashboardFetch.ts`
- [UI Store](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/store/uiSlice.ts): redux slice · Local UI state such as layout and drawers · `apps/web/client/src/store/uiSlice.ts`
- [UI Components](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/client/src/components/dashboard/MainContentArea.tsx): feature components · Reusable page, dashboard, profile, landing, and legal components · `apps/web/client/src/components/dashboard/MainContentArea.tsx`

### Main API

Express application server and business logic

- [Routes](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/routes/indexRoute.ts): express routes · Request surface for sign-in, user, content, sharing, OTP, and AI · `apps/web/server/src/routes/indexRoute.ts`
- [Middlewares](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/middlewares/authMiddleware.ts): request pipeline · Auth, validation, rate limiting, request IDs, and error handling · `apps/web/server/src/middlewares/authMiddleware.ts`
- [User Ctrl](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/controllers/user/signController.ts): account controllers · Sign, account, email, OTP, and reset-password controllers · `apps/web/server/src/controllers/user/signController.ts`
- [Content Ctrl](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/controllers/content/contentController.ts): domain controller · Bookmark/content management entrypoint · `apps/web/server/src/controllers/content/contentController.ts`
- [Share Ctrl](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/controllers/share/contentShareController.ts): public access · Controllers for shared content and shared profiles · `apps/web/server/src/controllers/share/contentShareController.ts`
- [AI Ctrl](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/controllers/ai/aiController.ts): integration controller · Server-side gateway for chat, embeddings, and Magic Fill · `apps/web/server/src/controllers/ai/aiController.ts`
- [Services](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/services/content/contentService.ts): business logic · Content, embedding, share, and account service layer · `apps/web/server/src/services/content/contentService.ts`
- [Server Libs](https://github.com/kunal-rathore-111/neptune/blob/main/apps/web/server/src/libs/sessions.ts): support libs · Sessions, hashing, env config, and rate limiting · `apps/web/server/src/libs/sessions.ts`

### AI Service

Hono-based microservice for AI-assisted features

- [AI Routes](https://github.com/kunal-rathore-111/neptune/blob/main/apps/aiServer/src/routes/chat.ts): hono routes · Chat, embedding, and Magic Fill endpoints · `apps/aiServer/src/routes/chat.ts`
- [AI Controllers](https://github.com/kunal-rathore-111/neptune/blob/main/apps/aiServer/src/controller/chatController.ts): request handlers · Chat, embedding, and Magic Fill handlers · `apps/aiServer/src/controller/chatController.ts`
- [AI Models](https://github.com/kunal-rathore-111/neptune/blob/main/apps/aiServer/src/models/groqModels.ts): model/scrape logic · Embedding prompts, Groq integration, and URL content processing · `apps/aiServer/src/models/groqModels.ts`

### Shared Packages

Reusable code shared across runtimes

- [Validator](https://github.com/kunal-rathore-111/neptune/blob/main/packages/validator/src/index.ts): zod schemas · Shared Zod schemas for content, account, chat, and OTP validation · `packages/validator/src/index.ts`
- [UI Kit](https://github.com/kunal-rathore-111/neptune/blob/main/packages/ui/src/index.tsx): react library · Shared design-system components used by the client · `packages/ui/src/index.tsx`
- [Icons](https://github.com/kunal-rathore-111/neptune/blob/main/packages/icons/src/index.tsx): icon library · Shared icon set for navigation, content, auth, and actions · `packages/icons/src/index.tsx`
- [Shared Utils](https://github.com/kunal-rathore-111/neptune/blob/main/packages/libs/src/index.ts): helpers · Common categories and utility helpers · `packages/libs/src/index.ts`

### Data & Infra

Persistence and deployment surfaces

- [Schema](https://github.com/kunal-rathore-111/neptune/blob/main/packages/database/src/drizzle/schema.ts): drizzle schema · PostgreSQL tables and shared database schema · `packages/database/src/drizzle/schema.ts`
- [DB Client](https://github.com/kunal-rathore-111/neptune/blob/main/packages/database/src/drizzle/dbDrizzle.ts): drizzle client · Drizzle database connection and migration-backed access · `packages/database/src/drizzle/dbDrizzle.ts`

## Connections

- App Shell → Pages: renders · App shell routes into page-level views
- Pages → UI Components: composes · Pages are built from reusable feature components
- Pages → Query Hooks: reads data via · Pages rely on query hooks for server state
- Query Hooks → API Services: calls · Hooks wrap the service layer
- API Services → Routes: requests · Client services talk to the Express API
- UI Store → UI Components: drives · UI state influences layout and drawers
- UI Components → UI Kit: uses · Client components reuse shared UI primitives
- UI Components → Icons: uses · Client components reuse shared icons
- API Services → Validator: adheres to · Request payloads follow shared schemas
- Routes → Middlewares: passes through · Requests are filtered by validation and auth middleware
- Routes → User Ctrl: dispatches to · Auth and account routes map to user controllers
- Routes → Content Ctrl: dispatches to · Content routes map to content controllers
- Routes → Share Ctrl: dispatches to · Share routes expose public content/profile access
- Routes → AI Ctrl: dispatches to · AI-related actions route through the AI controller
- User Ctrl → Services: delegates · Controllers hand off persistence and auth work
- Content Ctrl → Services: delegates · Bookmark CRUD is implemented in services
- Share Ctrl → Services: delegates · Share links and public views use service logic
- AI Ctrl → Services: orchestrates · AI actions are coordinated from the server layer
- Services → DB Client: persists via · Business logic writes and reads through the database client
- DB Client → Schema: uses · Database access is grounded in the shared schema
- Services → Validator: validates with · Server enforces shared input and domain rules
- Middlewares → Server Libs: depends on · Middleware relies on sessions, hashing, limits, and env config
- AI Ctrl → AI Routes: calls service · Main API forwards AI work to the microservice
- AI Routes → AI Controllers: invokes · Routes connect to AI request handlers
- AI Controllers → AI Models: uses · Controllers rely on model, embedding, and scraping logic
- AI Models → Validator: shares schemas · AI request shapes align with shared validation
- AI Ctrl → AI Routes: forwards to · AI requests are routed out of the main API
- AI Models → Routes: responds to · AI results flow back through the main application
