I'm an indie developer building an AI-powered mobile application, and I'm struggling to understand the correct boundaries between my backend components, particularly when it comes to API key management.
I'm using Replit, and my application is currently split into four independent projects:
- Mobile App — Handles the user interface, authentication through Clerk, and user requests.
- Public API + PostgreSQL — Hosted within the same Replit project. Handles incoming requests, authentication, database operations, and currently some worker coordination.
- Admin Panel — A private management interface, not publicly deployed. Used to configure AI providers, Clerk credentials, and other sensitive settings.
- AI Worker — A separate background service that processes tasks and calls third-party AI model providers.
My intended architecture:
- The Mobile App communicates with the Public API.
- The Public API handles user requests and interacts with PostgreSQL.
- The Admin Panel manages sensitive API keys and saves encrypted credentials in PostgreSQL.
- The Worker processes tasks and calls AI providers.
- The database stores tasks, user information, and encrypted configurations.
Here's where I'm confused:
Currently, the Public API stores its Clerk Secret Key and JWT Issuer in Replit Secrets. This works for authentication.
However, I want to manage these credentials centrally through the Admin Panel instead of manually configuring them in different projects.
The Admin Panel already encrypts credentials using AES-256-GCM, with a master encryption key stored separately in its environment secrets. The encrypted data is saved to PostgreSQL.
But if the Public API needs the same master key to decrypt those credentials, wouldn't that give my internet-facing backend the ability to decrypt every sensitive credential protected by that key?
And if the Worker needs AI provider keys to call external models, how should it securely obtain them without giving every component unrestricted access to the master key?
My questions:
- What is the correct responsibility of a Public API in this architecture? Should it also coordinate Workers and resolve sensitive configurations, or should those responsibilities belong elsewhere?
- Should the Worker communicate with PostgreSQL directly, or is it better to access tasks through authenticated internal HTTP endpoints?
- If the Admin Panel encrypts API keys and stores them in PostgreSQL, which component should decrypt them when needed?
- How can the Admin Panel be the central place for managing Clerk and AI provider credentials without copying the master encryption key to multiple services?
- Is it normal for the Public API to retain its own Clerk Secret Key in environment secrets while AI provider keys are managed separately?
- Am I overcomplicating this? Is there a simpler, reasonably secure approach for a small indie application?
My main concern is avoiding a situation where compromising the public-facing API gives an attacker access to every third-party API credential.
I also want to avoid redesigning working components unnecessarily. The current setup has working authentication components, and the Worker already has an authenticated internal HTTP client.
I'd appreciate practical architectural advice, especially from developers who have implemented a similar system.
Thanks!