# apna-college/zerodha-clone architecture

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

- Interactive diagram: https://gitdiagram.com/apna-college/zerodha-clone
- Repository: https://github.com/apna-college/zerodha-clone

## Overview

1. This repository is a three-part frontend/backoffice setup plus a small API backend. Each top-level folder is its own app with its own `package.json`, so the likely deployment boundary is:
   - `backend`: server and persistence layer
   - `dashboard`: trading/portfolio console
   - `frontend`: public marketing site and onboarding pages

2. The `backend` folder is the data service for trading entities. Its domain is split into three objects:
   - `Holdings`
   - `Orders`
   - `Positions`
   The `model/` and `schemas/` pairs strongly suggest a document database layer with separate persistence definitions for each entity.

3. The backend’s architecture is domain-centric rather than feature-centric: holdings, orders, and positions are modeled separately, which matches the typical trading lifecycle:
   - orders are created first
   - filled orders affect positions
   - holdings reflect current portfolio state

4. `backend/index.js` is the server entry point and likely exposes the API consumed by the dashboard. The `.env` file indicates runtime configuration is externalized, which usually means database connection details and server settings are injected at startup.

5. The `dashboard` app is the operational UI for portfolio management. Its component set shows the main screens and widgets:
   - portfolio summary
   - holdings table
   - open positions
   - orders list
   - funds view
   - watchlist
   - top bar and side menu navigation
   - buy action modal/window

6. The dashboard also contains charting/analytics components:
   - `DoughnoutChart.js`
   - `VerticalGraph.js`
   These imply the UI is not just tabular; it also visualizes portfolio allocation and performance metrics.

7. `dashboard/src/components/GeneralContext.js` indicates shared client-side state is centralized, probably to coordinate watchlist, selected instrument, order entry, and portfolio data across multiple panels. That makes the dashboard a stateful single-page app rather than a set of isolated pages.

8. `dashboard/src/data/data.js` suggests some UI data is static or mocked locally, likely for watchlists or demo analytics. So the dashboard probably mixes backend-fetched account data with local reference data for UI rendering.

9. The `frontend` app is separate from the dashboard and reads like the public-facing website. It contains route/grouped sections for:
   - home
   - about
   - products
   - pricing
   - support
   - signup
   - open account
   This is a marketing and acquisition surface, not the trading console.

10. The frontend is organized by page-level folders with reusable subcomponents such as hero sections, navbar, footer, team, stats, education, brokerage, universe, and ticket creation. That structure indicates a content-heavy site with multiple landing pages and a small amount of interactive onboarding.

11. There is no visible shared code package between `frontend` and `dashboard`; they appear to be independently built React apps. Architecturally, that means the public site and the trading console can evolve and deploy separately, while sharing only the product/domain concept, not implementation code.

12. A good diagram for this repo would show:
   - users entering through the `frontend` marketing site
   - users moving into the `dashboard` trading app for account activity
   - the `dashboard` calling the `backend` API for holdings/orders/positions data
   - the backend persisting those entities in a database-backed model layer

13. The main architectural boundary is therefore between presentation and domain data:
   - `frontend` = acquisition/onboarding content
   - `dashboard` = authenticated operational UI
   - `backend` = trading/account API and persistence
   This separation is the key thing to preserve when drawing the system.

Main entry points: [`dashboard/src/components/Dashboard.js`](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Dashboard.js) (Dashboard shell), [`frontend/src/landing_page/Navbar.js`](https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/Navbar.js) (Site shell), [`backend/index.js`](https://github.com/apna-college/zerodha-clone/blob/main/backend/index.js) (API server), [`backend/model/PositionsModel.js`](https://github.com/apna-college/zerodha-clone/blob/main/backend/model/PositionsModel.js) (Positions model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_frontend["frontend"]
  node_frontend_app["Frontend app<br/>React SPA<br/>[index.js]"]
  node_frontend_home["Home page<br/>Landing pages<br/>[HomePage.js]"]
  node_frontend_products["Products<br/>Product pages<br/>[ProductsPage.js]"]
  node_frontend_pricing["Pricing<br/>[PricingPage.js]"]
  node_frontend_support["Support<br/>[SupportPage.js]"]
  node_frontend_signup["Signup<br/>Onboarding<br/>[Signup.js]"]
  node_frontend_shell["Site shell<br/>Layout<br/>[Navbar.js]"]
end

subgraph group_grp_dashboard["dashboard"]
  node_dashboard_app["Dashboard app<br/>React SPA<br/>[index.js]"]
  node_dashboard_shell["Dashboard shell<br/>Layout<br/>[Dashboard.js]"]
  node_dashboard_context(("Shared state<br/>Client state<br/>[GeneralContext.js]"))
  node_dashboard_summary["Summary<br/>Portfolio overview<br/>[Summary.js]"]
  node_dashboard_holdings["Holdings<br/>Portfolio table<br/>[Holdings.js]"]
  node_dashboard_positions["Positions<br/>Trading table<br/>[Positions.js]"]
  node_dashboard_orders["Orders<br/>Order book<br/>[Orders.js]"]
  node_dashboard_funds["Funds<br/>[Funds.js]"]
  node_dashboard_watchlist["Watchlist<br/>Market watch<br/>[WatchList.js]"]
  node_dashboard_trade["Buy ticket<br/>Trade modal<br/>[BuyActionWindow.js]"]
  node_dashboard_charts["Charts<br/>Analytics widgets<br/>[DoughnoutChart.js]"]
end

subgraph group_grp_backend["backend"]
  node_backend_api["API server<br/>Node server<br/>[index.js]"]
  node_backend_holdings[("Holdings model<br/>Persistence model<br/>[HoldingsModel.js]")]
  node_backend_orders[("Orders model<br/>Persistence model<br/>[OrdersModel.js]")]
  node_backend_positions[("Positions model<br/>Persistence model<br/>[PositionsModel.js]")]
  node_backend_holdings_schema["Holdings schema<br/>Schema definition<br/>[HoldingsSchema.js]"]
  node_backend_orders_schema["Orders schema<br/>Schema definition<br/>[OrdersSchema.js]"]
  node_backend_positions_schema["Positions schema<br/>Schema definition<br/>[PositionsSchema.js]"]
end

node_frontend_app -->|"renders"| node_frontend_shell
node_frontend_shell -->|"routes to"| node_frontend_home
node_frontend_shell -->|"routes to"| node_frontend_products
node_frontend_shell -->|"routes to"| node_frontend_pricing
node_frontend_shell -->|"routes to"| node_frontend_support
node_frontend_shell -->|"routes to"| node_frontend_signup
node_dashboard_app -->|"renders"| node_dashboard_shell
node_dashboard_shell -->|"shares state"| node_dashboard_context
node_dashboard_shell -->|"shows"| node_dashboard_summary
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_funds
node_dashboard_shell -->|"shows"| node_dashboard_watchlist
node_dashboard_shell -->|"opens"| node_dashboard_trade
node_dashboard_shell -->|"visualizes"| node_dashboard_charts
node_dashboard_app -->|"consumes"| node_backend_api
node_backend_api -->|"serves"| node_backend_holdings
node_backend_api -->|"serves"| node_backend_orders
node_backend_api -->|"serves"| node_backend_positions
node_backend_holdings -->|"defined by"| node_backend_holdings_schema
node_backend_orders -->|"defined by"| node_backend_orders_schema
node_backend_positions -->|"defined by"| node_backend_positions_schema
node_backend_orders -.->|"affects"| node_backend_positions
node_backend_positions -.->|"rolls up"| node_backend_holdings

click node_frontend_app "https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/index.js"
click node_frontend_home "https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/home/HomePage.js"
click node_frontend_products "https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/products/ProductsPage.js"
click node_frontend_pricing "https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/pricing/PricingPage.js"
click node_frontend_support "https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/support/SupportPage.js"
click node_frontend_signup "https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/signup/Signup.js"
click node_frontend_shell "https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/Navbar.js"
click node_dashboard_app "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/index.js"
click node_dashboard_shell "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Dashboard.js"
click node_dashboard_context "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/GeneralContext.js"
click node_dashboard_summary "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Summary.js"
click node_dashboard_holdings "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Holdings.js"
click node_dashboard_positions "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Positions.js"
click node_dashboard_orders "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Orders.js"
click node_dashboard_funds "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Funds.js"
click node_dashboard_watchlist "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/WatchList.js"
click node_dashboard_trade "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/BuyActionWindow.js"
click node_dashboard_charts "https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/DoughnoutChart.js"
click node_backend_api "https://github.com/apna-college/zerodha-clone/blob/main/backend/index.js"
click node_backend_holdings "https://github.com/apna-college/zerodha-clone/blob/main/backend/model/HoldingsModel.js"
click node_backend_orders "https://github.com/apna-college/zerodha-clone/blob/main/backend/model/OrdersModel.js"
click node_backend_positions "https://github.com/apna-college/zerodha-clone/blob/main/backend/model/PositionsModel.js"
click node_backend_holdings_schema "https://github.com/apna-college/zerodha-clone/blob/main/backend/schemas/HoldingsSchema.js"
click node_backend_orders_schema "https://github.com/apna-college/zerodha-clone/blob/main/backend/schemas/OrdersSchema.js"
click node_backend_positions_schema "https://github.com/apna-college/zerodha-clone/blob/main/backend/schemas/PositionsSchema.js"

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_home,node_frontend_products,node_frontend_pricing,node_frontend_support,node_frontend_signup,node_frontend_shell toneBlue
class node_dashboard_app,node_dashboard_shell,node_dashboard_context,node_dashboard_summary,node_dashboard_holdings,node_dashboard_positions,node_dashboard_orders,node_dashboard_funds,node_dashboard_watchlist,node_dashboard_trade,node_dashboard_charts toneAmber
class node_backend_api,node_backend_holdings,node_backend_orders,node_backend_positions,node_backend_holdings_schema,node_backend_orders_schema,node_backend_positions_schema toneMint
```

## Components

### frontend

Public marketing and onboarding app

- [Frontend app](https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/index.js): React SPA · Public site for acquisition and onboarding · `frontend/src/index.js`
- [Home page](https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/home/HomePage.js): Landing pages · Main marketing entry with hero, stats, education, and pricing · `frontend/src/landing_page/home/HomePage.js`
- [Products](https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/products/ProductsPage.js): Product pages · Product overview and universe exploration pages · `frontend/src/landing_page/products/ProductsPage.js`
- [Pricing](https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/pricing/PricingPage.js): Pricing pages · Pricing and brokerage information pages · `frontend/src/landing_page/pricing/PricingPage.js`
- [Support](https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/support/SupportPage.js): Support pages · Help and ticket creation pages · `frontend/src/landing_page/support/SupportPage.js`
- [Signup](https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/signup/Signup.js): Onboarding · Account creation entry point · `frontend/src/landing_page/signup/Signup.js`
- [Site shell](https://github.com/apna-college/zerodha-clone/blob/main/frontend/src/landing_page/Navbar.js): Layout · Shared navbar and footer framing the public site · `frontend/src/landing_page/Navbar.js`

### dashboard

Operational trading console

- [Dashboard app](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/index.js): React SPA · Authenticated trading and portfolio console · `dashboard/src/index.js`
- [Dashboard shell](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Dashboard.js): Layout · Top bar, side menu, and main app composition · `dashboard/src/components/Dashboard.js`
- [Shared state](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/GeneralContext.js): Client state · Centralized app state for panels and actions · `dashboard/src/components/GeneralContext.js`
- [Summary](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Summary.js): Portfolio overview · Account snapshot and portfolio summary · `dashboard/src/components/Summary.js`
- [Holdings](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Holdings.js): Portfolio table · Current holdings view · `dashboard/src/components/Holdings.js`
- [Positions](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Positions.js): Trading table · Open positions view · `dashboard/src/components/Positions.js`
- [Orders](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Orders.js): Order book · Orders list and order status view · `dashboard/src/components/Orders.js`
- [Funds](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/Funds.js): Account funds · Funding and balance panel · `dashboard/src/components/Funds.js`
- [Watchlist](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/WatchList.js): Market watch · Instrument watchlist and quick access · `dashboard/src/components/WatchList.js`
- [Buy ticket](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/BuyActionWindow.js): Trade modal · Buy action window for order entry · `dashboard/src/components/BuyActionWindow.js`
- [Charts](https://github.com/apna-college/zerodha-clone/blob/main/dashboard/src/components/DoughnoutChart.js): Analytics widgets · Allocation and performance visualizations · `dashboard/src/components/DoughnoutChart.js`

### backend

Trading API and persistence layer

- [API server](https://github.com/apna-college/zerodha-clone/blob/main/backend/index.js): Node server · Backend entry point serving trading data · `backend/index.js`
- [Holdings model](https://github.com/apna-college/zerodha-clone/blob/main/backend/model/HoldingsModel.js): Persistence model · Document model for holdings · `backend/model/HoldingsModel.js`
- [Orders model](https://github.com/apna-college/zerodha-clone/blob/main/backend/model/OrdersModel.js): Persistence model · Document model for orders · `backend/model/OrdersModel.js`
- [Positions model](https://github.com/apna-college/zerodha-clone/blob/main/backend/model/PositionsModel.js): Persistence model · Document model for positions · `backend/model/PositionsModel.js`
- [Holdings schema](https://github.com/apna-college/zerodha-clone/blob/main/backend/schemas/HoldingsSchema.js): Schema definition · Schema for holdings documents · `backend/schemas/HoldingsSchema.js`
- [Orders schema](https://github.com/apna-college/zerodha-clone/blob/main/backend/schemas/OrdersSchema.js): Schema definition · Schema for order documents · `backend/schemas/OrdersSchema.js`
- [Positions schema](https://github.com/apna-college/zerodha-clone/blob/main/backend/schemas/PositionsSchema.js): Schema definition · Schema for position documents · `backend/schemas/PositionsSchema.js`

## Connections

- Frontend app → Site shell: renders · Public app uses shared site layout
- Site shell → Home page: routes to · Primary landing experience
- Site shell → Products: routes to · Product discovery pages
- Site shell → Pricing: routes to · Pricing information pages
- Site shell → Support: routes to · Support and help pages
- Site shell → Signup: routes to · Account creation entry
- Dashboard app → Dashboard shell: renders · Dashboard app composition
- Dashboard shell → Shared state: shares state · Central app state for panels and actions
- Dashboard shell → Summary: shows · Portfolio overview panel
- Dashboard shell → Holdings: shows · Holdings panel
- Dashboard shell → Positions: shows · Positions panel
- Dashboard shell → Orders: shows · Orders panel
- Dashboard shell → Funds: shows · Funds panel
- Dashboard shell → Watchlist: shows · Watchlist panel
- Dashboard shell → Buy ticket: opens · Buy order entry modal
- Dashboard shell → Charts: visualizes · Portfolio charts and analytics
- Dashboard app → API server: consumes · Dashboard fetches trading/account data
- API server → Holdings model: serves · Holdings domain data
- API server → Orders model: serves · Orders domain data
- API server → Positions model: serves · Positions domain data
- Holdings model → Holdings schema: defined by · Holdings persistence schema
- Orders model → Orders schema: defined by · Orders persistence schema
- Positions model → Positions schema: defined by · Positions persistence schema
- Orders model → Positions model: affects · Filled orders update positions
- Positions model → Holdings model: rolls up · Positions contribute to current holdings state
