Database Map
Questi contenuti non sono ancora disponibili nella tua lingua.
🗄️ DATABASE MAP - BLACKTRAILS
Section titled “🗄️ DATABASE MAP - BLACKTRAILS”Database Name: blacktrails
Provider: Neon.tech (PostgreSQL 17)
Architecture: Multi-schema (separated by domain)
📋 QUICK REFERENCE
Section titled “📋 QUICK REFERENCE”| Schema | Brand | Tables Count | Purpose |
|---|---|---|---|
auth | All | 4 | Authentication & authorization |
in1 | IN-1 | 2 | Haiku generation app |
library | All | 2 | Knowledge base (RAG) |
elements | Elements | 3 | Booking system |
finance | All | 3 | Financial transactions |
system | All | 3 | Logs & audits |
Total Tables: 17 (6 active, 11 planned)
🔐 SCHEMA: auth
Section titled “🔐 SCHEMA: auth”Brand: All (shared authentication) Purpose: User authentication, sessions, roles, tokens
Table: auth.users
Section titled “Table: auth.users”What it does: Stores user accounts (email, password, profile)
Columns:
id UUID PRIMARY KEY -- Unique user ID (gen_random_uuid)email VARCHAR(255) UNIQUE -- User email (login identifier)email_verified BOOLEAN DEFAULT FALSE -- Email verification statushashed_password VARCHAR(255) -- Bcrypt hashed password (NOT plain text!)name VARCHAR(255) -- Display nameavatar_url TEXT -- Profile picture URLcreated_at TIMESTAMP -- Account creation dateupdated_at TIMESTAMP -- Last profile updateUsed by:
- IN-1 (future: save haikus to account)
- Elements (booking user accounts)
- All apps (centralized authentication)
Example row:
id: 550e8400-e29b-41d4-a716-446655440000email: [email protected]hashed_password: $2b$10$...name: Francesco Pelosiocreated_at: 2025-12-01 10:30:00Table: auth.sessions
Section titled “Table: auth.sessions”What it does: Tracks active user sessions (login state)
Columns:
id VARCHAR(255) PRIMARY KEY -- Session ID (random string)user_id UUID REFERENCES users -- Which user owns this sessionexpires_at TIMESTAMP -- When session expirescreated_at TIMESTAMP -- When session was createdUsed by:
- All apps (check if user is logged in)
- Automatic cleanup (delete expired sessions)
Example row:
id: sess_abc123xyz789user_id: 550e8400-e29b-41d4-a716-446655440000expires_at: 2025-12-25 10:30:00created_at: 2025-12-18 10:30:00Table: auth.roles
Section titled “Table: auth.roles”What it does: Assigns roles to users per product (admin, user, etc.)
Columns:
id SERIAL PRIMARY KEY -- Auto-increment IDuser_id UUID REFERENCES users -- Which userproduct_code VARCHAR(50) -- Which product (in1, elements, gcore)role VARCHAR(50) -- Role name (owner, admin, member)granted_at TIMESTAMP -- When role was assignedUsed by:
- Permission checks (can this user do X?)
- Multi-tenant access control
Example row:
id: 1user_id: 550e8400-e29b-41d4-a716-446655440000product_code: in1role: ownergranted_at: 2025-12-01 10:30:00Table: auth.tokens
Section titled “Table: auth.tokens”What it does: Stores temporary tokens (password reset, email verification)
Columns:
id SERIAL PRIMARY KEY -- Auto-increment IDuser_id UUID REFERENCES users -- Which user owns this tokentoken VARCHAR(255) UNIQUE -- Token string (random, secure)type VARCHAR(50) -- Token type (refresh, reset_password, verify_email)expires_at TIMESTAMP -- When token expirescreated_at TIMESTAMP -- When token was createdUsed by:
- Password reset flow
- Email verification flow
- JWT refresh tokens
Example row:
id: 1user_id: 550e8400-e29b-41d4-a716-446655440000token: abc123xyz789...type: reset_passwordexpires_at: 2025-12-18 11:30:00created_at: 2025-12-18 10:30:00🌲 SCHEMA: in1
Section titled “🌲 SCHEMA: in1”Brand: IN-1 (Haiku generation app) Purpose: Store haikus generated by users
Table: in1.haikus
Section titled “Table: in1.haikus”What it does: Stores every haiku generated by IN-1 app
Columns:
id SERIAL PRIMARY KEY -- Auto-increment haiku IDuser_id UUID REFERENCES users -- Which user (nullable = anonymous)session_id VARCHAR(255) -- Session identifier (crypto.randomBytes)prompt_text TEXT -- Full user conversation (all 5 turns concatenated)haiku_text TEXT -- Generated haiku (3 lines, 5-7-5 syllables)emotion VARCHAR(50) -- Detected emotion (gioia, tristezza, paura, etc.)language VARCHAR(10) DEFAULT 'it' -- Language (it, en, es, fr, de)tree_planted BOOLEAN DEFAULT FALSE -- If tree was planted for this haikutree_id VARCHAR(255) -- External tree planting service IDcreated_at TIMESTAMP -- When haiku was generatedUsed by:
- IN-1 app (save haiku after generation)
- Forest gallery (read haikus for display)
- Analytics (count haikus by language, emotion)
Indexes:
idx_haikus_user -- Fast lookup by useridx_haikus_session -- Fast lookup by sessionidx_haikus_language -- Filter by languageidx_haikus_emotion -- Filter by emotionidx_haikus_created_at -- Sort by date (DESC)Example row:
id: 1user_id: NULL (anonymous)session_id: a1b2c3d4e5f6prompt_text: "paura del futuro... incertezza... buio..."haiku_text: "Notte senza stelle\nIl sentiero si nasconde\nMa l'alba arriverà"emotion: pauralanguage: ittree_planted: falsecreated_at: 2025-12-18 10:30:00Table: in1.generations (Future)
Section titled “Table: in1.generations (Future)”What it does: Track generation metadata (analytics, costs)
Columns:
id SERIAL PRIMARY KEY -- Auto-increment IDhaiku_id INT REFERENCES haikus -- Which haikumodel_conversation VARCHAR(100) -- Model used for chat (claude-haiku-4.5)model_analyzer VARCHAR(100) -- Model used for analysis (claude-sonnet-3.5)model_poet VARCHAR(100) -- Model used for haiku (claude-sonnet-3.5)turns INTEGER -- Number of conversation turns (1-5)tokens_used INTEGER -- Total tokens consumedcost_usd DECIMAL(10, 6) -- API cost in USDlatency_ms INTEGER -- Total generation time (milliseconds)created_at TIMESTAMP -- When generatedUsed by:
- Analytics dashboard (cost tracking)
- Performance monitoring
- A/B testing different models
📚 SCHEMA: library
Section titled “📚 SCHEMA: library”Brand: All (shared knowledge base) Purpose: Knowledge base, RAG system, document management
Table: library.documents
Section titled “Table: library.documents”What it does: Stores markdown documents (philosophy, projects, legal, etc.)
Columns:
id SERIAL PRIMARY KEY -- Auto-increment doc IDslug VARCHAR(255) UNIQUE -- URL-friendly identifier (rhama, in1-algorithm)title VARCHAR(500) -- Document titlecategory VARCHAR(100) -- Category (filosofia, progetti, algoritmi, legal, strategie, finanza)content TEXT -- Full markdown contentcontent_hash VARCHAR(64) -- MD5 hash (detect changes)public BOOLEAN DEFAULT FALSE -- Public (true) or private (false)author VARCHAR(255) -- Author nametags TEXT[] -- Array of tags (["philosophy", "rhama"])metadata JSONB -- Frontmatter fields (custom data)language VARCHAR(5) DEFAULT 'it' -- Language code (it, en, es, fr, de)translation_id VARCHAR(100) -- Links translated versions (rhama = same for all langs)last_updated TIMESTAMP -- Last content updatecreated_at TIMESTAMP -- When document was createdUsed by:
- Website (display public documents)
- RAG system (semantic search)
- Sync script (
npm run sync-library)
Indexes:
idx_documents_slug -- Fast lookup by slugidx_documents_category -- Filter by categoryidx_documents_public -- Filter public/privateidx_documents_hash -- Detect content changesidx_documents_language -- Filter by languageidx_documents_translation_id -- Find translationsExample row:
id: 1slug: rhamatitle: La Nascita di Rhamacategory: filosofiacontent: "# La Nascita di Rhama\n\nRhama nasce dall'amore..."content_hash: a1b2c3d4e5f6...public: trueauthor: Francesco Pelosiotags: ["filosofia", "rhama", "origine"]metadata: {"lang": "it", "date": "2025-12-01"}language: ittranslation_id: rhamalast_updated: 2025-12-18 10:30:00created_at: 2025-12-01 10:00:00Table: library.embeddings
Section titled “Table: library.embeddings”What it does: Stores vector embeddings for semantic search (RAG)
Columns:
id SERIAL PRIMARY KEY -- Auto-increment IDdocument_id INT REFERENCES documents -- Which document this chunk belongs tochunk_index INTEGER -- Position in document (0, 1, 2...)chunk_text TEXT -- Text chunk (~500 words)embedding vector(1536) -- OpenAI embedding (1536 dimensions)created_at TIMESTAMP -- When embedding was generatedUsed by:
- RAG queries (find similar documents)
- Semantic search (natural language queries)
Indexes:
idx_embeddings_document -- Fast lookup by documentidx_embeddings_vector -- Vector similarity search (IVFFlat, cosine)Example row:
id: 1document_id: 1chunk_index: 0chunk_text: "Rhama nasce dall'amore di una madre..."embedding: [0.123, -0.456, 0.789, ...] (1536 values)created_at: 2025-12-18 10:30:00RAG Query Example:
-- Find 5 most similar documents to a query embeddingSELECT d.title, d.slug, e.chunk_text, 1 - (e.embedding <=> $1::vector) AS similarityFROM library.embeddings eJOIN library.documents d ON d.id = e.document_idWHERE d.public = true AND d.language = 'it'ORDER BY e.embedding <=> $1::vectorLIMIT 5;🏠 SCHEMA: elements
Section titled “🏠 SCHEMA: elements”Brand: Elements (Booking system) Purpose: Room booking, guest management
Table: elements.rooms
Section titled “Table: elements.rooms”What it does: Stores available rooms for booking
Columns:
id SERIAL PRIMARY KEY -- Auto-increment room IDname VARCHAR(255) -- Room name (Camera Deluxe, Suite Presidenziale)description TEXT -- Room descriptionmax_guests INTEGER DEFAULT 2 -- Maximum guests allowedprice_per_night DECIMAL(10, 2) -- Price per night (€)amenities JSONB -- Amenities (["wifi", "tv", "balcony"])images TEXT[] -- Array of image URLsavailable BOOLEAN DEFAULT TRUE -- Room available for bookingcreated_at TIMESTAMP -- When room was addedupdated_at TIMESTAMP -- Last room updateUsed by:
- Elements booking app (list rooms)
- Admin panel (manage rooms)
Example row:
id: 1name: Camera Deluxedescription: Camera spaziosa con vista montagnamax_guests: 2price_per_night: 120.00amenities: {"wifi": true, "tv": true, "balcony": true}images: ["https://cdn.../room1.jpg", "https://cdn.../room2.jpg"]available: truecreated_at: 2025-12-01 10:00:00Table: elements.bookings
Section titled “Table: elements.bookings”What it does: Stores room bookings
Columns:
id SERIAL PRIMARY KEY -- Auto-increment booking IDuser_id UUID REFERENCES users -- Which user made booking (nullable)room_id INT REFERENCES rooms -- Which room was bookedguest_name VARCHAR(255) -- Guest nameguest_email VARCHAR(255) -- Guest emailcheck_in DATE -- Check-in datecheck_out DATE -- Check-out dateguests INTEGER DEFAULT 1 -- Number of gueststotal_price DECIMAL(10, 2) -- Total price (calculated)status VARCHAR(50) DEFAULT 'pending' -- Status (pending, confirmed, cancelled)notes TEXT -- Special requestscreated_at TIMESTAMP -- When booking was madeupdated_at TIMESTAMP -- Last booking updateUsed by:
- Elements booking app (create booking)
- Admin panel (manage bookings)
- Email notifications (send confirmation)
Indexes:
idx_bookings_user -- Fast lookup by useridx_bookings_room -- Fast lookup by roomidx_bookings_dates -- Fast lookup by date rangeidx_bookings_status -- Filter by statusExample row:
id: 1user_id: 550e8400-e29b-41d4-a716-446655440000room_id: 1guest_name: Francesco Pelosioguest_email: [email protected]check_in: 2025-12-20check_out: 2025-12-22guests: 2total_price: 240.00status: confirmednotes: Late check-in requestedcreated_at: 2025-12-18 10:00:00Table: elements.guests
Section titled “Table: elements.guests”What it does: Stores guest details for bookings (legal requirement)
Columns:
id SERIAL PRIMARY KEY -- Auto-increment guest IDbooking_id INT REFERENCES bookings -- Which bookingname VARCHAR(255) -- Guest full nameemail VARCHAR(255) -- Guest emailphone VARCHAR(50) -- Guest phonedocument_type VARCHAR(50) -- Document type (passport, id_card)document_number VARCHAR(100) -- Document numbernationality VARCHAR(100) -- Nationalitycreated_at TIMESTAMP -- When guest was addedUsed by:
- Legal compliance (registry of guests)
- Check-in process
💰 SCHEMA: finance
Section titled “💰 SCHEMA: finance”Brand: All (shared financial transactions) Purpose: Track payments, invoices, Stripe logs
Table: finance.transactions
Section titled “Table: finance.transactions”What it does: Stores all financial transactions
Columns:
id SERIAL PRIMARY KEY -- Auto-increment transaction IDuser_id UUID REFERENCES users -- Which userbooking_id INT REFERENCES bookings -- Which booking (nullable)amount DECIMAL(10, 2) -- Transaction amountcurrency VARCHAR(3) DEFAULT 'EUR' -- Currency codetype VARCHAR(50) -- Type (payment, refund, payout)status VARCHAR(50) DEFAULT 'pending' -- Status (pending, completed, failed)payment_method VARCHAR(50) -- Payment method (card, bank_transfer, cash)stripe_payment_intent_id VARCHAR(255) -- Stripe payment IDmetadata JSONB -- Additional datacreated_at TIMESTAMP -- When transaction was createdUsed by:
- Payment processing (Stripe integration)
- Accounting (track revenue)
- Refunds (process refunds)
Indexes:
idx_transactions_user -- Fast lookup by useridx_transactions_booking -- Fast lookup by bookingidx_transactions_status -- Filter by statusidx_transactions_created -- Sort by dateTable: finance.invoices
Section titled “Table: finance.invoices”What it does: Stores invoices for bookings
Columns:
id SERIAL PRIMARY KEY -- Auto-increment invoice IDbooking_id INT REFERENCES bookings -- Which bookinginvoice_number VARCHAR(100) UNIQUE -- Invoice number (INV-2025-001)amount DECIMAL(10, 2) -- Invoice amountcurrency VARCHAR(3) DEFAULT 'EUR' -- Currency codestatus VARCHAR(50) DEFAULT 'draft' -- Status (draft, sent, paid, cancelled)pdf_url TEXT -- PDF invoice URLissued_at DATE -- Issue datedue_at DATE -- Due datepaid_at DATE -- Payment datecreated_at TIMESTAMP -- When invoice was createdUsed by:
- Accounting (generate invoices)
- Email (send invoice PDF)
Table: finance.stripe_logs
Section titled “Table: finance.stripe_logs”What it does: Logs all Stripe webhook events
Columns:
id SERIAL PRIMARY KEY -- Auto-increment log IDevent_type VARCHAR(100) -- Event type (payment_intent.succeeded)stripe_event_id VARCHAR(255) UNIQUE -- Stripe event IDpayload JSONB -- Full webhook payloadprocessed BOOLEAN DEFAULT FALSE -- Event processedcreated_at TIMESTAMP -- When event was receivedUsed by:
- Webhook processing (handle Stripe events)
- Debugging (track payment issues)
Indexes:
idx_stripe_logs_event_type -- Filter by event typeidx_stripe_logs_processed -- Find unprocessed events🔧 SCHEMA: system
Section titled “🔧 SCHEMA: system”Brand: All (shared system logs) Purpose: Audit logs, migrations, health checks
Table: system.audit_logs
Section titled “Table: system.audit_logs”What it does: Logs all important user actions (security audit)
Columns:
id SERIAL PRIMARY KEY -- Auto-increment log IDuser_id UUID REFERENCES users -- Which user performed actionaction VARCHAR(100) -- Action (login, logout, create, update, delete)resource_type VARCHAR(100) -- Resource type (user, booking, haiku)resource_id VARCHAR(255) -- Resource IDip_address INET -- IP addressuser_agent TEXT -- Browser user agentmetadata JSONB -- Additional datacreated_at TIMESTAMP -- When action was performedUsed by:
- Security audits (track suspicious activity)
- Compliance (GDPR data access logs)
Indexes:
idx_audit_user -- Fast lookup by useridx_audit_action -- Filter by actionidx_audit_resource -- Fast lookup by resourceidx_audit_created -- Sort by dateTable: system.migrations
Section titled “Table: system.migrations”What it does: Tracks database migrations (schema changes)
Columns:
id SERIAL PRIMARY KEY -- Auto-increment migration IDname VARCHAR(255) UNIQUE -- Migration name (002_add_refresh_tokens)executed_at TIMESTAMP -- When migration was executedUsed by:
- Migration scripts (prevent duplicate runs)
Table: system.health_checks
Section titled “Table: system.health_checks”What it does: Logs health check results (uptime monitoring)
Columns:
id SERIAL PRIMARY KEY -- Auto-increment check IDservice VARCHAR(100) -- Service name (database, redis, api, stripe)status VARCHAR(50) -- Status (healthy, degraded, down)response_time_ms INTEGER -- Response time (milliseconds)error_message TEXT -- Error message (if failed)checked_at TIMESTAMP -- When check was performedUsed by:
- Monitoring dashboard (uptime status)
- Alerts (send notification if service down)
Indexes:
idx_health_service -- Filter by serviceidx_health_checked -- Sort by date📊 SUMMARY BY BRAND
Section titled “📊 SUMMARY BY BRAND”IN-1 (Haiku App)
Section titled “IN-1 (Haiku App)”in1.haikus- Generated haikusin1.generations- Generation metadata (future)auth.*- User authentication (shared)library.*- Knowledge base (shared)
Elements (Booking System)
Section titled “Elements (Booking System)”elements.rooms- Available roomselements.bookings- Room bookingselements.guests- Guest detailsfinance.*- Payments & invoices (shared)auth.*- User authentication (shared)
Library (Knowledge Base)
Section titled “Library (Knowledge Base)”library.documents- Markdown documentslibrary.embeddings- Vector embeddings (RAG)- Used by all brands
Shared Services
Section titled “Shared Services”auth.*- Authentication (all brands)finance.*- Financial transactions (all brands)system.*- Logs & audits (all brands)
End of Document 🌲✨