# arxane/semantic-code-refactorer architecture

> Architecture diagram of the GitHub repository arxane/semantic-code-refactorer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arxane/semantic-code-refactorer
- Repository: https://github.com/arxane/semantic-code-refactorer

## Overview

##### Project type and purpose
- This is a full-stack web application (“AI Semantic Code Refactorer”)
- Frontend: React (in `frontend/`)
- Backend: FastAPI (in `app/`), Python 3.8+
- Database: PostgreSQL, with Alembic migrations
- External AI service: OpenAI API

##### File structure
- Top-level folders:
- `frontend/` → React SPA (package.json, src/)
- `app/` → FastAPI application
– `core/` (config, DB connection)
– `models/` (SQLAlchemy ORM models)
– `schemas/` (Pydantic request/response models)
– `routes/` (API endpoints)
– `services/` (business logic, AI refactoring modules)
- `alembic/` → migration scripts for schema versioning
- `tests/` → integration/unit tests
- `requirements.txt`, `.env.example`

##### README
- Confirms key components, tech stack, and runtime flow
- Describes features: semantic analysis, refactor suggestions, feedback loop

##### Elements
- Labels: “React Frontend,” “FastAPI API,” “AI Service,” “PostgreSQL DB,” “OpenAI”
- User actions → Frontend
- Frontend API calls → FastAPI
- FastAPI → Service layer & DB → OpenAI

##### Detailed capture of essential architecture
- `main.py` bootstraps the app, includes routes
- `core/config.py` reads env vars
- `core/database.py` initializes SQLAlchemy engine & sessions
- `models/` ↔ ORM mapping
- `schemas/` ↔ request/response contracts
- `services/` ↔ AI logic (real vs. mock)
- Migration flow: Alembic CLI → `alembic/env.py` → versions → PostgreSQL

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        ReactFE["React Frontend<br/>(SPA)"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        Main["FastAPI Bootstrap<br/>(main.py)"]:::backend
        Routes["Code Refactoring Routes<br/>(code_refactoring.py)"]:::backend
        Config["Config Module<br/>(config.py)"]:::backend
        DBModule["Database Init<br/>(database.py)"]:::backend
    end

    %% Service Layer
    subgraph "Service Layer"
        AIServiceReal["AI Refactoring Service<br/>(ai_refactoring.py)"]:::service
        AIServiceMock["Mock AI Service<br/>(mock_ai_refactoring.py)"]:::service
    end

    %% Data Layer
    subgraph "Data Layer"
        ORMModels["ORM Models<br/>(code_refactoring.py)"]:::database
        PostgreSQL["PostgreSQL DB"]:::database
    end

    %% Migration Layer
    subgraph "Migration Layer"
        AlembicEnv["Alembic Env Setup<br/>(env.py)"]:::database
        AlembicVersions["Versions Scripts<br/>(alembic/versions/)"]:::database
        AlembicIni["Alembic Config<br/>(alembic.ini)"]:::database
    end

    %% External & Config
    subgraph "External & Config"
        EnvExample["Env Example<br/>(.env.example)"]:::backend
        OpenAI["OpenAI API"]:::external
    end

    %% Testing
    subgraph "Testing"
        TestsAPI["API Tests<br/>(tests/test_api.py)"]:::test
        TestsConfig["Config Tests<br/>(app/test_config.py)"]:::test
    end

    %% Flows
    ReactFE -->|"REST API"| Main
    Main -->|includes| Routes
    Main -->|loads| Config
    Config -->|env vars| EnvExample
    Main -->|initializes| DBModule
    Routes -->|calls| AIServiceReal
    Routes -->|calls| AIServiceMock
    Routes -->|queries| DBModule
    DBModule -->|manages sessions| ORMModels
    ORMModels -->|CRUD| PostgreSQL
    AIServiceReal -->|HTTP| OpenAI
    AlembicEnv -->|runs migrations| PostgreSQL
    AlembicEnv -->|loads| AlembicIni
    AlembicEnv -->|executes| AlembicVersions
    TestsAPI -->|tests endpoints| Routes
    TestsConfig -->|tests| Config

    %% Click Events
    click ReactFE "https://github.com/arxane/semantic-code-refactorer/tree/main/frontend/"
    click Main "https://github.com/arxane/semantic-code-refactorer/blob/main/app/main.py"
    click Routes "https://github.com/arxane/semantic-code-refactorer/blob/main/app/routes/code_refactoring.py"
    click AIServiceReal "https://github.com/arxane/semantic-code-refactorer/blob/main/app/services/ai_refactoring.py"
    click AIServiceMock "https://github.com/arxane/semantic-code-refactorer/blob/main/app/services/mock_ai_refactoring.py"
    click DBModule "https://github.com/arxane/semantic-code-refactorer/blob/main/app/core/database.py"
    click ORMModels "https://github.com/arxane/semantic-code-refactorer/blob/main/app/models/code_refactoring.py"
    click Config "https://github.com/arxane/semantic-code-refactorer/blob/main/app/core/config.py"
    click EnvExample "https://github.com/arxane/semantic-code-refactorer/blob/main/.env.example"
    click AlembicEnv "https://github.com/arxane/semantic-code-refactorer/blob/main/alembic/env.py"
    click AlembicVersions "https://github.com/arxane/semantic-code-refactorer/tree/main/alembic/versions/"
    click AlembicIni "https://github.com/arxane/semantic-code-refactorer/blob/main/alembic.ini"
    click TestsAPI "https://github.com/arxane/semantic-code-refactorer/blob/main/tests/test_api.py"
    click TestsConfig "https://github.com/arxane/semantic-code-refactorer/blob/main/app/test_config.py"

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#1E88E5,color:#0D47A1
    classDef backend fill:#E8F5E9,stroke:#43A047,color:#1B5E20
    classDef service fill:#FFF3E0,stroke:#FB8C00,color:#E65100
    classDef database fill:#FFFDE7,stroke:#FDD835,color:#F9A825
    classDef external fill:#E1F5FE,stroke:#0288D1,color:#01579B
    classDef test fill:#F3E5F5,stroke:#8E24AA,color:#4A148C
```
