# Milestone 1.1 — Tenant Registration Learning Documentation

Welcome to the comprehensive learning guide for **Milestone 1, Step 1.1: Tenant Registration API**.

This folder contains step-by-step beginner-friendly notes explaining the architecture, code execution, data models, and database interactions of the current M1.1 implementation.

---

## Study Guide & Recommended Reading Order

Follow this chronological sequence to master the M1.1 implementation:

```text
01-big-picture.md ➔ 02-project-structure.md ➔ 03-config.md ➔ 04-database.md
        ↓
05-pydantic-model.md ➔ 06-repository.md ➔ 07-router.md ➔ 08-main.md
        ↓
09-testing.md ➔ 10-complete-request-flow.md ➔ 11-important-terms.md ➔ 12-m1-1-revision.md
```

---

### Module Guide

#### 1. [01-big-picture.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/01-big-picture.md)
- **What you should understand:** High-level request journey from client to database.
- **What you should NOT try to memorize:** Exact line numbers or function parameters.
- **Practical Question Answered:** *Why is tenant registration the very first step in building a multi-tenant chatbot?*

#### 2. [02-project-structure.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/02-project-structure.md)
- **What you should understand:** The role and responsibility of each directory and file in `backend/`.
- **What you should NOT try to memorize:** Python import paths.
- **Practical Question Answered:** *Why is database logic placed in `repositories/` instead of `routers/`?*

#### 3. [03-config.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/03-config.md)
- **What you should understand:** How `.env` variables are safely parsed into `settings` via Pydantic `BaseSettings`.
- **What you should NOT try to memorize:** `SettingsConfigDict` syntax options.
- **Practical Question Answered:** *Why should secrets like database connection strings never be hardcoded into Python source code?*

#### 4. [04-database.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/04-database.md)
- **What you should understand:** How PyMongo's `AsyncMongoClient` initializes connection pools with SSL `certifi` support.
- **What you should NOT try to memorize:** Low-level CPython socket connection internals.
- **Practical Question Answered:** *What is the difference between a Database, Collection, and Document in MongoDB?*

#### 5. [05-pydantic-model.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/05-pydantic-model.md)
- **What you should understand:** How `TenantCreate` validates & cleans input domains, and why `TenantResponse` isolates public fields.
- **What you should NOT try to memorize:** Pydantic regex helper options.
- **Practical Question Answered:** *Why do we separate request schemas from response schemas?*

#### 6. [06-repository.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/06-repository.md)
- **What you should understand:** How `insert_one` and `find_one` operate asynchronously on MongoDB documents.
- **What you should NOT try to memorize:** Internal BSON byte encoding details.
- **Practical Question Answered:** *What is `siteId`, how is it generated, and why do we use it alongside MongoDB's default `_id`?*

#### 7. [07-router.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/07-router.md)
- **What you should understand:** How `APIRouter` mounts `POST /api/v1/tenant/register`, enforces HTTP `201 Created`, and handles duplicate domain errors with `HTTPException`.
- **What you should NOT try to memorize:** Starlette framework internal routing table structures.
- **Practical Question Answered:** *How does FastAPI handle duplicate domain registration attempts?*

#### 8. [08-main.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/08-main.md)
- **What you should understand:** Application startup, router registration, lifespan context manager, and auto-generated Swagger UI (`/docs`).
- **What you should NOT try to memorize:** ASGI spec dictionary keys.
- **Practical Question Answered:** *How does FastAPI automatically generate interactive API documentation at `/docs`?*

#### 9. [09-testing.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/09-testing.md)
- **What you should understand:** How pytest fixtures (`conftest.py`) override `settings.database_name` to run in-memory API tests against `chatbot_test_db`.
- **What you should NOT try to memorize:** Pytest internal plugin hooks.
- **Practical Question Answered:** *How do automated tests verify backend endpoints without polluting development data?*

#### 10. [10-complete-request-flow.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/10-complete-request-flow.md)
- **What you should understand:** Step-by-step execution timeline of a single HTTP registration request.
- **What you should NOT try to memorize:** Timestamp formatting strings.
- **Practical Question Answered:** *What exact transformation happens to raw JSON from Swagger UI before it hits MongoDB Atlas?*

#### 11. [11-important-terms.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/11-important-terms.md)
- **What you should understand:** Fundamental glossary definitions for key backend, web, and database terminology.
- **What you should NOT try to memorize:** RFC specification numbers.
- **Practical Question Answered:** *What does non-blocking `async`/`await` execution mean in Python?*

#### 12. [12-m1-1-revision.md](file:///c:/Users/alokc/chatbot/backend/docs/learning/m1-1-tenant-registration/12-m1-1-revision.md)
- **What you should understand:** Quick revision summary, commands cheat sheet, troubleshooting solutions, and top 10 interview Q&As.
- **What you should NOT try to memorize:** Nothing — review this before moving to M1.2!
- **Practical Question Answered:** *How do I troubleshoot SSL connection issues when connecting to MongoDB Atlas?*

---

## Learning checkpoint

After studying the documentation, ensure you can comfortably answer these 10 questions:

1. **What happens when POST `/api/v1/tenant/register` is called?**
2. **Why do we have a router?**
3. **Why do we have a repository?**
4. **What does Pydantic validate?**
5. **What is the difference between database and collection?**
6. **What is `siteId` and why do we need it?**
7. **What does `AsyncMongoClient` do?**
8. **Why is `.env` used?**
9. **Where is the tenant actually stored?**
10. **How does the response travel back to the client?**
