How achrafaitmbarek/unicent works
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