# arthurmousinho/selffy architecture

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

- Interactive diagram: https://gitdiagram.com/arthurmousinho/selffy
- Repository: https://github.com/arthurmousinho/selffy

## Overview

##### Project type and purpose
- This is a full‐stack SaaS web application (“Selffy”) for managing freelance projects, tasks, costs, and users, with an AI assistant to generate task descriptions/guides.
- It consists of three independently deployable components:
- Web client (“web/”) built in React + Vite
- Main REST API server (“api/”) built on NestJS + Prisma + PostgreSQL
- AI Model microservice (“model/”) built in Node, connecting to Ollama

##### File structure
- Top-level folders:
- api/ — NestJS monolith implementing controllers, application/use-case layer, domain entities, Prisma repositories, storage & AI services
- web/ — React/Vite SPA with components, hooks, pages, routing, UI library
- model/ — Lightweight Express-style service exposing AI endpoints
- docs/ — architecture TLDR, features, RBAC
- The api/ folder follows a layered “Hexagonal/Clean” architecture:
- infra/http → controllers, DTOs, guards
- application/use-cases → business logic modules (user, project, task, cost)
- domain → entities, repository interfaces, domain services
- infra/database → Prisma service, mappers, repository implementations
- infra/services → Cloudinary (storage), Ollama (AI)
- Docker files in api/ coordinate the API + PostgreSQL.
- model/ has its own .env, router, middleware for API key auth.
- web/ uses Vite’s TS setup, React components, Tailwind, and axios for HTTP.

##### README for additional insights
- README.MD in root instructs developers to run each component separately.
- RBAC.md and features.md list data flows and security requirements (JWT auth, role guard).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Side
    subgraph "Client Side"
        direction TB
        Browser["User Browser"]:::frontend
        Web["Web Client (React SPA)"]:::frontend
    end
    Browser -->|"Interacts"| Web
    Web -->|"HTTPS/REST (JWT auth)"| API["API Server (NestJS)"]:::backend

    %% API Server Layers
    subgraph "API Server (NestJS)"
        direction TB
        subgraph "HTTP Layer"
            HTTP["Controllers/DTOs/Guards"]:::backend
        end
        subgraph "Application Layer"
            App["Use-Cases"]:::backend
        end
        subgraph "Domain Layer"
            Domain["Entities/Repositories/Services"]:::backend
        end
        subgraph "Infra Database"
            DBInfra["Prisma & Repos"]:::backend
        end
        subgraph "Infra Services"
            Cloud["Cloudinary Service"]:::external
            AIService["Ollama AI Service"]:::external
        end
    end
    API --> HTTP
    HTTP --> App
    App --> Domain
    Domain --> DBInfra
    Domain --> AIService
    HTTP --> Cloud

    %% Database
    DBInfra -->|"Prisma ORM"| PostgreSQL["PostgreSQL"]:::external

    %% AI Microservice Interaction
    API -->|"HTTP/gRPC"| ModelService["AI Model Microservice"]:::backend

    %% AI Model Microservice
    subgraph "AI Model Microservice"
        direction TB
        MS_HTTP["Express Router"]:::backend
        MS_Biz["Task Description/Guide Logic"]:::backend
        MS_Config["Ollama Config"]:::backend
    end
    ModelService --> MS_HTTP
    MS_HTTP --> MS_Biz
    MS_Biz --> MS_Config
    MS_Config --> Ollama["Ollama AI Engine"]:::external

    %% Click Events
    click Web "https://github.com/arthurmousinho/selffy/tree/main/web/"
    click API "https://github.com/arthurmousinho/selffy/tree/main/api/"
    click HTTP "https://github.com/arthurmousinho/selffy/tree/main/api/src/infra/http/"
    click App "https://github.com/arthurmousinho/selffy/tree/main/api/src/application/use-cases/"
    click Domain "https://github.com/arthurmousinho/selffy/tree/main/api/src/domain/"
    click DBInfra "https://github.com/arthurmousinho/selffy/tree/main/api/src/infra/database/prisma/"
    click PostgreSQL "https://github.com/arthurmousinho/selffy/blob/main/api/prisma/schema.prisma"
    click Cloud "https://github.com/arthurmousinho/selffy/blob/main/api/src/infra/services/cloudinary/cloudinary-storage.service.ts"
    click AIService "https://github.com/arthurmousinho/selffy/blob/main/api/src/infra/services/ollama/ollama-ai-model.service.ts"
    click ModelService "https://github.com/arthurmousinho/selffy/blob/main/model/src/server.ts"
    click MS_HTTP "https://github.com/arthurmousinho/selffy/blob/main/model/src/router.ts"
    click MS_Biz "https://github.com/arthurmousinho/selffy/blob/main/model/src/app/generate-task-description.ts"
    click MS_Biz "https://github.com/arthurmousinho/selffy/blob/main/model/src/app/generate-task-guide.ts"
    click MS_Config "https://github.com/arthurmousinho/selffy/blob/main/model/src/config/ollama.config.ts"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#004D40
    classDef backend fill:#E8F5E9,stroke:#2E7D32,color:#1B5E20
    classDef external fill:#FFF3E0,stroke:#EF6C00,color:#E65100
```
