# dheerajok/digital-portfolio architecture

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

- Interactive diagram: https://gitdiagram.com/dheerajok/digital-portfolio
- Repository: https://github.com/dheerajok/digital-portfolio

## Overview

1. **Top-level shape**
   - This is a **Next.js App Router** project with a mix of public marketing pages, authenticated dashboard pages, tenant-specific portfolio pages, and a sizeable API layer.
   - The architecture is centered around a **portfolio SaaS**: users create/edit a portfolio in a dashboard, store it in MongoDB, and publish it under a username/custom link.

2. **Public marketing and acquisition layer**
   - `app/page.js` plus pages like `app/pricing`, `app/about`, `app/support`, `app/terms`, `app/privacy`, and the blog/guide-style routes (`how-to-create-portfolio-2025`, `how-to-make-video-editor-portfolio`, `online-portfolio-maker`, `portfolio-website-builder`, etc.) form the **public funnel**.
   - Reusable landing-page UI lives in `app/components/home` and shared UI primitives in `components/ui`.

3. **Authenticated app shell and session boundary**
   - `app/layout.js`, `app/contexts/SessionContext.js`, `app/contexts/UserContext.js`, and `app/components/SessionWrapper.js` indicate a client/server session boundary around logged-in experiences.
   - `middleware.js` likely protects routes or handles redirects/auth gating for dashboard and user-specific areas.

4. **Dashboard subsystem**
   - `app/dashboard` is the product workspace: overview, analytics, edit portfolio, referrals, and settings.
   - `Sidebar`, `TopNavbar`, and the section components suggest a **single authenticated shell** that swaps feature panels rather than separate standalone apps.

5. **Portfolio builder/editor subsystem**
   - The core product logic is in `app/dashboard/components/edit-portfolio`.
   - There are two main editing tracks: **freelancer portfolios** and **video editor portfolios**, each with its own editor component, step flow, and form fields.
   - The multi-step forms in `forms/*` and `steps/*` imply a guided wizard that collects structured content, then persists it to the backend.

6. **Template rendering subsystem**
   - Public portfolio pages are rendered from template sets under `app/[username]/templates`.
   - There are distinct template families for different portfolio types and styles:
     - freelancer-oriented templates
     - video editor templates
     - text/template descriptors for categories like marketing, designers, and linktree
     - one named template set under `dheerajok`
   - This suggests a **content-model-to-template mapping** where the stored portfolio data drives which frontend composition is shown.

7. **Tenant/public portfolio routes**
   - `app/[username]/page.js` is the key dynamic route for a user’s public portfolio.
   - `app/[username]/websites/page.js` appears to support a portfolio sub-section or listing page.
   - `NotPublic.jsx`, `Freelancer.jsx`, `VideoEditor.jsx`, and analytics helper code in the same folder indicate the public route may branch based on visibility and portfolio type.

8. **Backend API layer**
   - The app exposes many route handlers under `app/api`, organized by domain:
     - portfolio CRUD and lookup
     - video-editor-portfolio
     - analytics tracking and batch tracking
     - form submission
     - image upload/delete
     - auth via NextAuth
     - AI generation/quota
     - Razorpay payment/order verification
     - referral registration, validation, dashboard, withdrawal
     - admin cleanup/export
   - This API layer is the central boundary between the dashboard/public UI and persistence/external services.

9. **Data and persistence model**
   - MongoDB is the primary datastore, via `app/db/mongodb.js`.
   - Mongoose-style models in `app/model` define the main entities:
     - `User`
     - `Portfolio`
     - `VideoEditorPortfolio`
     - `AnalyticsSchema`
     - `ImageModel`
   - The architecture is data-driven: portfolio content, analytics events, images, and user records are stored separately and served through API routes.

10. **Analytics and behavioral tracking**
   - Analytics is first-class, with dedicated routes under `app/api/analytics/[username]` and `app/api/track-batch`.
   - The dashboard has an `Analytics` section, and the public portfolios likely emit view/event data back to the backend for aggregation.
   - `app/model/AnalyticsSchema.js` indicates event storage is part of the core domain, not an add-on.

11. **AI-assisted content generation**
   - `app/api/ai/generate-text` and `app/api/ai/quota` support text generation inside the editor flow.
   - `app/dashboard/hooks/useAIGenerator.js` and AI-specific form fields show AI is integrated directly into the portfolio creation experience, with quota enforcement as a backend concern.

12. **Payments, billing, and monetization**
   - `app/api/razorpay/create-order` and `app/api/razorpay/verify-payment` show a payment flow backed by Razorpay.
   - The presence of `app/payment/page.js` and `app/api/admin/cleanup-unpaid` suggests purchase state matters for access or provisioning.
   - Pricing and payment are tightly coupled to dashboard actions rather than being a standalone checkout app.

13. **Referral and growth loop**
   - `app/api/referral/register`, `validate-code`, `dashboard`, and `withdraw` indicate a referral system with account-level tracking and payout/withdrawal logic.
   - The dashboard includes a dedicated `Refer` section, so referrals are a product feature integrated with user identity and monetization.

14. **File/media handling**
   - `upload-image` and `delete-image` APIs, plus `app/model/ImageModel.js`, define a media storage workflow separate from portfolio documents.
   - This implies portfolio entries reference uploaded assets rather than embedding raw files in the main portfolio records.

15. **Build/runtime and deployment boundaries**
   - The repo uses standard Next.js/Vercel conventions: `vercel.json`, `next.config.mjs`, `sitemap.js`, `robots.js`, `tailwind.config.mjs`, and app-level CSS.
   - Overall the system is a **single Next.js deployment** with server routes, client components, and MongoDB-backed state, rather than a multi-service architecture.

16. **How data moves through the system**
   - A user signs in, creates or edits a portfolio in the dashboard, optionally uses AI/image upload/payment/referral features, and the client submits data through API routes.
   - The backend stores structured records in MongoDB, then the public dynamic route under `app/[username]` reads that data and renders the appropriate template.
   - Analytics and monetization flows run alongside this core loop, feeding back into dashboard views and admin endpoints.

Main entry points: [`app/dashboard/page.js`](https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/page.js) (Dashboard), [`app/db/mongodb.js`](https://github.com/dheerajok/digital-portfolio/blob/main/app/db/mongodb.js) (MongoDB), [`app/page.js`](https://github.com/dheerajok/digital-portfolio/blob/main/app/page.js) (Home), [`app/[username]/page.js`](https://github.com/dheerajok/digital-portfolio/blob/main/app/[username]/page.js) (Tenant page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public funnel"]
  node_landing["Home<br/>page<br/>[page.js]"]
  node_marketing_ui["Hero UI<br/>marketing component<br/>[HeroSection.jsx]"]
  node_pricing_page["Pricing<br/>public page<br/>[page.js]"]
  node_guide_page["Guides<br/>content page<br/>[page.js]"]
  node_template_gallery["Templates<br/>catalog page<br/>[page.js]"]
end

subgraph group_dashboard["Dashboard app"]
  node_dashboard_home["Dashboard<br/>workspace page<br/>[page.js]"]
  node_workspace_panels["Panels<br/>dashboard sections<br/>[Overview.jsx]"]
  node_editor_shell["Editor<br/>[EditPortfolio.jsx]"]
  node_freelancer_editor["Freelancer edit<br/>wizard editor"]
  node_video_editor["Video edit<br/>wizard editor"]
end

subgraph group_portfolio["Portfolio runtime"]
  node_dynamic_portfolio["Tenant page<br/>dynamic route<br/>[page.js]"]
  node_portfolio_view["Freelancer view<br/>public renderer<br/>[Freelancer.jsx]"]
  node_video_view["Video view<br/>public renderer<br/>[VideoEditor.jsx]"]
  node_visibility_gate["Not public<br/>access gate<br/>[NotPublic.jsx]"]
  node_template_packs["Templates pack<br/>render templates"]
end

subgraph group_api["API boundary"]
  node_auth_route["Auth<br/>[route.js]"]
  node_portfolio_api["Portfolio API<br/>crud route<br/>[route.js]"]
  node_video_api["Video API<br/>crud route<br/>[route.js]"]
  node_analytics_api["Analytics API<br/>tracking route<br/>[route.js]"]
  node_media_api["Media API<br/>upload route<br/>[route.js]"]
  node_ai_api["AI API<br/>generation route<br/>[route.js]"]
  node_payments_api["Payments API<br/>billing route<br/>[route.js]"]
  node_referral_api["Referral API<br/>growth route<br/>[route.js]"]
end

subgraph group_data["Data layer"]
  node_db[("MongoDB<br/>database connection<br/>[mongodb.js]")]
  node_models["Models<br/>[Portfolio.js]"]
  node_analytics_model["Analytics model<br/>event schema<br/>[AnalyticsSchema.js]"]
end

subgraph group_shared["Shared infra"]
  node_session_shell["Session<br/>app shell<br/>[SessionWrapper.js]"]
  node_ai_hook["AI hook<br/>client hook<br/>[useAIGenerator.js]"]
end

node_landing -->|"uses"| node_marketing_ui
node_landing -->|"links"| node_pricing_page
node_landing -->|"acquires"| node_guide_page
node_landing -->|"shows"| node_template_gallery
node_session_shell -->|"wraps"| node_dashboard_home
node_auth_route -->|"issues"| node_session_shell
node_dashboard_home -->|"switches"| node_workspace_panels
node_dashboard_home -->|"opens"| node_editor_shell
node_editor_shell -->|"loads"| node_freelancer_editor
node_editor_shell -->|"loads"| node_video_editor
node_editor_shell -->|"uses"| node_ai_hook
node_dynamic_portfolio -->|"renders"| node_portfolio_view
node_dynamic_portfolio -->|"renders"| node_video_view
node_dynamic_portfolio -->|"falls back"| node_visibility_gate
node_dynamic_portfolio -->|"maps to"| node_template_packs
node_portfolio_view -->|"reads"| node_portfolio_api
node_video_view -->|"reads"| node_video_api
node_portfolio_api -->|"persists"| node_db
node_video_api -->|"persists"| node_db
node_analytics_api -->|"writes"| node_analytics_model
node_analytics_api -->|"stores"| node_db
node_media_api -->|"stores"| node_db
node_ai_api -->|"checks quota"| node_db
node_payments_api -->|"records"| node_db
node_referral_api -->|"updates"| node_db
node_models -->|"uses"| node_db
node_dashboard_home -->|"edits via"| node_portfolio_api
node_dashboard_home -->|"edits via"| node_video_api
node_dashboard_home -->|"inspects"| node_analytics_api
node_dashboard_home -->|"manages"| node_referral_api
node_dashboard_home -->|"pays"| node_payments_api

click node_landing "https://github.com/dheerajok/digital-portfolio/blob/main/app/page.js"
click node_marketing_ui "https://github.com/dheerajok/digital-portfolio/blob/main/app/components/home/HeroSection.jsx"
click node_pricing_page "https://github.com/dheerajok/digital-portfolio/blob/main/app/pricing/page.js"
click node_guide_page "https://github.com/dheerajok/digital-portfolio/blob/main/app/how-to-create-portfolio-2025/page.js"
click node_template_gallery "https://github.com/dheerajok/digital-portfolio/blob/main/app/templates/page.js"
click node_session_shell "https://github.com/dheerajok/digital-portfolio/blob/main/app/components/SessionWrapper.js"
click node_auth_route "https://github.com/dheerajok/digital-portfolio/blob/main/app/api/auth/[...nextauth]/route.js"
click node_dashboard_home "https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/page.js"
click node_workspace_panels "https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/components/Overview.jsx"
click node_editor_shell "https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/components/EditPortfolio.jsx"
click node_freelancer_editor "https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/components/edit-portfolio/EditFreelancerPortfolio.jsx"
click node_video_editor "https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/components/edit-portfolio/EditVideoEditorPortfolio.jsx"
click node_ai_hook "https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/hooks/useAIGenerator.js"
click node_dynamic_portfolio "https://github.com/dheerajok/digital-portfolio/blob/main/app/[username]/page.js"
click node_portfolio_view "https://github.com/dheerajok/digital-portfolio/blob/main/app/[username]/Freelancer.jsx"
click node_video_view "https://github.com/dheerajok/digital-portfolio/blob/main/app/[username]/VideoEditor.jsx"
click node_visibility_gate "https://github.com/dheerajok/digital-portfolio/blob/main/app/[username]/NotPublic.jsx"
click node_portfolio_api "https://github.com/dheerajok/digital-portfolio/blob/main/app/api/portfolio/route.js"
click node_video_api "https://github.com/dheerajok/digital-portfolio/blob/main/app/api/video-editor-portfolio/route.js"
click node_analytics_api "https://github.com/dheerajok/digital-portfolio/blob/main/app/api/analytics/[username]/route.js"
click node_media_api "https://github.com/dheerajok/digital-portfolio/blob/main/app/api/upload-image/route.js"
click node_ai_api "https://github.com/dheerajok/digital-portfolio/blob/main/app/api/ai/generate-text/route.js"
click node_payments_api "https://github.com/dheerajok/digital-portfolio/blob/main/app/api/razorpay/create-order/route.js"
click node_referral_api "https://github.com/dheerajok/digital-portfolio/blob/main/app/api/referral/register/route.js"
click node_db "https://github.com/dheerajok/digital-portfolio/blob/main/app/db/mongodb.js"
click node_models "https://github.com/dheerajok/digital-portfolio/blob/main/app/model/Portfolio.js"
click node_analytics_model "https://github.com/dheerajok/digital-portfolio/blob/main/app/model/AnalyticsSchema.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_landing,node_marketing_ui,node_pricing_page,node_guide_page,node_template_gallery toneBlue
class node_dashboard_home,node_workspace_panels,node_editor_shell,node_freelancer_editor,node_video_editor toneAmber
class node_dynamic_portfolio,node_portfolio_view,node_video_view,node_visibility_gate,node_template_packs toneMint
class node_auth_route,node_portfolio_api,node_video_api,node_analytics_api,node_media_api,node_ai_api,node_payments_api,node_referral_api toneRose
class node_db,node_models,node_analytics_model toneIndigo
class node_session_shell,node_ai_hook toneTeal
```

## Components

### Public funnel

Marketing pages, guides, and public portfolio rendering.

- [Home](https://github.com/dheerajok/digital-portfolio/blob/main/app/page.js): page · Top-level marketing entry page. · `app/page.js`
- [Hero UI](https://github.com/dheerajok/digital-portfolio/blob/main/app/components/home/HeroSection.jsx): marketing component · Reusable public landing-page sections. · `app/components/home/HeroSection.jsx`
- [Pricing](https://github.com/dheerajok/digital-portfolio/blob/main/app/pricing/page.js): public page · Pricing and monetization entry point. · `app/pricing/page.js`
- [Guides](https://github.com/dheerajok/digital-portfolio/blob/main/app/how-to-create-portfolio-2025/page.js): content page · SEO-oriented tutorial and acquisition pages. · `app/how-to-create-portfolio-2025/page.js`
- [Templates](https://github.com/dheerajok/digital-portfolio/blob/main/app/templates/page.js): catalog page · Public template browsing and discovery. · `app/templates/page.js`

### Dashboard app

Authenticated product workspace and editor shell.

- [Dashboard](https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/page.js): workspace page · Authenticated product workspace entry. · `app/dashboard/page.js`
- [Panels](https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/components/Overview.jsx): dashboard sections · Overview, settings, analytics, and referral panels. · `app/dashboard/components/Overview.jsx`
- [Editor](https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/components/EditPortfolio.jsx): portfolio editor · Main entry for creating and updating portfolios. · `app/dashboard/components/EditPortfolio.jsx`
- [Freelancer edit](https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/components/edit-portfolio/EditFreelancerPortfolio.jsx): wizard editor · Guided freelancer portfolio editing flow. · `app/dashboard/components/edit-portfolio/EditFreelancerPortfolio.jsx`
- [Video edit](https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/components/edit-portfolio/EditVideoEditorPortfolio.jsx): wizard editor · Guided video-editor portfolio editing flow. · `app/dashboard/components/edit-portfolio/EditVideoEditorPortfolio.jsx`

### Portfolio runtime

Public tenant routes and template-driven profile pages.

- [Tenant page](https://github.com/dheerajok/digital-portfolio/blob/main/app/[username]/page.js): dynamic route · Public username-based portfolio route. · `app/[username]/page.js`
- [Freelancer view](https://github.com/dheerajok/digital-portfolio/blob/main/app/[username]/Freelancer.jsx): public renderer · Freelancer portfolio presentation branch. · `app/[username]/Freelancer.jsx`
- [Video view](https://github.com/dheerajok/digital-portfolio/blob/main/app/[username]/VideoEditor.jsx): public renderer · Video editor portfolio presentation branch. · `app/[username]/VideoEditor.jsx`
- [Not public](https://github.com/dheerajok/digital-portfolio/blob/main/app/[username]/NotPublic.jsx): access gate · Fallback for hidden or unavailable portfolios. · `app/[username]/NotPublic.jsx`
- **Templates pack**: render templates · Template families and composition assets for public profiles.

### API boundary

Route handlers for CRUD, AI, media, payments, referrals, and analytics.

- [Auth](https://github.com/dheerajok/digital-portfolio/blob/main/app/api/auth/[...nextauth]/route.js): nextauth route · Authentication and session issuance boundary. · `app/api/auth/[...nextauth]/route.js`
- [Portfolio API](https://github.com/dheerajok/digital-portfolio/blob/main/app/api/portfolio/route.js): crud route · Primary portfolio persistence and lookup boundary. · `app/api/portfolio/route.js`
- [Video API](https://github.com/dheerajok/digital-portfolio/blob/main/app/api/video-editor-portfolio/route.js): crud route · Video-editor portfolio persistence boundary. · `app/api/video-editor-portfolio/route.js`
- [Analytics API](https://github.com/dheerajok/digital-portfolio/blob/main/app/api/analytics/[username]/route.js): tracking route · Per-username analytics ingestion and aggregation. · `app/api/analytics/[username]/route.js`
- [Media API](https://github.com/dheerajok/digital-portfolio/blob/main/app/api/upload-image/route.js): upload route · Image upload and deletion workflow boundary. · `app/api/upload-image/route.js`
- [AI API](https://github.com/dheerajok/digital-portfolio/blob/main/app/api/ai/generate-text/route.js): generation route · Text generation and quota enforcement endpoints. · `app/api/ai/generate-text/route.js`
- [Payments API](https://github.com/dheerajok/digital-portfolio/blob/main/app/api/razorpay/create-order/route.js): billing route · Razorpay order creation and payment verification. · `app/api/razorpay/create-order/route.js`
- [Referral API](https://github.com/dheerajok/digital-portfolio/blob/main/app/api/referral/register/route.js): growth route · Referral registration, validation, dashboard, and withdrawal endpoints. · `app/api/referral/register/route.js`

### Data layer

MongoDB connection and domain models.

- [MongoDB](https://github.com/dheerajok/digital-portfolio/blob/main/app/db/mongodb.js): database connection · Shared MongoDB connection helper. · `app/db/mongodb.js`
- [Models](https://github.com/dheerajok/digital-portfolio/blob/main/app/model/Portfolio.js): domain models · Core persisted entities for users, portfolios, analytics, and images. · `app/model/Portfolio.js`
- [Analytics model](https://github.com/dheerajok/digital-portfolio/blob/main/app/model/AnalyticsSchema.js): event schema · Stored analytics event schema. · `app/model/AnalyticsSchema.js`

### Shared infra

App-wide session, auth, and supporting client hooks.

- [Session](https://github.com/dheerajok/digital-portfolio/blob/main/app/components/SessionWrapper.js): app shell · Client/server session wrapper for authenticated experiences. · `app/components/SessionWrapper.js`
- [AI hook](https://github.com/dheerajok/digital-portfolio/blob/main/app/dashboard/hooks/useAIGenerator.js): client hook · Dashboard-side generator integration used in form flows. · `app/dashboard/hooks/useAIGenerator.js`

## Connections

- Home → Hero UI: uses · Landing page composes shared marketing sections.
- Home → Pricing: links · Public homepage routes users to pricing.
- Home → Guides: acquires · SEO guides feed the acquisition funnel.
- Home → Templates: shows · Template browsing is part of the public funnel.
- Session → Dashboard: wraps · Session wrapper guards the authenticated workspace.
- Auth → Session: issues · Auth route supplies the session boundary.
- Dashboard → Panels: switches · Dashboard swaps between feature panels.
- Dashboard → Editor: opens · Workspace launches the portfolio editor.
- Editor → Freelancer edit: loads · Freelancer portfolio editing flow.
- Editor → Video edit: loads · Video editor portfolio editing flow.
- Editor → AI hook: uses · Editor forms can request AI-generated copy.
- Tenant page → Freelancer view: renders · Username route branches to freelancer presentation.
- Tenant page → Video view: renders · Username route branches to video-editor presentation.
- Tenant page → Not public: falls back · Hidden portfolios resolve to the access gate.
- Tenant page → Templates pack: maps to · Stored portfolio data selects a template family.
- Freelancer view → Portfolio API: reads · Public portfolio rendering depends on portfolio data.
- Video view → Video API: reads · Video portfolio rendering depends on specialized data.
- Portfolio API → MongoDB: persists · Portfolio CRUD is stored in MongoDB.
- Video API → MongoDB: persists · Video-editor portfolios are stored in MongoDB.
- Analytics API → Analytics model: writes · Analytics events are stored through a dedicated schema.
- Analytics API → MongoDB: stores · Tracking data is persisted in the shared database.
- Media API → MongoDB: stores · Uploaded media metadata is backed by MongoDB.
- AI API → MongoDB: checks quota · AI generation is gated by stored quota/state.
- Payments API → MongoDB: records · Payment and verification state is persisted.
- Referral API → MongoDB: updates · Referral lifecycle data is stored centrally.
- Models → MongoDB: uses · Domain models are built on the shared MongoDB connection.
- Dashboard → Portfolio API: edits via · Dashboard content is saved through portfolio APIs.
- Dashboard → Video API: edits via · Video-editor content is saved through video portfolio APIs.
- Dashboard → Analytics API: inspects · Analytics panel reads aggregated tracking data.
- Dashboard → Referral API: manages · Referral features are exposed inside the dashboard.
- Dashboard → Payments API: pays · Monetization flows begin from the authenticated app.
