# olukeye/fastapi-shop-app architecture

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

- Interactive diagram: https://gitdiagram.com/olukeye/fastapi-shop-app
- Repository: https://github.com/olukeye/fastapi-shop-app

## Overview

##### Main Components
- API Layer: Represented by the FastAPI application itself. This includes the main entry point (main.py) and the “routes” directory. Within “routes”, you have dedicated modules for auth, business, category, order, product, and user endpoints.
- Business Logic & Service Layer: Include the “app” directory (which has mail handling and helper functions) and possibly parts of “utils” focused on authentication (e.g., oauth2) and date or hashing functionalities.
- Data Model & Domain Layer: Captured by the “models” directory, which defines ORM models (business, category, orders, product, user). The “pydantic_schemas” directory provides data validation and serialization using Pydantic, ensuring correct data formats between layers.
- Data Access & Repository Layer: Modules in the “repositories” directory abstract direct database interactions for business, category, order, product, and user data.
- Database Layer & Migrations: The “db” directory (specifically database.py) is responsible for the database connection and operations, while the “alembic” folder contains migration scripts that manage schema changes.
- Configuration & Environment Management: The “setttings” directory (with its config.py) likely handles environment variables and other configuration parameters.
- External Integrations & Utilities:
- The flutterwave.py file indicates integration with a payment service.
- Deployment and containerization are facilitated via Dockerfile, docker-compose.yml, and Procfile.
- Email functionalities are managed in the “app/mails” folder.

##### Relationships and Data Flow
- Reverse data flow for returning response objects back to the client.

##### Architectural Patterns
- The separation of concerns is clear: routing (API layer), business logic (service layer), data persistence (repository & database layers), and configuration.
- Dependency inversion: routes depend on repository interfaces (abstracting direct DB calls) and utilize Pydantic schemas for data validation/serialization.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Client Layer
    Client["Client/Frontend"]:::client

    %% API Layer
    subgraph "API Layer (FastAPI)"
        APIMain["FastAPI App (main.py)"]:::api
        APIAuth["Auth Routes (routes/auth.py)"]:::api
        APIBusiness["Business Routes (routes/business.py)"]:::api
        APICategory["Category Routes (routes/category.py)"]:::api
        APIOrder["Order Routes (routes/order.py)"]:::api
        APIProduct["Product Routes (routes/product.py)"]:::api
        APIUser["User Routes (routes/user.py)"]:::api
    end

    %% Business Logic & Services
    subgraph "Business Logic & Services"
        BusinessHelper["Business Helper (app/helper.py)"]:::business
        EmailService["Email Service (app/mails/email.py)"]:::business
        UtilsOAuth2["OAuth2 Utils (utils/oauth2.py)"]:::utils
        UtilsDate["Date Utils (utils/date_stuff.py)"]:::utils
        UtilsHash["Hash Verification (utils/hashVerify.py)"]:::utils
    end

    %% Data Model & Domain Layer
    subgraph "Data Model & Domain"
        ORMModels["ORM Models (models/*.py)"]:::domain
        PydanticSchemas["Pydantic Schemas (pydantic_schemas/*.py)"]:::domain
    end

    %% Data Access & Repository Layer
    subgraph "Data Access & Repositories"
        BusinessRepo["Business Repo (repositories/busisnessRepo.py)"]:::repository
        CategoryRepo["Category Repo (repositories/categoryRepo.py)"]:::repository
        OrderRepo["Order Repo (repositories/orderRepo.py)"]:::repository
        ProductRepo["Product Repo (repositories/productRepo.py)"]:::repository
        UserRepo["User Repo (repositories/userRepo.py)"]:::repository
    end

    %% Database & Migrations
    subgraph "Database & Migrations"
        DatabaseNode["Database (db/database.py)"]:::database
        AlembicNode["Alembic Migrations (alembic/)"]:::database
    end

    %% Configuration
    subgraph "Configuration"
        ConfigNode["Config (setttings/config.py)"]:::config
    end

    %% External Integrations
    subgraph "External Integrations"
        PaymentIntegration["Payment Integration (flutterwave.py)"]:::external
    end

    %% Deployment & Containerization
    subgraph "Deployment & Containerization"
        DockerfileNode["Dockerfile"]:::deployment
        DockerComposeNode["docker-compose.yml"]:::deployment
        ProcfileNode["Procfile"]:::deployment
    end

    %% Connections
    Client -->|"HTTP_Request"| APIMain

    APIMain -->|"Delegates"| APIAuth
    APIMain -->|"Delegates"| APIBusiness
    APIMain -->|"Delegates"| APICategory
    APIMain -->|"Delegates"| APIOrder
    APIMain -->|"Delegates"| APIProduct
    APIMain -->|"Delegates"| APIUser

    APIAuth -->|"Auth_Check"| UtilsOAuth2

    APIBusiness -->|"Process"| BusinessHelper
    APICategory -->|"Process"| BusinessHelper
    APIOrder -->|"Process"| BusinessHelper
    APIProduct -->|"Process"| BusinessHelper
    APIUser -->|"Process"| BusinessHelper

    BusinessHelper -->|"RepoCall"| BusinessRepo
    BusinessHelper -->|"RepoCall"| CategoryRepo
    BusinessHelper -->|"RepoCall"| OrderRepo
    BusinessHelper -->|"RepoCall"| ProductRepo
    BusinessHelper -->|"RepoCall"| UserRepo

    BusinessHelper -->|"Validation"| PydanticSchemas
    BusinessHelper -->|"ModelUsage"| ORMModels

    BusinessHelper -->|"Triggers"| PaymentIntegration

    BusinessRepo -->|"DB_Query"| DatabaseNode
    CategoryRepo -->|"DB_Query"| DatabaseNode
    OrderRepo -->|"DB_Query"| DatabaseNode
    ProductRepo -->|"DB_Query"| DatabaseNode
    UserRepo -->|"DB_Query"| DatabaseNode

    %% Configuration used by API and Business Layers (dotted lines)
    ConfigNode -.-> APIMain
    ConfigNode -.-> BusinessHelper

    %% Deployment indicating containerized environment for API
    DockerfileNode --- APIMain
    DockerComposeNode --- APIMain
    ProcfileNode --- APIMain

    %% Styles
    classDef client fill:#cccccc,stroke:#333,stroke-width:1px
    classDef api fill:#ADD8E6,stroke:#0000FF,stroke-width:1px
    classDef business fill:#90ee90,stroke:#008000,stroke-width:1px
    classDef domain fill:#FFD700,stroke:#DAA520,stroke-width:1px
    classDef repository fill:#FFFF99,stroke:#CCCC00,stroke-width:1px
    classDef database fill:#FFA07A,stroke:#FF4500,stroke-width:1px
    classDef config fill:#DDA0DD,stroke:#8A2BE2,stroke-width:1px
    classDef external fill:#FFB6C1,stroke:#FF69B4,stroke-width:1px
    classDef deployment fill:#E6E6FA,stroke:#9370DB,stroke-width:1px
    classDef utils fill:#E0FFFF,stroke:#20B2AA,stroke-width:1px

    %% Click Events for API Layer
    click APIMain "https://github.com/olukeye/fastapi-shop-app/blob/main/main.py"
    click APIAuth "https://github.com/olukeye/fastapi-shop-app/blob/main/routes/auth.py"
    click APIBusiness "https://github.com/olukeye/fastapi-shop-app/blob/main/routes/business.py"
    click APICategory "https://github.com/olukeye/fastapi-shop-app/blob/main/routes/category.py"
    click APIOrder "https://github.com/olukeye/fastapi-shop-app/blob/main/routes/order.py"
    click APIProduct "https://github.com/olukeye/fastapi-shop-app/blob/main/routes/product.py"
    click APIUser "https://github.com/olukeye/fastapi-shop-app/blob/main/routes/user.py"

    %% Click Events for Business Logic & Services
    click BusinessHelper "https://github.com/olukeye/fastapi-shop-app/blob/main/app/helper.py"
    click EmailService "https://github.com/olukeye/fastapi-shop-app/blob/main/app/mails/email.py"
    click UtilsOAuth2 "https://github.com/olukeye/fastapi-shop-app/blob/main/utils/oauth2.py"
    click UtilsDate "https://github.com/olukeye/fastapi-shop-app/blob/main/utils/date_stuff.py"
    click UtilsHash "https://github.com/olukeye/fastapi-shop-app/blob/main/utils/hashVerify.py"

    %% Click Events for Data Model & Domain
    click ORMModels "https://github.com/olukeye/fastapi-shop-app/tree/main/models/"
    click PydanticSchemas "https://github.com/olukeye/fastapi-shop-app/tree/main/pydantic_schemas/"

    %% Click Events for Repositories
    click BusinessRepo "https://github.com/olukeye/fastapi-shop-app/blob/main/repositories/busisnessRepo.py"
    click CategoryRepo "https://github.com/olukeye/fastapi-shop-app/blob/main/repositories/categoryRepo.py"
    click OrderRepo "https://github.com/olukeye/fastapi-shop-app/blob/main/repositories/orderRepo.py"
    click ProductRepo "https://github.com/olukeye/fastapi-shop-app/blob/main/repositories/productRepo.py"
    click UserRepo "https://github.com/olukeye/fastapi-shop-app/blob/main/repositories/userRepo.py"

    %% Click Events for Database & Migrations
    click DatabaseNode "https://github.com/olukeye/fastapi-shop-app/blob/main/db/database.py"
    click AlembicNode "https://github.com/olukeye/fastapi-shop-app/tree/main/alembic/"

    %% Click Event for Configuration
    click ConfigNode "https://github.com/olukeye/fastapi-shop-app/blob/main/setttings/config.py"

    %% Click Event for External Integration
    click PaymentIntegration "https://github.com/olukeye/fastapi-shop-app/blob/main/flutterwave.py"

    %% Click Events for Deployment
    click DockerfileNode "https://github.com/olukeye/fastapi-shop-app/tree/main/Dockerfile"
    click DockerComposeNode "https://github.com/olukeye/fastapi-shop-app/blob/main/docker-compose.yml"
    click ProcfileNode "https://github.com/olukeye/fastapi-shop-app/tree/main/Procfile"
```
