{ "openapi": "3.0.0", "info": { "title": "AI Email Assistant API", "version": "1.0.0", "description": "API documentation for the AI Email Assistant application backend." }, "servers": [ { "url": "http://localhost:5000/api", "description": "Local Development Server" } ], "components": { "securitySchemes": { "bearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "JWT" } }, "schemas": { "ErrorResponse": { "type": "object", "properties": { "success": { "type": "boolean", "example": false }, "message": { "type": "string", "example": "Detailed error summary explanation" }, "error": { "type": "string", "example": "INTERNAL_SERVER_ERROR" } } } } }, "paths": { "/auth/signup": { "post": { "summary": "User registration", "description": "Registers a new user and returns JWT token.", "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["name", "email", "password"], "properties": { "name": { "type": "string", "example": "John Doe" }, "email": { "type": "string", "example": "john@example.com" }, "password": { "type": "string", "example": "Password123!" } } } } } }, "responses": { "201": { "description": "Successfully registered", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean", "example": true }, "message": { "type": "string", "example": "User registered successfully" }, "data": { "type": "object", "properties": { "user": { "type": "object", "properties": { "_id": { "type": "string", "example": "65b9e078a0cf9e3408cfbb1d" }, "name": { "type": "string", "example": "John Doe" }, "email": { "type": "string", "example": "john@example.com" } } }, "token": { "type": "string", "example": "eyJhbGciOiJIUzI1NiIs..." } } } } } } } }, "400": { "description": "Input validation error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } }, "409": { "description": "Email conflict", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } } } } }, "/auth/login": { "post": { "summary": "User login", "description": "Authenticates a user and returns JWT token.", "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["email", "password"], "properties": { "email": { "type": "string", "example": "john@example.com" }, "password": { "type": "string", "example": "Password123!" } } } } } }, "responses": { "200": { "description": "Successfully authenticated", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean", "example": true }, "message": { "type": "string", "example": "Login successful" }, "data": { "type": "object", "properties": { "user": { "type": "object", "properties": { "_id": { "type": "string", "example": "65b9e078a0cf9e3408cfbb1d" }, "name": { "type": "string", "example": "John Doe" }, "email": { "type": "string", "example": "john@example.com" } } }, "token": { "type": "string", "example": "eyJhbGciOiJIUzI1NiIs..." } } } } } } } }, "401": { "description": "Invalid credentials", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" } } } } } } }, "/emails": { "post": { "summary": "Save email", "description": "Saves an email draft to user history. Protected by JWT.", "security": [{ "bearerAuth": [] }], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["purpose", "tone", "length", "subject", "generatedEmail"], "properties": { "purpose": { "type": "string", "example": "Request feedback" }, "recipient": { "type": "string", "example": "Lead Lead" }, "tone": { "type": "string", "example": "professional" }, "length": { "type": "string", "example": "medium" }, "subject": { "type": "string", "example": "Project Milestones Review" }, "generatedEmail": { "type": "string", "example": "Dear Lead,\n\nI hope this email..." } } } } } }, "responses": { "201": { "description": "Email saved", "content": { "application/json": { "schema": { "type": "object" } } } }, "401": { "description": "Unauthenticated" } } }, "get": { "summary": "List emails", "description": "Retrieves paginated, sorted, and searched email logs. Protected by JWT.", "security": [{ "bearerAuth": [] }], "parameters": [ { "name": "favorite", "in": "query", "schema": { "type": "boolean" } }, { "name": "page", "in": "query", "schema": { "type": "integer" } }, { "name": "limit", "in": "query", "schema": { "type": "integer" } }, { "name": "sort", "in": "query", "schema": { "type": "string" } }, { "name": "search", "in": "query", "schema": { "type": "string" } } ], "responses": { "200": { "description": "Success retrieval", "content": { "application/json": { "schema": { "type": "object" } } } } } } }, "/emails/stats": { "get": { "summary": "User metrics", "description": "Returns calculated totals, favorites, most used tones. Protected by JWT.", "security": [{ "bearerAuth": [] }], "responses": { "200": { "description": "Stats computed", "content": { "application/json": { "schema": { "type": "object" } } } } } } }, "/ai/generate": { "post": { "summary": "AI generation", "description": "Calls OpenAI API completions to generate structured drafts. Protected by JWT.", "security": [{ "bearerAuth": [] }], "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["purpose"], "properties": { "purpose": { "type": "string", "example": "remind team of project deadline" }, "recipient": { "type": "string", "example": "Product Team" }, "tone": { "type": "string", "example": "urgent" }, "length": { "type": "string", "example": "short" } } } } } }, "responses": { "200": { "description": "Draft generated", "content": { "application/json": { "schema": { "type": "object", "properties": { "success": { "type": "boolean", "example": true }, "data": { "type": "object", "properties": { "subject": { "type": "string", "example": "Urgent Sync" }, "email": { "type": "string", "example": "Dear team..." }, "tone": { "type": "string", "example": "urgent" }, "tips": { "type": "array", "items": { "type": "string" } } } } } } } } }, "429": { "description": "AI Service Throttled" }, "503": { "description": "OpenAI offline or keys invalid" } } } } } }