# rishabhprasad-12/dhansetu architecture

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

- Interactive diagram: https://gitdiagram.com/rishabhprasad-12/dhansetu
- Repository: https://github.com/rishabhprasad-12/dhansetu

## Overview

1. **Repository shape**
   - This is a small monorepo with three distinct applications: a backend API in `backend/`, a public-facing React site in `frontend/`, and an authenticated trading dashboard in `dashboard/`.
   - The readme describes the product as a full-stack trading app with authentication, holdings, positions, and portfolio management.

2. **Backend as the central service boundary**
   - `backend/index.js` is the server entry point.
   - The backend exposes routes under three route groups: `AuthRoute`, `GetRoute`, and `PostRoute`, which suggests a REST-style API split by authentication and read/write operations.
   - This backend is the integration point used by both frontends.

3. **Backend layering**
   - The backend follows a controller/service/model structure:
     - **Controllers** handle request/response logic: `AuthController`, `GetController`, `PostController`, `OtpController`.
     - **Services** contain business logic: `HoldingsService`, `PositionService`.
     - **Models** represent persisted domain entities: `UserModel`, `OtpModel`, `OrdersModel`, `HoldingsModel`, `PositionsModel`.
   - This separation suggests the API is not a thin proxy; it owns validation, business rules, and state changes.

4. **Authentication and account verification flow**
   - Authentication is handled through `AuthController` and protected by `AuthMiddleware`.
   - OTP-based verification is explicit via `OtpController` and `OtpModel`, with `SendEmail` used to deliver the one-time code.
   - `SecretToken` indicates token generation/signing for authenticated sessions or API access.

5. **Trading-domain data flow**
   - `OrdersModel`, `HoldingsModel`, and `PositionsModel` show the core portfolio entities.
   - `HoldingsService` and `PositionService` likely derive or update dashboard-visible portfolio state from order activity and market data.
   - `PriceEngine` is a backend utility, so price calculation or valuation is centralized server-side rather than duplicated in the UI.

6. **Dashboard application: authenticated user workspace**
   - `dashboard/` is the trading interface for logged-in users.
   - Major UI areas include `Holdings`, `Positions`, `Orders`, `WatchList`, `Funds`, `Summary`, `TopBar`, and `Dashboard`.
   - Graph components (`DoughnutGraph`, `VerticalGraph`) indicate portfolio analytics and allocation visualization.

7. **Dashboard data access**
   - `dashboard/src/api/api.js` is the dashboard’s backend integration layer.
   - `GeneralContext.js` suggests shared client state across dashboard components, likely for user/session and portfolio data.
   - The dashboard is organized as a client-side application with reusable components rather than page-level server rendering.

8. **Public frontend: marketing and login entry point**
   - `frontend/` is a separate React app focused on the external website experience and onboarding.
   - It includes landing-page sections for home, about, products, pricing, signup, support, and account opening.
   - `Login.js` and `frontend/src/api/api.js` indicate this app also talks to the backend, but it is not the trading workspace itself.

9. **Functional split between frontend and dashboard**
   - The `frontend` app handles acquisition and onboarding: marketing content, signup flow, support, and login.
   - The `dashboard` app handles authenticated trading activity and portfolio management.
   - This is an important architectural boundary: one app for pre-login/public flows, another for post-login product usage.

10. **Backend utilities and supporting infrastructure**
   - `SendEmail` adds outbound email capability.
   - `PriceEngine` encapsulates valuation/pricing logic.
   - `public/` under the backend suggests static asset support, but the main architecture is still API-centric.

11. **Likely request lifecycle**
   - A user interacts first with the public `frontend` site, signs up or logs in, receives OTP/email verification if needed, then obtains authenticated access via token-based flow.
   - Authenticated requests from the `dashboard` go through `AuthMiddleware` and then into controllers/services/models for holdings, positions, and orders.
   - The UI consumes backend data through the client API wrappers in each React app.

12. **What to draw in an architecture diagram**
   - Show three top-level systems: public React frontend, authenticated React dashboard, and Node backend API.
   - Inside the backend, show route/controller/service/model layers plus OTP/email/token utilities and price engine.
   - Inside the dashboard, show the portfolio UI components and shared client state/API layer.
   - Treat data entities such as users, OTPs, orders, holdings, and positions as backend-owned domain objects.

Main entry points: [`dashboard/src/components/Dashboard.js`](https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/Dashboard.js) (Dashboard Shell), [`backend/routes`](https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/routes) (Routes), [`frontend/src/index.js`](https://github.com/rishabhprasad-12/dhansetu/blob/main/frontend/src/index.js) (Frontend App), [`dashboard/src/index.js`](https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/index.js) (Dashboard App)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_frontend["Public Frontend"]
  node_frontend_app["Frontend App<br/>react site<br/>[index.js]"]
  node_frontend_landing["Landing Pages<br/>marketing UI"]
  node_frontend_login["Login<br/>auth entry<br/>[Login.js]"]
  node_frontend_api["API Client<br/>client adapter<br/>[api.js]"]
end

subgraph group_group_dashboard["Trading Dashboard"]
  node_dashboard_app["Dashboard App<br/>react workspace<br/>[index.js]"]
  node_dashboard_shell["Dashboard Shell<br/>ui shell<br/>[Dashboard.js]"]
  node_dashboard_context["Shared State<br/>client state<br/>[GeneralContext.js]"]
  node_dashboard_api["API Client<br/>client adapter<br/>[api.js]"]
  node_dashboard_holdings["Holdings<br/>portfolio ui<br/>[Holdings.js]"]
  node_dashboard_positions["Positions<br/>portfolio ui<br/>[Positions.js]"]
  node_dashboard_orders["Orders<br/>trade ui<br/>[Orders.js]"]
  node_dashboard_watchlist["WatchList<br/>market ui<br/>[WatchList.js]"]
  node_dashboard_graphs["Analytics<br/>visualization"]
end

subgraph group_group_backend["Backend API"]
  node_backend_entry["Server Entry<br/>node api<br/>[index.js]"]
  node_backend_routes["Routes<br/>route layer"]
  node_backend_auth_controller["Auth Controller<br/>[AuthController.js]"]
  node_backend_otp_controller["OTP Controller<br/>[OtpController.js]"]
  node_backend_data_controllers["Data Controllers"]
  node_backend_middleware["Auth Middleware<br/>[AuthMiddleware.js]"]
  node_backend_services["Trading Services<br/>service layer"]
  node_backend_models[("Domain Models<br/>data models")]
  node_backend_util["Utilities"]
end

node_frontend_app -->|"renders"| node_frontend_landing
node_frontend_app -->|"entry"| node_frontend_login
node_frontend_app -->|"calls"| node_frontend_api
node_dashboard_app -->|"composes"| node_dashboard_shell
node_dashboard_app -->|"shares state"| node_dashboard_context
node_dashboard_app -->|"calls"| node_dashboard_api
node_dashboard_shell -->|"shows"| node_dashboard_holdings
node_dashboard_shell -->|"shows"| node_dashboard_positions
node_dashboard_shell -->|"shows"| node_dashboard_orders
node_dashboard_shell -->|"shows"| node_dashboard_watchlist
node_dashboard_shell -->|"shows"| node_dashboard_graphs
node_backend_entry -->|"mounts"| node_backend_routes
node_backend_routes -->|"dispatches"| node_backend_auth_controller
node_backend_routes -->|"dispatches"| node_backend_otp_controller
node_backend_routes -->|"dispatches"| node_backend_data_controllers
node_backend_data_controllers -->|"protects"| node_backend_middleware
node_backend_auth_controller -->|"uses"| node_backend_util
node_backend_otp_controller -->|"reads/writes"| node_backend_models
node_backend_data_controllers -->|"delegates"| node_backend_services
node_backend_services -->|"updates"| node_backend_models
node_backend_services -->|"uses"| node_backend_util
node_frontend_api -.->|"requests"| node_backend_routes
node_dashboard_api -.->|"requests"| node_backend_routes
node_dashboard_context -->|"orchestrates"| node_dashboard_api

click node_frontend_app "https://github.com/rishabhprasad-12/dhansetu/blob/main/frontend/src/index.js"
click node_frontend_landing "https://github.com/rishabhprasad-12/dhansetu/tree/main/frontend/src/landing-page"
click node_frontend_login "https://github.com/rishabhprasad-12/dhansetu/blob/main/frontend/src/Login.js"
click node_frontend_api "https://github.com/rishabhprasad-12/dhansetu/blob/main/frontend/src/api/api.js"
click node_dashboard_app "https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/index.js"
click node_dashboard_shell "https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/Dashboard.js"
click node_dashboard_context "https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/GeneralContext.js"
click node_dashboard_api "https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/api/api.js"
click node_dashboard_holdings "https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/Holdings.js"
click node_dashboard_positions "https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/Positions.js"
click node_dashboard_orders "https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/Orders.js"
click node_dashboard_watchlist "https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/WatchList.js"
click node_dashboard_graphs "https://github.com/rishabhprasad-12/dhansetu/tree/main/dashboard/src/components/Graphs"
click node_backend_entry "https://github.com/rishabhprasad-12/dhansetu/blob/main/backend/index.js"
click node_backend_routes "https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/routes"
click node_backend_auth_controller "https://github.com/rishabhprasad-12/dhansetu/blob/main/backend/controllers/AuthController.js"
click node_backend_otp_controller "https://github.com/rishabhprasad-12/dhansetu/blob/main/backend/controllers/OtpController.js"
click node_backend_data_controllers "https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/controllers"
click node_backend_middleware "https://github.com/rishabhprasad-12/dhansetu/blob/main/backend/middleware/AuthMiddleware.js"
click node_backend_services "https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/services"
click node_backend_models "https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/models"
click node_backend_util "https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/util"

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_frontend_app,node_frontend_landing,node_frontend_login,node_frontend_api toneBlue
class node_dashboard_app,node_dashboard_shell,node_dashboard_context,node_dashboard_api,node_dashboard_holdings,node_dashboard_positions,node_dashboard_orders,node_dashboard_watchlist,node_dashboard_graphs toneAmber
class node_backend_entry,node_backend_routes,node_backend_auth_controller,node_backend_otp_controller,node_backend_data_controllers,node_backend_middleware,node_backend_services,node_backend_models,node_backend_util toneMint
```

## Components

### Public Frontend

Marketing and onboarding React app.

- [Frontend App](https://github.com/rishabhprasad-12/dhansetu/blob/main/frontend/src/index.js): react site · Public-facing acquisition and onboarding app. · `frontend/src/index.js`
- [Landing Pages](https://github.com/rishabhprasad-12/dhansetu/tree/main/frontend/src/landing-page): marketing UI · Home, about, products, pricing, signup, and support flows. · `frontend/src/landing-page`
- [Login](https://github.com/rishabhprasad-12/dhansetu/blob/main/frontend/src/Login.js): auth entry · Login and sign-in entry point for public users. · `frontend/src/Login.js`
- [API Client](https://github.com/rishabhprasad-12/dhansetu/blob/main/frontend/src/api/api.js): client adapter · Frontend wrapper for backend requests. · `frontend/src/api/api.js`

### Trading Dashboard

Authenticated React workspace for portfolio management.

- [Dashboard App](https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/index.js): react workspace · Authenticated trading interface for logged-in users. · `dashboard/src/index.js`
- [Dashboard Shell](https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/Dashboard.js): ui shell · Top-level dashboard composition and navigation. · `dashboard/src/components/Dashboard.js`
- [Shared State](https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/GeneralContext.js): client state · Shared dashboard context for user and portfolio data. · `dashboard/src/components/GeneralContext.js`
- [API Client](https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/api/api.js): client adapter · Dashboard wrapper for backend requests. · `dashboard/src/api/api.js`
- [Holdings](https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/Holdings.js): portfolio ui · Displays owned instruments and allocation details. · `dashboard/src/components/Holdings.js`
- [Positions](https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/Positions.js): portfolio ui · Shows active positions and exposure. · `dashboard/src/components/Positions.js`
- [Orders](https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/Orders.js): trade ui · Order activity and trading history view. · `dashboard/src/components/Orders.js`
- [WatchList](https://github.com/rishabhprasad-12/dhansetu/blob/main/dashboard/src/components/WatchList.js): market ui · Tracked symbols and market watch area. · `dashboard/src/components/WatchList.js`
- [Analytics](https://github.com/rishabhprasad-12/dhansetu/tree/main/dashboard/src/components/Graphs): visualization · Portfolio charts and allocation graphs. · `dashboard/src/components/Graphs`

### Backend API

Node service boundary for auth, trading data, and persistence.

- [Server Entry](https://github.com/rishabhprasad-12/dhansetu/blob/main/backend/index.js): node api · Backend process bootstrap and app wiring. · `backend/index.js`
- [Routes](https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/routes): route layer · REST-style route groups for auth, reads, and writes. · `backend/routes`
- [Auth Controller](https://github.com/rishabhprasad-12/dhansetu/blob/main/backend/controllers/AuthController.js): controller · Authentication request handling and session setup. · `backend/controllers/AuthController.js`
- [OTP Controller](https://github.com/rishabhprasad-12/dhansetu/blob/main/backend/controllers/OtpController.js): controller · One-time password verification flow. · `backend/controllers/OtpController.js`
- [Data Controllers](https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/controllers): controller · Read and write request handlers for portfolio APIs. · `backend/controllers`
- [Auth Middleware](https://github.com/rishabhprasad-12/dhansetu/blob/main/backend/middleware/AuthMiddleware.js): middleware · Protects authenticated backend routes. · `backend/middleware/AuthMiddleware.js`
- [Trading Services](https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/services): service layer · Business logic for holdings and positions. · `backend/services`
- [Domain Models](https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/models): data models · Persisted user, OTP, order, holding, and position entities. · `backend/models`
- [Utilities](https://github.com/rishabhprasad-12/dhansetu/tree/main/backend/util): support utilities · Token, email, and price calculation helpers. · `backend/util`

## Connections

- Frontend App → Landing Pages: renders · Public site is organized into landing-page sections.
- Frontend App → Login: entry · Login is part of the public onboarding flow.
- Frontend App → API Client: calls · Public app uses the backend client wrapper.
- Dashboard App → Dashboard Shell: composes · Dashboard entry mounts the main workspace shell.
- Dashboard App → Shared State: shares state · Context provides common client state across components.
- Dashboard App → API Client: calls · Dashboard data access goes through its API layer.
- Dashboard Shell → Holdings: shows · Shell includes holdings view.
- Dashboard Shell → Positions: shows · Shell includes positions view.
- Dashboard Shell → Orders: shows · Shell includes orders view.
- Dashboard Shell → WatchList: shows · Shell includes watchlist view.
- Dashboard Shell → Analytics: shows · Shell includes analytics charts.
- Server Entry → Routes: mounts · Server entry wires route groups into the app.
- Routes → Auth Controller: dispatches · Auth route group forwards to auth controller.
- Routes → OTP Controller: dispatches · OTP-related routes forward to OTP controller.
- Routes → Data Controllers: dispatches · Read/write route groups forward to data controllers.
- Data Controllers → Auth Middleware: protects · Authenticated endpoints are guarded by middleware.
- Auth Controller → Utilities: uses · Authentication uses token and email helpers.
- OTP Controller → Domain Models: reads/writes · OTP verification persists to domain storage.
- Data Controllers → Trading Services: delegates · Controllers hand business logic to services.
- Trading Services → Domain Models: updates · Services derive and persist trading state.
- Trading Services → Utilities: uses · Pricing and valuation helpers support portfolio logic.
- API Client → Routes: requests · Public frontend sends auth and onboarding requests to backend APIs.
- API Client → Routes: requests · Dashboard fetches portfolio and trading data from backend APIs.
- Shared State → API Client: orchestrates · Shared state coordinates API-driven dashboard data.
