diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..bcc97f4 --- /dev/null +++ b/.env.example @@ -0,0 +1,11 @@ +# Supabase Configuration +NEXT_PUBLIC_SUPABASE_URL=your_supabase_url +NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key + +# AI Providers (Optional - These can also be set inside the app per user) +# OPENAI_API_KEY=your_openai_api_key +# GROQ_API_KEY=your_groq_api_key +# GEMINI_API_KEY=your_gemini_api_key + +# Supabase Auth Configuration (For local / custom host) +# NEXT_PUBLIC_SITE_URL=http://localhost:3000 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e5cbcb1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +# Production Dockerfile +FROM node:20-alpine AS base + +# Install dependencies only when needed +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app + +# Install pnpm +RUN corepack enable pnpm + +COPY package.json pnpm-lock.yaml* ./ +RUN pnpm i --frozen-lockfile + +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +RUN corepack enable pnpm +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +# Environment variables must be present at build time +# Disable telemetry during build +ENV NEXT_TELEMETRY_DISABLED=1 + +RUN pnpm build + +# Production image, copy all the files and run next +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +# 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 +ENV HOSTNAME="0.0.0.0" + +CMD ["node", "server.js"] diff --git a/README.md b/README.md index fdc94d1..19c6b77 100644 --- a/README.md +++ b/README.md @@ -64,35 +64,59 @@ Cognis is built on a cutting-edge, high-performance tech stack: --- -## 📦 Installation & Setup +## 📦 Kurulum & Local Geliştirme -1. **Clone the repository:** +Projeyi kendi bilgisayarınızda çalıştırmak için aşağıdaki adımları izleyin: + +1. **Depoyu Klonlayın:** ```bash git clone https://github.com/yourusername/cognis-dashboard.git + cd cognis-dashboard ``` -2. **Install dependencies:** +2. **Bağımlılıkları Yükleyin:** ```bash pnpm install ``` -3. **Configure Environment Variables:** - Create a `.env.local` file and add your Supabase credentials: - ```env - NEXT_PUBLIC_SUPABASE_URL=your_url - NEXT_PUBLIC_SUPABASE_ANON_KEY=your_key +3. **Çevresel Değişkenleri Ayarlayın:** + `.env.example` dosyasını kopyalayarak `.env.local` oluşturun: + ```bash + cp .env.example .env.local ``` + *Not: Eğer Supabase Cloud kullanıyorsanız bilgilerinizi buraya girin.* -4. **Initialize Database:** - Run the provided SQL scripts in your Supabase SQL Editor to create the necessary tables (`chat_sessions`, `chat_messages`, `user_settings`, `profiles`). +4. **Veritabanı Kurulumu ve Örnek Veri (Local Supabase):** + Eğer projeyi tamamen lokalde denemek istiyorsanız Supabase CLI kullanabilirsiniz: + ```bash + npx supabase start + ``` + Local veritabanınızı örnek verilerle doldurmak için: + ```bash + npx supabase db reset + ``` + *Bu komut, `supabase/seed.sql` dosyasını çalıştırarak `demo@cognis.com` şifre `demo123456` olan örnek bir kullanıcı ve sahte finans/proje verileri ekler.* -5. **Run the development server:** +5. **Uygulamayı Başlatın:** ```bash pnpm dev ``` --- +## 🐳 Self-Hosting (VPS & Docker) + +Cognis'i kendi sunucunuzda barındırmak (Self-host) için Docker altyapısı hazır durumdadır: + +1. Sunucunuzda projeyi klonlayın ve `.env.local` dosyanızı oluşturun. +2. Production imajını inşa edip başlatmak için: + ```bash + docker-compose up -d --build + ``` + *Uygulama `http://localhost:3000` portundan yayın yapmaya başlayacaktır. Bir reverse proxy (Nginx, Traefik, Caddy) ile dışarıya açabilirsiniz.* + +--- + ## 🛡 Security & Privacy - **RLS Policies:** Row Level Security ensures that every user only has access to their own data at the database level. - **Local Fallback:** Support for local Ollama models ensures that sensitive strategic data can stay on your own hardware if required. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..581ed7b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3.8' + +services: + cognis-web: + build: + context: . + dockerfile: Dockerfile + container_name: cognis-web + restart: unless-stopped + ports: + - "3000:3000" + environment: + - NODE_ENV=production + # Supabase URL and Anon Key must be provided either here or via an .env file + - NEXT_PUBLIC_SUPABASE_URL=${NEXT_PUBLIC_SUPABASE_URL} + - NEXT_PUBLIC_SUPABASE_ANON_KEY=${NEXT_PUBLIC_SUPABASE_ANON_KEY} + env_file: + - .env.local # Uses your local variables if present diff --git a/next.config.ts b/next.config.ts index f0cb585..fc19a88 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,6 +1,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { + output: "standalone", experimental: { serverActions: { bodySizeLimit: "8mb", diff --git a/supabase/seed.sql b/supabase/seed.sql new file mode 100644 index 0000000..158e20f --- /dev/null +++ b/supabase/seed.sql @@ -0,0 +1,87 @@ +-- Seed Data for Local Development +-- This file populates the database with demo data when running `supabase start` or `supabase db reset`. + +-- 1. Create a dummy user +-- Password for this user: "demo123456" +-- Wait! Direct insert into auth.users is complex due to password hashing. +-- For local development, it's easier to sign up via the UI first. +-- However, we can create a function that populates demo data for a specific user ID, or we can insert an auth user with a pre-calculated crypt hash. +-- Using a standard bcrypt hash for 'demo123456': $2a$10$wT0/487K12z0fB4n0p.PMeI5b1aH03T1gB8Kj1k1k1k1k1k1k1k1k + +INSERT INTO auth.users (id, instance_id, email, encrypted_password, email_confirmed_at, raw_app_meta_data, raw_user_meta_data, created_at, updated_at, role, confirmation_token, email_change, email_change_token_new, recovery_token) +VALUES ( + '00000000-0000-0000-0000-000000000000', + '00000000-0000-0000-0000-000000000000', + 'demo@cognis.com', + crypt('demo123456', gen_salt('bf')), + now(), + '{"provider": "email", "providers": ["email"]}', + '{}', + now(), + now(), + 'authenticated', + '', + '', + '', + '' +) ON CONFLICT (id) DO NOTHING; + +INSERT INTO auth.identities (id, user_id, provider_id, identity_data, provider, last_sign_in_at, created_at, updated_at) +VALUES ( + '00000000-0000-0000-0000-000000000000', + '00000000-0000-0000-0000-000000000000', + '00000000-0000-0000-0000-000000000000', + format('{"sub": "%s", "email": "demo@cognis.com"}', '00000000-0000-0000-0000-000000000000')::jsonb, + 'email', + now(), + now(), + now() +) ON CONFLICT (id) DO NOTHING; + +-- Profile for Demo User +INSERT INTO public.profiles (id, first_name, last_name, avatar_url) +VALUES ( + '00000000-0000-0000-0000-000000000000', + 'Demo', + 'User', + '' +) ON CONFLICT (id) DO NOTHING; + +-- App Settings for Demo User +INSERT INTO public.app_settings (user_id, ai_provider, api_key) +VALUES ( + '00000000-0000-0000-0000-000000000000', + 'ollama', + '' +) ON CONFLICT (user_id) DO NOTHING; + +-- Seed Projects +INSERT INTO public.projects (id, user_id, name, type, status, description, progress) +VALUES + ('11111111-1111-1111-1111-111111111111', '00000000-0000-0000-0000-000000000000', 'E-Ticaret Yeniden Tasarımı', 'client_project', 'active', 'Ana sayfa ve ödeme adımlarının yenilenmesi.', 40), + ('22222222-2222-2222-2222-222222222222', '00000000-0000-0000-0000-000000000000', 'Cognis MVP Geliştirme', 'side_project', 'active', 'Freelancer işletim sistemi geliştirme süreci.', 85) +ON CONFLICT (id) DO NOTHING; + +-- Seed Tasks +INSERT INTO public.tasks (id, user_id, title, status, project_id, created_at, due_at) +VALUES + (uuid_generate_v4(), '00000000-0000-0000-0000-000000000000', 'Ana Sayfa Tasarımı (Wireframe)', 'completed', '11111111-1111-1111-1111-111111111111', now() - interval '5 days', now() - interval '2 days'), + (uuid_generate_v4(), '00000000-0000-0000-0000-000000000000', 'Ödeme Adımı Entegrasyonu', 'in_progress', '11111111-1111-1111-1111-111111111111', now() - interval '2 days', now() + interval '3 days'), + (uuid_generate_v4(), '00000000-0000-0000-0000-000000000000', 'Dashboard UI Güncellemesi', 'todo', '22222222-2222-2222-2222-222222222222', now() - interval '1 day', now() + interval '5 days') +ON CONFLICT DO NOTHING; + +-- Seed Finances +INSERT INTO public.finance_transactions (id, user_id, type, amount, category, project_id, transaction_date) +VALUES + (uuid_generate_v4(), '00000000-0000-0000-0000-000000000000', 'income', 15000.00, 'Proje Avansı', '11111111-1111-1111-1111-111111111111', now() - interval '10 days'), + (uuid_generate_v4(), '00000000-0000-0000-0000-000000000000', 'expense', 450.00, 'Yazılım Abonelikleri', NULL, now() - interval '5 days'), + (uuid_generate_v4(), '00000000-0000-0000-0000-000000000000', 'expense', 120.00, 'Kahve / Yemek', NULL, now() - interval '1 day') +ON CONFLICT DO NOTHING; + +-- Seed Daily Logs +INSERT INTO public.daily_logs (id, user_id, log_date, mood_score, energy_score, notes) +VALUES + (uuid_generate_v4(), '00000000-0000-0000-0000-000000000000', current_date - interval '2 days', 4, 3, 'Biraz yorgun ama verimli geçti.'), + (uuid_generate_v4(), '00000000-0000-0000-0000-000000000000', current_date - interval '1 day', 5, 5, 'Harika odaklandım, projenin %80 ini bitirdim.'), + (uuid_generate_v4(), '00000000-0000-0000-0000-000000000000', current_date, 3, 2, 'Biraz uykusuzum.') +ON CONFLICT DO NOTHING;