# m0ndyg/kinomatch-vanya-backend architecture

> Architecture diagram of the GitHub repository m0ndyg/kinomatch-vanya-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/m0ndyg/kinomatch-vanya-backend
- Repository: https://github.com/m0ndyg/kinomatch-vanya-backend

## Overview

##### Main Components
- Frontend: This is a Next.js application (notice files like next.config.ts, next-env.d.ts, and the use of React components, layouts, and pages) that handles the user interface. It includes components, layouts, context providers, hooks, and API calls defined under the “frontend” folder.
- Backend: This is a TypeScript-based REST API or server application running under Bun (as indicated by bun commands). It resides in the “backend” folder and contains structured directories for routes, DTOs, middleware, service layers, and providers.
- Database: The backend uses Prisma (see the prisma directory and schema.prisma file) for ORM operations, which implies integration with a relational database.
- External Services/Tools: Bun is used for installation and running both frontend and backend. Additionally, third-party dependencies (likely from package.json) and runtime environment variables (like backend/.env) are present.

##### Interactions and Relationships
- The Frontend sends API calls to the Backend (e.g., via axios utility defined in the “frontend/src/utils/axios.ts” and API files under “frontend/src/api”).
- The Backend exposes several endpoints corresponding to entities such as Actors, Movies, Directors, Countries, Genres, Profiles, and authentication routes (visible under “backend/src/route”).
- Middleware (e.g., the authentication middleware in backend/src/middleware) intercepts and validates requests ensuring security.
- Data Transfer Objects (DTOs) in the backend (under backend/src/dto) structure the data exchanged between the backend and other components.
- Prisma interacts with the underlying database for CRUD operations on domain entities.
- Providers and Services (e.g., auth service and user provider) encapsulate business logic and data fetching.

##### Architectural Patterns / Design Principles
- Separation of concerns: The system is clearly divided with the frontend managing user interactions and the backend handling business logic, data management, and authentication.
- Layered architecture / MVC patterns: The backend organizes code into controllers/routes, DTOs, service layers, and middleware, reflecting an MVC-style or layered architecture.
- API-First design: The backend is built around exposing RESTful endpoints while the frontend consumes them.
- Modularity and reusability: Both frontend and backend have modular components, whether in UI components or service/provider modules.

##### Final Recommendations
- A high level of detail by breaking down the project into its smallest fundamental modules.
- Avoid oversimplification: even though dividing everything into individual components (DTOs, middleware, services, etc.) might seem granular, it ensures that the essential architectural elements are captured.
- Constantly refer back to the file tree and README to check for any components or dependencies you might have missed.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Runtime Environment
    Bun["Bun Runtime Environment"]:::runtime

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE_App["Next.js Application (frontend)"]:::frontend
        FE_Pages["Frontend Pages & Routing (frontend/src/app)"]:::frontend
        FE_LoginForm["LoginForm Component"]:::frontend
        FE_RegisterForm["RegisterForm Component"]:::frontend
        FE_UserProfileModal["UserProfileModal Component"]:::frontend
        FE_Axios["Axios Utility"]:::frontend
        FE_API_Calls["API Calls"]:::frontend
        FE_Layouts["Layouts & Context Providers"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BE_App["Bun-run Server Application (backend)"]:::backend
        BE_Routes["RESTful Routes (backend/src/route)"]:::backend
        BE_Middleware["Authentication Middleware"]:::backend
        BE_AuthService["Auth Service"]:::backend
        BE_DTOs["DTOs"]:::backend
        BE_UserProvider["User Provider"]:::backend
        BE_PrismaUtil["Prisma Utility"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB_Prism["Prisma ORM & Database"]:::database
    end

    %% Connections for Runtime
    Bun --> FE_App
    Bun --> BE_App

    %% Frontend Internal Connections
    FE_App --> FE_Pages
    FE_App --> FE_Axios
    FE_App --> FE_Layouts
    FE_Pages --> FE_LoginForm
    FE_Pages --> FE_RegisterForm
    FE_Pages --> FE_UserProfileModal
    FE_Axios --> FE_API_Calls

    %% Frontend to Backend API Call
    FE_API_Calls --> BE_Routes

    %% Backend Internal Connections
    BE_App --> BE_Routes
    BE_Routes --> BE_Middleware
    BE_Middleware --> BE_AuthService
    BE_AuthService --> BE_DTOs
    BE_AuthService --> BE_UserProvider
    BE_AuthService --> BE_PrismaUtil
    BE_PrismaUtil --> DB_Prism

    %% Click Events
    click FE_App "https://github.com/m0ndyg/kinomatch-vanya-backend/tree/main/frontend/"
    click FE_Pages "https://github.com/m0ndyg/kinomatch-vanya-backend/tree/main/frontend/src/app/"
    click FE_LoginForm "https://github.com/m0ndyg/kinomatch-vanya-backend/blob/main/frontend/src/widgets/LoginForm/LoginForm.tsx"
    click FE_RegisterForm "https://github.com/m0ndyg/kinomatch-vanya-backend/blob/main/frontend/src/widgets/RegisterForm/RegisterForm.tsx"
    click FE_UserProfileModal "https://github.com/m0ndyg/kinomatch-vanya-backend/blob/main/frontend/src/modals/UserProfileModal/UserProfileModal.tsx"
    click FE_API_Calls "https://github.com/m0ndyg/kinomatch-vanya-backend/blob/main/frontend/src/api/auth.ts"
    click FE_Axios "https://github.com/m0ndyg/kinomatch-vanya-backend/blob/main/frontend/src/utils/axios.ts"
    click FE_Layouts "https://github.com/m0ndyg/kinomatch-vanya-backend/tree/main/frontend/src/layouts/"
    click BE_App "https://github.com/m0ndyg/kinomatch-vanya-backend/tree/main/backend/"
    click BE_Routes "https://github.com/m0ndyg/kinomatch-vanya-backend/tree/main/backend/src/route/"
    click BE_Middleware "https://github.com/m0ndyg/kinomatch-vanya-backend/blob/main/backend/src/middleware/authentication.middleware.ts"
    click BE_AuthService "https://github.com/m0ndyg/kinomatch-vanya-backend/blob/main/backend/src/service/auth.service.ts"
    click BE_DTOs "https://github.com/m0ndyg/kinomatch-vanya-backend/tree/main/backend/src/dto/"
    click BE_UserProvider "https://github.com/m0ndyg/kinomatch-vanya-backend/blob/main/backend/src/providers/user.provider.ts"
    click BE_PrismaUtil "https://github.com/m0ndyg/kinomatch-vanya-backend/blob/main/backend/src/util/prisma.ts"
    click DB_Prism "https://github.com/m0ndyg/kinomatch-vanya-backend/blob/main/backend/prisma/schema.prisma"

    %% Styles
    classDef runtime fill:#FDD835,stroke:#BF360C,stroke-width:2px
    classDef frontend fill:#81D4FA,stroke:#01579B,stroke-width:2px
    classDef backend fill:#A5D6A7,stroke:#1B5E20,stroke-width:2px
    classDef database fill:#FFF59D,stroke:#F9A825,stroke-width:2px
```
