# saurabhalex/sql-server-user-module architecture

> Architecture diagram of the GitHub repository saurabhalex/sql-server-user-module, 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/saurabhalex/sql-server-user-module
- Repository: https://github.com/saurabhalex/sql-server-user-module

## Overview

##### Project type and purpose
- This is a backend RESTful API service built with FastAPI, SQLAlchemy, and Pydantic.
- Its single purpose is to manage users (CRUD operations) against a relational database (PostgreSQL or SQL Server via ODBC/Azure).

##### File structure
- Top-level:
- `.env` – holds the `DATABASE_URL`.
- `main.py` – entry point that creates the FastAPI app and mounts routers.
- `azure_sql_api.py` & helper scripts – demonstrate or patch Azure/ODBC connectivity.
- `requirements.txt` – Python dependencies.
- `app/` module:
- `database.py` – initializes SQLAlchemy engine and session.
- `models.py` – declares ORM models (the User table).
- `schemas.py` – Pydantic request/response models for data validation.
- `routers/users.py` – defines all user endpoints (GET, POST, PUT, DELETE).

##### README
- Confirms the tech stack: FastAPI + Uvicorn, SQLAlchemy ORM, Pydantic, Azure/Postgres DB.
- Lists available endpoints and database schema.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Client
    Client["Client\n(Browser/Postman)"]:::external

    %% Configuration and Dependencies
    .env[".env\n(Environment Config)"]:::config
    requirements["requirements.txt\n(Dependencies)"]:::config
    README["README.md\n(Architecture & Schema Docs)"]:::external

    %% API Layer
    subgraph "API Layer"
        direction TB
        main["main.py\n(FastAPI Entry Point)"]:::api
        usersRouter["Users Router\napp/routers/users.py"]:::api
        userMgmtRouter["User Management Router\napp/routers/usermanagement.py"]:::api
        schemas["Pydantic Schemas\napp/schemas.py"]:::api
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        direction TB
        database["SQLAlchemy Engine & Session\napp/database.py"]:::data
        models["ORM Models (User Table)\napp/models.py"]:::data
    end

    %% Database
    DB[(Relational DB\nAzure SQL / PostgreSQL)]:::external

    %% Infrastructure Scripts
    subgraph "Infra & Utilities"
        direction TB
        azureDemo["azure_sql_api.py\n(Demo & Patch)"]:::infra
        azurePatch["azure_sql_api.py.patch\n(Patch)"]:::infra
        installODBC["install_odbc_driver_mac.sh\n(ODBC Installer)"]:::infra
    end

    %% Interactions
    Client -->|"HTTP Request"| main
    main -->|"Mount Routers"| usersRouter
    main -->|"Mount Routers"| userMgmtRouter
    usersRouter -->|"Validate & parse"| schemas
    userMgmtRouter -->|"Validate & parse"| schemas
    schemas -->|"Invoke CRUD"| database
    database -->|"Use Models"| models
    database -->|"Execute SQL"| DB
    DB -->|"Return Rows"| database
    database -->|"Map to Pydantic"| schemas
    schemas -->|"Construct Response"| main
    main -->|"JSON Response"| Client

    .env -->|"Provids DATABASE_URL"| database
    requirements -->|"Defines Dependencies"| main
    README -->|"Documents Architecture"| main

    azureDemo -->|"Optional Setup"| database
    azurePatch -->|"Patches Connectivity"| azureDemo
    installODBC -->|"Installs Driver"| azureDemo

    %% Click Events
    click main "https://github.com/saurabhalex/sql-server-user-module/blob/main/main.py"
    click .env "https://github.com/saurabhalex/sql-server-user-module/blob/main/.env"
    click requirements "https://github.com/saurabhalex/sql-server-user-module/blob/main/requirements.txt"
    click database "https://github.com/saurabhalex/sql-server-user-module/blob/main/app/database.py"
    click models "https://github.com/saurabhalex/sql-server-user-module/blob/main/app/models.py"
    click schemas "https://github.com/saurabhalex/sql-server-user-module/blob/main/app/schemas.py"
    click usersRouter "https://github.com/saurabhalex/sql-server-user-module/blob/main/app/routers/users.py"
    click userMgmtRouter "https://github.com/saurabhalex/sql-server-user-module/blob/main/app/routers/usermanagement.py"
    click azureDemo "https://github.com/saurabhalex/sql-server-user-module/blob/main/azure_sql_api.py"
    click azurePatch "https://github.com/saurabhalex/sql-server-user-module/blob/main/azure_sql_api.py.patch"
    click installODBC "https://github.com/saurabhalex/sql-server-user-module/blob/main/install_odbc_driver_mac.sh"
    click README "https://github.com/saurabhalex/sql-server-user-module/blob/main/README.md"

    %% Styles
    classDef api fill:#D0E8FF,stroke:#75AADB,color:#034F84;
    classDef data fill:#E0FFD6,stroke:#7BC47F,color:#2C5F2D;
    classDef external fill:#FFF3BF,stroke:#FCCB00,color:#B18205;
    classDef config fill:#FFF3BF,stroke:#FCCB00,color:#B18205;
    classDef infra fill:#FFE5D9,stroke:#FF8BA7,color:#B8002D;
```
