Passa al contenuto principale

Struttura Progetto

Guida dettagliata alla struttura del monorepo Emblema e organizzazione del codice.

πŸ“‚ Struttura Monorepo​

emblema/
β”œβ”€β”€ apps/ # Applicazioni principali
β”‚ β”œβ”€β”€ www-emblema/ # 🌐 Web app principale (Next.js 14)
β”‚ β”œβ”€β”€ ui/ # 🎨 Libreria componenti condivisi
β”‚ β”œβ”€β”€ doc-emblema/ # πŸ“š Documentazione (Docusaurus)
β”‚ β”œβ”€β”€ background-task/ # βš™οΈ Worker AI (Python/Celery)
β”‚ β”œβ”€β”€ document-render/ # πŸ“„ Rendering documenti (Python)
β”‚ β”œβ”€β”€ novu-bridge/ # πŸ“¬ Bridge notifiche (Node.js)
β”‚ β”œβ”€β”€ mcp-demo/ # πŸ€– Demo MCP server (Python)
β”‚ └── keycloakify-starter/ # πŸ” Tema Keycloak personalizzato
β”œβ”€β”€ packages/ # Pacchetti condivisi
β”‚ β”œβ”€β”€ ui/ # Componenti UI Shadcn
β”‚ └── config/ # Configurazioni condivise
β”œβ”€β”€ config/ # Configurazioni infrastruttura
β”‚ β”œβ”€β”€ traefik/ # Reverse proxy config
β”‚ β”œβ”€β”€ keycloak/ # Auth config
β”‚ └── monitoring/ # Grafana dashboards
β”œβ”€β”€ install/ # Script installazione
β”œβ”€β”€ scripts/ # Script utility
β”‚ └── security/ # Security scanning
β”œβ”€β”€ docker/ # Dockerfile templates
β”œβ”€β”€ hasura/ # GraphQL schema & migrations
└── templates/ # Template generatori codice

🌐 Frontend Applications​

apps/www-emblema/​

Applicazione web principale con Next.js 14 App Router.

www-emblema/
β”œβ”€β”€ app/ # Next.js App Router
β”‚ β”œβ”€β”€ layout.tsx # Root layout
β”‚ β”œβ”€β”€ page.tsx # Homepage
β”‚ β”œβ”€β”€ (auth)/ # Gruppo auth
β”‚ β”‚ β”œβ”€β”€ login/
β”‚ β”‚ └── register/
β”‚ β”œβ”€β”€ dashboard/ # Dashboard utente
β”‚ β”‚ β”œβ”€β”€ layout.tsx
β”‚ β”‚ β”œβ”€β”€ page.tsx
β”‚ β”‚ └── documents/
β”‚ β”œβ”€β”€ documents/ # Gestione documenti
β”‚ β”‚ β”œβ”€β”€ [id]/
β”‚ β”‚ β”œβ”€β”€ upload/
β”‚ β”‚ └── list/
β”‚ β”œβ”€β”€ chat/ # Chat AI
β”‚ β”‚ β”œβ”€β”€ [chatId]/
β”‚ β”‚ └── components/
β”‚ β”œβ”€β”€ api/ # API Routes
β”‚ β”‚ β”œβ”€β”€ v1/ # API versionate
β”‚ β”‚ β”œβ”€β”€ auth/[...nextauth]/ # NextAuth
β”‚ β”‚ └── cron/ # Cron jobs
β”‚ └── settings/ # Impostazioni utente
β”œβ”€β”€ components/ # React components
β”‚ β”œβ”€β”€ ui/ # UI base components
β”‚ β”œβ”€β”€ features/ # Feature components
β”‚ β”‚ β”œβ”€β”€ document/
β”‚ β”‚ β”œβ”€β”€ chat/
β”‚ β”‚ β”œβ”€β”€ chunk/
β”‚ β”‚ └── knowledge-base/
β”‚ └── layout/ # Layout components
β”œβ”€β”€ hooks/ # Custom React hooks
β”œβ”€β”€ lib/ # Utility functions
β”œβ”€β”€ contexts/ # React contexts
β”œβ”€β”€ schema/ # Zod validation schemas
β”œβ”€β”€ types/ # TypeScript types
β”œβ”€β”€ public/ # Static assets
└── config/ # App configuration

apps/ui/​

Libreria componenti condivisi basata su Shadcn/ui.

ui/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ components/ # Componenti esportati
β”‚ β”‚ β”œβ”€β”€ button.tsx
β”‚ β”‚ β”œβ”€β”€ card.tsx
β”‚ β”‚ β”œβ”€β”€ dialog.tsx
β”‚ β”‚ └── ...
β”‚ β”œβ”€β”€ lib/ # Utilities
β”‚ └── index.ts # Export principale
β”œβ”€β”€ package.json
└── tsconfig.json

βš™οΈ Backend Services​

apps/background-task/​

Worker Celery per elaborazioni AI intensive.

background-task/
β”œβ”€β”€ app/
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ main.py # FastAPI application
β”‚ β”œβ”€β”€ celery_app.py # Celery configuration
β”‚ β”œβ”€β”€ config.py # Settings
β”‚ β”œβ”€β”€ dependencies.py # Dependency injection
β”‚ β”œβ”€β”€ tasks.py # Celery tasks
β”‚ β”œβ”€β”€ chunkers/ # Document chunking
β”‚ β”‚ β”œβ”€β”€ __init__.py
β”‚ β”‚ β”œβ”€β”€ base.py
β”‚ β”‚ β”œβ”€β”€ document.py # PDF/TXT chunker
β”‚ β”‚ β”œβ”€β”€ audio.py # Audio chunker
β”‚ β”‚ └── video.py # Video chunker
β”‚ β”œβ”€β”€ handlers/ # Business logic
β”‚ β”‚ β”œβ”€β”€ document.py
β”‚ β”‚ β”œβ”€β”€ audio.py
β”‚ β”‚ β”œβ”€β”€ storage.py
β”‚ β”‚ └── vector_db.py
β”‚ β”œβ”€β”€ routers/ # API endpoints
β”‚ β”‚ └── tasks.py
β”‚ └── utils/ # Utilities
β”œβ”€β”€ tests/ # Test suite
β”œβ”€β”€ pyproject.toml # Python dependencies
β”œβ”€β”€ Dockerfile # Container config
└── docker-compose.yaml # Local development

apps/document-render/​

Servizio rendering documenti PDF.

document-render/
β”œβ”€β”€ app/
β”‚ β”œβ”€β”€ main.py # FastAPI app
β”‚ β”œβ”€β”€ renderer.py # Rendering logic
β”‚ └── config.py # Configuration
β”œβ”€β”€ templates/ # HTML templates
β”œβ”€β”€ static/ # CSS/JS assets
└── Dockerfile

πŸ”§ Configuration Files​

Root Configuration​

emblema/
β”œβ”€β”€ .env.example # Template variabili ambiente
β”œβ”€β”€ .gitignore # Git ignore rules
β”œβ”€β”€ docker-compose.yaml # Compose principale
β”œβ”€β”€ docker-compose-*.yaml # Compose modulari
β”œβ”€β”€ package.json # Root package.json
β”œβ”€β”€ pnpm-workspace.yaml # pnpm workspace config
β”œβ”€β”€ turbo.json # Turborepo config
└── tsconfig.json # TypeScript base config

Docker Compose Files​

  • docker-compose.yaml - File principale con includes
  • docker-compose-base.yaml - Servizi base (DB, Redis, MinIO)
  • docker-compose-data-source.yaml - Hasura, Milvus
  • docker-compose-auth.yaml - Keycloak
  • docker-compose-llm.yaml - LiteLLM gateway
  • docker-compose-monitoring.yaml - Grafana, Prometheus
  • docker-compose-notification.yaml - Novu
  • docker-compose-background-task.yaml - Celery workers

πŸ“ Important Directories​

/hasura​

Schema GraphQL e migrations Hasura.

hasura/
β”œβ”€β”€ metadata/ # Hasura metadata
β”‚ β”œβ”€β”€ tables.yaml
β”‚ β”œβ”€β”€ actions.yaml
β”‚ └── permissions/
β”œβ”€β”€ migrations/ # Database migrations
└── seeds/ # Seed data

/config​

Configurazioni servizi infrastruttura.

config/
β”œβ”€β”€ traefik/
β”‚ β”œβ”€β”€ traefik.yml # Config principale
β”‚ β”œβ”€β”€ traefik-le.yml # Let's Encrypt config
β”‚ β”œβ”€β”€ dynamic/ # Routing dinamico
β”‚ └── certs/ # Certificati custom
β”œβ”€β”€ keycloak/
β”‚ └── realm-export.json # Realm configuration
└── monitoring/
β”œβ”€β”€ prometheus.yml # Prometheus config
└── dashboards/ # Grafana dashboards

/scripts​

Script utility per sviluppo e deployment.

scripts/
β”œβ”€β”€ security/ # Security scanning
β”‚ β”œβ”€β”€ scan.sh
β”‚ β”œβ”€β”€ generate-html-report.sh
β”‚ └── generate-sbom.sh
β”œβ”€β”€ export-docker-images.sh # Export per air-gap
β”œβ”€β”€ import-docker-images.sh # Import immagini
└── health-check.sh # Health monitoring

πŸ—οΈ Build Artifacts​

Frontend Build​

apps/www-emblema/
β”œβ”€β”€ .next/ # Next.js build output
β”œβ”€β”€ out/ # Static export (se usato)
└── node_modules/ # Dependencies

Python Services​

apps/background-task/
β”œβ”€β”€ .venv/ # Virtual environment
β”œβ”€β”€ __pycache__/ # Python cache
└── dist/ # Build artifacts

Docker Images​

# Naming convention
emblema/www:dev
emblema/background-task:dev
emblema/document-render:dev

πŸ“ Naming Conventions​

File Naming​

  • Components: PascalCase.tsx (es. DocumentCard.tsx)
  • Hooks: camelCase.ts con prefisso use (es. useDocuments.ts)
  • Utils: kebab-case.ts (es. format-date.ts)
  • Types: kebab-case.types.ts (es. document.types.ts)
  • Constants: UPPER_SNAKE_CASE.ts (es. API_ENDPOINTS.ts)

Directory Structure​

  • Feature-based: Raggruppa per funzionalitΓ 
  • Colocation: Tieni vicini file correlati
  • Shallow nesting: Max 3-4 livelli di profonditΓ 

Import Paths​

// Usa alias assoluti
import { Button } from "@/components/ui/button";
import { useDocuments } from "@/hooks/use-documents";

// Non path relativi profondi
// ❌ import { Button } from "../../../components/ui/button";

πŸ”’ Security Considerations​

Sensitive Files​

Non committare mai:

  • .env (usa .env.example)
  • *.key, *.pem, *.crt
  • secrets/, credentials/
  • .venv/, node_modules/

Docker Secrets​

# docker-compose.yaml
secrets:
db_password:
file: ./secrets/db_password.txt

πŸš€ Development Workflow​

1. Setup Locale​

# Clone e setup
git clone <repo>
cd emblema
pnpm install
./install.sh

2. Development Mode​

# Frontend
pnpm --filter=www-emblema dev

# Backend
cd apps/background-task
uv run fastapi dev

3. Build & Test​

# Build all
pnpm build

# Test
pnpm test

# Lint
pnpm lint

πŸ“š Best Practices​

  1. Monorepo Management

    • Usa pnpm workspace per dipendenze condivise
    • Turbo per build caching
    • Cambia solo ciΓ² che serve
  2. Code Organization

    • Feature-based structure
    • Colocate test vicino al codice
    • Shared code in packages/
  3. Configuration

    • Environment-specific in .env
    • Defaults in code
    • Type-safe configuration objects
  4. Documentation

    • README in ogni app/package
    • Inline comments per logica complessa
    • API documentation con OpenAPI/GraphQL

πŸ’‘ Tip: Usa tree -I 'node_modules|.next|.venv' -L 3 per visualizzare la struttura senza file di build.

Questa pagina ti Γ¨ stata utile?