Skip to content

Project Structure

πŸ—οΈ BLACKTRAILS PLATFORM - PROJECT STRUCTURE

Section titled β€œπŸ—οΈ BLACKTRAILS PLATFORM - PROJECT STRUCTURE”

Last Updated: 18 Dicembre 2025 Version: 2.0 Author: BlackTrails Team


  1. Overview
  2. Complete Structure
  3. Folder Descriptions
  4. Library System
  5. Tech Stack

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


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)

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


Technical project documentation:

  • database.md - Complete database architecture
  • structure.md - This file (directory map)
  • in1_algoritmo.md - IN-1 algorithm detailed specification
  • API docs (future)

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
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.md
Terminal window
npm run sync-library
  1. Scans library/public/ and library/private/
  2. Extracts frontmatter metadata (title, category, tags, language)
  3. Generates slugs from filenames
  4. Calculates MD5 hash for change detection
  5. Inserts/updates library.documents table
  6. 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

Node.js scripts for maintenance and deployment:

ScriptPurpose
setup-database.jsInitialize database from schema.sql
check-*.jsHealth checks and schema verification
verify-db-v2.jsConnection test and integrity check
sync-library.js✨ Sync library/ folder to database
reset-prod-db.js⚠️ Reset production (DANGER)
alter-prod-language.jsSchema migration (add language column)
cloudflare-deploy*.jsDeploy to Cloudflare Pages
deploy-render.jsDeploy to Render.com

Execution: node scripts/<script-name>.js


Platform core modules (shared across brands):

FileResponsibility
auth.jsJWT generation, session management, user authentication
db.jsPostgreSQL connection pool (pg), query helpers
email.jsEmail sending via Resend API
middleware.jsExpress middleware (CORS, auth check, error handler)
permissions.jsACL (Access Control List), role-based permissions

Imported by: server.js, routes


Served via Express: app.use('/static', express.static('src/public/public')) Public URL: https://domain.com/static/css/in1/style.css

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

Vanilla JavaScript (NO frameworks). Modular with IIFE pattern.

IN-1 Modules (/js/in1/):

FileResponsibility
tree.jsCanvas animation (fractal tree, GSAP growth)
chat-ui.jsChat UI logic (loader morphing, typewriter effect)
haiku.jsAI conversation (API calls, state management)
home.jsLanding page logic (form, ROOT DETECTED, nav)

Libraries:

  • lucide.min.js - Icon library
  • marked.min.js - Markdown parser

7. /src/public/routes/ - Express Routes πŸ›€οΈ

Section titled β€œ7. /src/public/routes/ - Express Routes πŸ›€οΈβ€

Modular routing for brand detection:

FileRoute PathBrandPurpose
landing.js/BlackTrails, IN-1, ForestLanding pages (switch on req.brand)
in1.js/api/in1/*IN-1API endpoints (chat, haiku generation)
library.js/api/library/*Library✨ Document search and RAG queries
auth.js/auth/*-Login, signup, logout (future)
gcore.js/gcore/*GCoreGCore pages (WIP)
elements.js/elements/*ElementsComponent library (placeholder)

Brand Detection Logic (server.js):

// Development: ?brand=in1|forest|blacktrails
if (process.env.NODE_ENV === 'development') {
req.brand = req.query.brand || 'blacktrails';
}
// Production: domain-based
if (req.hostname === 'in-1.it') req.brand = 'in1';
else if (req.hostname === 'forest.in-1.it') req.brand = 'forest';
else req.brand = 'blacktrails';

Server-Side Rendering with EJS:

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)

FileResponsibility
almaHaiku.jsAI Haiku Generation Engine (Anthropic Claude API)
emotionAnalyzer.jsSentiment 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)

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:

Terminal window
# Development
npm run dev # nodemon src/public/server.js
# Production
npm start # node src/public/server.js

  • 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
  • JavaScript: Vanilla ES6+ (no frameworks)
  • CSS: Modular, mobile-first, BEM naming
  • Icons: Lucide (minified)
  • Animations: GSAP 3.x
  • Markdown: marked.js
  • 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)

  1. Created /library/ structure:

    • public/ for website content
    • private/ for internal documents
    • i18n folders (it/en)
  2. 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
  3. Database integration:

    • Added language column to library.documents
    • Added translation_id for linking versions
    • Created indexes for performance
  4. Current content:

    • Philosophy: Rhama, Rhama Paradigm (IT)
    • Algorithms: IN-1 flow (IT)
    • Private: Business strategies, finance docs

Terminal window
# Development
npm run dev # Start server with nodemon (hot reload)
# Production
npm start # Start Node.js server
# Database
node scripts/setup-database.js # Initialize database
node scripts/verify-db-v2.js # Verify connection
node scripts/sync-library.js # Sync library/ to database
# Deploy
node scripts/deploy-render.js # Deploy to Render.com
node scripts/cloudflare-deploy-v2.js # Deploy to Cloudflare Pages
# Test
node tests/test-alma-v2-flow.js # Test conversation flow
node tests/test-emotion-analyzer.js # Test sentiment analysis

BlackTrails Team Email: francesco.pelosio@gmail.com Website: https://blacktrails.com


End of Document 🌲✨