CannaTinker is a single Next.js application backed by a MariaDB database. Around it sit three AI providers, a hosted research library and a dozen shop websites. This chapter maps the pieces and follows one chat message through them.
The pieces
browser
│ HTTPS
▼
web server (TLS, security headers, request limits)
│
▼
Next.js application (App Router: pages + API routes)
├─ AI crew Google Gemini · Anthropic Claude · OpenAI
├─ assistant prompt built from plain Markdown files
├─ research library 154 papers in a hosted vector store + evidence cards
├─ shop scanner 12 shops, link analysis, budget kit, price history
├─ accounts sessions, invites, settings, plans, conversations
├─ Ganjopedia the encyclopedia: entries, the variety register, morphology dossiers, plates, Markdown files
├─ contact mailbox admin@ · support@ · legal@, read and answered in the admin area
├─ scheduler background jobs (price refresh, data retention)
└─ content articles, legal centre, grow guide, evidence cards
│
├─► MariaDB database
├─► AI provider APIs
├─► shop sites (Shopify / WooCommerce JSON) and daily ECB exchange rates
├─► web pages and PDFs a morphology dossier reads (through the same URL protection)
└─◄► e-mail provider (Resend): incoming mail by signed webhook, replies by API
Pages and API routes live in one codebase. Most pages render on the server. The interactive parts run in the browser: the chat, the side panels and the dashboard cards.
A message, step by step
When a signed-in grower sends a message, the browser opens a streaming request (Server-Sent Events). It shows each step as it happens.
- Check. The request goes through the common guard (same-site origin, session) and a per-user rate limit. Messages are capped at 4,000 characters.
- Context. The server loads the grower's profile, their active plan (or the latest plan card in the conversation), their three latest grow-log entries and the last 20 turns of the conversation.
- Intent. A rule-based router decides what kind of question this is:
- a product link → page analysis;
- a request for a plan → the planner;
- a kit with a budget → the budget kit builder;
- a gear search → the scanner;
- anything else → a normal answer.
- The question is saved before any AI is called, so it is never lost.
- The crew works, partly in parallel:
- the research library looks for matching evidence cards and passages;
- the web scout runs only for price and product questions;
- the scanner asks the shops;
- the planner builds a structured plan;
- the voice writes the reply, word by word.
- Events stream back: status lines, crew steps with timings, data cards (offers, a kit, a plan), the research note, and the text itself.
- The reply is saved even if the browser disconnects. It is marked complete, partial (interrupted or cut off) or error.
The browser and the server merge stream events with the same code. That way the saved message is exactly what the grower saw on screen.
Data
All persistent state lives in one MariaDB database:
- accounts and sessions;
- conversations and messages;
- plans and their progress;
- grow-log entries and reminders;
- watched products and their price history;
- invites and the waiting list;
- Ganjopedia: entries and their texts, the variety register and its tags, each entry's editorial state, morphology dossiers and plates;
- mail received at and sent from the site's addresses;
- page-builder versions and application settings.
Changes to the schema are versioned migrations that only add: new tables, new columns. Nothing is ever dropped or edited in place. Each migration carries a checksum, so an applied one cannot be changed silently.
The research papers themselves are not in the database. The PDFs and their embeddings sit in a hosted vector store, and the application keeps only the catalogue and an index of file ids.
Background work
A small scheduler inside the application wakes every five minutes. Each job takes a lease in the database, so it runs exactly once even while a new release is starting.
- Price refresh re-checks watched products, about every six hours each.
- Retention deletes data the site no longer needs, such as expired sessions, old sign-in records and e-mail left in the trash for 30 days. Details are in Accounts and privacy.
Content on disk
Some content is plain files that ship with the application:
- articles;
- the legal centre;
- the assistant's instructions;
- the grow guide;
- the evidence cards;
- these docs and the handbook;
- Ganjopedia's source data: the book's registries and texts and the variety register, imported into the database by a command after each release that changes them.
Every public Ganjopedia plant is also exported as a Markdown file into the repository, so the encyclopedia's content can be read and compared outside the site.
These files are reviewed like code: every change goes through a pull request with a changelog entry.
Known limits
- One instance. Per-minute rate limits and some caches live in process memory. Daily AI caps and job leases are already in the database, so scaling out would mostly mean moving the per-minute limits.
- One tent size. The 1 × 1 m tent is built into the scanner's scores, the product-variant picker and the budget kit.
Next: The AI crew.
