Skip to main content
Reading progress: 0%

Lesson 4.2: Project Structure, Auth Basics, and Technical Decisions

Lesson Quick-Jump (10 Sections)

1. What Are We Learning?​

In this lesson, you will learn how to:

  • Design a clean, predictable project folder structure before generating files.
  • Understand authentication vs. authorization (if your app has users).
  • Document key technical decisions clearly so neither you nor future AI chats forget why choices were made.

2. Why Does It Matter?​

info

Without an agreed folder structure, an AI agent scatters files wherever it feels like in each prompt—putting helper functions inside UI pages, mixing database queries with button styles, and creating duplicate files.

Similarly, if you don't document why you chose SQLite instead of Postgres, or how user permissions work, a fresh AI session two weeks later may try to rewrite half your architecture without asking. Writing a short Architecture Doc prevents that chaos.


3. Simple Explanation for a Complete Beginner​

Project Structure (Organizing Your Kitchen)​

Just as a kitchen puts plates in one cabinet, spices on one rack, and knives in a block, a clean codebase separates responsibilities:

  • docs/ — Your PRD, development plan, design direction, and architecture doc.
  • src/ (or app/) — Your actual application code, grouped clearly (UI components/pages, API routes/controllers, data/database models, shared helpers).
  • tests/ — Automated checks verifying your app works.
  • Root files — Configuration, .gitignore, README, and package list.

Authentication vs. Authorization (The Concert Ticket Analogy)​

People constantly mix these two up, but they are distinct:

  • Authentication ("Who are you?"): Checking your ID or ticket at the front door. In apps: logging in with email/password or OAuth.
  • Authorization ("What are you allowed to touch?"): Checking whether your ticket grants access to general seating or backstage. In apps: verifying on the backend that User A can only edit or delete User A's bookmarks—never User B's!
danger

Mandatory Rule: Never rely on hiding a button in the frontend as your security check. An attacker can send requests directly to your backend API. Authorization MUST be enforced on the backend.

Documenting Technical Decisions (ADRs)​

An Architecture Decision Record (ADR) is a short note capturing:

  1. The question/problem
  2. Options considered
  3. What you decided and why
  4. Tradeoffs accepted

4. Practical Example​

Here is a clean architecture summary for a small Bookmark & Reading Vault:

Folder Layout:

bookmark-vault/
├── docs/
│ ├── prd.md
│ ├── design-direction.md
│ └── architecture.md
├── src/
│ ├── routes/ # Page views & API endpoints
│ ├── services/ # Business rules (save bookmark, search tags)
│ ├── db/ # Database schema & connection
│ └── components/ # Reusable UI pieces
├── tests/ # Unit & API integration tests
├── .env.example # Template of required environment variables (NO real secrets)
├── .gitignore
└── README.md

Sample Technical Decision Log Entry:

  • Decision: Use email + magic-link/password session cookies handled by a standard vetted auth library instead of writing custom password encryption from scratch.
  • Why: Writing custom cryptography/auth from scratch is high-risk for security bugs.
  • Authorization Rule: Every /api/bookmarks/* endpoint reads the logged-in userId from the verified session on the server and filters all database queries by WHERE user_id = current_user_id.

5. Step-by-Step Instructions​

  1. Copy templates/architecture-doc-template.md to docs/architecture.md in your project planning folder.
  2. Fill in your chosen Tech Stack from Lesson 4.1.
  3. Sketch your simple Data Model in plain language (e.g., "A Bookmark has: id, user_id, url, title, tag, created_at").
  4. Define Authentication & Authorization rules (or explicitly write "No auth in v1—single-user local app" if not needed).
  5. Propose a clear folder structure with the AI prompt below and record 2–3 key technical decisions in docs/architecture.md.

6. Ready-to-Use AI Prompt​

Context:
I have selected my MVP tech stack: [name your chosen stack].
Here are my MVP features and data needs:
[Summarize features and what data needs to be saved]
Auth needed? [Yes / No]

Objective:
Design a clean, minimal starter folder structure, a plain-English data model, and a security/authorization checklist tailored to this MVP—documented for `docs/architecture.md`.

Boundaries:
- Keep the folder structure shallow and easy for a beginner to navigate (no over-abstracted enterprise layers).
- Do NOT write full implementation code yet.
- Explicitly separate Authentication ("who is logged in") from Authorization ("who owns which record").

Expected Output:
1. Recommended folder tree with a 1-line explanation of what belongs in each folder.
2. Simple data tables/entities with fields and relationships.
3. API boundaries (list of core endpoints or actions) and where validation + auth checks must happen.
4. 2-3 Key Technical Decisions (with alternatives and why this choice fits an MVP).

7. What to Expect from the AI Agent​

Good ResponseWarning Sign
The AI creates a straightforward folder layout, clearly defines each data entity, and states explicitly that ownership checks happen on the server before returning or modifying data.The AI invents 15 nested folders (repositories/factories/interfaces/adapters) or suggests building your own custom JWT/password hashing helpers instead of using standard, audited auth mechanisms. Simplify the structure and insist on proven libraries.

8. What You Must Personally Verify​

  • Can you explain what every folder holds in one sentence? If not, simplify the folder tree.
  • Does your data model store only what the MVP needs? Remove unused fields (like profile_banner_url when there is no profile page).
  • Are authorization boundaries explicit? Every private data action must specify who is allowed to read/modify/delete it on the backend.

9. Common Mistakes​

  1. Skipping the data model before coding: Changing database columns randomly mid-build creates messy migrations and broken forms. Sketch entities clearly first.
  2. Rolling custom authentication: Never invent your own password hashing or session token algorithm. Use standard, well-maintained libraries or auth providers.
  3. Trusting user IDs sent from the browser: Never let the frontend send ?userId=123 to fetch someone else's data without verifying on the server that the logged-in session actually belongs to user 123.

10. Small Practical Exercise​

  1. Copy templates/architecture-doc-template.md and fill out the Overview and Tech Stack sections.
  2. Run the AI prompt above.
  3. Review the suggested folder layout and data model, remove anything unnecessary for your MVP, and save the completed docs/architecture.md.

Completed the exercise? Track your progress

Check off this lesson in PROGRESS-CHECKLIST.md once you have verified every step in Section 8.