# skevo18/backend-projekt architecture

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

- Interactive diagram: https://gitdiagram.com/skevo18/backend-projekt
- Repository: https://github.com/skevo18/backend-projekt

## Overview

##### Main Components
- Frontend: A Vue 3 application (located in the frontend folder) with its own routing, components, and state management.
- Backend API: The FastAPI backend (in the backend directory) which includes:
- Main application entry point (main.py)
- Router modules handling different endpoints (authentication, page CRUD, email, etc.)
- Utility modules (e.g., mail functions)
- Database: Managed via SQLAlchemy with migration support from Alembic (within backend/db). Include components for:
- Database migration scripts (migrations directory)
- ORM definitions (e.g., orm.py)
- Docker & Deployment: Docker configuration files that define multiple services:
- Nginx (with its configuration files located in docker/nginx)
- A service running Uvicorn (or another webserver) for hosting FastAPI
- Containers for running PHP-FPM as required (as per the README, even if files are minimal, plan for it)
- MariaDB container for the database service

##### Relationships and Data Flow
- How the Frontend Vue application interacts with the Backend API via REST calls.
- That the Backend (FastAPI) interacts with the Database to perform CRUD operations and handle authentication.
- Docker container interactions:
- Nginx serves as a reverse proxy dispatching requests to the Uvicorn server.
- The Uvicorn server runs the FastAPI application.
- Database container (MariaDB) is used by the backend.
- (Include PHP-FPM container if applicable based on the Docker configuration.)
- Frontend → Backend: API calls (with authentication tokens exchanged via cookies)
- Backend → Database: ORM and migration-driven data operations
- Docker/Nginx → Uvicorn/Backend: Routing and load balancing

##### Architectural Patterns and Design Principles
- Separation of Concerns: The frontend and backend are clearly separated. The backend provides a RESTful API while the frontend consumes these services.
- Modular Design: Within the backend, routers and utilities are divided into their own modules (authentication, CRUD for various entities, etc.), and the database migrations are modular.
- Containerization: Docker is used to keep services isolated and replaceable, promoting a microservices-like architecture even within a monorepo setup.
- Security: Emphasis on authentication using HttpOnly cookies for token storage and safe handling of user input (e.g., sanitizing HTML inputs on the backend).

##### Incorporate Relevant Technologies and Tools
- Frontend: Vue 3, Vite (as seen in vite.config.js), and Typescript (noted with .ts files).
- Backend: FastAPI, Uvicorn (via Docker), SQLAlchemy 2.0, Alembic for migrations, and custom router modules.
- Deployment: Docker, Nginx, PHP-FPM configuration, and MariaDB.
- Version control and contribution guidelines (e.g., CONTRIBUTING.md, .gitignore, etc.) can be mentioned but are secondary to the core architectural components.

##### Specific Elements
- Clear labels for every component (e.g., “Vue 3 Frontend”, “FastAPI Backend”, “SQLAlchemy + Alembic”, “MariaDB Database”, “Nginx Reverse Proxy”, etc.).
- API calls from the frontend to the backend.
- Database queries from backend services to the database.
- Routing paths from Nginx to the appropriate container (Uvicorn/Backend).

##### Detailed Capture of Essential Elements
- Also, note external integrations like the SMTP service (for sending registration emails) and any external links (like Cloudflare suggestions) based on the README.
- Don’t omit details related to Docker setup, as many deployment and scalability aspects hinge upon container orchestration.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        FE["Vue 3 Frontend"]:::client
    end

    %% API Layer
    subgraph "API Layer"
        BE_Main["FastAPI Backend (main.py)"]:::api
        Auth["Authentication Router"]:::api
        CRUD_Page["Page CRUD Router"]:::api
        CRUD_Category["Category CRUD Router"]:::api
        Email_Router["Email Router"]:::api
        Email_Util["Email Utils"]:::api
        JWT["JWT Utilities"]:::api
    end

    %% Data Layer
    subgraph "Data Layer"
        ORM["SQLAlchemy ORM"]:::database
        Migration["Alembic Migrations"]:::database
        MariaDB["MariaDB Database"]:::database
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        Nginx["Nginx Reverse Proxy"]:::infra
        Uvicorn["Uvicorn Server (FastAPI)"]:::infra
        PHPFPM["PHP-FPM Service"]:::infra
        Docker_Config["Docker Configuration"]:::infra
        BE_Container["Backend Container"]:::infra
        FE_Container["Frontend Container"]:::infra
    end

    %% Connections between layers
    FE -->|"APIcalls"| BE_Main
    BE_Main -->|"delegates"| Auth
    BE_Main -->|"delegates"| CRUD_Page
    BE_Main -->|"delegates"| CRUD_Category
    BE_Main -->|"delegates"| Email_Router
    BE_Main -->|"delegates"| Email_Util
    BE_Main -->|"delegates"| JWT
    BE_Main -->|"DBoperations"| ORM
    BE_Main -->|"uses"| Migration
    BE_Main -->|"queries"| MariaDB

    %% Docker and Infrastructure flows
    Nginx -->|"routesTo"| Uvicorn
    Uvicorn -->|"runs"| BE_Main
    Docker_Config --> Nginx
    Docker_Config --> BE_Container
    Docker_Config --> FE_Container
    FE -->|"deployedIn"| FE_Container
    BE_Main -->|"deployedIn"| BE_Container

    %% Styles
    classDef client fill:#a2d2ff,stroke:#333,stroke-width:2px;
    classDef api fill:#f9d56e,stroke:#333,stroke-width:2px;
    classDef database fill:#cdeac0,stroke:#333,stroke-width:2px;
    classDef infra fill:#f4a261,stroke:#333,stroke-width:2px;

    %% Click Events
    click FE "https://github.com/skevo18/backend-projekt/tree/main/frontend/"
    click BE_Main "https://github.com/skevo18/backend-projekt/blob/main/backend/main.py"
    click Auth "https://github.com/skevo18/backend-projekt/blob/main/backend/router/authentication.py"
    click CRUD_Page "https://github.com/skevo18/backend-projekt/blob/main/backend/router/page_crud.py"
    click CRUD_Category "https://github.com/skevo18/backend-projekt/blob/main/backend/router/category_crud.py"
    click Email_Router "https://github.com/skevo18/backend-projekt/blob/main/backend/router/email.py"
    click Email_Util "https://github.com/skevo18/backend-projekt/blob/main/backend/utils/mail.py"
    click JWT "https://github.com/skevo18/backend-projekt/blob/main/backend/router/jwt_utils.py"
    click ORM "https://github.com/skevo18/backend-projekt/blob/main/backend/db/orm.py"
    click Migration "https://github.com/skevo18/backend-projekt/tree/main/backend/db/migrations/"
    click Docker_Config "https://github.com/skevo18/backend-projekt/tree/main/docker/"
    click BE_Container "https://github.com/skevo18/backend-projekt/tree/main/backend/Dockerfile"
    click FE_Container "https://github.com/skevo18/backend-projekt/tree/main/frontend/Dockerfile"
```
