Chapter 7

AI and System Design

One of the biggest shifts AI enables is that developers can design complex systems much faster than before. Instead of coding first and regretting later, you can use AI to explore, compare, and validate architectures before writing a single line.


Why Start with System Design?

The most expensive mistakes in software don't happen in functions — they happen in architecture. Choosing the wrong database, the wrong component structure, or the wrong API pattern creates problems that compound over months, eventually requiring painful rewrites.

Common Beginner Pattern

  • Start coding immediately
  • No overall plan
  • Architecture emerges accidentally
  • Discover problems late

Result: technical debt, painful refactors, or full rewrites.

Senior Developer Pattern

  • Design architecture first
  • Identify risks upfront
  • Compare alternatives
  • Then implement modularly

Result: solid foundation that evolves cleanly over time.

AI makes the "design first" approach dramatically more accessible. What used to require years of experience — evaluating architectures, comparing trade-offs, identifying risks — can now be explored conversationally in minutes.


AI as Architect

The first and most powerful use of AI in system design is asking it to propose a complete architecture for your project. Give it your requirements and let it design the system before you write any code.

Design a system architecture for a family schedule planner.

Requirements:
- React frontend (TypeScript)
- Node.js / Express backend
- MySQL database
- REST API
- Should support multiple family members
- Needs to scale to ~1000 concurrent users eventually

Show:
1. High-level system diagram (frontend → API → database)
2. React component hierarchy
3. API endpoint structure
4. Database tables and relationships
5. Where state lives (client vs. server)

Don't write implementation code — just the blueprint.

This prompt produces a comprehensive architectural overview in seconds. You get a map of the entire system — its layers, connections, and data flow — that you can evaluate, critique, and refine before investing time in code.


Visualizing Architecture

AI-generated architecture descriptions become much easier to evaluate when visualized. Here's the kind of layered view you should ask for — and what a typical three-tier architecture looks like:

Frontend Layer
App Shell
Header
FilterBar
WeekView
DayColumn
ActivityCard
AddModal
→ REST API
Backend Layer
Express Router
Auth Middleware
Validation
Controllers
→ SQL Queries
Data Layer
families
members
activities

You can ask AI to generate diagrams in various formats — ASCII art (works in any text context), Mermaid syntax (renders as actual diagrams in many tools), or structured lists. The format matters less than having a visual map to reason about.


Always Ask for Alternatives

Never accept the first architecture AI proposes. The most valuable design conversations happen when you compare multiple approaches. This is where AI truly outperforms solo thinking — it can generate and compare alternatives in seconds.

Give me three different architecture approaches for this project.

For each approach:
- Describe the architecture
- List pros and cons
- Identify the main risk
- Rate complexity (simple / moderate / complex)
- Say when you'd choose this approach

Then recommend which one I should use for an MVP,
and which one I should migrate to later if the
project grows.

This prompt forces AI to think comparatively — not just generate one plausible answer, but evaluate trade-offs across multiple options. The "recommend for MVP vs. later" question is especially valuable because it separates what you need now from what you might need eventually, preventing over-engineering.

Pro Tip: The "When Would This Fail?" Question

After AI proposes an architecture, ask: "Under what conditions would this architecture fail or become a bottleneck?" This stress-tests the design and reveals hidden assumptions. AI might reveal that the approach works for 100 users but breaks at 10,000, or that it's fine for reads but terrible for write-heavy workloads.


Monolith vs. Microservices

One of the most common architectural decisions — and one where beginners consistently over-engineer — is choosing between a monolith and microservices. AI can help you think through this clearly.

For this project, should I use a monolith or microservices?

Context:
- Solo developer (for now)
- Expected users: ~500 initially
- Team might grow to 2-3 developers in 6 months
- Budget: low (personal project)

Be honest about the trade-offs.
When is microservices overkill for a project like this?
Factor Monolith Microservices
Complexity Simple High
Solo developer Ideal Overhead
Deployment One unit Many services
Scaling team Gets harder at ~10+ devs Independent teams
Performance scaling Scale entire app Scale per service
MVP speed Fastest Slower setup

For most projects by solo developers or small teams — especially at the MVP stage — a well-structured monolith is the right choice. You can always extract services later. AI can help you identify the exact point where that migration becomes worthwhile.


Database Design

AI is remarkably effective at database schema design. Give it your entities and relationships, and it will produce normalized tables, indexes, and constraints that would take significantly longer to design manually.

Design a MySQL database schema for this family planner.

Entities:
- Family (name, created date)
- FamilyMember (name, color, avatar, belongs to family)
- Activity (name, day, start time, end time, belongs to member)

Requirements:
- Proper foreign keys and relationships
- Indexed for common queries (activities by day, by member)
- Soft delete support (deleted_at)
- Created/updated timestamps on all tables

Show CREATE TABLE statements with comments explaining
design decisions.

AI will produce production-ready SQL with proper constraints, indexes on commonly queried columns, and timestamp patterns. Review the output for your specific needs — AI sometimes over-indexes or under-normalizes depending on the workload assumptions.

Pro Tip: Ask About Query Patterns

After generating a schema, ask: "What are the 5 most common queries this app will need, and how does this schema perform for each?" This validates that the schema serves actual usage patterns, not just a theoretically clean data model. If a common query requires complex joins across 4 tables, the schema might need restructuring.


API Design

A well-designed API is the contract between your frontend and backend. AI can generate consistent, RESTful endpoints that follow naming conventions and cover all CRUD operations.

Design REST API endpoints for this family planner.

Requirements:
- Follow REST conventions
- Consistent naming
- Proper HTTP methods
- Include authentication endpoints
- Pagination for list endpoints
- Error response format

Show each endpoint with: method, path, request body,
and response format.

A typical result might include:

GET /api/activities List activities (with filters)
GET /api/activities/:id Get single activity
POST /api/activities Create new activity
PUT /api/activities/:id Update activity
DELETE /api/activities/:id Delete activity
GET /api/members List family members
POST /api/auth/login Authenticate user
POST /api/auth/register Register new user

Scalability and Security Review

Two dimensions that beginners consistently neglect — and that AI can surface proactively — are scalability bottlenecks and security vulnerabilities.

Analyze this architecture for scalability bottlenecks.

What will break first as users grow from 100 → 1,000 → 10,000?
What's the cheapest fix at each stage?
Review this system design for security vulnerabilities.

Consider:
- Authentication / authorization gaps
- Data exposure risks
- Input validation
- SQL injection vectors
- CORS configuration
- API rate limiting

These reviews are incredibly valuable when done before implementation. Fixing an architectural security flaw in a design document takes minutes. Fixing it in a running application takes days.


The Architecture Review Loop

System design with AI follows a specific iteration pattern that's different from the code-level iteration in earlier chapters. Here, you're iterating on decisions, not on implementation.

1
Describe your idea — What are you building? For whom? What are the constraints?
2
AI designs the system — Get a complete architecture proposal with diagrams, schemas, and API design.
3
You review critically — Does this match your needs? Is it too complex? Too simple? Are there blind spots?
4
AI stress-tests — Ask for failure modes, scaling limits, and security vulnerabilities.
5
AI improves — Address the issues found. Iterate until the design feels solid.

Most projects need two or three passes through this loop. The first pass creates the skeleton, the second pass identifies and fixes weaknesses, and the third pass simplifies anything that was over-designed. Only then do you start coding.


Common Mistakes

System Design Anti-Patterns

🧪 Practical Exercise

Choose a project — your own or one of these: a team task manager, a recipe sharing platform, or a personal finance tracker. Run through the full architecture review loop:

The goal isn't to build the project — it's to practice the design conversation. By the end, you should have a solid blueprint you'd feel confident implementing.


Key Takeaways

Previous Chapter Refactoring and Code Quality
Next Chapter AI + Git Workflow