# rakeshgombi/autoapi architecture

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

- Interactive diagram: https://gitdiagram.com/rakeshgombi/autoapi
- Repository: https://github.com/rakeshgombi/autoapi

## Overview

##### Project Type and Purpose
- **Type**: Backend API service (FastAPI-based).
- **Purpose**: Dynamically generate and expose RESTful endpoints for managing “resources” (directories) and “records” (JSON files) located under a configurable root directory.

##### File Structure Analysis
- **Entry Point**:
- `main.py` – initializes the FastAPI app, includes routers, and launches Uvicorn.
- **Routing Layer** (`routes/`):
- `apis.py` – aggregates all route sub-routers into the main FastAPI app.
- `endpoints/`
- `resource_router.py` – static endpoints for resource (directory) CRUD.
- `dynamic_router.py` – logic to discover subdirectories and generate record-level routes at runtime.
- **Service Layer** (`routes/services/`):
- `resource_service.py` – business logic for creating, listing, deleting directories.
- `records_service.py` – logic for reading, writing, updating, deleting JSON files, plus pagination.
- **Utilities** (`utils/`):
- `config.py` – reads environment (`.env`) for `ROOT_DIR`.
- `logger.py` – configures centralized logging.
- **Configuration & Packaging**:
- `pyproject.toml` & `requirements.txt` – dependency management.
- `Dockerfile`, `.dockerignore` – containerization setup.
- `.env` – environment overrides.

##### Key Architectural Patterns
- **Layered Architecture**:
- Presentation (FastAPI routes) → Application Logic (Service layer) → Data Storage (file system).
- **Dynamic Route Generation**:
- Reflects the file-system structure in API endpoints without hard-coding each route.
- **Separation of Concerns**:
- Routers only handle HTTP and parameter extraction.
- Services encapsulate file-system interactions.
- Utils handle environment and logging.

##### Main Components & Interactions (to include
A. **Client / API Consumer**
- Swagger UI or external HTTP client (curl, Postman)
→ sends HTTP requests (GET/POST/PUT/DELETE)
B. **API Gateway / FastAPI App** (`main.py`)
- Receives requests, mounts routers from `routes/apis.py`.
C. **Router Layer**
1. **ResourceRouter** (`routes/endpoints/resource_router.py`)
- Endpoints: `/create-directory/{name}`, `/list-resources`, `/delete-resource/{name}`
2. **DynamicRouter** (`routes/endpoints/dynamic_router.py`)
- Discovers `ROOT_DIR` contents, auto-registers routes per resource:
- Records: `GET /{resource}`
- CRUD on individual records: `GET/PUT/DELETE /{resource}/{entry_id}`, `POST /{resource}`
D. **Service Layer**
- **ResourceService** – Creates, lists, deletes directories under `ROOT_DIR`.
- **RecordsService** – Reads/writes JSON files, enforces pagination, entry lookups.
E. **File System Storage**
- Root directory (configured via `utils/config.py` + `.env`)
- Subdirectories = resources; JSON files = records.
F. **Utilities**
- **Config** – Environment loading (e.g., `ROOT_DIR`).
- **Logger** – Centralized logging pipeline (console/file).
G. **External/Infrastructure**
- **Uvicorn ASGI Server** – Hosts the FastAPI app.
- **Docker Container** – Encapsulates runtime environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Interface
    Client["HTTP Client / Swagger UI"]:::external

    %% API Gateway
    FastAPIApp["FastAPI App\n(main.py)"]:::api

    %% Routing Layer
    subgraph "Routing Layer"
        Aps["API Aggregator Router\n(routes/apis.py)"]:::router
        RRouter["ResourceRouter\n(routes/endpoints/resource_router.py)"]:::router
        DRouter["DynamicRouter\n(routes/endpoints/dynamic_router.py)"]:::router
    end

    %% Service Layer
    subgraph "Service Layer"
        RService["ResourceService\n(routes/services/resource_service.py)"]:::service
        RecService["RecordsService\n(routes/services/records_service.py)"]:::service
    end

    %% Storage
    FileSystem["File System Storage\n(ROOT_DIR)"]:::storage

    %% Utilities
    subgraph "Utilities"
        Config["Config Utility\n(utils/config.py)"]:::utils
        Logger["Logger Utility\n(utils/logger.py)"]:::utils
    end

    %% Configuration & Packaging
    Env["Environment Overrides\n(.env)"]:::utils
    DepMgmt["Dependency Management\n(pyproject.toml, requirements.txt)"]:::utils

    %% Infrastructure
    subgraph "Infrastructure"
        Uvicorn["Uvicorn ASGI Server"]:::infra
        Docker["Docker Container\n(Dockerfile, .dockerignore)"]:::infra
    end

    %% Flow: Client to API
    Client -->|"HTTP Request"| FastAPIApp
    FastAPIApp -->|"mount routers"| Aps

    %% Routing to Services
    Aps -->|"static routes"| RRouter
    Aps -->|"dynamic routes"| DRouter
    RRouter -->|"calls directory ops"| RService
    DRouter -->|"calls record ops"| RecService

    %% Services to Storage
    RService -->|"mkdir, rmdir, list"| FileSystem
    RecService -->|"read/write JSON"| FileSystem

    %% Configuration Injection
    Env -->|"defines ROOT_DIR"| Config
    Config -->|"provides ROOT_DIR"| RService
    Config -->|"provides ROOT_DIR"| RecService
    Config -->|"provides ROOT_DIR"| DRouter

    %% Logging
    Logger -->|"logs from"| FastAPIApp
    Logger -->|"logs from"| RRouter
    Logger -->|"logs from"| DRouter
    Logger -->|"logs from"| RService
    Logger -->|"logs from"| RecService

    %% Infrastructure Hosting
    Docker -->|contains| Uvicorn
    Uvicorn -->|"serves app"| FastAPIApp

    %% Click Events
    click FastAPIApp "https://github.com/rakeshgombi/autoapi/blob/master/main.py"
    click Aps "https://github.com/rakeshgombi/autoapi/blob/master/routes/apis.py"
    click RRouter "https://github.com/rakeshgombi/autoapi/blob/master/routes/endpoints/resource_router.py"
    click DRouter "https://github.com/rakeshgombi/autoapi/blob/master/routes/endpoints/dynamic_router.py"
    click RService "https://github.com/rakeshgombi/autoapi/blob/master/routes/services/resource_service.py"
    click RecService "https://github.com/rakeshgombi/autoapi/blob/master/routes/services/records_service.py"
    click Config "https://github.com/rakeshgombi/autoapi/blob/master/utils/config.py"
    click Logger "https://github.com/rakeshgombi/autoapi/blob/master/utils/logger.py"
    click Env "https://github.com/rakeshgombi/autoapi/blob/master/.env"
    click DepMgmt "https://github.com/rakeshgombi/autoapi/blob/master/pyproject.toml"
    click Docker "https://github.com/rakeshgombi/autoapi/tree/master/Dockerfile"

    %% Styles
    classDef api fill:#cce5ff,stroke:#004085,color:#004085;
    classDef router fill:#b8daff,stroke:#004085,color:#004085;
    classDef service fill:#d4edda,stroke:#155724,color:#155724;
    classDef storage fill:#fff3cd,stroke:#856404,color:#856404;
    classDef utils fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef infra fill:#d6d8d9,stroke:#1b1e21,color:#1b1e21;
    classDef external fill:#f1f1f1,stroke:#111111,color:#111111;
```
