Foundations
The three pillars of every software system
The Three Pillars
Every software system you will ever build β TradeCraft, the rental platform, a simple contact form β is made of three things:
Databases
Where truth lives
Interfaces
What users see
API Calls
The math in between
That's it. Everything else is implementation details.
Databases: The Source of Truth
A database is where your application's state lives. State is just a fancy word for "what's true right now."
- Who are the users? β
userstable - What trailers are available? β
listingstable - What was AAPL's price at 2:35pm on March 4th? β
candlestable - What evidence exists for this case? β
evidencetable
Without a database, your app has amnesia. Refresh the page, everything's gone.
- MySQL (port 3306) - Case portal, Moodle, general purpose
- PostgreSQL (port 5432) - Trailer rental
- TimescaleDB (port 5433) - TradeCraft (time-series data)
Interfaces: What Users See
An interface is the surface users interact with. It shows data from the database and accepts input that changes the database.
Two main approaches:
| Approach | How it works | You use it for |
|---|---|---|
| Server-rendered (PHP) | Server builds complete HTML, sends to browser | Case portal, Praxis, TradeCraft |
| Hybrid (Next.js) | Server renders initial HTML, React takes over for interactivity | Trailer rental |
Neither is "better." PHP is simpler for content-heavy sites. Next.js is better when you need complex interactivity (drag-and-drop, real-time updates, etc).
API Calls: The Math in Between
This is where "code" lives. An API call is just:
- Receive a request (user clicked something, timer fired, webhook arrived)
- Do some logic (validate, calculate, transform)
- Read or write to the database
- Return a response
User clicks "Place Order"
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β API CALL β
β β
β 1. Validate: Is the card valid? Is item in stock?β
β 2. Calculate: Total = price Γ quantity + tax β
β 3. Write DB: INSERT INTO orders (...) β
β 4. Call Stripe: Charge the card β
β 5. Write DB: UPDATE orders SET status='paid' β
β 6. Return: { success: true, orderId: 12345 } β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
Interface updates: "Order confirmed!"
The code inside that box? That's what Copilot writes. Your job is knowing what the box needs to do, not how to write it.
Putting It Together
Let's trace a real flow from your TradeCraft app:
User visits /backtest and clicks "Run Backtest"
β
βΌ
βββββββββββββββββ
β INTERFACE β
β (PHP page) β
βββββββββ¬ββββββββ
β POST /api/backtest.php
βΌ
βββββββββββββββββ
β API CALL β
β β
β β’ Parse strategy parameters
β β’ Query 2 years of candles from TimescaleDB
β β’ Simulate trades day by day
β β’ Calculate returns, win rate, drawdown
β β’ Return results as JSON
β β
βββββββββ¬ββββββββ
β
βββββββββββββ΄ββββββββββββ
β β
βΌ βΌ
βββββββββββββββββ βββββββββββββββββ
β DATABASE β β INTERFACE β
β TimescaleDB β β Shows chart, β
β (read only) β β stats, tradesβ
βββββββββββββββββ βββββββββββββββββ
The Mental Model
When you look at any feature request, break it down:
- What data do I need? β Database tables
- What does the user see? β Interface (page, component)
- What happens when they act? β API call (the logic)
Then tell Copilot what to build. The architecture is yours. The syntax is mine.
Deep dive into MySQL vs PostgreSQL vs TimescaleDB β when to use each, and why TradeCraft needs time-series.