How nandinideshmukh/blogwebsite works
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: __init__.py HTTP routes · layout.tsx App shell · interface.ts API types · NavBar.tsx Shared UI
Components 21
Next.js UI
Presentation, routing, and client-side interactions
- App shell · Top-level Next.js entry and shared layout
narrative-frontend/app/layout.tsx - Landing · Public entry page
narrative-frontend/app/page.tsx - Main feed · Primary authenticated feed view
narrative-frontend/app/main_page/page.tsx - Post detail · Post view and engagement surface
narrative-frontend/app/post/[postId]/page.tsx - Profile view · User profile and activity view
narrative-frontend/app/profile/[userId]/page.tsx - Login · Authentication entry
narrative-frontend/app/login/page.tsx - Register · Account creation entry
narrative-frontend/app/register/page.tsx - Create blog · Blog creation workflow
narrative-frontend/app/blog/create_blog.tsx - About · Static informational page
narrative-frontend/app/about/page.tsx - Policy pages · Privacy and service terms
narrative-frontend/app/privacy/page.tsx - API types · Shared client-side data shapes
narrative-frontend/app/types/interface.ts - Shared UI · Reusable navigation, forms, cards, and dialogs
narrative-frontend/components/NavBar.tsx
FastAPI API
HTTP API, business rules, and persistence
- API entry · Application wiring and route registration
backend/app.py - HTTP routes · Resource endpoints for users, blogs, comments, and likes
backend/routes/__init__.py - Domain services · Business logic and authorization boundaries
backend/services/__init__.py - Persistence models · Database entities and relationships
backend/models/blog_model.py - Schemas · Request and response validation
backend/schemas/blog_schemas.py
Data & External
Local database, migrations, and media storage boundary
- DB bootstrap · Local database creation and initialization
backend/db/create_db.py - Migrations · Schema evolution, including threaded comments
backend/alembic/versions/0172150666b0_add_parent_comment_id_to_comments.py - SQLite DB · Repository-local persistence file
backend/blog.db - Cloudinary · External image hosting and upload boundary
Connections 31
- 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