# amalour/pattern-ai architecture

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

- Interactive diagram: https://gitdiagram.com/amalour/pattern-ai
- Repository: https://github.com/amalour/pattern-ai

## Overview

##### Project Type and Purpose
- The application is a full-stack solution that offers AI-driven analysis for codebases.
- It includes a sophisticated microservices architecture with an Angular frontend, a Spring Boot backend for handling business logic (authentication, API endpoints, and integration with AI services), and a Python backend for embedding generation and vector similarity searches.
- Additionally, it uses a PostgreSQL database with the pgvector extension for vector storage.

##### File Structure Highlights
- The top-level directories clearly separate the major components:
- “frontend”: Hosts an Angular application, with dedicated configuration files (e.g., angular.json, tailwind.config.js), component directories (header, login, chat, etc.), and routing/guard setups.
- “backend_python”: Contains the Python backend with an “app.py” file and dependencies (“requirements.txt”). This backend is meant for handling tasks like code embeddings using LangChain and Hugging Face Transformers.
- Similar to most microservices architectures, Dockerfiles and a docker-compose.yml file are present, indicating container-based development and deployment.

a. Main Components:
- Frontend: Angular UI handling user interactions, dashboards, code analysis visualizations, and charts.
- Spring Boot Backend: Executes business logic, handles REST API endpoints for authentication and design pattern analysis (also integrates with OpenAI), manages Java-based processing, and enforces security with JWT.
- Python Backend: Focused on generating code embeddings, performing vector similarity searches using pgvector, and utilizing LangChain and transformers for analysis.
- Database: PostgreSQL with pgvector integration, acting as the central data store for persisting user data, analysis results, vector embeddings, and possibly session/authentication info.
- External Services: OpenAI integration and any other external APIs (like Swagger UI for API documentation).

b. Component Relationships and Interactions:
- The Angular Frontend communicates with the Spring Boot backend via HTTP/REST API calls. This includes authentication, fetching analysis results, and retrieving design pattern recommendations.
- The Spring Boot backend enforces security (via JWT), orchestrates business logic, and then may interact with the PostgreSQL database using Spring Data JPA.
- For AI tasks such as vector embedding generation and similarity matching, the Spring Boot backend might call the Python backend. Alternatively, the Python backend could be triggered independently by the frontend through an API call.
- PostgreSQL with pgvector is accessible from both backend services to store and retrieve embeddings and data.
- Frontend ⇄ Spring Boot backend (secured APIs)
- Spring Boot backend ⇄ Python backend (data/AI requests)
- Both backends ⇄ PostgreSQL (database read/write operations)

c. Architectural Patterns and Principles:
- Microservices Architecture: Clear separation of concerns with distinct services running in individual containers.
- API-Driven Communication: Use of REST and Swagger for interactive API documentation.
- Security Best Practices: Spring Security implemented with JWT to secure endpoints.
- Containerization: Emphasis on Docker (with Dockerfiles and docker-compose) for development and deployment consistency.

d. Technologies, Frameworks, and Libraries:
- Frontend: Angular 17+, TailwindCSS, TypeScript.
- Spring Boot Backend: Spring Boot 3.x, Spring Security, Spring Data JPA, Maven for dependency management.
- Python Backend: LangChain, Hugging Face Transformers, pgvector.
- Database: PostgreSQL with pgvector extension.
- Other: Docker and Docker Compose for container orchestration.

## Diagram (Mermaid)

```mermaid
flowchart TD 
    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Angular Frontend"]:::frontend
    end

    %% Backend Services
    subgraph "Backend Services"
        SB["Spring Boot Backend (JWT,Swagger)"]:::sb
        PY["Python Backend (Embeddings)"]:::python
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["PostgreSQL (pgvector)"]:::db
    end

    %% External Services
    OPENAI["OpenAI"]:::external

    %% Deployment & Containerization
    subgraph "Deployment & Containerization"
        DC["Docker Compose"]:::container
        FD["Frontend Dockerfile"]:::container
        SBD["Spring Boot Dockerfile"]:::container
        PYD["Python Dockerfile"]:::container
    end

    %% Connections between main components
    FE -->|"HTTP:Auth,Analysis,Chat"| SB
    SB -->|"API_CALL:Embeddings"| PY
    SB -->|"CRUD"| DB
    PY -->|"CRUD"| DB
    SB -->|"OpenAI_API"| OPENAI

    %% Containerization associations (dotted connections)
    FE -.-> FD
    SB -.-> SBD
    PY -.-> PYD
    FD -.-> DC
    SBD -.-> DC
    PYD -.-> DC

    %% Click Events
    click FE "https://github.com/amalour/pattern-ai/tree/main/frontend/"
    click SB "https://github.com/amalour/pattern-ai/tree/main/backend_springboot/"
    click PY "https://github.com/amalour/pattern-ai/tree/main/backend_python/"
    click DB "https://github.com/amalour/pattern-ai/blob/main/init.sql"
    click DC "https://github.com/amalour/pattern-ai/blob/main/docker-compose.yml"
    click FD "https://github.com/amalour/pattern-ai/tree/main/frontend/Dockerfile"
    click SBD "https://github.com/amalour/pattern-ai/tree/main/backend_springboot/Dockerfile"
    click PYD "https://github.com/amalour/pattern-ai/tree/main/backend_python/Dockerfile"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef sb fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef python fill:#f3e5f5,stroke:#6f42c1,stroke-width:2px;
    classDef db fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef container fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
```
