# iloveitaly/python-starter-template architecture

> Architecture diagram of the GitHub repository iloveitaly/python-starter-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/iloveitaly/python-starter-template
- Repository: https://github.com/iloveitaly/python-starter-template

## Overview

##### Main System Components

a) Frontend Layer:
- React + React Router SPA application
- UI Components (ShadCN + Tailwind)
- TypeScript integration
- Frontend tooling (Vite, Vitest, ESLint)

b) Backend Layer:
- FastAPI application
- SQLModel + SQLAlchemy ORM
- Alembic migrations
- Celery job processing

c) Data Layer:
- PostgreSQL database
- Redis cache

d) External Services Layer:
- Clerk (Authentication)
- Sentry (Error tracking)
- PostHog (Analytics)
- Mailpit (Email testing)

##### Component Relationships

a) Client-Server Communication:
- Frontend → Backend (OpenAPI/REST)
- Type safety through generated TypeScript types

b) Data Flow:
- Backend → Database (SQLAlchemy)
- Backend → Redis (Caching/Jobs)
- Backend → External Services

##### Development Infrastructure

A separate section showing:
- Docker Compose environment
- Development tooling (Justfile, Direnv, Mise)
- Testing infrastructure (Playwright, Pytest)

##### Specific Implementation Details

a) Authentication Flow:
- Clerk integration with both frontend and backend
- User session management

b) API Layer:
- FastAPI routes structure
- Middleware pipeline
- Dependencies injection

c) Database Architecture:
- Model relationships
- Migration system
- TypeID implementation

##### Key Architectural Patterns to Highlight

- Clear separation between frontend and backend
- Type safety across the stack
- Container-based deployment
- Environment-based configuration
- Testing pyramid (unit, functional, integration)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Legend"
        L1[Frontend Component]:::frontend
        L2[Backend Component]:::backend
        L3[(Database)]:::database
        L4[External Service]:::external
        L5[Development Tool]:::devtool
    end

    subgraph "Frontend Layer"
        React["React + Router"]:::frontend
        UIComponents["UI Components"]:::frontend
        TypeScript["TypeScript"]:::frontend
        FrontendTools["Frontend Tools"]:::frontend
    end

    subgraph "Backend Layer"
        FastAPI["FastAPI Server"]:::backend
        SQLModel["SQLModel + SQLAlchemy"]:::backend
        Alembic["Alembic Migrations"]:::backend
        Celery["Celery Jobs"]:::backend
        EmailSystem["Email System"]:::backend
    end

    subgraph "Data Layer"
        PostgreSQL[(PostgreSQL)]:::database
        Redis[(Redis Cache)]:::database
    end

    subgraph "External Services"
        Clerk["Clerk Auth"]:::external
        Sentry["Sentry Monitoring"]:::external
        PostHog["PostHog Analytics"]:::external
        Mailpit["Mailpit"]:::external
    end

    subgraph "Development Infrastructure"
        Docker["Docker Compose"]:::devtool
        Testing["Testing Suite"]:::devtool
        DevTools["Development Tools"]:::devtool
    end

    React --> FastAPI
    UIComponents --> React
    TypeScript --> React
    FrontendTools --> React

    FastAPI --> SQLModel
    SQLModel --> PostgreSQL
    FastAPI --> Redis
    FastAPI --> Celery
    Celery --> Redis
    FastAPI --> EmailSystem
    EmailSystem --> Mailpit

    FastAPI --> Clerk
    React --> Clerk
    FastAPI --> Sentry
    React --> Sentry
    FastAPI --> PostHog
    React --> PostHog

    classDef frontend fill:#3b82f6,color:white
    classDef backend fill:#22c55e,color:white
    classDef database fill:#eab308,color:white
    classDef external fill:#a855f7,color:white
    classDef devtool fill:#64748b,color:white

    click React "https://github.com/iloveitaly/python-starter-template/blob/master/web/app/root.tsx"
    click UIComponents "https://github.com/iloveitaly/python-starter-template/tree/master/web/app/components/ui/"
    click FastAPI "https://github.com/iloveitaly/python-starter-template/blob/master/app/server.py"
    click SQLModel "https://github.com/iloveitaly/python-starter-template/tree/master/app/models/"
    click Alembic "https://github.com/iloveitaly/python-starter-template/tree/master/migrations/"
    click EmailSystem "https://github.com/iloveitaly/python-starter-template/tree/master/app/templates/mail/"
    click Testing "https://github.com/iloveitaly/python-starter-template/tree/master/tests/functional/"
    click Docker "https://github.com/iloveitaly/python-starter-template/blob/master/docker-compose.yml"
    click Clerk "https://github.com/iloveitaly/python-starter-template/blob/master/app/configuration/clerk.py"
    click Sentry "https://github.com/iloveitaly/python-starter-template/blob/master/app/configuration/sentry.py"
    click PostHog "https://github.com/iloveitaly/python-starter-template/blob/master/app/configuration/posthog.py"
```
