# caspermohit/movie-review architecture

> Architecture diagram of the GitHub repository caspermohit/movie-review, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/caspermohit/movie-review
- Repository: https://github.com/caspermohit/movie-review

## Overview

##### Project Type and Purpose
- This is a modern full-stack web application (“Movie Review Application”) with a React + TypeScript + Vite frontend and a Node.js + Express + MongoDB backend.
- Primary goal: Allow users to browse movies/TV/anime (via external APIs), register/login, post reviews, and manage a personal watchlist.

##### File Structure Analysis
- Top-level:
- frontend code under `/src` (React components, pages, services, contexts, assets)
- backend code under `/backend` (Express server, models, middleware, DB init)
- config/build files (.env, netlify.toml, render-build.sh, tsconfigs, package.json)
- Patterns:
- Frontend: SPA with React Router, Context for auth, service layer for HTTP calls
- Backend: RESTful API with JWT auth middleware, Mongoose models (User, Review, Wishlist)
- Deployment: Netlify (frontend) and likely Render or another host for backend

##### Core Components
- Frontend SPA
- React/Vite Development Server → Builds static assets → Served via Netlify
- UI Components (MovieCard, MovieDetails, Navbar, Pages)
- Service Layer:
– movieService: HTTP calls directly to external TMDB (and optionally Jikan) APIs
– authService: HTTP calls to your own backend’s `/api/auth` endpoints
- Backend API
- Express Server (`server.ts`)
- Middleware: JWT authentication (`auth.ts`)
- Controllers/Routes: Exposed under `/api` (e.g., `/api/user`, `/api/review`, `/api/wishlist`)
- Models: Mongoose schemas for User, Review, Wishlist
- DB Initialization (`initDb.ts`) connecting to MongoDB
- Database
- MongoDB (cloud or local instance)
- External Services
- TMDB API (The Movie Database)
- Jikan API (MyAnimeList)

##### Relationships and Data Flow
- User’s Browser
→ Requests HTML/JS from Netlify → Runs React SPA
→ On page load & interactions, React calls:
- Backend API (`/api/*`) for user data, reviews, watchlist
- External APIs (TMDB/Jikan) for fetching movie/TV/anime details
- Backend
→ Verifies JWT, processes CRUD operations against MongoDB
→ Returns JSON payloads to frontend
- MongoDB
← Stores user profiles, reviews, watchlist entries

##### Architectural Patterns & Principles
- Layered Architecture (Presentation → Service/Controller → Data Access)
- Separation of Concerns (frontend vs backend vs database)
- Single Page Application (React + client-side routing)
- RESTful API (Express)
- Token-based Authentication (JWT in HTTP headers)
- External API integration (Axios via service modules)

##### Technologies & Libraries to Annotate
- Frontend: React, React Router, TypeScript, Vite, Chakra UI, Axios
- Backend: Node.js, Express, TypeScript, Mongoose, JSON Web Token
- Database: MongoDB
- Deployment: Netlify (frontend), Render/Heroku/AWS (backend)
- External APIs: TMDB, Jikan

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    subgraph "User's Browser"
        direction TB
        ReactSPA["React SPA"]:::frontend
        subgraph "Entry Points"
            direction TB
            MainTSX["main.tsx"]:::frontend
            AppTSX["App.tsx"]:::frontend
        end
        subgraph "UI Components"
            direction TB
            MovieCard["MovieCard"]:::frontend
            MovieDetailsComp["MovieDetails"]:::frontend
            Navbar["Navbar"]:::frontend
            Footer["Footer"]:::frontend
        end
        subgraph "Pages (React Router)"
            direction TB
            HomePage["HomePage"]:::frontend
            MovieDetailsPage["MovieDetailsPage"]:::frontend
            LoginPage["LoginPage"]:::frontend
            RegisterPage["RegisterPage"]:::frontend
            WishlistPage["WishlistPage"]:::frontend
        end
        AuthContext["AuthContext"]:::frontend
        subgraph "Service Layer"
            direction TB
            MovieService["movieService"]:::frontend
            AuthService["authService"]:::frontend
        end
        Types["Type Definitions"]:::frontend
        StaticAssets["Static Assets & Config"]:::frontend
        ReactSPA --> MainTSX
        ReactSPA --> AppTSX
        ReactSPA --> MovieCard
        ReactSPA --> MovieDetailsComp
        ReactSPA --> Navbar
        ReactSPA --> Footer
        ReactSPA --> HomePage
        ReactSPA --> MovieDetailsPage
        ReactSPA --> LoginPage
        ReactSPA --> RegisterPage
        ReactSPA --> WishlistPage
        ReactSPA --> AuthContext
        ReactSPA --> MovieService
        ReactSPA --> AuthService
        ReactSPA --> Types
        ReactSPA --> StaticAssets
    end

    %% Backend Layer
    subgraph "Backend API (Express)" 
        direction TB
        Server["server.ts"]:::backend
        InitDB["initDb.ts"]:::backend
        AuthMiddleware["auth.ts"]:::backend
        subgraph "Controllers"
            direction TB
            UserController["User Controller"]:::backend
            ReviewController["Review Controller"]:::backend
            WishlistController["Wishlist Controller"]:::backend
        end
        subgraph "Models"
            direction TB
            UserModel["User Model"]:::backend
            ReviewModel["Review Model"]:::backend
            WishlistModel["Wishlist Model"]:::backend
        end
        Server --> AuthMiddleware
        Server --> UserController
        Server --> ReviewController
        Server --> WishlistController
        Server --> InitDB
        InitDB --> UserModel
        InitDB --> ReviewModel
        InitDB --> WishlistModel
    end

    %% Database
    MongoDB[(MongoDB)]:::database

    %% External Services
    TMDB["TMDB API"]:::external
    Jikan["Jikan API"]:::external

    %% Data Flows
    ReactSPA -->|GET external details| TMDB
    ReactSPA -->|GET external details| Jikan
    ReactSPA -->|API calls /api/*| Server
    Server -->|CRUD operations| MongoDB

    %% Click Events
    click MainTSX "https://github.com/caspermohit/movie-review/blob/main/src/main.tsx"
    click AppTSX "https://github.com/caspermohit/movie-review/blob/main/src/App.tsx"
    click MovieCard "https://github.com/caspermohit/movie-review/blob/main/src/components/MovieCard.tsx"
    click MovieDetailsComp "https://github.com/caspermohit/movie-review/blob/main/src/components/MovieDetails.tsx"
    click Navbar "https://github.com/caspermohit/movie-review/blob/main/src/components/Navbar.tsx"
    click Footer "https://github.com/caspermohit/movie-review/blob/main/src/components/footer.tsx"
    click HomePage "https://github.com/caspermohit/movie-review/blob/main/src/pages/HomePage.tsx"
    click MovieDetailsPage "https://github.com/caspermohit/movie-review/blob/main/src/pages/MovieDetailsPage.tsx"
    click LoginPage "https://github.com/caspermohit/movie-review/blob/main/src/pages/LoginPage.tsx"
    click RegisterPage "https://github.com/caspermohit/movie-review/blob/main/src/pages/RegisterPage.tsx"
    click WishlistPage "https://github.com/caspermohit/movie-review/blob/main/src/pages/WishlistPage.tsx"
    click AuthContext "https://github.com/caspermohit/movie-review/blob/main/src/contexts/AuthContext.tsx"
    click MovieService "https://github.com/caspermohit/movie-review/blob/main/src/services/movieService.ts"
    click AuthService "https://github.com/caspermohit/movie-review/blob/main/src/services/authService.ts"
    click Server "https://github.com/caspermohit/movie-review/blob/main/backend/src/server.ts"
    click InitDB "https://github.com/caspermohit/movie-review/blob/main/backend/src/initDb.ts"
    click AuthMiddleware "https://github.com/caspermohit/movie-review/blob/main/backend/src/middleware/auth.ts"
    click UserModel "https://github.com/caspermohit/movie-review/blob/main/backend/src/models/User.ts"
    click ReviewModel "https://github.com/caspermohit/movie-review/blob/main/backend/src/models/Review.ts"
    click WishlistModel "https://github.com/caspermohit/movie-review/blob/main/backend/src/models/Wishlist.ts"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#D0FFD8,stroke:#228B22,stroke-width:1px
    classDef database fill:#FFE0B2,stroke:#FF8C00,stroke-width:1px
    classDef external fill:#E0E0E0,stroke:#6e6e6e,stroke-width:1px
```
