SQLAlchemy models + custom repository classes abstract DB
Factory
create_app() function in __init__.py
Blueprint
Modular route organization (Flask-specific)
DTO
Marshmallow/Pydantic schemas for serialization
MERN vs Flask: Architectural Comparison
Aspect
MERN
Flask
Presentation
React (separate SPA)
Jinja2 templates or separate SPA
API Layer
Express routes + controllers
Flask Blueprints + route functions
Business Logic
services/ directory
services/ directory
Data Access
Mongoose ODM
SQLAlchemy ORM
Database
MongoDB (document)
PostgreSQL/MySQL (relational)
Validation
Joi, express-validator
Marshmallow, Pydantic
Auth Middleware
Express middleware
Flask decorators
Common Anti-Patterns to Avoid
Fat Controllers/Routes
// ❌ BAD: Business logic in controllerrouter.post('/order',async (req, res) => {// 50 lines of business logic here// Validation, calculations, DB calls...});// ✅ GOOD: Thin controller, logic in servicerouter.post('/order',async (req, res) => {const order =await orderService.create(req.body); res.json(order);});
Anemic Domain Model
# ❌ BAD: Model is just data, no behaviorclass User(db.Model): email = db.Column(db.String)# All logic lives elsewhere# ✅ GOOD: Model has domain behaviorclass User(db.Model): email = db.Column(db.String)def can_purchase(self, item):returnself.balance >= item.pricedef apply_discount(self, code):# Domain logic here
Architectural Decision: When to Use What
If You Need…
Consider
Flexible schema, rapid iteration
MERN (MongoDB)
Complex queries, transactions
Flask + PostgreSQL
Real-time features
MERN + Socket.io
Data science integration
Flask + Python ecosystem
Large existing React codebase
MERN
Team knows Python well
Flask
Horizontal scaling priority
MERN (MongoDB sharding)
Strong data integrity
Flask + PostgreSQL
System Decomposition
The Art of Decomposition
“The key to controlling complexity is a good domain model.”
— Eric Evans
Goal: Break systems into pieces that are:
Cohesive - Related things together
Loosely Coupled - Minimal dependencies
Independently Deployable - Change without coordination
Key Insight: Same concept (Customer) has different meanings in different contexts
Context Mapping
Pattern
Description
Example
Shared Kernel
Teams share a subset of model
Common types library
Customer-Supplier
Upstream serves downstream
Orders → Shipping
Conformist
Downstream adopts upstream model
Using external API as-is
Anti-Corruption Layer
Translation layer
Legacy system integration
Open Host Service
Published interface
Public API
Published Language
Shared standard
Industry standard format
Service Boundaries Checklist
When defining service boundaries, ask:
The Two-Pizza Rule
“If you can’t feed a team with two pizzas, it’s too big.”
— Jeff Bezos
Applied to Services: - If one team can’t understand the whole service, it’s too big - If there’s nothing meaningful a service can do alone, it’s too small - Aim for services that map to teams and business capabilities
Quality Attributes
Quality Attribute Scenarios
┌─────────────────────────────────────────────────────────────────┐
│ Quality Attribute Scenario │
├──────────────┬──────────────────────────────────────────────────┤
│ Source │ Who/what causes the stimulus │
│ Stimulus │ The event or condition │
│ Environment │ System state when stimulus occurs │
│ Artifact │ What part of system is affected │
│ Response │ How the system responds │
│ Measure │ How we evaluate the response │
└──────────────┴──────────────────────────────────────────────────┘
# ADR 001: Use MongoDB for Primary Data Store## StatusAccepted## ContextWe need a database for our MERN application that supports:- Flexible schema for evolving data models- Horizontal scaling for growing data- JSON-native storage for API compatibility## DecisionWe will use MongoDB as our primary data store.## Consequences### Positive- Schema flexibility accelerates development- Native JSON support simplifies API layer- Horizontal scaling with sharding### Negative- No ACID transactions across documents (until MongoDB 4.0+)- Complex queries may be less efficient than SQL- Team needs MongoDB expertise
Project Scoping
What Makes a Good Project?
Good Scope
Clear problem statement
Well-defined user stories
Achievable in semester
Demonstrates patterns
Meaningful AI integration
Clear success criteria
Poor Scope
“We’ll build the next Facebook”
Vague requirements
Feature creep built-in
No architectural depth
AI as afterthought
No measurable outcome
Scoping Techniques
1. MoSCoW Prioritization
MUST have - Core functionality (MVP)
SHOULD have - Important but not critical
COULD have - Nice to have if time permits
WON'T have - Out of scope (explicitly)
Team estimates relative complexity, discusses outliers
Risk Assessment
Identify and mitigate project risks:
Risk
Likelihood
Impact
Mitigation
Team member drops
Medium
High
Document knowledge, pair program
Technology unknown
High
Medium
Spike early, have backup
Scope creep
High
High
Fixed scope, say no
Integration issues
Medium
High
Early integration, mocks
AI API costs
Medium
Medium
Budget limits, caching
Project Proposal
Proposal Requirements
Presentations in class: January 30, 2026
Required Sections
Problem Statement - What problem are you solving?
Target Users - Who benefits from this?
Core Features - What does the MVP include?
Architecture Overview - High-level system design
Technology Stack - What tools and frameworks?
AI Integration - How will AI/agents be used?
Team & Roles - Who is responsible for what?
Risks & Mitigations - What could go wrong?
Example Proposal Outline
# Project: Smart Study Buddy## Problem StatementStudents struggle to effectively review course materialand identify knowledge gaps for exams.## Target Users- University students preparing for exams- Study groups collaborating on material## Core Features (MVP)1. Upload course materials (PDFs, notes)2. AI-generated practice questions3. Spaced repetition flashcards4. Progress tracking dashboard5. Study session scheduling## Architecture[Diagram showing frontend, API, database, AI service]## Tech Stack- Frontend: React + TypeScript- Backend: Node.js + Express- Database: MongoDB + PostgreSQL- AI: OpenAI API + LangChain- Infrastructure: Docker + GitHub Actions## AI Integration- Question generation from uploaded content- Adaptive difficulty based on performance- Natural language Q&A for clarification## Team- Alice: Frontend lead- Bob: Backend lead- Carol: AI/ML integration- Dave: DevOps and infrastructure## Risks- AI response quality → Human review, prompt engineering- Cost of API calls → Caching, rate limiting, budgeting
Presentation Format (5-7 minutes)
Problem & Users (1 min)
What problem? Who cares?
Solution Overview (2 min)
Key features, demo mockup
Architecture (2 min)
System diagram, tech choices, why
AI Integration (1 min)
Specific AI capabilities
Team & Timeline (1 min)
Roles, major milestones
Evaluation Criteria
Criteria
Weight
Problem clarity and relevance
20%
Technical feasibility
20%
Architectural thinking
20%
AI integration meaningfulness
15%
Presentation quality
15%
Team organization
10%
Activity: Project Ideation
Brainstorming Session (20 minutes)
In your teams:
Individual (5 min): Each person writes 3 project ideas
Share (5 min): Present ideas to team, no judgment
Vote (3 min): Each person gets 3 votes
Discuss (7 min): Top 2-3 ideas - feasibility, interest
Idea Evaluation Matrix
Criteria
Idea 1
Idea 2
Idea 3
Problem clarity
1-5
1-5
1-5
Technical feasibility
1-5
1-5
1-5
Team interest
1-5
1-5
1-5
AI integration fit
1-5
1-5
1-5
Uniqueness
1-5
1-5
1-5
Total
Report Out (15 minutes)
Each team shares:
Your top project idea
Why you chose it
Biggest risk or concern
One question for the class
Summary
Key Takeaways
Patterns provide proven solutions - know when to apply them
Decomposition is about finding the right boundaries
Quality attributes drive architectural decisions
Trade-offs are inevitable - document and justify them