# nandinideshmukh/blogwebsite architecture

> Architecture diagram of the GitHub repository nandinideshmukh/blogwebsite, 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/nandinideshmukh/blogwebsite
- Repository: https://github.com/nandinideshmukh/blogwebsite

## Overview

1. **High-level shape**
   - This repo is a two-tier blog platform: a **Next.js frontend** in `narrative-frontend/` and a **FastAPI backend** in `backend/`.
   - The frontend is responsible for presentation, routing, and user interactions; the backend owns authentication, business rules, and persistence.

2. **Frontend application boundary**
   - The frontend uses the **Next.js App Router** with route folders under `app/`, including dynamic routes for `post/[postId]` and `profile/[userId]`.
   - Core pages include landing, login/register, main feed, post detail, profile, about/privacy/service, and blog creation.
   - Reusable UI logic lives in `components/` (nav/footer, search, edit/delete dialogs, profile cards, password/account actions).

3. **Frontend data model**
   - `app/types/interface.ts` centralizes TypeScript shapes for API data passed between pages and components.
   - The frontend likely consumes backend DTOs directly, so the API contract is an important boundary for the architecture.

4. **Backend application boundary**
   - The backend is organized as a classic FastAPI layered structure:
     - `routes/` = HTTP endpoints
     - `services/` = business logic
     - `models/` = SQLAlchemy persistence models
     - `schemas/` = request/response validation via Pydantic
   - `app.py` is the FastAPI entrypoint that wires routes together.

5. **Domain subsystems**
   - The backend exposes separate domains for **users**, **blogs**, **comments**, and **likes**.
   - These are split into dedicated route and service modules, which keeps authorization and domain logic out of the transport layer.
   - The presence of `comment.py`, `likes.py`, `blog.py`, and `user.py` indicates the main application workflows are segmented by resource type.

6. **Persistence layer**
   - Persistence is handled with **SQLAlchemy** and **SQLite**; the repo includes `backend/blog.db`.
   - There is no separate database service in Docker Compose, so the backend carries the database state locally.
   - `backend/db/create_db.py` suggests bootstrapping/initialization logic for the database schema.

7. **Schema evolution**
   - Alembic is used for migrations, with `backend/alembic/` and a version file adding `parent_comment_id` to comments.
   - That migration is a strong signal that comments are modeled as a **tree/threaded structure**, not just a flat list.

8. **Core data flows**
   - **Auth flow:** register/login requests go from frontend pages to backend user routes; credentials are validated, and token-based auth is implied by env vars like `SECRET_KEY`, `ALGORITHM`, and token expiry settings.
   - **Content flow:** blog creation/edit/delete goes through blog routes → services → SQLAlchemy models → SQLite.
   - **Engagement flow:** likes and comments are handled through dedicated endpoints, with server-side checks for ownership and duplicate actions.

9. **Nested comments and N+1 concern**
   - The repo explicitly supports **nested replies** and notes that the **N+1 problem is solved**.
   - Architecturally, this means the backend read paths for posts/profiles/comments are likely optimized to fetch related users/comments efficiently rather than issuing per-item lookups.

10. **Media and external services**
    - Image upload support is part of the platform, and backend env vars include `CLOUDINARY_*`, which suggests an external image hosting/service integration.
    - This is an important boundary: the app handles content metadata in the API/database, while media blobs are likely stored outside the main SQLite persistence layer.

11. **Deployment/runtime**
    - Both frontend and backend are containerized with their own Dockerfiles, and `docker-compose.yml` orchestrates them as two services on a shared network.
    - The documented ports are **3000** for Next.js and **8000** for FastAPI, making the frontend the primary user-facing entrypoint and the backend the API origin.
    - `render.yaml` indicates an additional deployment target beyond local Docker Compose.

12. **What an architecture diagram should emphasize**
    - Draw two main boxes: **Next.js UI** and **FastAPI API**.
    - Show the backend split into **routes → services → models/schemas → SQLite/Alembic**, with a side connection to the external image service.
    - Highlight the dynamic frontend routes (`postId`, `userId`) and the main server-managed domains: auth, posts, comments, likes, and profile management.

Main entry points: [`backend/routes/__init__.py`](https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/routes/__init__.py) (HTTP routes), [`narrative-frontend/app/layout.tsx`](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/layout.tsx) (App shell), [`narrative-frontend/app/types/interface.ts`](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/types/interface.ts) (API types), [`narrative-frontend/components/NavBar.tsx`](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/components/NavBar.tsx) (Shared UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Next.js UI"]
  node_fe_root["App shell<br/>nextjs app<br/>[layout.tsx]"]
  node_fe_home["Landing<br/>route page<br/>[page.tsx]"]
  node_fe_main["Main feed<br/>route page<br/>[page.tsx]"]
  node_fe_post["Post detail<br/>dynamic route<br/>[page.tsx]"]
  node_fe_profile["Profile view<br/>dynamic route<br/>[page.tsx]"]
  node_fe_login["Login<br/>route page<br/>[page.tsx]"]
  node_fe_register["Register<br/>route page<br/>[page.tsx]"]
  node_fe_create["Create blog<br/>editor page<br/>[create_blog.tsx]"]
  node_fe_about["About<br/>content page<br/>[page.tsx]"]
  node_fe_policy["Policy pages<br/>content pages<br/>[page.tsx]"]
  node_fe_types["API types<br/>ts interfaces<br/>[interface.ts]"]
  node_fe_ui["Shared UI<br/>components<br/>[NavBar.tsx]"]
end

subgraph group_backend["FastAPI API"]
  node_be_app["API entry<br/>fastapi app<br/>[app.py]"]
  node_be_routes["HTTP routes<br/>api routers<br/>[__init__.py]"]
  node_be_services["Domain services<br/>service layer<br/>[__init__.py]"]
  node_be_models[("Persistence models<br/>sqlalchemy models<br/>[blog_model.py]")]
  node_be_schemas["Schemas<br/>[blog_schemas.py]"]
end

subgraph group_storage["Data & External"]
  node_be_dbinit["DB bootstrap<br/>db init<br/>[create_db.py]"]
  node_be_migrate["Migrations<br/>alembic"]
  node_be_sqlite[("SQLite DB<br/>local database<br/>[blog.db]")]
  node_ext_media(("Cloudinary<br/>media service"))
end

node_fe_root -->|"routes to"| node_fe_home
node_fe_root -->|"routes to"| node_fe_main
node_fe_root -->|"routes to"| node_fe_post
node_fe_root -->|"routes to"| node_fe_profile
node_fe_root -->|"routes to"| node_fe_login
node_fe_root -->|"routes to"| node_fe_register
node_fe_root -->|"routes to"| node_fe_create
node_fe_ui -->|"supports"| node_fe_home
node_fe_ui -->|"supports"| node_fe_main
node_fe_ui -->|"supports"| node_fe_post
node_fe_ui -->|"supports"| node_fe_profile
node_fe_types -->|"types"| node_fe_main
node_fe_types -->|"types"| node_fe_post
node_fe_types -->|"types"| node_fe_profile
node_fe_types -->|"types"| node_fe_create
node_fe_login -->|"auth API"| node_be_routes
node_fe_register -->|"auth API"| node_be_routes
node_fe_main -->|"fetches"| node_be_routes
node_fe_post -->|"fetches"| node_be_routes
node_fe_profile -->|"fetches"| node_be_routes
node_fe_create -->|"writes"| node_be_routes
node_be_app -->|"registers"| node_be_routes
node_be_routes -->|"delegates"| node_be_services
node_be_services -->|"persists"| node_be_models
node_be_services -->|"validates"| node_be_schemas
node_be_models -->|"stores"| node_be_sqlite
node_be_dbinit -->|"initializes"| node_be_sqlite
node_be_migrate -->|"evolves"| node_be_sqlite
node_be_services -.->|"uploads media"| node_ext_media
node_be_routes -.->|"domains"| node_be_routes
node_be_models -.->|"schema change"| node_be_migrate

click node_fe_root "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/layout.tsx"
click node_fe_home "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/page.tsx"
click node_fe_main "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/main_page/page.tsx"
click node_fe_post "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/post/[postId]/page.tsx"
click node_fe_profile "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/profile/[userId]/page.tsx"
click node_fe_login "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/login/page.tsx"
click node_fe_register "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/register/page.tsx"
click node_fe_create "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/blog/create_blog.tsx"
click node_fe_about "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/about/page.tsx"
click node_fe_policy "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/privacy/page.tsx"
click node_fe_types "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/types/interface.ts"
click node_fe_ui "https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/components/NavBar.tsx"
click node_be_app "https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/app.py"
click node_be_routes "https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/routes/__init__.py"
click node_be_services "https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/services/__init__.py"
click node_be_models "https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/models/blog_model.py"
click node_be_schemas "https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/schemas/blog_schemas.py"
click node_be_dbinit "https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/db/create_db.py"
click node_be_migrate "https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/alembic/versions/0172150666b0_add_parent_comment_id_to_comments.py"
click node_be_sqlite "https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/blog.db"

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_fe_root,node_fe_home,node_fe_main,node_fe_post,node_fe_profile,node_fe_login,node_fe_register,node_fe_create,node_fe_about,node_fe_policy,node_fe_types,node_fe_ui toneBlue
class node_be_app,node_be_routes,node_be_services,node_be_models,node_be_schemas toneAmber
class node_be_dbinit,node_be_migrate,node_be_sqlite,node_ext_media toneMint
```

## Components

### Next.js UI

Presentation, routing, and client-side interactions

- [App shell](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/layout.tsx): nextjs app · Top-level Next.js entry and shared layout · `narrative-frontend/app/layout.tsx`
- [Landing](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/page.tsx): route page · Public entry page · `narrative-frontend/app/page.tsx`
- [Main feed](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/main_page/page.tsx): route page · Primary authenticated feed view · `narrative-frontend/app/main_page/page.tsx`
- [Post detail](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/post/[postId]/page.tsx): dynamic route · Post view and engagement surface · `narrative-frontend/app/post/[postId]/page.tsx`
- [Profile view](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/profile/[userId]/page.tsx): dynamic route · User profile and activity view · `narrative-frontend/app/profile/[userId]/page.tsx`
- [Login](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/login/page.tsx): route page · Authentication entry · `narrative-frontend/app/login/page.tsx`
- [Register](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/register/page.tsx): route page · Account creation entry · `narrative-frontend/app/register/page.tsx`
- [Create blog](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/blog/create_blog.tsx): editor page · Blog creation workflow · `narrative-frontend/app/blog/create_blog.tsx`
- [About](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/about/page.tsx): content page · Static informational page · `narrative-frontend/app/about/page.tsx`
- [Policy pages](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/privacy/page.tsx): content pages · Privacy and service terms · `narrative-frontend/app/privacy/page.tsx`
- [API types](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/app/types/interface.ts): ts interfaces · Shared client-side data shapes · `narrative-frontend/app/types/interface.ts`
- [Shared UI](https://github.com/nandinideshmukh/blogwebsite/blob/main/narrative-frontend/components/NavBar.tsx): components · Reusable navigation, forms, cards, and dialogs · `narrative-frontend/components/NavBar.tsx`

### FastAPI API

HTTP API, business rules, and persistence

- [API entry](https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/app.py): fastapi app · Application wiring and route registration · `backend/app.py`
- [HTTP routes](https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/routes/__init__.py): api routers · Resource endpoints for users, blogs, comments, and likes · `backend/routes/__init__.py`
- [Domain services](https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/services/__init__.py): service layer · Business logic and authorization boundaries · `backend/services/__init__.py`
- [Persistence models](https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/models/blog_model.py): sqlalchemy models · Database entities and relationships · `backend/models/blog_model.py`
- [Schemas](https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/schemas/blog_schemas.py): pydantic schemas · Request and response validation · `backend/schemas/blog_schemas.py`

### Data & External

Local database, migrations, and media storage boundary

- [DB bootstrap](https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/db/create_db.py): db init · Local database creation and initialization · `backend/db/create_db.py`
- [Migrations](https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/alembic/versions/0172150666b0_add_parent_comment_id_to_comments.py): alembic · Schema evolution, including threaded comments · `backend/alembic/versions/0172150666b0_add_parent_comment_id_to_comments.py`
- [SQLite DB](https://github.com/nandinideshmukh/blogwebsite/blob/main/backend/blog.db): local database · Repository-local persistence file · `backend/blog.db`
- **Cloudinary**: media service · External image hosting and upload boundary

## Connections

- App shell → Landing: routes to · App shell hosts public landing path
- App shell → Main feed: routes to · App shell hosts main feed path
- App shell → Post detail: routes to · App shell hosts dynamic post path
- App shell → Profile view: routes to · App shell hosts dynamic profile path
- App shell → Login: routes to · App shell hosts login path
- App shell → Register: routes to · App shell hosts registration path
- App shell → Create blog: routes to · App shell hosts creation flow
- Shared UI → Landing: supports · Shared UI composes the public pages
- Shared UI → Main feed: supports · Shared UI powers feed interactions
- Shared UI → Post detail: supports · Shared UI powers post actions
- Shared UI → Profile view: supports · Shared UI powers profile actions
- API types → Main feed: types · Shared DTOs shape feed data
- API types → Post detail: types · Shared DTOs shape post data
- API types → Profile view: types · Shared DTOs shape profile data
- API types → Create blog: types · Shared DTOs shape creation payloads
- Login → HTTP routes: auth API · Login submits credentials to backend
- Register → HTTP routes: auth API · Registration submits account data to backend
- Main feed → HTTP routes: fetches · Feed reads blogs and user context
- Post detail → HTTP routes: fetches · Post detail loads content, comments, likes
- Profile view → HTTP routes: fetches · Profile loads user data and authored content
- Create blog → HTTP routes: writes · Blog editor creates and updates posts
- API entry → HTTP routes: registers · FastAPI entry mounts domain routers
- HTTP routes → Domain services: delegates · Transport layer forwards to business logic
- Domain services → Persistence models: persists · Services read and write domain entities
- Domain services → Schemas: validates · Services consume typed request/response contracts
- Persistence models → SQLite DB: stores · SQLAlchemy models map onto the local DB
- DB bootstrap → SQLite DB: initializes · Bootstrap creates or prepares the database file
- Migrations → SQLite DB: evolves · Migrations change the database schema
- Domain services → Cloudinary: uploads media · Image assets are handled outside SQLite
- HTTP routes → HTTP routes: domains · Users, blogs, comments, and likes are separated by resource
- Persistence models → Migrations: schema change · Threaded comments are represented through migration history
