forked from git.gladyson/openmonetis
Merge pull request #2 from Dionizioaf:main
feat: add AI coding assistant instructions and update Node.js version…
This commit is contained in:
58
.github/copilot-instructions.md
vendored
Normal file
58
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
# AI Coding Assistant Instructions for Opensheets
|
||||||
|
|
||||||
|
## Project Overview
|
||||||
|
|
||||||
|
Opensheets is a self-hosted personal finance management application built with Next.js 16, TypeScript, PostgreSQL, and Drizzle ORM. It provides manual transaction tracking, account management, budgeting, and financial insights with a Portuguese interface.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
- **Frontend**: Next.js App Router with React 19, shadcn/ui components, Tailwind CSS
|
||||||
|
- **Backend**: Server actions in Next.js, API routes for auth/health
|
||||||
|
- **Database**: PostgreSQL with Drizzle ORM, schema in `db/schema.ts`
|
||||||
|
- **Auth**: Better Auth (OAuth + email magic links)
|
||||||
|
- **Deployment**: Docker multi-stage build, health checks
|
||||||
|
|
||||||
|
## Key Patterns
|
||||||
|
|
||||||
|
- **Server Actions**: Use `"use server"` for mutations, validate with Zod schemas, handle errors with `handleActionError`
|
||||||
|
- **Database Queries**: Use Drizzle's query API with relations, e.g., `db.query.lancamentos.findMany({ with: { categoria: true } })`
|
||||||
|
- **Authentication**: Import from `lib/auth/server`, redirect on failure
|
||||||
|
- **Revalidation**: Call `revalidateForEntity("lancamentos")` after mutations
|
||||||
|
- **Portuguese Naming**: DB fields like `nome`, `tipo_conta`, `pagador` (payer), `lancamento` (transaction)
|
||||||
|
- **Component Structure**: Feature-based folders in `components/`, shared UI in `components/ui/`
|
||||||
|
|
||||||
|
## Development Workflow
|
||||||
|
|
||||||
|
- **Start Dev**: `pnpm dev` (Turbopack), `docker compose up db -d` for DB
|
||||||
|
- **Database**: `pnpm db:push` to sync schema, `pnpm db:studio` for visual editor
|
||||||
|
- **Build**: `pnpm build`, `pnpm start` for production
|
||||||
|
- **Docker**: `pnpm docker:up` for full stack, `pnpm docker:logs` for monitoring
|
||||||
|
|
||||||
|
## Common Tasks
|
||||||
|
|
||||||
|
- **Add Transaction**: Create server action in `app/(dashboard)/lancamentos/actions.ts`, validate with Zod, insert via Drizzle
|
||||||
|
- **New Entity**: Add to `db/schema.ts`, define relations, create CRUD actions in `lib/[entity]/actions.ts`
|
||||||
|
- **UI Component**: Use shadcn/ui, place in `components/[feature]/`, export from `components/ui/`
|
||||||
|
- **API Route**: Add to `app/api/`, use `getUserSession()` for auth
|
||||||
|
|
||||||
|
## Conventions
|
||||||
|
|
||||||
|
- **Imports**: Absolute paths with `@/`, group by external/internal
|
||||||
|
- **Error Handling**: Return `{ success: false, error: string }` from actions
|
||||||
|
- **Currency**: Store as decimal strings (e.g., "123.45"), convert to cents for calculations
|
||||||
|
- **Periods**: Format as "YYYY-MM", use `parsePeriodParam()` for URL params
|
||||||
|
- **Notifications**: Send emails via `sendPagadorAutoEmails()` for payer updates
|
||||||
|
|
||||||
|
## External Integrations
|
||||||
|
|
||||||
|
- **Better Auth**: Config in `lib/auth/config.ts`, session handling
|
||||||
|
- **Drizzle**: Migrations in `drizzle/`, studio at `pnpm db:studio`
|
||||||
|
- **AI Features**: Use `@ai-sdk/*` for insights, configured in environment
|
||||||
|
- **Email**: Resend for notifications, configured via `RESEND_API_KEY`
|
||||||
|
|
||||||
|
## File Examples
|
||||||
|
|
||||||
|
- Schema: `db/schema.ts` (relations, indexes)
|
||||||
|
- Actions: `app/(dashboard)/lancamentos/actions.ts` (CRUD with validation)
|
||||||
|
- Components: `components/lancamentos/page/lancamentos-page.tsx` (client component)
|
||||||
|
- Utils: `lib/lancamentos/page-helpers.ts` (data transformation)
|
||||||
16
README.md
16
README.md
@@ -206,7 +206,7 @@ Esta é a **melhor opção para desenvolvedores** que vão modificar o código.
|
|||||||
|
|
||||||
#### Pré-requisitos
|
#### Pré-requisitos
|
||||||
|
|
||||||
- Node.js 22+ instalado
|
- Node.js 22+ instalado (se usar nvm, execute `nvm install` ou `nvm use`)
|
||||||
- pnpm instalado (ou npm/yarn)
|
- pnpm instalado (ou npm/yarn)
|
||||||
- Docker e Docker Compose instalados
|
- Docker e Docker Compose instalados
|
||||||
|
|
||||||
@@ -251,19 +251,27 @@ Esta é a **melhor opção para desenvolvedores** que vão modificar o código.
|
|||||||
|
|
||||||
Isso sobe **apenas o banco de dados** em container. A aplicação roda localmente.
|
Isso sobe **apenas o banco de dados** em container. A aplicação roda localmente.
|
||||||
|
|
||||||
5. **Execute as migrations**
|
5. **Ative as extensões necessárias no PostgreSQL**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pnpm db:enableExtensions
|
||||||
|
```
|
||||||
|
|
||||||
|
Ou você pode importar o script diretamente no banco de dados: `scripts/postgres/init.sql`
|
||||||
|
|
||||||
|
6. **Execute as migrations**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm db:push
|
pnpm db:push
|
||||||
```
|
```
|
||||||
|
|
||||||
6. **Inicie o servidor de desenvolvimento**
|
7. **Inicie o servidor de desenvolvimento**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pnpm dev
|
pnpm dev
|
||||||
```
|
```
|
||||||
|
|
||||||
7. **Acesse a aplicação**
|
8. **Acesse a aplicação**
|
||||||
```
|
```
|
||||||
http://localhost:3000
|
http://localhost:3000
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
import dotenv from "dotenv";
|
||||||
|
|
||||||
|
// Carregar variáveis de ambiente explicitamente
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
// Output standalone para Docker (gera build otimizado com apenas deps necessárias)
|
// Output standalone para Docker (gera build otimizado com apenas deps necessárias)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev --turbopack",
|
"dev": "next dev --turbopack",
|
||||||
|
"dev-env": "tsx scripts/dev.ts",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
@@ -12,6 +13,7 @@
|
|||||||
"db:generate": "drizzle-kit generate",
|
"db:generate": "drizzle-kit generate",
|
||||||
"db:migrate": "drizzle-kit migrate",
|
"db:migrate": "drizzle-kit migrate",
|
||||||
"db:push": "drizzle-kit push",
|
"db:push": "drizzle-kit push",
|
||||||
|
"db:enableExtensions": "tsx scripts/postgres/enable-extensions.ts",
|
||||||
"db:studio": "drizzle-kit studio",
|
"db:studio": "drizzle-kit studio",
|
||||||
"docker:up": "docker compose up --build",
|
"docker:up": "docker compose up --build",
|
||||||
"docker:up:db": "docker compose up -d db",
|
"docker:up:db": "docker compose up -d db",
|
||||||
@@ -79,9 +81,11 @@
|
|||||||
"@tailwindcss/postcss": "4.1.17",
|
"@tailwindcss/postcss": "4.1.17",
|
||||||
"@types/d3-array": "^3.2.2",
|
"@types/d3-array": "^3.2.2",
|
||||||
"@types/node": "24.10.1",
|
"@types/node": "24.10.1",
|
||||||
|
"@types/pg": "^8.15.6",
|
||||||
"@types/react": "19.2.7",
|
"@types/react": "19.2.7",
|
||||||
"@types/react-dom": "19.2.3",
|
"@types/react-dom": "19.2.3",
|
||||||
"depcheck": "^1.4.7",
|
"depcheck": "^1.4.7",
|
||||||
|
"dotenv": "^17.2.3",
|
||||||
"drizzle-kit": "0.31.7",
|
"drizzle-kit": "0.31.7",
|
||||||
"eslint": "9.39.1",
|
"eslint": "9.39.1",
|
||||||
"eslint-config-next": "16.0.4",
|
"eslint-config-next": "16.0.4",
|
||||||
|
|||||||
26
pnpm-lock.yaml
generated
26
pnpm-lock.yaml
generated
@@ -112,7 +112,7 @@ importers:
|
|||||||
version: 4.1.0
|
version: 4.1.0
|
||||||
drizzle-orm:
|
drizzle-orm:
|
||||||
specifier: 0.44.7
|
specifier: 0.44.7
|
||||||
version: 0.44.7(@opentelemetry/api@1.9.0)(better-sqlite3@12.4.1)(kysely@0.28.8)(pg@8.16.3)
|
version: 0.44.7(@opentelemetry/api@1.9.0)(@types/pg@8.15.6)(better-sqlite3@12.4.1)(kysely@0.28.8)(pg@8.16.3)
|
||||||
lucide-react:
|
lucide-react:
|
||||||
specifier: 0.554.0
|
specifier: 0.554.0
|
||||||
version: 0.554.0(react@19.2.0)
|
version: 0.554.0(react@19.2.0)
|
||||||
@@ -165,6 +165,9 @@ importers:
|
|||||||
'@types/node':
|
'@types/node':
|
||||||
specifier: 24.10.1
|
specifier: 24.10.1
|
||||||
version: 24.10.1
|
version: 24.10.1
|
||||||
|
'@types/pg':
|
||||||
|
specifier: ^8.15.6
|
||||||
|
version: 8.15.6
|
||||||
'@types/react':
|
'@types/react':
|
||||||
specifier: 19.2.7
|
specifier: 19.2.7
|
||||||
version: 19.2.7
|
version: 19.2.7
|
||||||
@@ -174,6 +177,9 @@ importers:
|
|||||||
depcheck:
|
depcheck:
|
||||||
specifier: ^1.4.7
|
specifier: ^1.4.7
|
||||||
version: 1.4.7
|
version: 1.4.7
|
||||||
|
dotenv:
|
||||||
|
specifier: ^17.2.3
|
||||||
|
version: 17.2.3
|
||||||
drizzle-kit:
|
drizzle-kit:
|
||||||
specifier: 0.31.7
|
specifier: 0.31.7
|
||||||
version: 0.31.7
|
version: 0.31.7
|
||||||
@@ -1682,6 +1688,9 @@ packages:
|
|||||||
'@types/parse-json@4.0.2':
|
'@types/parse-json@4.0.2':
|
||||||
resolution: {integrity: sha512-dISoDXWWQwUquiKsyZ4Ng+HX2KsPL7LyHKHQwgGFEA3IaKac4Obd+h2a/a6waisAoepJlBcx9paWqjA8/HVjCw==}
|
resolution: {integrity: sha512-dISoDXWWQwUquiKsyZ4Ng+HX2KsPL7LyHKHQwgGFEA3IaKac4Obd+h2a/a6waisAoepJlBcx9paWqjA8/HVjCw==}
|
||||||
|
|
||||||
|
'@types/pg@8.15.6':
|
||||||
|
resolution: {integrity: sha512-NoaMtzhxOrubeL/7UZuNTrejB4MPAJ0RpxZqXQf2qXuVlTPuG6Y8p4u9dKRaue4yjmC7ZhzVO2/Yyyn25znrPQ==}
|
||||||
|
|
||||||
'@types/react-dom@19.2.3':
|
'@types/react-dom@19.2.3':
|
||||||
resolution: {integrity: sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==}
|
resolution: {integrity: sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@@ -2301,6 +2310,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==}
|
resolution: {integrity: sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
|
|
||||||
|
dotenv@17.2.3:
|
||||||
|
resolution: {integrity: sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==}
|
||||||
|
engines: {node: '>=12'}
|
||||||
|
|
||||||
drizzle-kit@0.31.7:
|
drizzle-kit@0.31.7:
|
||||||
resolution: {integrity: sha512-hOzRGSdyKIU4FcTSFYGKdXEjFsncVwHZ43gY3WU5Bz9j5Iadp6Rh6hxLSQ1IWXpKLBKt/d5y1cpSPcV+FcoQ1A==}
|
resolution: {integrity: sha512-hOzRGSdyKIU4FcTSFYGKdXEjFsncVwHZ43gY3WU5Bz9j5Iadp6Rh6hxLSQ1IWXpKLBKt/d5y1cpSPcV+FcoQ1A==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
@@ -5308,6 +5321,12 @@ snapshots:
|
|||||||
|
|
||||||
'@types/parse-json@4.0.2': {}
|
'@types/parse-json@4.0.2': {}
|
||||||
|
|
||||||
|
'@types/pg@8.15.6':
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 24.10.1
|
||||||
|
pg-protocol: 1.10.3
|
||||||
|
pg-types: 2.2.0
|
||||||
|
|
||||||
'@types/react-dom@19.2.3(@types/react@19.2.7)':
|
'@types/react-dom@19.2.3(@types/react@19.2.7)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/react': 19.2.7
|
'@types/react': 19.2.7
|
||||||
@@ -5944,6 +5963,8 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
esutils: 2.0.3
|
esutils: 2.0.3
|
||||||
|
|
||||||
|
dotenv@17.2.3: {}
|
||||||
|
|
||||||
drizzle-kit@0.31.7:
|
drizzle-kit@0.31.7:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@drizzle-team/brocli': 0.10.2
|
'@drizzle-team/brocli': 0.10.2
|
||||||
@@ -5953,9 +5974,10 @@ snapshots:
|
|||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
drizzle-orm@0.44.7(@opentelemetry/api@1.9.0)(better-sqlite3@12.4.1)(kysely@0.28.8)(pg@8.16.3):
|
drizzle-orm@0.44.7(@opentelemetry/api@1.9.0)(@types/pg@8.15.6)(better-sqlite3@12.4.1)(kysely@0.28.8)(pg@8.16.3):
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@opentelemetry/api': 1.9.0
|
'@opentelemetry/api': 1.9.0
|
||||||
|
'@types/pg': 8.15.6
|
||||||
better-sqlite3: 12.4.1
|
better-sqlite3: 12.4.1
|
||||||
kysely: 0.28.8
|
kysely: 0.28.8
|
||||||
pg: 8.16.3
|
pg: 8.16.3
|
||||||
|
|||||||
17
scripts/dev.ts
Normal file
17
scripts/dev.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env tsx
|
||||||
|
|
||||||
|
import { execSync } from 'child_process';
|
||||||
|
import { config } from 'dotenv';
|
||||||
|
|
||||||
|
// Carregar variáveis de ambiente
|
||||||
|
config();
|
||||||
|
|
||||||
|
const port = process.env.PORT || '3000';
|
||||||
|
|
||||||
|
console.log(`Starting Next.js development server on port ${port}...`);
|
||||||
|
|
||||||
|
// Executar next dev com a porta especificada
|
||||||
|
execSync(`npx next dev --turbopack --port ${port}`, {
|
||||||
|
stdio: 'inherit',
|
||||||
|
env: { ...process.env, PORT: port }
|
||||||
|
});
|
||||||
47
scripts/postgres/enable-extensions.ts
Normal file
47
scripts/postgres/enable-extensions.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Script to initialize database extensions before running migrations
|
||||||
|
* This ensures pgcrypto extension is available for gen_random_bytes()
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { config } from 'dotenv';
|
||||||
|
import { drizzle } from 'drizzle-orm/node-postgres';
|
||||||
|
import { Pool } from 'pg';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
// Load environment variables from .env
|
||||||
|
config();
|
||||||
|
|
||||||
|
async function initDatabase() {
|
||||||
|
const databaseUrl = process.env.DATABASE_URL;
|
||||||
|
|
||||||
|
if (!databaseUrl) {
|
||||||
|
console.error('DATABASE_URL environment variable is required');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pool = new Pool({ connectionString: databaseUrl });
|
||||||
|
const db = drizzle(pool);
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log('🔧 Initializing database extensions...');
|
||||||
|
|
||||||
|
// Read and execute init.sql as a single query
|
||||||
|
const initSqlPath = path.join(process.cwd(), 'scripts', 'postgres', 'init.sql');
|
||||||
|
const initSql = fs.readFileSync(initSqlPath, 'utf-8');
|
||||||
|
|
||||||
|
console.log('Executing init.sql...');
|
||||||
|
await db.execute(initSql);
|
||||||
|
|
||||||
|
console.log('✅ Database initialization completed');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ Database initialization failed:', error);
|
||||||
|
process.exit(1);
|
||||||
|
} finally {
|
||||||
|
await pool.end();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initDatabase();
|
||||||
Reference in New Issue
Block a user