diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cc1bf4a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,38 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ +build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo + +# BMad and Antigravity +_bmad-output/ +.gemini/ +.antigravityignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ac33370 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,55 @@ +FROM node:18-alpine AS base + +# Install dependencies only when needed +FROM base AS deps +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat +WORKDIR /app + +# Install dependencies based on the preferred package manager +COPY package.json package-lock.json* ./ +RUN npm ci + +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +# Next.js telemetry is disabled +ENV NEXT_TELEMETRY_DISABLED=1 + +RUN npm run build + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production +# Next.js telemetry is disabled +ENV NEXT_TELEMETRY_DISABLED=1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +# Set the correct permission for prerender cache +RUN mkdir .next +RUN chown nextjs:nodejs .next + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT=3000 +# set hostname to localhost +ENV HOSTNAME="0.0.0.0" + +# Run the standalone server +CMD ["node", "server.js"] diff --git a/README.md b/README.md index e215bc4..cf3590e 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,57 @@ -This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). +# CollectFlow -## Getting Started +CollectFlow est une application de révision d'assortiment et d'analyse de performances des produits en point de vente, conçue pour consolider les données issues de plusieurs fournisseurs et magasins. -First, run the development server: +## Prérequis +- **Node.js** 18+ (pour le développement local) +- **Docker** et **Docker Compose** (pour le déploiement conteneurisé) +- **PostgreSQL** 16+ + +## Lancer avec Docker + +Le projet est configuré pour tourner dans un conteneur Docker optimisé (mode standalone de Next.js). +**Note :** Vous devez disposer d'une base de données PostgreSQL séparée (le conteneur ne lance que l'application web). + +### 1. Démarrer l'application +À la racine du projet, lancez : ```bash -npm run dev -# or -yarn dev -# or -pnpm dev -# or -bun dev +npm run docker:build +# ou directement +docker-compose up -d --build +``` +L'application sera accessible sur [http://localhost:3000](http://localhost:3000). + +*Si votre base de données se trouve sur la machine locale, le `docker-compose.yml` utilise `network_mode: "host"` par défaut pour faciliter la connexion localhost.* + +### 2. Arrêter l'application +```bash +npm run docker:down +# ou directement +docker-compose down ``` -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. +## Développement Local (Sans Docker) -You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. +Si vous préférez développer en local, vous devrez configurer votre propre base de données PostgreSQL. -This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. +1. Installer les dépendances : +```bash +npm install +``` -## Learn More +2. Configurer la connexion DB : +Allez sur la page des Paramètres (`/settings`) dans l'application pour configurer l'accès à votre PostgreSQL local. -To learn more about Next.js, take a look at the following resources: +3. Lancer le serveur de développement : +```bash +npm run dev +``` -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. +## Structure du Projet (BMAD) -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! - -## Deploy on Vercel - -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. - -Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. +Ce projet respecte l'architecture **BMAD** (Business, Model, Application/API, Data) : +- `src/features/*` : Logique métier (Business) isolée par feature (ex: `grid`, `snapshots`) +- `src/types/*` : Interfaces TypeScript (Model) +- `src/app/*` : Routeurs Next.js UI et endpoints d'API (Application/API) +- `src/db/*` : Schémas Drizzle ORM et connexions (Data) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a19a333 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,16 @@ +version: "3.8" + +services: + web: + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" + environment: + - NODE_ENV=production + # L'URL de la base de données peut être passée ici si nécessaire (ex: postgres://user:pass@host:5432/db) + # Mais comme CollectFlow permet de le configurer depuis l'interface (settings), ce n'est pas strictement obligatoire au lancement. + restart: unless-stopped + # Pour s'assurer que le container peut accéder à une base de données sur la machine hôte + network_mode: "host" diff --git a/next.config.ts b/next.config.ts index e9ffa30..68a6c64 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + output: "standalone", }; export default nextConfig; diff --git a/package.json b/package.json index d1bca6f..8e7e6c4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,10 @@ "dev": "next dev", "build": "next build", "start": "next start", - "lint": "eslint" + "lint": "eslint", + "docker:up": "docker-compose up -d", + "docker:down": "docker-compose down", + "docker:build": "docker-compose up -d --build" }, "dependencies": { "@tanstack/react-query": "^5.90.21", @@ -43,4 +46,4 @@ "tw-animate-css": "^1.4.0", "typescript": "^5" } -} +} \ No newline at end of file