# achrafaitmbarek/unicent architecture

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

- Interactive diagram: https://gitdiagram.com/achrafaitmbarek/unicent
- Repository: https://github.com/achrafaitmbarek/unicent

## Overview

##### Project Type and Purpose
- This is a full-stack financial management application built on Next.js 13+ (App Router) with TypeScript.
- It provides user authentication (NextAuth.js), bank data integration (Powens API), transaction analysis via OpenAI GPT, and presents a responsive dashboard.

##### Main Components
a. Frontend (Next.js App Router)
- App directory: React Server Components (layout.tsx, page.tsx) and Client Components in `components/` and `app/` sub-folders (auth, dashboard, UI primitives).
- Custom Hooks: `hooks/use-mobile.tsx`, `hooks/use-toast.ts`
- Styling: Tailwind CSS (`tailwind.config.ts`, `globals.css`)

b. Backend (Next.js API Routes & Middleware)
- API Routes under `app/api/` (auth endpoints via NextAuth, other REST/GraphQL endpoints if any).
- Custom middleware (`middleware.ts`) for route protection.
- NextAuth configuration (`auth.ts`, `auth.config.ts`)

c. Database and ORM
- PostgreSQL database (via Docker Compose).
- Prisma ORM (schema in `prisma/schema.prisma`, migrations, `lib/prisma.ts`).
- Prisma Studio (exposed on port 5555)

d. Caching / Rate Limiting
- Redis instance (via `lib/redis.ts`), used by rate-limit library (`lib/rate-limit.ts`).

e. External Services
- Powens Banking API (client credentials in environment, service calls in `services/actions/login.ts`, `register.ts`).
- OpenAI GPT API (transaction analysis logic in `services/…`)

f. Containerization & Development Tooling
- Docker Compose orchestrates:
- Next.js app (port 3000)
- PostgreSQL (port 5432)
- Adminer (DB UI on port 8080, custom theme)
- Named volumes for data persistence
- Dockerfile for building the Next.js image

##### Relationships and Data Flows
- User → Next.js Frontend (React pages)
- Frontend ↔ NextAuth Middleware → Prisma → PostgreSQL
- Frontend/API Routes → Services layer → External Powens API → Banking data
- Services layer → OpenAI GPT → AI-powered insights
- API Routes ↔ Redis (for rate limiting, caching)
- Docker Compose manages network connections among these containers

##### Architectural Patterns & Design Principles
- Monolithic “serverless-style” back end via Next.js API Routes
- Separation of concerns:
- UI and layout in `app/` and `components/`
- Business logic in `services/`
- Data access in `lib/prisma.ts` and Prisma client
- Caching and utilities in `lib/` and `utils/`
- Modular folder structure matching feature domains (auth, dashboard, AI-insights)
- Infrastructure as code with Docker Compose

## Diagram (Mermaid)

```mermaid
flowchart TB
    User["User/Browser"]:::external

    subgraph "Docker Compose Network" 
        style DockerComposeNetwork stroke-dasharray: 5 5

        subgraph "Presentation Layer"
            direction TB
            Layout["layout.tsx"]:::frontend
            click Layout "https://github.com/achrafaitmbarek/unicent/blob/main/app/layout.tsx"
            Page["page.tsx"]:::frontend
            click Page "https://github.com/achrafaitmbarek/unicent/blob/main/app/page.tsx"
            AuthFolder["app/auth/"]:::frontend
            click AuthFolder "https://github.com/achrafaitmbarek/unicent/tree/main/app/auth/"
            DashboardFolder["app/dashboard/"]:::frontend
            click DashboardFolder "https://github.com/achrafaitmbarek/unicent/tree/main/app/dashboard/"
            Fonts["app/fonts/"]:::frontend
            click Fonts "https://github.com/achrafaitmbarek/unicent/tree/main/app/fonts/"
            GlobalsCSS["globals.css"]:::frontend
            click GlobalsCSS "https://github.com/achrafaitmbarek/unicent/blob/main/app/globals.css"

            subgraph "UI Components"
                direction TB
                AuthComps["components/auth/"]:::frontend
                click AuthComps "https://github.com/achrafaitmbarek/unicent/tree/main/components/auth/"
                DashboardComps["components/dashboard/"]:::frontend
                click DashboardComps "https://github.com/achrafaitmbarek/unicent/tree/main/components/dashboard/"
                UIPrimitives["components/ui/"]:::frontend
                click UIPrimitives "https://github.com/achrafaitmbarek/unicent/tree/main/components/ui/"
            end

            subgraph "Custom Hooks"
                direction TB
                UM["use-mobile.tsx"]:::frontend
                click UM "https://github.com/achrafaitmbarek/unicent/blob/main/hooks/use-mobile.tsx"
                UT["use-toast.ts"]:::frontend
                click UT "https://github.com/achrafaitmbarek/unicent/blob/main/hooks/use-toast.ts"
            end

            subgraph "Styling"
                direction TB
                TC["tailwind.config.ts"]:::frontend
                click TC "https://github.com/achrafaitmbarek/unicent/blob/main/tailwind.config.ts"
                PC["postcss.config.mjs"]:::frontend
                click PC "https://github.com/achrafaitmbarek/unicent/blob/main/postcss.config.mjs"
                GC2["globals.css"]:::frontend
                click GC2 "https://github.com/achrafaitmbarek/unicent/blob/main/app/globals.css"
            end
        end

        subgraph "API & Auth Layer"
            direction TB
            API["NextAuth Route"]:::api
            click API "https://github.com/achrafaitmbarek/unicent/blob/main/app/api/auth/[...nextauth]/route.ts"
            AuthConfig["auth.ts"]:::api
            click AuthConfig "https://github.com/achrafaitmbarek/unicent/blob/main/auth.ts"
            AuthConf2["auth.config.ts"]:::api
            click AuthConf2 "https://github.com/achrafaitmbarek/unicent/blob/main/auth.config.ts"
            Middleware["middleware.ts"]:::api
            click Middleware "https://github.com/achrafaitmbarek/unicent/blob/main/middleware.ts"
        end

        subgraph "Service Layer"
            direction TB
            LoginSrv["login.ts"]:::api
            click LoginSrv "https://github.com/achrafaitmbarek/unicent/blob/main/services/actions/login.ts"
            RegisterSrv["register.ts"]:::api
            click RegisterSrv "https://github.com/achrafaitmbarek/unicent/blob/main/services/actions/register.ts"
            UtilsLib["utils.ts"]:::api
            click UtilsLib "https://github.com/achrafaitmbarek/unicent/blob/main/lib/utils.ts"
        end

        subgraph "Cache & Rate Limiting"
            direction TB
            RedisLib["redis.ts"]:::cache
            click RedisLib "https://github.com/achrafaitmbarek/unicent/blob/main/lib/redis.ts"
            RateLimit["rate-limit.ts"]:::cache
            click RateLimit "https://github.com/achrafaitmbarek/unicent/blob/main/lib/rate-limit.ts"
            RedisCache["Redis"]:::cache
        end

        subgraph "Data Layer"
            direction TB
            PrismaSchema["schema.prisma"]:::db
            click PrismaSchema "https://github.com/achrafaitmbarek/unicent/blob/main/prisma/schema.prisma"
            Migrations["migrations/"]:::db
            click Migrations "https://github.com/achrafaitmbarek/unicent/tree/main/prisma/migrations/"
            PrismaClient["prisma.ts"]:::db
            click PrismaClient "https://github.com/achrafaitmbarek/unicent/blob/main/lib/prisma.ts"
            Postgres["PostgreSQL"]:::db
        end

        subgraph "Dev & Infra"
            direction TB
            DockerCompose["docker-compose.yml"]:::infra
            click DockerCompose "https://github.com/achrafaitmbarek/unicent/blob/main/docker-compose.yml"
            Dockerfile["Dockerfile"]:::infra
            click Dockerfile "https://github.com/achrafaitmbarek/unicent/tree/main/dockerfile"
            Dockerignore[".dockerignore"]:::infra
            click Dockerignore "https://github.com/achrafaitmbarek/unicent/blob/main/.dockerignore"
            EnvExample[".env.example"]:::infra
            click EnvExample "https://github.com/achrafaitmbarek/unicent/blob/main/.env.example"
            Adminer["Adminer UI"]:::external
            PrismaStudio["Prisma Studio"]:::external
        end
    end

    subgraph "External Services"
        direction TB
        Powens["Powens Banking API"]:::external
        OpenAI["OpenAI GPT API"]:::external
    end

    User -->|"loads app"| Layout
    Layout --> Page
    Page --> AuthFolder
    Page --> DashboardFolder

    Page --> Middleware
    Middleware --> API
    API --> LoginSrv
    API --> RegisterSrv

    LoginSrv --> RedisLib
    LoginSrv --> PrismaClient
    RegisterSrv --> PrismaClient
    LoginSrv --> Powens
    RegisterSrv --> Powens
    LoginSrv --> OpenAI
    UtilsLib --> Powens

    RedisLib --> RedisCache
    PrismaClient --> Postgres
    Adminer --> Postgres
    PrismaStudio --> Postgres

    classDef frontend fill:#e0f7fa,stroke:#0277bd,color:#000
    classDef api fill:#ffe0b2,stroke:#ef6c00,color:#000
    classDef db fill:#c8e6c9,stroke:#388e3c,color:#000
    classDef cache fill:#fff9c4,stroke:#f9a825,color:#000
    classDef external fill:#f0f4c3,stroke:#afb42b,color:#000
    classDef infra fill:#e1bee7,stroke:#8e24aa,color:#000
```
