openapi: 3.0.3 info: title: AI Assistant API version: 0.1.0 description: "Phase 2 API specification (baseline + protected endpoints documentation)." servers: - url: http://localhost:3000 paths: /health: get: responses: '200': description: Health status content: application/json: schema: type: object properties: status: type: string example: "ok" phase: type: string example: "phase-2" '404': description: Not found content: application/json: schema: $ref: '#/components/schemas/Error' example: error: not_found message: Endpoint not found '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' example: error: internal_error message: Internal server error /api/info: get: responses: '200': description: Basic API info content: application/json: schema: type: object properties: name: type: string example: "AI Assistant" phase: type: string example: "phase-2" status: type: string example: "backend baseline active" '404': description: Not found content: application/json: schema: $ref: '#/components/schemas/Error' example: error: not_found message: Endpoint not found '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' example: error: internal_error message: Internal server error /api/version: get: summary: Get API version description: Return static API version and current phase. responses: '200': description: API version info content: application/json: schema: type: object required: - version - phase properties: version: type: string example: "0.1.0" phase: type: string example: "phase-2" '404': description: Not found content: application/json: schema: $ref: '#/components/schemas/Error' example: error: not_found message: Endpoint not found '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' example: error: internal_error message: Internal server error /api/user/profile: get: summary: Get user profile description: Retrieve the authenticated user's profile information security: - bearerAuth: [read:profile] responses: '200': description: User profile information content: application/json: schema: $ref: '#/components/schemas/UserProfile' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' put: summary: Update user profile description: Update the authenticated user's profile information security: - bearerAuth: [write:profile] requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/UserProfileUpdate' responses: '200': description: Profile updated successfully content: application/json: schema: $ref: '#/components/schemas/UserProfile' '400': description: Bad request content: application/json: schema: $ref: '#/components/schemas/Error' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' /api/user/preferences: get: summary: Get user preferences description: Retrieve the authenticated user's preferences (language, theme, etc.) security: - bearerAuth: [read:preferences] responses: '200': description: User preferences content: application/json: schema: $ref: '#/components/schemas/UserPreferences' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' put: summary: Update user preferences description: Update the authenticated user's preferences security: - bearerAuth: [write:preferences] requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/UserPreferencesUpdate' responses: '200': description: Preferences updated successfully content: application/json: schema: $ref: '#/components/schemas/UserPreferences' '400': description: Bad request content: application/json: schema: $ref: '#/components/schemas/Error' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' /api/conversations: get: summary: List user conversations description: Retrieve all conversations for the authenticated user security: - bearerAuth: [read:conversations] responses: '200': description: List of conversations content: application/json: schema: type: array items: $ref: '#/components/schemas/Conversation' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' post: summary: Create a new conversation description: Create a new conversation for the authenticated user security: - bearerAuth: [write:conversations] requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/ConversationCreate' responses: '201': description: Conversation created successfully content: application/json: schema: $ref: '#/components/schemas/Conversation' '400': description: Bad request content: application/json: schema: $ref: '#/components/schemas/Error' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' /api/conversations/{id}: get: summary: Get a specific conversation description: Retrieve a specific conversation for the authenticated user security: - bearerAuth: [read:conversations] parameters: - name: id in: path required: true description: Conversation ID schema: type: string responses: '200': description: Conversation details content: application/json: schema: $ref: '#/components/schemas/Conversation' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '404': description: Conversation not found content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' delete: summary: Delete a conversation description: Delete a specific conversation for the authenticated user security: - bearerAuth: [write:conversations] parameters: - name: id in: path required: true description: Conversation ID schema: type: string responses: '204': description: Conversation deleted successfully '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '404': description: Conversation not found content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' /api/conversations/{id}/messages: get: summary: Get messages in a conversation description: Retrieve all messages in a specific conversation security: - bearerAuth: [read:messages] parameters: - name: id in: path required: true description: Conversation ID schema: type: string responses: '200': description: List of messages content: application/json: schema: type: array items: $ref: '#/components/schemas/Message' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '404': description: Conversation not found content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' post: summary: Send a message in a conversation description: Send a new message in a specific conversation security: - bearerAuth: [write:messages] parameters: - name: id in: path required: true description: Conversation ID schema: type: string requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/MessageCreate' responses: '201': description: Message sent successfully content: application/json: schema: $ref: '#/components/schemas/Message' '400': description: Bad request content: application/json: schema: $ref: '#/components/schemas/Error' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '404': description: Conversation not found content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' /api/admin/users: get: summary: List all users (admin) description: Retrieve a list of all users (admin access required) security: - bearerAuth: [admin:users] responses: '200': description: List of users content: application/json: schema: type: array items: $ref: '#/components/schemas/UserAdmin' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' /api/admin/stats: get: summary: Get system statistics (admin) description: Retrieve system statistics (admin access required) security: - bearerAuth: [admin:read] responses: '200': description: System statistics content: application/json: schema: $ref: '#/components/schemas/AdminStats' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' /api/admin/users/{id}/status: put: summary: Update user status (admin) description: Update a user's status (activate/deactivate) - admin access required security: - bearerAuth: [admin:users] parameters: - name: id in: path required: true description: User ID schema: type: string requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/UserStatusUpdate' responses: '200': description: User status updated successfully content: application/json: schema: $ref: '#/components/schemas/UserAdmin' '400': description: Bad request content: application/json: schema: $ref: '#/components/schemas/Error' '401': description: Unauthorized content: application/json: schema: $ref: '#/components/schemas/Error' '403': description: Forbidden content: application/json: schema: $ref: '#/components/schemas/Error' '404': description: User not found content: application/json: schema: $ref: '#/components/schemas/Error' '500': description: Internal server error content: application/json: schema: $ref: '#/components/schemas/Error' components: securitySchemes: bearerAuth: type: http scheme: bearer bearerFormat: JWT description: | JWT token-based authentication (conceptual - not yet implemented) Available scopes: - read:profile - Read user profile information - write:profile - Update user profile information - read:preferences - Read user preferences - write:preferences - Update user preferences - read:conversations - Read user conversations - write:conversations - Create and delete conversations - read:messages - Read conversation messages - write:messages - Send messages in conversations - admin:users - Manage users (admin only) - admin:read - Read system statistics (admin only) The token payload will contain: - token_id: Unique token identifier - user_id: User identifier - issued_at: Token issue timestamp - expires_at: Token expiration timestamp - scopes: List of granted scopes - issuer: Token issuer - version: Token format version schemas: Error: type: object properties: error: type: string example: "internal_error" message: type: string example: "Internal server error" required: - error - message UserProfile: type: object properties: id: type: string example: "user-123" email: type: string example: "user@example.com" full_name: type: string example: "John Doe" roles: type: array items: type: string example: ["user"] created_at: type: string format: date-time updated_at: type: string format: date-time required: - id - email - full_name UserProfileUpdate: type: object properties: full_name: type: string example: "John Doe" email: type: string example: "user@example.com" UserPreferences: type: object properties: language: type: string example: "en" theme: type: string example: "dark" notifications_enabled: type: boolean example: true required: - language - theme UserPreferencesUpdate: type: object properties: language: type: string example: "en" theme: type: string example: "dark" notifications_enabled: type: boolean example: true Conversation: type: object properties: id: type: string example: "conv-123" title: type: string example: "My conversation" created_at: type: string format: date-time updated_at: type: string format: date-time message_count: type: integer example: 5 required: - id - title - created_at ConversationCreate: type: object properties: title: type: string example: "New conversation" required: - title Message: type: object properties: id: type: string example: "msg-123" conversation_id: type: string example: "conv-123" content: type: string example: "Hello, how can I help you?" role: type: string enum: [user, assistant] example: "user" created_at: type: string format: date-time required: - id - conversation_id - content - role - created_at MessageCreate: type: object properties: content: type: string example: "Hello, I need help with..." role: type: string enum: [user, assistant] example: "user" required: - content - role UserAdmin: type: object properties: id: type: string example: "user-123" email: type: string example: "user@example.com" full_name: type: string example: "John Doe" roles: type: array items: type: string example: ["user"] status: type: string enum: [active, inactive, suspended] example: "active" created_at: type: string format: date-time updated_at: type: string format: date-time required: - id - email - full_name - status UserStatusUpdate: type: object properties: status: type: string enum: [active, inactive, suspended] example: "active" required: - status AdminStats: type: object properties: total_users: type: integer example: 100 active_users: type: integer example: 75 total_conversations: type: integer example: 500 total_messages: type: integer example: 5000 required: - total_users - active_users - total_conversations - total_messages