Project Structure
ποΈ BLACKTRAILS PLATFORM - PROJECT STRUCTURE
Section titled βποΈ BLACKTRAILS PLATFORM - PROJECT STRUCTUREβLast Updated: 18 Dicembre 2025 Version: 2.0 Author: BlackTrails Team
π INDEX
Section titled βπ INDEXβπ― OVERVIEW
Section titled βπ― OVERVIEWβBLACKTRAILS PLATFORM is a multi-brand modular platform hosting:
- BlackTrails - Digital Studio (static landing)
- IN-1 - AI Haiku Experience (conversation + database)
- Forest - Haiku Collection (gallery)
- Library - Knowledge Base (RAG system) β¨ NEW
Architecture: Monorepo with brand detection and dynamic routing. Tech Stack: Node.js + Express + EJS + PostgreSQL + pgvector
π COMPLETE STRUCTURE
Section titled βπ COMPLETE STRUCTUREβBLACKTRAILS-PLATFORM/ββββ π db/ # Database Schema & Migrationsβ βββ schema.sql # PostgreSQL schema (multi-schema)β βββ migrations/ # Future migration filesβ βββ seeds/ # Seed data (future)ββββ π docs/ # π Project Documentationβ βββ database.md # Database architectureβ βββ structure.md # This file (directory map)β βββ in1_algoritmo.md # IN-1 algorithm detailed specβ βββ MASTER_PLAN.md # Strategic roadmap (moved to /DOCS)ββββ π library/ # π Knowledge Base (RAG) β¨ NEWβ ββ βββ π public/ # Public documents (website)β β βββ π it/ # Italian documentsβ β β βββ π filosofia/β β β β βββ rhama.mdβ β β β βββ rhama-paradigm.mdβ β β βββ π progetti/β β β βββ π algoritmi/β β β βββ in1.mdβ β ββ β βββ π en/ # English documents (future)β ββ βββ π private/ # Private documents (internal)β βββ π strategie/ # Business strategiesβ β βββ piano-triennale.mdβ βββ π finanza/ # Financial documentsβ βββ budget-2025.mdβ βββ previsioni-q1.mdββββ π scripts/ # π οΈ Maintenance & Deploy Scriptsβ βββ setup-database.js # Initialize databaseβ βββ check-haikus-schema.js # Verify haikus schemaβ βββ check-prod-schema.js # Verify production schemaβ βββ verify-db-v2.js # Database health checkβ βββ reset-prod-db.js # Reset production DB (DANGER!)β βββ alter-prod-language.js # Language column migrationβ βββ sync-library.js # β¨ NEW: Sync library/ β databaseβ βββ cloudflare-deploy.js # Deploy Cloudflare Pages (old)β βββ cloudflare-deploy-v2.js # Deploy Cloudflare Pages (v2)β βββ deploy-render.js # Deploy Render.comββββ π src/ # π Source Codeβ ββ βββ π engine/ # βοΈ Core Platform Logicβ β βββ auth.js # Authentication (JWT + sessions)β β βββ db.js # Database connection pool (PostgreSQL)β β βββ email.js # Email service (Resend API)β β βββ middleware.js # Express middleware (CORS, auth, error)β β βββ permissions.js # ACL and permission logicβ ββ βββ π public/ # π Web Applicationβ ββ βββ π public/ # π¦ Static Assets (served via /static/)β β ββ β βββ π css/ # π¨ Stylesheets (modular per brand)β β β βββ design-system.css # Common tokens (colors, fonts)β β β βββ dashboard-common.css # Dashboard styles (WIP)β β β βββ π in1/ # IN-1 CSSβ β β β βββ style.css # Haiku experience stylesβ β β βββ π forest/ # Forest CSSβ β β βββ style.css # Forest page stylesβ β ββ β βββ π js/ # β‘ JavaScript Modules (vanilla)β β β βββ lucide.min.js # Icon library (minified)β β β βββ marked.min.js # Markdown parser (minified)β β β βββ π in1/ # IN-1 JavaScript Modulesβ β β β βββ tree.js # Tree canvas animation (GSAP)β β β β βββ chat-ui.js # Chat UI logic (loader morph)β β β β βββ haiku.js # AI conversation logic (API)β β β β βββ home.js # Landing page logicβ β β βββ π forest/ # Forest JavaScript Modulesβ β β βββ forest.js # Forest logic (placeholder)β β ββ β βββ π favicons/ # πΌοΈ Icons & Manifestsβ β β βββ favicon.ico # Legacy faviconβ β β βββ favicon.svg # SVG favicon (modern)β β β βββ apple-touch-icon.png # iOS icon (180x180)β β β βββ icon-192.png # Android icon (192x192)β β β βββ icon-512.png # Android icon (512x512)β β β βββ site.webmanifest # PWA manifestβ β ββ β βββ π img/ # πΌοΈ Images (empty, future assets)β β ββ β βββ π content/ # π Markdown Content (legal pages)β β βββ about.md # About pageβ β βββ privacy.md # Privacy policyβ β βββ terms.md # Terms of serviceβ ββ βββ π routes/ # π€οΈ Express Routes (brand-based)β β βββ landing.js # Landing pages (BlackTrails, IN-1, Forest)β β βββ in1.js # IN-1 API (/api/in1/*)β β βββ auth.js # Auth routes (/auth/*)β β βββ library.js # β¨ NEW: Library API (/api/library/*)β β βββ gcore.js # GCore routes (WIP)β β βββ elements.js # Elements routes (placeholder)β ββ βββ π views/ # π¨ EJS Templatesβ β ββ β βββ π landing/ # Landing Pages (per brand)β β β βββ π blacktrails/ # BlackTrails Landingβ β β β βββ index.ejs # Homepage BlackTrails (static)β β β ββ β β βββ π in1/ # IN-1 Landing & Chatβ β β β βββ index.ejs # IN-1 Homepage (tree + form)β β β β βββ haiku.ejs # IN-1 Chat Experienceβ β β β βββ vision.ejs # Vision pageβ β β β βββ legal.ejs # Legal pageβ β β ββ β β βββ π forest/ # Forest Landingβ β β β βββ index.ejs # Forest Gallery (3 haiku cards)β β β ββ β β βββ π gcore/ # GCore Pages (WIP)β β β β βββ index.ejs # GCore homepageβ β β β βββ (8 other pages)β β β ββ β β βββ π elements/ # Elements Pages (placeholder)β β ββ β βββ π app-user/ # User Dashboard (WIP)β β ββ β βββ π partials/ # EJS Partials Reusable (empty)β ββ βββ π utils/ # π§° Utility Modulesβ β βββ almaHaiku.js # AI Haiku Generation (Anthropic Claude)β β βββ emotionAnalyzer.js # Sentiment Analysis (input safety)β ββ βββ server.js # π Express Server Entry Pointββββ π tests/ # π§ͺ Test Suiteβ βββ test-alma-v2-flow.js # Test conversation flowβ βββ test-emotion-analyzer.js # Test sentiment analyzerβ βββ test-natura-vocabolario.js # Test nature vocabularyβ βββ test-safety-keyword.js # Test keyword safetyβ βββ test-gsap.html # Test GSAP animationβ βββ test-*.json # Sample conversation turns (mock data)ββββ package.json # π¦ Dependencies & Scriptsβββ package-lock.json # π Lockfileβββ .env # π Environment variables (gitignored)βββ .gitignore # π« Git ignore rulesβββ README.md # π Project READMEβββ server.log # π Server logs (gitignored)π FOLDER DESCRIPTIONS
Section titled βπ FOLDER DESCRIPTIONSβ1. /db/ - Database
Section titled β1. /db/ - DatabaseβPostgreSQL schema for the entire platform. Includes:
- Multi-schema architecture (auth, in1, elements, library, finance)
- Migration files (future)
- Seed data (future)
Key file: schema.sql
2. /docs/ - Documentation π
Section titled β2. /docs/ - Documentation πβTechnical project documentation:
database.md- Complete database architecturestructure.md- This file (directory map)in1_algoritmo.md- IN-1 algorithm detailed specification- API docs (future)
3. /library/ - Knowledge Base π β¨ NEW
Section titled β3. /library/ - Knowledge Base π β¨ NEWβCentralized knowledge management system with:
- Public documents: Website content (philosophy, projects, algorithms)
- Private documents: Internal docs (strategies, finance, planning)
- i18n support: Multilingual (it/en/es/fr/de)
- RAG integration: Embeddings for semantic search
Structure:
Section titled βStructure:βlibrary/βββ public/β βββ it/ # Italian public docsβ β βββ filosofia/ # Philosophyβ β β βββ rhama.mdβ β β βββ rhama-paradigm.mdβ β βββ progetti/ # Projectsβ β βββ algoritmi/ # Algorithmsβ β βββ in1.mdβ ββ βββ en/ # English public docs (future)ββββ private/ βββ strategie/ # Business strategies β βββ piano-triennale.md βββ finanza/ # Financial documents βββ budget-2025.md βββ previsioni-q1.mdSync Process:
Section titled βSync Process:βnpm run sync-library- Scans
library/public/andlibrary/private/ - Extracts frontmatter metadata (title, category, tags, language)
- Generates slugs from filenames
- Calculates MD5 hash for change detection
- Inserts/updates
library.documentstable - Logs sync results
Database Integration:
- Table:
library.documents - Columns: slug, title, category, content, language, translation_id, public, metadata
- Indexes: slug, category, language, translation_id, content_hash
4. /scripts/ - Utility Scripts π οΈ
Section titled β4. /scripts/ - Utility Scripts π οΈβNode.js scripts for maintenance and deployment:
| Script | Purpose |
|---|---|
setup-database.js | Initialize database from schema.sql |
check-*.js | Health checks and schema verification |
verify-db-v2.js | Connection test and integrity check |
sync-library.js | β¨ Sync library/ folder to database |
reset-prod-db.js | β οΈ Reset production (DANGER) |
alter-prod-language.js | Schema migration (add language column) |
cloudflare-deploy*.js | Deploy to Cloudflare Pages |
deploy-render.js | Deploy to Render.com |
Execution: node scripts/<script-name>.js
5. /src/engine/ - Core Logic βοΈ
Section titled β5. /src/engine/ - Core Logic βοΈβPlatform core modules (shared across brands):
| File | Responsibility |
|---|---|
auth.js | JWT generation, session management, user authentication |
db.js | PostgreSQL connection pool (pg), query helpers |
email.js | Email sending via Resend API |
middleware.js | Express middleware (CORS, auth check, error handler) |
permissions.js | ACL (Access Control List), role-based permissions |
Imported by: server.js, routes
6. /src/public/public/ - Static Assets π¦
Section titled β6. /src/public/public/ - Static Assets π¦βServed via Express: app.use('/static', express.static('src/public/public'))
Public URL: https://domain.com/static/css/in1/style.css
6.1 /css/ - Stylesheets π¨
Section titled β6.1 /css/ - Stylesheets π¨βModular CSS organized by brand:
design-system.css- Common tokens (βaccent, βfont-display)dashboard-common.css- Dashboard styles (WIP)in1/style.css- IN-1 chat experience (tree, loader, final haiku)forest/style.css- Forest gallery (haiku cards, navbar, footer)
Architecture: Mobile-first, BEM naming, CSS Variables
6.2 /js/ - JavaScript Modules β‘
Section titled β6.2 /js/ - JavaScript Modules β‘βVanilla JavaScript (NO frameworks). Modular with IIFE pattern.
IN-1 Modules (/js/in1/):
| File | Responsibility |
|---|---|
tree.js | Canvas animation (fractal tree, GSAP growth) |
chat-ui.js | Chat UI logic (loader morphing, typewriter effect) |
haiku.js | AI conversation (API calls, state management) |
home.js | Landing page logic (form, ROOT DETECTED, nav) |
Libraries:
lucide.min.js- Icon librarymarked.min.js- Markdown parser
7. /src/public/routes/ - Express Routes π€οΈ
Section titled β7. /src/public/routes/ - Express Routes π€οΈβModular routing for brand detection:
| File | Route Path | Brand | Purpose |
|---|---|---|---|
landing.js | / | BlackTrails, IN-1, Forest | Landing pages (switch on req.brand) |
in1.js | /api/in1/* | IN-1 | API endpoints (chat, haiku generation) |
library.js | /api/library/* | Library | β¨ Document search and RAG queries |
auth.js | /auth/* | - | Login, signup, logout (future) |
gcore.js | /gcore/* | GCore | GCore pages (WIP) |
elements.js | /elements/* | Elements | Component library (placeholder) |
Brand Detection Logic (server.js):
// Development: ?brand=in1|forest|blacktrailsif (process.env.NODE_ENV === 'development') { req.brand = req.query.brand || 'blacktrails';}
// Production: domain-basedif (req.hostname === 'in-1.it') req.brand = 'in1';else if (req.hostname === 'forest.in-1.it') req.brand = 'forest';else req.brand = 'blacktrails';8. /src/public/views/ - EJS Templates π¨
Section titled β8. /src/public/views/ - EJS Templates π¨βServer-Side Rendering with EJS:
8.1 /landing/ - Landing Pages
Section titled β8.1 /landing/ - Landing PagesβOrganized by brand:
BlackTrails (/landing/blacktrails/):
index.ejs- Homepage (static, company portfolio)
IN-1 (/landing/in1/):
index.ejs- Landing page (tree animation + prompt form)haiku.ejs- Chat experience (AI conversation β haiku)vision.ejs- Vision page (mission, values)legal.ejs- Legal page (privacy, terms)
Forest (/landing/forest/):
index.ejs- Haiku gallery (3 cards hardcoded, future DB)
GCore (/landing/gcore/):
- 8 pages (index, about, business, contact, docs, legal, privacy, terms, vision)
- Status: WIP (placeholder)
9. /src/public/utils/ - Utility Modules π§°
Section titled β9. /src/public/utils/ - Utility Modules π§°β| File | Responsibility |
|---|---|
almaHaiku.js | AI Haiku Generation Engine (Anthropic Claude API) |
emotionAnalyzer.js | Sentiment Analysis + Safety Filter (input validation) |
almaHaiku.js:
- Manages 5 conversation turns
- Analyzes emotional depth
- Generates final haiku (5-7-5 syllables)
- Multi-language support (IT/EN/ES/FR/DE)
emotionAnalyzer.js:
- Detects sentiment (positive/negative/neutral)
- Blocks dangerous keywords (hate speech, violence)
- Score 0-100 (emotional depth)
10. /src/public/server.js - Entry Point π
Section titled β10. /src/public/server.js - Entry Point πβExpress server main entry. Responsibilities:
- Middleware setup (CORS, body-parser, static files)
- Brand detection (development query param, production hostname)
- Route mounting (landing, in1, library, auth, gcore, elements)
- Error handling (404, 500)
- Server startup (port 3000 local, process.env.PORT prod)
Startup:
# Developmentnpm run dev # nodemon src/public/server.js
# Productionnpm start # node src/public/server.jsπ§ TECH STACK
Section titled βπ§ TECH STACKβBackend
Section titled βBackendβ- Runtime: Node.js v20+
- Framework: Express.js 4.x
- Template Engine: EJS
- Database: PostgreSQL 17 (Neon.tech)
- ORM: pg (connection pool)
- AI: Anthropic Claude API (Sonnet 4.5)
- Email: Resend API
- Auth: JWT + sessions
Frontend
Section titled βFrontendβ- JavaScript: Vanilla ES6+ (no frameworks)
- CSS: Modular, mobile-first, BEM naming
- Icons: Lucide (minified)
- Animations: GSAP 3.x
- Markdown: marked.js
Database Extensions
Section titled βDatabase Extensionsβ- pgvector: Embeddings for RAG (1536 dimensions)
- pg_trgm: Trigram similarity search (future)
- Hosting: Render.com (production)
- CDN: Cloudflare Pages (static assets)
- Monitoring: Server logs (Winston) - future
- CI/CD: GitHub Actions (future)
π RECENT UPDATES
Section titled βπ RECENT UPDATESβLibrary System (18 Dec 2025) β¨
Section titled βLibrary System (18 Dec 2025) β¨β-
Created
/library/structure:public/for website contentprivate/for internal documents- i18n folders (it/en)
-
Implemented sync script:
Terminal window npm run sync-library- Auto-detects language from frontmatter
- Links translated documents via
translation_id - Updates database with content + metadata
-
Database integration:
- Added
languagecolumn tolibrary.documents - Added
translation_idfor linking versions - Created indexes for performance
- Added
-
Current content:
- Philosophy: Rhama, Rhama Paradigm (IT)
- Algorithms: IN-1 flow (IT)
- Private: Business strategies, finance docs
π USEFUL COMMANDS
Section titled βπ USEFUL COMMANDSβ# Developmentnpm run dev # Start server with nodemon (hot reload)
# Productionnpm start # Start Node.js server
# Databasenode scripts/setup-database.js # Initialize databasenode scripts/verify-db-v2.js # Verify connectionnode scripts/sync-library.js # Sync library/ to database
# Deploynode scripts/deploy-render.js # Deploy to Render.comnode scripts/cloudflare-deploy-v2.js # Deploy to Cloudflare Pages
# Testnode tests/test-alma-v2-flow.js # Test conversation flownode tests/test-emotion-analyzer.js # Test sentiment analysisπ CONTACTS
Section titled βπ CONTACTSβBlackTrails Team Email: francesco.pelosio@gmail.com Website: https://blacktrails.com
End of Document π²β¨