To register domains directly with the registry you must be ICANN Accredited, this in itself is a long and expensive process - $2,500 application fee, $4000/year and another variable fee each quarter. You must also have $70K working capitol among numerous other requirements
You will also need a fully ICANN compliant system, pay ICANN Fees for each domain registered, and get setup with the registries - most of which will require a deposit.
Unless you have a considerable number of domains, a lot of time and some good developers, or are willing to pay even more to use someone elses platform it's much better to find a decent registrar and work with them, some will offer an API so you can manage domains programmatically too such as Tucows if you sign up as a Reseller.
Source: Just completed all the above.